本文整理匯總了Java中edu.stanford.nlp.util.CoreMap.set方法的典型用法代碼示例。如果您正苦於以下問題:Java CoreMap.set方法的具體用法?Java CoreMap.set怎麽用?Java CoreMap.set使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類edu.stanford.nlp.util.CoreMap
的用法示例。
在下文中一共展示了CoreMap.set方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: annotate
import edu.stanford.nlp.util.CoreMap; //導入方法依賴的package包/類
@Override
public void annotate(Annotation annotation) {
if (annotation.get(CoreAnnotations.SentencesAnnotation.class) != null) {
// open index
try {
index.open();
} catch (IOException e) {
throw new RuntimeException("unable to open IMWEIndex index");
}
// create the detector
IMWEDetector detector = getDetector(index, detectorName);
// capture jMWE per sentence
for (CoreMap sentence : annotation.get(CoreAnnotations.SentencesAnnotation.class)) {
List<IMWE<IToken>> mwes = getjMWEInSentence(sentence, index, detector, verbose);
sentence.set(JMWEAnnotation.class, mwes);
}
// close index
index.close();
} else {
throw new RuntimeException("the sentence annotation was null");
}
}
示例2: concreteSectionToCoreMapList
import edu.stanford.nlp.util.CoreMap; //導入方法依賴的package包/類
public static List<CoreMap> concreteSectionToCoreMapList(final Section sect, final String commText) {
List<CoreMap> toRet = new ArrayList<>();
List<Sentence> sentList = sect.getSentenceList();
int tokOffset = 0;
for (int i = 0; i < sentList.size(); i++) {
Sentence st = sentList.get(i);
CoreMap cm = new ArrayCoreMap();
cm.set(SentenceIndexAnnotation.class, i);
final TextSpan sts = st.getTextSpan();
final int sentCharStart = sts.getStart();
final int sentCharEnd = sts.getEnding();
LOGGER.debug("Setting stanford sentence BeginChar = {}", sentCharStart);
cm.set(CharacterOffsetBeginAnnotation.class, sentCharStart);
LOGGER.debug("Setting stanford sentence EndChar = {}", sentCharEnd);
cm.set(CharacterOffsetEndAnnotation.class, sentCharEnd);
String sectText = commText.substring(sentCharStart, sentCharEnd);
LOGGER.debug("Setting text: {}", sectText);
cm.set(TextAnnotation.class, sectText);
Tokenization tkz = st.getTokenization();
List<CoreLabel> clList = tokenizationToCoreLabelList(tkz, i, sentCharStart);
final int maxIdx = clList.size();
LOGGER.debug("Setting stanford sentence token begin: {}", tokOffset);
cm.set(TokenBeginAnnotation.class, tokOffset);
final int tokEnd = tokOffset + maxIdx;
LOGGER.debug("Setting stanford sentence token end: {}", tokEnd);
cm.set(TokenEndAnnotation.class, tokEnd);
cm.set(TokensAnnotation.class, clList);
tokOffset = tokEnd;
toRet.add(cm);
}
return toRet;
}
示例3: fixNullDependencyGraphs
import edu.stanford.nlp.util.CoreMap; //導入方法依賴的package包/類
/**
* sentences with no dependency structure have null values for the various dependency annotations. make sure these are empty dependencies instead to prevent
* coref-resolution from dying
*/
private static void fixNullDependencyGraphs(Annotation anno) {
for (CoreMap sent : anno.get(SentencesAnnotation.class)) {
if (sent.get(CollapsedDependenciesAnnotation.class) == null) {
sent.set(CollapsedDependenciesAnnotation.class, new SemanticGraph());
}
}
}
示例4: annotate
import edu.stanford.nlp.util.CoreMap; //導入方法依賴的package包/類
@Override
public void annotate(Annotation annotation) {
if (annotation.has(CoreAnnotations.SentencesAnnotation.class)) {
for (CoreMap sentence : annotation.get(CoreAnnotations.SentencesAnnotation.class)) {
SemanticGraph dependencies = sentence.get(
SemanticGraphCoreAnnotations.BasicDependenciesAnnotation.class);
if (dependencies != null) {
DepParseInfo info = new DepParseInfo(dependencies);
sentence.set(DepparseAnnotations.MstParserAnnotation.class, info);
}
}
} else {
throw new RuntimeException("unable to find words/tokens in: " + annotation);
}
}
示例5: annotate
import edu.stanford.nlp.util.CoreMap; //導入方法依賴的package包/類
@Override
public void annotate(Annotation annotation) {
if (annotation.has(CoreAnnotations.SentencesAnnotation.class)) {
for (CoreMap sentence : annotation.get(CoreAnnotations.SentencesAnnotation.class)) {
List<CoreLabel> tokens = sentence.get(CoreAnnotations.TokensAnnotation.class);
if (maxLen > 0 && tokens.size() > maxLen) {
continue;
}
ArrayList<String> forms = new ArrayList<>();
ArrayList<String> poss = new ArrayList<>();
for (CoreLabel stanfordToken : tokens) {
String form = stanfordToken.get(CoreAnnotations.TextAnnotation.class);
String pos = stanfordToken.get(CoreAnnotations.PartOfSpeechAnnotation.class);
forms.add(form);
poss.add(pos);
}
try {
DepParseInfo depParseInfo = parser.tag(forms, poss);
sentence.set(DepparseAnnotations.MstParserAnnotation.class, depParseInfo);
} catch (Exception e) {
e.printStackTrace();
}
}
}
else {
throw new RuntimeException("unable to find words/tokens in: " + annotation);
}
}
示例6: annotate
import edu.stanford.nlp.util.CoreMap; //導入方法依賴的package包/類
@Override public void annotate(Annotation annotation) {
if (annotation.containsKey(CoreAnnotations.SentencesAnnotation.class)) {
for (CoreMap sentence : annotation.get(CoreAnnotations.SentencesAnnotation.class)) {
List<CoreLabel> lastVerb = new ArrayList<>();
List<CoreLabel> tokens = sentence.get(CoreAnnotations.TokensAnnotation.class);
boolean followedByExMark = tokens.get(tokens.size() - 1).word().equals("!");
// boolean preceededByNot = false;
List<VerbMultiToken> verbs = new ArrayList<>();
for (int i = 0; i < tokens.size(); i++) {
CoreLabel token = tokens.get(i);
String pos = token.get(CoreAnnotations.PartOfSpeechAnnotation.class);
// System.out.println(token);
// System.out.println(pos);
// System.out.println();
// String form = token.word().toLowerCase();
// if (noWords.contains(form)) {
// preceededByNot = true;
// }
if (isSatisfied(pos, verbTags, usePrefix) || isSatisfied(pos, modalTags, modalUsePrefix)) {
lastVerb.add(token);
}
if (isSatisfied(pos, skipTags, usePrefix)) {
continue;
}
if (isSatisfied(pos, auxTags, auxUsePrefix)) {
continue;
}
if (lastVerb.size() > 0) {
addVerbs(lastVerb, verbs, followedByExMark);
lastVerb = new ArrayList<>();
}
}
if (lastVerb.size() > 0) {
addVerbs(lastVerb, verbs, followedByExMark);
}
sentence.set(VerbAnnotations.VerbsAnnotation.class, verbs);
}
}
}
示例7: processParses
import edu.stanford.nlp.util.CoreMap; //導入方法依賴的package包/類
/**
* Start from parsed trees, and run the coref.
*/
public List<EntityMention> processParses(Collection<Tree> trees) {
CoreLabelTokenFactory tokenfactory = new CoreLabelTokenFactory();
List<EntityMention> entities = null;
// Create an empty Annotation
Annotation document = new Annotation("");
try {
// Setup the sentences using CoreMaps and CoreLabels.
List<CoreMap> sentences = new ArrayList<CoreMap>();
for( Tree tree : trees ) {
List<CoreLabel> sentence = new ArrayList<CoreLabel>();
CoreMap sent = new ArrayCoreMap(1);
sent.set(TokensAnnotation.class,sentence);
sentences.add(sent);
// Now add the leaves from the trees as separate tokens.
List<String> strs = TreeOperator.stringLeavesFromTree(tree);
List<String> pos = TreeOperator.posTagsFromTree(tree);
int start = 0, index = 0;
for( String str : strs ) {
CoreLabel label = tokenfactory.makeToken(str, start, start+str.length());
start += str.length() + 1;
label.set(PartOfSpeechAnnotation.class, pos.get(index++));
sentence.add(label);
}
// Now add the parse tree.
sent.set(TreeAnnotation.class, tree);
}
// Add all sentences as an annotation to the document.
document.set(CoreAnnotations.SentencesAnnotation.class, sentences);
// for( CoreMap sen : sentences ) {
// System.out.println(sen);
// }
// NOTE: You can see each annotator get created in the StanfordCoreNLP.java class.
// Look at its function getDefaultAnnotatorPool()
pipeline.annotate(document);
// System.out.println("AFTER");
// for( CoreMap sen : sentences )
// System.out.println(sen);
// This is the coreference link graph
// Each chain stores a set of mentions that link to each other,
// along with a method for getting the most representative mention
// Both sentence and token offsets start at 1!
Map<Integer, CorefChain> graph = document.get(CorefChainAnnotation.class);
// for( Integer id : graph.keySet() ) System.out.println(id + "\t" + graph.get(id));
entities = extractEntities(graph);
} catch( Exception ex ) {
System.out.println("--STANFORD COREF EXCEPTION-- Parses skipped...");
ex.printStackTrace();
}
return entities;
}
示例8: annotate
import edu.stanford.nlp.util.CoreMap; //導入方法依賴的package包/類
@Override
public void annotate(Annotation annotation) {
if (annotation.has(CoreAnnotations.SentencesAnnotation.class)) {
for (CoreMap stanfordSentence : annotation.get(CoreAnnotations.SentencesAnnotation.class)) {
List<CoreLabel> tokens = stanfordSentence.get(CoreAnnotations.TokensAnnotation.class);
if (maxLen > 0 && tokens.size() > maxLen) {
continue;
}
List<Token> sentenceTokens = new ArrayList<>();
DepParseInfo depParseInfo = stanfordSentence.get(DepparseAnnotations.MstParserAnnotation.class);
if (depParseInfo == null) {
continue;
}
for (int i = 0; i < tokens.size(); i++) {
CoreLabel token = tokens.get(i);
String form = token.get(CoreAnnotations.TextAnnotation.class);
String pos = token.get(CoreAnnotations.PartOfSpeechAnnotation.class);
String lemma = token.get(CoreAnnotations.LemmaAnnotation.class);
Integer head = depParseInfo.getDepParents().get(i + 1);
String rel = depParseInfo.getDepLabels().get(i + 1);
Token fnToken = new Token(form, pos, head, rel);
fnToken.setLemma(lemma);
sentenceTokens.add(fnToken);
}
Sentence sentence = new Sentence(sentenceTokens);
try {
SemaforParseResult results = parser.parseSentence(sentence);
stanfordSentence.set(PikesAnnotations.SemaforAnnotation.class, results);
} catch (Exception e) {
e.printStackTrace();
}
}
} else {
throw new RuntimeException("unable to find words/tokens in: " + annotation);
}
}