Package edu.stanford.nlp.ling.tokensregex

Examples of edu.stanford.nlp.ling.tokensregex.CoreMapExpressionExtractor


      out = new PrintWriter(args[2]);
    } else {
      out = new PrintWriter(System.out);
    }

    CoreMapExpressionExtractor extractor = CoreMapExpressionExtractor
      .createExtractorFromFiles(
        TokenSequencePattern.getNewEnv(),
        rules);

    StanfordCoreNLP pipeline = new StanfordCoreNLP();
    Annotation annotation;
    if (args.length > 1) {
      annotation = new Annotation(IOUtils.slurpFileNoExceptions(args[1]));
    } else {
//      annotation = new Annotation("I know Fred has acne.  And Wilma has breast cancer.");
      annotation = new Annotation("( ( five plus three plus four ) * 2 ) divided by three");

    }

    pipeline.annotate(annotation);

    // An Annotation is a Map and you can get and use the various analyses individually.
    out.println();
    // The toString() method on an Annotation just prints the text of the Annotation
    // But you can see what is in it with other methods like toShorterString()
    out.println("The top level annotation");
    out.println(annotation.toShorterString());
    List<CoreMap> sentences = annotation.get(CoreAnnotations.SentencesAnnotation.class);

    for (CoreMap sentence : sentences) {
      List<MatchedExpression> matchedExpressions = extractor
        .extractExpressions(sentence);
      for (MatchedExpression matched:matchedExpressions) {
        // Print out matched text and value
        out.println("matched: " + matched.getText() + " with value " + matched.getValue());
        // Print out token information
View Full Code Here

TOP

Related Classes of edu.stanford.nlp.ling.tokensregex.CoreMapExpressionExtractor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.