toString() private method

private toString ( global par0 ) : global::java.lang.String
par0 global
return global::java.lang.String
Exemplo n.º 1
0
        static void Main()
        {
            // Path to the folder with models extracted from `stanford-corenlp-3.7.0-models.jar`
            var jarRoot = @"..\..\..\..\paket-files\nlp.stanford.edu\stanford-corenlp-full-2016-10-31\models";

            // Text for processing
            var text = "Kosgi Santosh sent an email to Stanford University. He didn't get a reply.";

            // Annotation pipeline configuration
            var props = new Properties();
            props.setProperty("annotators", "tokenize, ssplit, pos, lemma, parse, ner,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);

            // Annotation
            var annotation = new Annotation(text);
            pipeline.annotate(annotation);

            // Result - Pretty Print
            using (var stream = new ByteArrayOutputStream())
            {
                pipeline.prettyPrint(annotation, new PrintWriter(stream));
                Console.WriteLine(stream.toString());
                stream.close();
            }
        }
Exemplo n.º 2
0
        public void StanfordCoreNlpDemoThatChangeCurrentDirectory()
        {
            const string Text = "Kosgi Santosh sent an email to Stanford University. He didn't get a reply.";

            // Annotation pipeline configuration
            var props = new Properties();
            props.setProperty("annotators", "tokenize, ssplit, pos, lemma, ner, parse, dcoref");
            props.setProperty("sutime.binders", "0");

            // we should change current directory so StanfordCoreNLP could find all the model files
            var curDir = Environment.CurrentDirectory;
            Directory.SetCurrentDirectory(Config.JarRoot);
            var pipeline = new edu.stanford.nlp.pipeline.StanfordCoreNLP(props);
            Directory.SetCurrentDirectory(curDir);

            // Annotation
            var annotation = new Annotation(Text);
            pipeline.annotate(annotation);
    
            // Result - Pretty Print
            using (var stream = new ByteArrayOutputStream())
            {
                pipeline.prettyPrint(annotation, new PrintWriter(stream));
                Console.WriteLine(stream.toString());
            }

            this.CustomAnnotationPrint(annotation);
        }
Exemplo n.º 3
0
        public String testFreemarker()
        {
            Assembly _assembly;
            _assembly = Assembly.GetExecutingAssembly();
            //Console.WriteLine(_assembly.
            try{
                Configuration cfg = new Configuration();
                cfg.setDirectoryForTemplateLoading(new File("template"));
                //cfg.setDirectoryForTemplateLoading(new File(""));
                cfg.setObjectWrapper(new DefaultObjectWrapper());

                Template temp = cfg.getTemplate("c.ftl");

                Map root = new HashMap();
                root.put("codeGen", this);

                ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
                Writer output = new OutputStreamWriter(outputStream);

                temp.process(root, output);
                output.flush();
                //System.Console.WriteLine(outputStream.toString());
                return outputStream.toString();

            }
            catch (IOException exception) {

            } catch (TemplateException exception) {

            }
            return "";
        }
Exemplo n.º 4
0
        private string getAnnotation(string input)
        {
            Annotation annotation = new Annotation(input);
            pipeline.annotate(annotation);

            string result = "";
            using (var stream = new ByteArrayOutputStream())
            {
                pipeline.conllPrint(annotation, new PrintWriter(stream));
                result += stream.toString();
                stream.close();
            }
            return result;
        }
Exemplo n.º 5
0
        public void CustomAnnotationPrint(Annotation annotation)
        {
            Console.WriteLine("-------------");
            Console.WriteLine("Custom print:");
            Console.WriteLine("-------------");
            var sentences = (ArrayList)annotation.get(new CoreAnnotations.SentencesAnnotation().getClass());
            foreach(CoreMap sentence in sentences)
            {
                Console.WriteLine("\n\nSentence : '{0}'", sentence);

                var tokens = (ArrayList)sentence.get(new CoreAnnotations.TokensAnnotation().getClass());
                foreach (CoreLabel token in tokens)
                {
                    var word = token.get(new CoreAnnotations.TextAnnotation().getClass());
                    var pos  = token.get(new CoreAnnotations.PartOfSpeechAnnotation().getClass());
                    var ner  = token.get(new CoreAnnotations.NamedEntityTagAnnotation().getClass());
                    Console.WriteLine("{0} \t[pos={1}; ner={2}]", word, pos, ner);
                }

                Console.WriteLine("\nTree:");
                var tree = (Tree)sentence.get(new TreeCoreAnnotations.TreeAnnotation().getClass());
                using(var stream = new ByteArrayOutputStream())
                {
                    tree.pennPrint(new PrintWriter(stream));
                    Console.WriteLine("The first sentence parsed is:\n {0}", stream.toString());
                }

                Console.WriteLine("\nDependencies:");
                var deps = (SemanticGraph)sentence.get(new SemanticGraphCoreAnnotations.CollapsedDependenciesAnnotation().getClass());
                foreach (SemanticGraphEdge edge in deps.edgeListSorted().toArray())
                {
                    var gov = edge.getGovernor();
                    var dep = edge.getDependent();
                    Console.WriteLine(
                        "{0}({1}-{2},{3}-{4})", edge.getRelation(), 
                        gov.word(), gov.index(), dep.word(), dep.index());
                }
            }
        }
Exemplo n.º 6
0
 public virtual string toString()
 {
   ByteArrayOutputStream arrayOutputStream = new ByteArrayOutputStream();
   new TextListener(new PrintStream((OutputStream) arrayOutputStream)).testRunFinished(this.result);
   return arrayOutputStream.toString();
 }
Exemplo n.º 7
0
        public void StanfordCoreNlpDemoManualConfiguration()
        {
            Console.WriteLine(Environment.CurrentDirectory);
            const string Text = "Kosgi Santosh sent an email to Stanford University. He didn't get a reply.";

            // Annotation pipeline configuration
            var props = new Properties();

            props.setProperty("annotators", "tokenize, ssplit, pos, lemma, ner, parse, dcoref");
            props.setProperty("pos.model", Config.GetModel(@"pos-tagger\english-bidirectional\english-bidirectional-distsim.tagger"));
            props.setProperty("ner.model", Config.GetModel(@"ner\english.all.3class.distsim.crf.ser.gz"));
            props.setProperty("parse.model", Config.GetModel(@"lexparser\englishPCFG.ser.gz"));
    
            props.setProperty("dcoref.demonym", Config.GetModel(@"dcoref\demonyms.txt"));
            props.setProperty("dcoref.states", Config.GetModel(@"dcoref\state-abbreviations.txt"));
            props.setProperty("dcoref.animate", Config.GetModel(@"dcoref\animate.unigrams.txt"));
            props.setProperty("dcoref.inanimate", Config.GetModel(@"dcoref\inanimate.unigrams.txt"));
            props.setProperty("dcoref.male", Config.GetModel(@"dcoref\male.unigrams.txt"));
            props.setProperty("dcoref.neutral", Config.GetModel(@"dcoref\neutral.unigrams.txt"));
            props.setProperty("dcoref.female", Config.GetModel(@"dcoref\female.unigrams.txt"));
            props.setProperty("dcoref.plural", Config.GetModel(@"dcoref\plural.unigrams.txt"));
            props.setProperty("dcoref.singular", Config.GetModel(@"dcoref\singular.unigrams.txt"));
            props.setProperty("dcoref.countries", Config.GetModel(@"dcoref\countries"));
            props.setProperty("dcoref.extra.gender", Config.GetModel(@"dcoref\namegender.combine.txt"));
            props.setProperty("dcoref.states.provinces", Config.GetModel(@"dcoref\statesandprovinces"));
            props.setProperty("dcoref.singleton.predictor", Config.GetModel(@"dcoref\singleton.predictor.ser"));
            props.setProperty("dcoref.big.gender.number", Config.GetModel(@"dcoref\gender.data.gz"));

            var sutimeRules = new[] {
                                      Config.GetModel(@"sutime\defs.sutime.txt"),
                                      Config.GetModel(@"sutime\english.holidays.sutime.txt"),
                                      Config.GetModel(@"sutime\english.sutime.txt")
                                  };
            props.setProperty("sutime.rules", String.Join(",", sutimeRules));
            props.setProperty("sutime.binders", "0");

            var pipeline = new edu.stanford.nlp.pipeline.StanfordCoreNLP(props);

            // Annotation
            var annotation = new Annotation(Text);
            pipeline.annotate(annotation);
    
            // Result - Pretty Print
            using (var stream = new ByteArrayOutputStream())
            {
                pipeline.prettyPrint(annotation, new PrintWriter(stream));
                Console.WriteLine(stream.toString());
            }

            this.CustomAnnotationPrint(annotation);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Runs text processing using StanfordCoreNLP procject.
        /// </summary>
        /// <param name="text">Text to process</param>
        public void RunCoreNLP(String text)
        {
            // needs to be before Annotation(text)
            // otherwise it throws error
            StanfordCoreNLP pipeLine = Pipeline;
            Annotation annotation = new Annotation(text);
            pipeLine.annotate(annotation);

            if (_redirectOutputToFile)
            {
                FileStream filestream = new FileStream(_redirectOutputToFileFileName, FileMode.OpenOrCreate, FileAccess.Write);
                var streamwriter = new StreamWriter(filestream);
                streamwriter.AutoFlush = true;
                Console.SetOut(streamwriter);
                Console.SetError(streamwriter);
            }

            if (_verbose)
            {
                // Result - Pretty Print
                using (ByteArrayOutputStream stream = new ByteArrayOutputStream())
                {
                    pipeLine.prettyPrint(annotation, new PrintWriter(stream));
                    Console.WriteLine(stream.toString());
                    stream.close();
                }
            }

            _notes = Parse(annotation);
            PrintNotes(_notes);
        }