Search in sources :

Example 56 with StanfordCoreNLP

use of edu.stanford.nlp.pipeline.StanfordCoreNLP in project CoreNLP by stanfordnlp.

the class SceneGraphImageCleaner method getPipeline.

private static StanfordCoreNLP getPipeline() {
    if (pipeline == null) {
        Properties props = new Properties();
        props.put("annotators", "tokenize,ssplit,pos,lemma,ner");
        // props.put("tokenize.whitespace", "true");
        props.put("ssplit.eolonly", "true");
        pipeline = new StanfordCoreNLP(props);
    }
    return pipeline;
}
Also used : Properties(java.util.Properties) StanfordCoreNLP(edu.stanford.nlp.pipeline.StanfordCoreNLP)

Example 57 with StanfordCoreNLP

use of edu.stanford.nlp.pipeline.StanfordCoreNLP in project CoreNLP by stanfordnlp.

the class DcorefExactOutputITest method main.

/**
 * If run as a program, writes the expected output of args[0] to args[1].
 * This is useful for updating the desired test results when CoreNLP changes.
 */
public static void main(String[] args) throws Exception {
    if (args.length != 2) {
        System.err.println("Expected args <input> <output>");
        throw new IllegalArgumentException();
    }
    String input = args[0];
    String output = args[1];
    Properties props = new Properties();
    props.setProperty("annotators", "tokenize, cleanxml, ssplit, pos, lemma, ner, parse, dcoref");
    StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
    // for example
    // "edu/stanford/nlp/dcoref/STILLALONEWOLF_20050102.1100.eng.LDC2005E83.sgm"
    String doc = IOUtils.slurpFile(input);
    Annotation annotation = pipeline.process(doc);
    Map<Integer, CorefChain> chains = annotation.get(CorefCoreAnnotations.CorefChainAnnotation.class);
    saveResults(output, chains);
}
Also used : CorefChain(edu.stanford.nlp.coref.data.CorefChain) Properties(java.util.Properties) CorefCoreAnnotations(edu.stanford.nlp.coref.CorefCoreAnnotations) StanfordCoreNLP(edu.stanford.nlp.pipeline.StanfordCoreNLP) Annotation(edu.stanford.nlp.pipeline.Annotation)

Example 58 with StanfordCoreNLP

use of edu.stanford.nlp.pipeline.StanfordCoreNLP in project CoreNLP by stanfordnlp.

the class NumberSequenceClassifierITest method makeNumericPipeline.

private static StanfordCoreNLP makeNumericPipeline() {
    Properties props = new Properties();
    props.setProperty("annotators", "tokenize, ssplit, pos, number, qen");
    props.setProperty("tokenize.options", "splitHyphenated=false");
    props.setProperty("customAnnotatorClass.number", "edu.stanford.nlp.pipeline.NumberAnnotator");
    props.setProperty("customAnnotatorClass.qen", "edu.stanford.nlp.pipeline.QuantifiableEntityNormalizingAnnotator");
    StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
    return pipeline;
}
Also used : Properties(java.util.Properties) StanfordCoreNLP(edu.stanford.nlp.pipeline.StanfordCoreNLP)

Example 59 with StanfordCoreNLP

use of edu.stanford.nlp.pipeline.StanfordCoreNLP in project CoreNLP by stanfordnlp.

the class GetPatternsFromDataMultiClass method runPOSNEROnTokens.

