Esempio 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);
                }
            }
        }
Esempio n. 2
0
        private static Annotation Annotate(string text)
        {
            // create an empty Annotation just with the given text
            Annotation document = new Annotation(text);

            // run all Annotators on this text
            ServerPipeline.annotate(document);
            return(document);
        }