當前位置: 首頁>>代碼示例>>Java>>正文


Java CoreMap.set方法代碼示例

本文整理匯總了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");
    }
}
 
開發者ID:toliwa,項目名稱:CoreNLP-jMWE,代碼行數:23,代碼來源:JMWEAnnotator.java

示例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;
}
 
開發者ID:hltcoe,項目名稱:concrete-stanford-deprecated2,代碼行數:36,代碼來源:ConcreteToStanfordMapper.java

示例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());
    }
  }
}
 
開發者ID:hltcoe,項目名稱:concrete-stanford-deprecated2,代碼行數:12,代碼來源:ConcreteStanfordPreCorefAnalytic.java

示例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);
    }
}
 
開發者ID:dkmfbk,項目名稱:pikes,代碼行數:16,代碼來源:FakeMstParserAnnotator.java

示例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);
	}
}
 
開發者ID:dkmfbk,項目名稱:pikes,代碼行數:32,代碼來源:MstServerParserAnnotator.java

示例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);
            }
        }
    }
 
開發者ID:dhfbk,項目名稱:tint,代碼行數:49,代碼來源:VerbAnnotator.java

示例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;
}
 
開發者ID:nchambers,項目名稱:schemas,代碼行數:64,代碼來源:CorefStanford.java

示例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);
    }

}
 
開發者ID:dkmfbk,項目名稱:pikes,代碼行數:47,代碼來源:SemaforAnnotator.java


注:本文中的edu.stanford.nlp.util.CoreMap.set方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。