コード例 #1
0
        private static SemanticGraph GetParse(ICoreMap sentence)
        {
            GrammaticalStructure gs = parser.Predict(sentence);

            GrammaticalStructure.Extras maximal = GrammaticalStructure.Extras.Maximal;
            //        SemanticGraph deps = SemanticGraphFactory.makeFromTree(gs, SemanticGraphFactory.Mode.ENHANCED, maximal, true, null),
            //                uncollapsedDeps = SemanticGraphFactory.makeFromTree(gs, SemanticGraphFactory.Mode.BASIC, maximal, true, null),
            //    SemanticGraph ccDeps = SemanticGraphFactory.makeFromTree(gs, SemanticGraphFactory.Mode.ENHANCED_PLUS_PLUS, maximal, true, null);
            SemanticGraph ccDeps = SemanticGraphFactory.GenerateEnhancedPlusPlusDependencies(gs);

            return(ccDeps);
        }
コード例 #2
0
        protected internal override void DoOneSentence(Annotation annotation, ICoreMap sentence)
        {
            GrammaticalStructure gs                   = parser.Predict(sentence);
            SemanticGraph        deps                 = SemanticGraphFactory.MakeFromTree(gs, SemanticGraphFactory.Mode.Collapsed, extraDependencies, null);
            SemanticGraph        uncollapsedDeps      = SemanticGraphFactory.MakeFromTree(gs, SemanticGraphFactory.Mode.Basic, extraDependencies, null);
            SemanticGraph        ccDeps               = SemanticGraphFactory.MakeFromTree(gs, SemanticGraphFactory.Mode.Ccprocessed, extraDependencies, null);
            SemanticGraph        enhancedDeps         = SemanticGraphFactory.MakeFromTree(gs, SemanticGraphFactory.Mode.Enhanced, extraDependencies, null);
            SemanticGraph        enhancedPlusPlusDeps = SemanticGraphFactory.MakeFromTree(gs, SemanticGraphFactory.Mode.EnhancedPlusPlus, extraDependencies, null);

            sentence.Set(typeof(SemanticGraphCoreAnnotations.CollapsedDependenciesAnnotation), deps);
            sentence.Set(typeof(SemanticGraphCoreAnnotations.BasicDependenciesAnnotation), uncollapsedDeps);
            sentence.Set(typeof(SemanticGraphCoreAnnotations.CollapsedCCProcessedDependenciesAnnotation), ccDeps);
            sentence.Set(typeof(SemanticGraphCoreAnnotations.EnhancedDependenciesAnnotation), enhancedDeps);
            sentence.Set(typeof(SemanticGraphCoreAnnotations.EnhancedPlusPlusDependenciesAnnotation), enhancedPlusPlusDeps);
        }
コード例 #3
0
        // static main method only
        public static void Main(string[] args)
        {
            string modelPath  = DependencyParser.DefaultModel;
            string taggerPath = "edu/stanford/nlp/models/pos-tagger/english-left3words/english-left3words-distsim.tagger";

            for (int argIndex = 0; argIndex < args.Length;)
            {
                switch (args[argIndex])
                {
                case "-tagger":
                {
                    taggerPath = args[argIndex + 1];
                    argIndex  += 2;
                    break;
                }

                case "-model":
                {
                    modelPath = args[argIndex + 1];
                    argIndex += 2;
                    break;
                }

                default:
                {
                    throw new Exception("Unknown argument " + args[argIndex]);
                }
                }
            }
            string               text      = "I can almost always tell when movies use fake dinosaurs.";
            MaxentTagger         tagger    = new MaxentTagger(taggerPath);
            DependencyParser     parser    = DependencyParser.LoadFromModelFile(modelPath);
            DocumentPreprocessor tokenizer = new DocumentPreprocessor(new StringReader(text));

            foreach (IList <IHasWord> sentence in tokenizer)
            {
                IList <TaggedWord>   tagged = tagger.TagSentence(sentence);
                GrammaticalStructure gs     = parser.Predict(tagged);
                // Print typed dependencies
                log.Info(gs);
            }
        }