public static Map<String, DataInstance> runPOSNEROnTokens(List<CoreMap> sentsCM, String posModelPath, boolean useTargetNERRestriction, String prefix, boolean useTargetParserParentRestriction, String numThreads, PatternFactory.PatternType type) {
    Annotation doc = new Annotation(sentsCM);
    Properties props = new Properties();
    List<String> anns = new ArrayList<>();
    anns.add("pos");
    anns.add("lemma");
    if (useTargetParserParentRestriction) {
        anns.add("parse");
    } else if (type.equals(PatternFactory.PatternType.DEP))
        anns.add("depparse");
    if (useTargetNERRestriction) {
        anns.add("ner");
    }
    props.setProperty("annotators", StringUtils.join(anns, ","));
    props.setProperty("parse.maxlen", "80");
    props.setProperty("nthreads", numThreads);
    props.setProperty("threads", numThreads);
    if (posModelPath != null) {
        props.setProperty("pos.model", posModelPath);
    }
    StanfordCoreNLP pipeline = new StanfordCoreNLP(props, false);
    Redwood.log(Redwood.DBG, "Annotating text");
    pipeline.annotate(doc);
    Redwood.log(Redwood.DBG, "Done annotating text");
    Map<String, DataInstance> sents = new HashMap<>();
    for (CoreMap s : doc.get(CoreAnnotations.SentencesAnnotation.class)) {
        if (useTargetParserParentRestriction)
            inferParentParseTag(s.get(TreeAnnotation.class));
        DataInstance d = DataInstance.getNewInstance(type, s);
        sents.put(prefix + s.get(CoreAnnotations.DocIDAnnotation.class), d);
    }
    return sents;
}
Also used : CoreAnnotations(edu.stanford.nlp.ling.CoreAnnotations) TreeAnnotation(edu.stanford.nlp.trees.TreeCoreAnnotations.TreeAnnotation) Annotation(edu.stanford.nlp.pipeline.Annotation) GoldAnswerAnnotation(edu.stanford.nlp.ling.CoreAnnotations.GoldAnswerAnnotation) StanfordCoreNLP(edu.stanford.nlp.pipeline.StanfordCoreNLP)

Example 60 with StanfordCoreNLP

use of edu.stanford.nlp.pipeline.StanfordCoreNLP in project CoreNLP by stanfordnlp.

the class SentenceTest method tokenizeAndSplitAnnotation.

public Sentence tokenizeAndSplitAnnotation(Annotation ann) {
    StanfordCoreNLP pipeline = new StanfordCoreNLP(new Properties() {

        {
            setProperty("annotators", "tokenize,ssplit");
        }
    });
    pipeline.annotate(ann);
    CoreMap map = ann.get(CoreAnnotations.SentencesAnnotation.class).get(0);
    return new Sentence(map);
}
Also used : Properties(java.util.Properties) CoreMap(edu.stanford.nlp.util.CoreMap) StanfordCoreNLP(edu.stanford.nlp.pipeline.StanfordCoreNLP)

Aggregations

StanfordCoreNLP (edu.stanford.nlp.pipeline.StanfordCoreNLP)71 Properties (java.util.Properties)44 Annotation (edu.stanford.nlp.pipeline.Annotation)40 CoreAnnotations (edu.stanford.nlp.ling.CoreAnnotations)33 CoreMap (edu.stanford.nlp.util.CoreMap)33 Test (org.junit.Test)15 CoreLabel (edu.stanford.nlp.ling.CoreLabel)12 SemanticGraphCoreAnnotations (edu.stanford.nlp.semgraph.SemanticGraphCoreAnnotations)12 SemanticGraph (edu.stanford.nlp.semgraph.SemanticGraph)10 CorefCoreAnnotations (edu.stanford.nlp.coref.CorefCoreAnnotations)6 SemanticGraphEdge (edu.stanford.nlp.semgraph.SemanticGraphEdge)6 StanfordTextProcessor (com.graphaware.nlp.processor.stanford.StanfordTextProcessor)5 TreeCoreAnnotations (edu.stanford.nlp.trees.TreeCoreAnnotations)5 PrintWriter (java.io.PrintWriter)5 ArrayList (java.util.ArrayList)5 AnnotatedText (com.graphaware.nlp.domain.AnnotatedText)3 CorefChain (edu.stanford.nlp.coref.data.CorefChain)3 GoldAnswerAnnotation (edu.stanford.nlp.ling.CoreAnnotations.GoldAnswerAnnotation)3 SentencesAnnotation (edu.stanford.nlp.ling.CoreAnnotations.SentencesAnnotation)3 TokenSequencePattern (edu.stanford.nlp.ling.tokensregex.TokenSequencePattern)3