Search in sources :

Example 51 with StanfordCoreNLP

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

the class GenericDataSetReader method modifyUsingCoreNLPNER.

private static void modifyUsingCoreNLPNER(Annotation doc) {
    Properties ann = new Properties();
    ann.setProperty("annotators", "pos, lemma, ner");
    StanfordCoreNLP pipeline = new StanfordCoreNLP(ann, false);
    pipeline.annotate(doc);
    for (CoreMap sentence : doc.get(CoreAnnotations.SentencesAnnotation.class)) {
        List<EntityMention> entities = sentence.get(MachineReadingAnnotations.EntityMentionsAnnotation.class);
        if (entities != null) {
            List<CoreLabel> tokens = sentence.get(CoreAnnotations.TokensAnnotation.class);
            for (EntityMention en : entities) {
                // System.out.println("old ner tag for " + en.getExtentString() + " was " + en.getType());
                Span s = en.getExtent();
                Counter<String> allNertagforSpan = new ClassicCounter<>();
                for (int i = s.start(); i < s.end(); i++) {
                    allNertagforSpan.incrementCount(tokens.get(i).ner());
                }
                String entityNertag = Counters.argmax(allNertagforSpan);
                en.setType(entityNertag);
            // System.out.println("new ner tag is " + entityNertag);
            }
        }
    }
}
Also used : Properties(java.util.Properties) Span(edu.stanford.nlp.ie.machinereading.structure.Span) StanfordCoreNLP(edu.stanford.nlp.pipeline.StanfordCoreNLP) ParserConstraint(edu.stanford.nlp.parser.common.ParserConstraint) MachineReadingAnnotations(edu.stanford.nlp.ie.machinereading.structure.MachineReadingAnnotations) CoreLabel(edu.stanford.nlp.ling.CoreLabel) EntityMention(edu.stanford.nlp.ie.machinereading.structure.EntityMention) TreeCoreAnnotations(edu.stanford.nlp.trees.TreeCoreAnnotations) CoreAnnotations(edu.stanford.nlp.ling.CoreAnnotations) ClassicCounter(edu.stanford.nlp.stats.ClassicCounter) CoreMap(edu.stanford.nlp.util.CoreMap)

Example 52 with StanfordCoreNLP

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

the class MachineReading method makeMachineReading.

public static MachineReading makeMachineReading(String[] args) throws IOException {
    // install global parameters
    MachineReading mr = new MachineReading(args);
    // TODO:
    ArgumentParser.fillOptions(MachineReadingProperties.class, args);
    // Arguments.parse(args, mr);
    log.info("PERCENTAGE OF TRAIN: " + MachineReadingProperties.percentageOfTrain);
    // convert args to properties
    Properties props = StringUtils.argsToProperties(args);
    if (props == null) {
        throw new RuntimeException("ERROR: failed to find Properties in the given arguments!");
    }
    String logLevel = props.getProperty("logLevel", "INFO");
    setLoggerLevel(Level.parse(logLevel.toUpperCase()));
    // install reader specific parameters
    GenericDataSetReader reader = mr.makeReader(props);
    GenericDataSetReader auxReader = mr.makeAuxReader();
    Level readerLogLevel = Level.parse(MachineReadingProperties.readerLogLevel.toUpperCase());
    reader.setLoggerLevel(readerLogLevel);
    if (auxReader != null) {
        auxReader.setLoggerLevel(readerLogLevel);
    }
    log.info("The reader log level is set to " + readerLogLevel);
    // Execution.fillOptions(GenericDataSetReaderProps.class, args);
    // Arguments.parse(args, reader);
    // create the pre-processing pipeline
    StanfordCoreNLP pipe = new StanfordCoreNLP(props, false);
    reader.setProcessor(pipe);
    if (auxReader != null) {
        auxReader.setProcessor(pipe);
    }
    // create the results printers
    mr.makeResultsPrinters(args);
    return mr;
}
Also used : Level(java.util.logging.Level) Properties(java.util.Properties) StanfordCoreNLP(edu.stanford.nlp.pipeline.StanfordCoreNLP)

Example 53 with StanfordCoreNLP

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

the class QuoteAttributionTest method testPP.

// Test QuoteAttributionAnnotator on a chapter of PP.
public static void testPP(String familyFile, String animateFile, String genderFile, String charactersFile, String modelFile) throws IOException, ClassNotFoundException {
    Properties props = new Properties();
    props.setProperty("annotators", "tokenize, ssplit, pos, lemma, ner, depparse, quote, quoteattribution");
    props.setProperty("quoteattribution.familyWordsFile", familyFile);
    props.setProperty("quoteattribution.animacyWordsFile", animateFile);
    props.setProperty("quoteattribution.genderNamesFile", genderFile);
    props.setProperty("quoteattribution.charactersPath", charactersFile);
    props.setProperty("quoteattribution.modelPath", modelFile);
    StanfordCoreNLP coreNLP = new StanfordCoreNLP(props);
    Annotation processedAnnotation = coreNLP.process(test);
    List<CoreMap> quotes = processedAnnotation.get(CoreAnnotations.QuotationsAnnotation.class);
    for (CoreMap quote : quotes) {
        System.out.println("Quote: " + quote.get(CoreAnnotations.TextAnnotation.class));
        if (quote.get(QuoteAttributionAnnotator.MentionAnnotation.class) != null) {
            System.out.println("Predicted Mention: " + quote.get(QuoteAttributionAnnotator.MentionAnnotation.class) + " Predictor: " + quote.get(QuoteAttributionAnnotator.MentionSieveAnnotation.class));
        } else {
            System.out.println("Predicted Mention: none");
        }
        if (quote.get(QuoteAttributionAnnotator.SpeakerAnnotation.class) != null) {
            System.out.println("Predicted Speaker: " + quote.get(QuoteAttributionAnnotator.SpeakerAnnotation.class) + " Predictor: " + quote.get(QuoteAttributionAnnotator.SpeakerSieveAnnotation.class));
        } else {
            System.out.println("Predicted Speaker: none");
        }
        System.out.println("====");
    }
    System.out.println("Finished");
}
Also used : QuoteAttributionAnnotator(edu.stanford.nlp.pipeline.QuoteAttributionAnnotator) CoreAnnotations(edu.stanford.nlp.ling.CoreAnnotations) CoreMap(edu.stanford.nlp.util.CoreMap) StanfordCoreNLP(edu.stanford.nlp.pipeline.StanfordCoreNLP) Annotation(edu.stanford.nlp.pipeline.Annotation)

Example 54 with StanfordCoreNLP

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

the class AbstractSceneGraphParser method initPipeline.

private void initPipeline() {
    Properties props = new Properties();
    props.setProperty("annotators", "tokenize,ssplit,parse,lemma,ner");
    props.setProperty("depparse.model", SceneGraphImagePCFGParser.PCFG_MODEL);
    props.setProperty("depparse.extradependencies", "MAXIMAL");
    this.pipeline = new StanfordCoreNLP(props);
}
Also used : Properties(java.util.Properties) StanfordCoreNLP(edu.stanford.nlp.pipeline.StanfordCoreNLP)

Example 55 with StanfordCoreNLP

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

the class SceneGraphImageCleaner method getTokenizerPipeline.

private static StanfordCoreNLP getTokenizerPipeline() {
    if (tokenizerPipeline == null) {
        Properties props = new Properties();
        props.put("annotators", "tokenize,ssplit,pos,lemma,ner");
        props.put("ssplit.eolonly", "true");
        tokenizerPipeline = new StanfordCoreNLP(props);
    }
    return tokenizerPipeline;
}
Also used : Properties(java.util.Properties) 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