Skip to content

Instantly share code, notes, and snippets.

@jonnybest
Created February 27, 2014 18:38
Show Gist options
  • Select an option

  • Save jonnybest/9256282 to your computer and use it in GitHub Desktop.

Select an option

Save jonnybest/9256282 to your computer and use it in GitHub Desktop.

Revisions

  1. jonnybest created this gist Feb 27, 2014.
    42 changes: 42 additions & 0 deletions example.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,42 @@
    public void checkAction() {

    String text = "The penguin jumps once.";
    edu.stanford.nlp.pipeline.Annotation annotationDocument = new edu.stanford.nlp.pipeline.Annotation(text);

    edu.stanford.nlp.pipeline.StanfordCoreNLP classificationsPipeline;
    // creates a StanfordCoreNLP object, with POS tagging,
    // lemmatization,
    // NER, parsing, and coreference resolution
    Properties pipelineConfiguration = new Properties();
    // alternative: wsj-bidirectional
    try {
    pipelineConfiguration.put(
    "pos.model",
    "edu/stanford/nlp/models/pos-tagger/wsj-bidirectional/wsj-0-18-bidirectional-distsim.tagger");
    } catch (Exception e) {
    e.printStackTrace();
    }
    // adding our own annotator property
    pipelineConfiguration.put("customAnnotatorClass.sdclassifier",
    "edu.kit.ipd.alicenlp.ivan.analyzers.StaticDynamicClassifier");
    // adding our declaration finder
    pipelineConfiguration.put("customAnnotatorClass.declarations",
    "edu.kit.ipd.alicenlp.ivan.analyzers.DeclarationPositionFinder");
    // configure pipeline
    pipelineConfiguration.put(
    "annotators", "tokenize, ssplit, pos, lemma, ner, parse, dcoref, declarations, sdclassifier");
    classificationsPipeline = new edu.stanford.nlp.pipeline.StanfordCoreNLP(pipelineConfiguration);

    // run pipeline
    classificationsPipeline.annotate(annotationDocument);
    // get the sentences from the document
    List<edu.stanford.nlp.util.CoreMap> allSentences = annotationDocument.get(edu.stanford.nlp.ling.CoreAnnotations.SentencesAnnotation.class);
    // retrieve results for the first sentence
    edu.stanford.nlp.util.CoreMap firstSentence = allSentences.get(0);
    // retrieve the classification for the first sentence
    edu.kit.ipd.alicenlp.ivan.analyzers.IvanAnalyzer.Classification myClassification = firstSentence.get(edu.kit.ipd.alicenlp.ivan.data.IvanAnnotations.SentenceClassificationAnnotation.class);

    boolean compare = myClassification == edu.kit.ipd.alicenlp.ivan.analyzers.IvanAnalyzer.Classification.ActionDescription;
    System.out.println("This sentence is classified as " + (compare ? "an action." : "something else."));

    }