Created
May 23, 2016 19:40
-
-
Save smcl/649903e60cb53aca8d228303a0caf468 to your computer and use it in GitHub Desktop.
Simple test of stanford NLP library - receive some input, then pretty print the NLP analysis.
This file contains 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 characters
using System; | |
using System.IO; | |
using java.util; | |
using java.io; | |
using edu.stanford.nlp.pipeline; | |
using Console = System.Console; | |
namespace NLPTest | |
{ | |
class Program | |
{ | |
static void Main() | |
{ | |
// Path to the folder with models extracted from `stanford-corenlp-3.6.0-models.jar` | |
var jarRoot = @"C:\dev\stanford-corenlp-full-2015-12-09\stanford-corenlp-3.6.0-models"; | |
// Annotation pipeline configuration | |
var props = new Properties(); | |
props.setProperty("annotators", "tokenize, ssplit, pos, lemma, ner, parse, dcoref"); | |
props.setProperty("ner.useSUTime", "0"); | |
// We should change current directory, so StanfordCoreNLP could find all the model files automatically | |
var curDir = Environment.CurrentDirectory; | |
Directory.SetCurrentDirectory(jarRoot); | |
var pipeline = new StanfordCoreNLP(props); | |
Directory.SetCurrentDirectory(curDir); | |
string line; | |
Console.Write("> "); | |
while (!String.IsNullOrEmpty(line = Console.ReadLine())) | |
{ | |
// Annotation | |
var annotation = new Annotation(line); | |
pipeline.annotate(annotation); | |
// Result - Pretty Print | |
using (var stream = new ByteArrayOutputStream()) | |
{ | |
pipeline.prettyPrint(annotation, new PrintWriter(stream)); | |
Console.WriteLine(stream.toString()); | |
stream.close(); | |
} | |
Console.Write("> "); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment