Search in sources :

Example 1 with QuoteAttributionAnnotator

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);
}
Also used : ParagraphAnnotator(edu.stanford.nlp.paragraphs.ParagraphAnnotator) QuoteAttributionAnnotator(edu.stanford.nlp.pipeline.QuoteAttributionAnnotator)

Example 2 with QuoteAttributionAnnotator

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

Aggregations

QuoteAttributionAnnotator (edu.stanford.nlp.pipeline.QuoteAttributionAnnotator)2 CoreAnnotations (edu.stanford.nlp.ling.CoreAnnotations)1 ParagraphAnnotator (edu.stanford.nlp.paragraphs.ParagraphAnnotator)1 Annotation (edu.stanford.nlp.pipeline.Annotation)1 StanfordCoreNLP (edu.stanford.nlp.pipeline.StanfordCoreNLP)1 CoreMap (edu.stanford.nlp.util.CoreMap)1