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);
}
}
}
}
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;
}
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");
}
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);
}
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;
}
Aggregations