Exemplo n.º 1
0
        // Sample from https://stanfordnlp.github.io/CoreNLP/corenlp-server.html
        static void Main()
        {
            // creates a StanfordCoreNLP object with POS tagging, lemmatization, NER, parsing, and coreference resolution
            var props = new java.util.Properties();

            props.setProperty("annotators", "tokenize, ssplit, pos, lemma, ner, parse, dcoref");
            StanfordCoreNLPClient pipeline = new StanfordCoreNLPClient(props, "http://localhost", 9000, 2);
            // read some text in the text variable
            var text = "Kosgi Santosh sent an email to Stanford University.";
            // create an empty Annotation just with the given text
            Annotation document = new Annotation(text);

            // run all Annotators on this text
            pipeline.annotate(document);

            var sentences = document.get(sentencesAnnotationClass) as java.util.AbstractList;

            foreach (CoreMap sentence in sentences)
            {
                var tokens = sentence.get(tokensAnnotationClass) as java.util.AbstractList;
                Console.WriteLine("----");
                foreach (CoreLabel token in tokens)
                {
                    var word = token.get(textAnnotationClass);
                    var pos  = token.get(partOfSpeechAnnotationClass);
                    var ner  = token.get(namedEntityTagAnnotationClass);
                    Console.WriteLine("{0}\t[pos={1};\tner={2};", word, pos, ner);
                }
            }
        }
Exemplo n.º 2
0
 static Client()
 {
     // Create a StanfordCoreNLPClient object with POS tagging, lemmatization, NER, parsing, and coreference resolution
     java.util.Properties props = new java.util.Properties();
     props.setProperty("annotators", "tokenize, ssplit, pos, lemma, ner, parse, dcoref");
     props.setProperty("coref.algorithm", "neural");
     ServerPipeline = new StanfordCoreNLPClient(props, Properties.Settings.Default.CoreNLP_ServerHost, Properties.Settings.Default.CoreNLP_ServerPort, ClientThreads);
 }