use of edu.stanford.nlp.pipeline.QuoteAttributionAnnotator in project CoreNLP by stanfordnlp.
the class SupervisedSieveTraining method main.
public static void main(String[] args) throws Exception {
String home = "/home/mjfang/action_grammars/";
// make the first argument one for a base directory
String specificFile = "1PPDevUncollapsed.props";
if (args.length >= 1) {
home = args[0];
}
if (args.length >= 2) {
specificFile = args[1];
}
System.out.println("Base directory: " + home);
Properties props = StringUtils.propFileToProperties(home + "ExtractQuotesXMLScripts/" + specificFile);
XMLToAnnotation.Data data = XMLToAnnotation.readXMLFormat(props.getProperty("file"));
Properties propsPara = new Properties();
propsPara.setProperty("paragraphBreak", "one");
ParagraphAnnotator pa = new ParagraphAnnotator(propsPara, false);
pa.annotate(data.doc);
Properties annotatorProps = new Properties();
// "characterList.txt"
annotatorProps.setProperty("charactersPath", props.getProperty("charactersPath"));
annotatorProps.setProperty("booknlpCoref", props.getProperty("booknlpCoref"));
// "model.ser");
annotatorProps.setProperty("modelPath", props.getProperty("modelPath"));
QuoteAttributionAnnotator qaa = new QuoteAttributionAnnotator(annotatorProps);
qaa.annotate(data.doc);
ChapterAnnotator ca = new ChapterAnnotator();
ca.annotate(data.doc);
train(data, annotatorProps);
}
use of edu.stanford.nlp.pipeline.QuoteAttributionAnnotator 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");
}
Aggregations