Created
February 27, 2014 18:38
-
-
Save jonnybest/9256282 to your computer and use it in GitHub Desktop.
Revisions
-
jonnybest created this gist
Feb 27, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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.")); }