当前位置: 首页>>代码示例>>Java>>正文


Java SemanticGraphCoreAnnotations类代码示例

本文整理汇总了Java中edu.stanford.nlp.trees.semgraph.SemanticGraphCoreAnnotations的典型用法代码示例。如果您正苦于以下问题:Java SemanticGraphCoreAnnotations类的具体用法?Java SemanticGraphCoreAnnotations怎么用?Java SemanticGraphCoreAnnotations使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


SemanticGraphCoreAnnotations类属于edu.stanford.nlp.trees.semgraph包,在下文中一共展示了SemanticGraphCoreAnnotations类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: fillInParseAnnotations

import edu.stanford.nlp.trees.semgraph.SemanticGraphCoreAnnotations; //导入依赖的package包/类
public static void fillInParseAnnotations(boolean verbose, boolean buildGraphs, CoreMap sentence, Tree tree) {
  // make sure all tree nodes are CoreLabels
  // TODO: why isn't this always true? something fishy is going on
  ParserAnnotatorUtils.convertToCoreLabels(tree);

  // index nodes, i.e., add start and end token positions to all nodes
  // this is needed by other annotators down stream, e.g., the NFLAnnotator
  tree.indexSpans(0);

  sentence.set(TreeAnnotation.class, tree);
  if (verbose) {
    System.err.println("Tree is:");
    tree.pennPrint(System.err);
  }

  if (buildGraphs) {
    // generate the dependency graph
    SemanticGraph deps = generateCollapsedDependencies(tree);
    SemanticGraph uncollapsedDeps = generateUncollapsedDependencies(tree);
    SemanticGraph ccDeps = generateCCProcessedDependencies(tree);
    if (verbose) {
      System.err.println("SDs:");
      System.err.println(deps.toString("plain"));
    }
    sentence.set(SemanticGraphCoreAnnotations.CollapsedDependenciesAnnotation.class, deps);
    sentence.set(SemanticGraphCoreAnnotations.BasicDependenciesAnnotation.class, uncollapsedDeps);
    sentence.set(SemanticGraphCoreAnnotations.CollapsedCCProcessedDependenciesAnnotation.class, ccDeps);
  }

  setMissingTags(sentence, tree);
}
 
开发者ID:amark-india,项目名称:eventspotter,代码行数:32,代码来源:ParserAnnotatorUtils.java

示例2: runTest

import edu.stanford.nlp.trees.semgraph.SemanticGraphCoreAnnotations; //导入依赖的package包/类
@Test
public void runTest() {
    // creates a StanfordCoreNLP object, with POS tagging, lemmatization, NER, parsing, and coreference resolution
    Properties props = new Properties();
    props.put("annotators", "tokenize, ssplit, pos, lemma, ner, parse, dcoref");
    StanfordCoreNLP pipeline = new StanfordCoreNLP(props);


    TextReader reader = new TextReader();
    String text = reader.readText(FILE_PATH);
    // create an empty Annotation just with the given text
    Annotation document = new Annotation(text);

    // run all Annotators on this text
    LOGGER.info("Annotating...");
    long start = System.currentTimeMillis();
    pipeline.annotate(document);
    long finish = System.currentTimeMillis();
    LOGGER.info("Finished in " + (finish - start) + " ms");

    // these are all the sentences in this document
    // a CoreMap is essentially a Map that uses class objects as keys and has values with custom types
    List<CoreMap> sentences = document.get(CoreAnnotations.SentencesAnnotation.class);
    StringBuilder log = new StringBuilder();
    for (CoreMap sentence : sentences) {
        // traversing the words in the current sentence
        // a CoreLabel is a CoreMap with additional token-specific methods
        for (CoreLabel token : sentence.get(CoreAnnotations.TokensAnnotation.class)) {
            // this is the text of the token
            String word = token.get(CoreAnnotations.TextAnnotation.class);
            // this is the POS tag of the token
            String pos = token.get(CoreAnnotations.PartOfSpeechAnnotation.class);
            // this is the NER label of the token
            String ne = token.get(CoreAnnotations.NamedEntityTagAnnotation.class);
            log.append(String.format("word \"%s\" POS %s NER %s\n", word, pos, ne));
        }
        LOGGER.info("\n Sentence: " + sentence.toString());
        LOGGER.info(log.toString());
        // this is the parse tree of the current sentence
        Tree tree = sentence.get(TreeCoreAnnotations.TreeAnnotation.class);

        LOGGER.info("\n Tree: \n" + tree.toString());

        // this is the Stanford dependency graph of the current sentence
        SemanticGraph dependencies = sentence.get(SemanticGraphCoreAnnotations.CollapsedCCProcessedDependenciesAnnotation.class);

        LOGGER.info("\n Dependencies: \n" + dependencies.toString());
    }

    // 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(CorefCoreAnnotations.CorefChainAnnotation.class);

    LOGGER.info("\n Graph: \n" + graph.toString());
}
 
开发者ID:pesua,项目名称:Project-Poppins,代码行数:58,代码来源:StanfordNLPTest.java


注:本文中的edu.stanford.nlp.trees.semgraph.SemanticGraphCoreAnnotations类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。