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);
        }
Ejemplo n.º 2
0
        // static methods
        /// <summary>
        /// Put the tree in the CoreMap for the sentence, also add any
        /// dependency graphs to the sentence, and fill in missing tag annotations.
        /// </summary>
        /// <remarks>
        /// Put the tree in the CoreMap for the sentence, also add any
        /// dependency graphs to the sentence, and fill in missing tag annotations.
        /// Thread safety note: nothing special is done to ensure the thread
        /// safety of the GrammaticalStructureFactory.  However, both the
        /// EnglishGrammaticalStructureFactory and the
        /// ChineseGrammaticalStructureFactory are thread safe.
        /// </remarks>
        public static void FillInParseAnnotations(bool verbose, bool buildGraphs, IGrammaticalStructureFactory gsf, ICoreMap sentence, IList <Tree> trees, GrammaticalStructure.Extras extras)
        {
            bool first = true;

            foreach (Tree tree in trees)
            {
                // make sure all tree nodes are CoreLabels
                // TODO: why isn't this always true? something fishy is going on
                Edu.Stanford.Nlp.Trees.Trees.ConvertToCoreLabels(tree);
                // index nodes, i.e., add start and end token positions to all nodes
                // this is needed by other annotators down stream, e.g., the NFLAnnotator
                tree.IndexSpans(0);
                if (first)
                {
                    sentence.Set(typeof(TreeCoreAnnotations.TreeAnnotation), tree);
                    if (verbose)
                    {
                        log.Info("Tree is:");
                        tree.PennPrint(System.Console.Error);
                    }
                    SetMissingTags(sentence, tree);
                    if (buildGraphs)
                    {
                        // generate the dependency graph
                        // unfortunately, it is necessary to make the
                        // GrammaticalStructure three times, as the dependency
                        // conversion changes the given data structure
                        SemanticGraph deps                 = SemanticGraphFactory.GenerateCollapsedDependencies(gsf.NewGrammaticalStructure(tree), extras);
                        SemanticGraph uncollapsedDeps      = SemanticGraphFactory.GenerateUncollapsedDependencies(gsf.NewGrammaticalStructure(tree), extras);
                        SemanticGraph ccDeps               = SemanticGraphFactory.GenerateCCProcessedDependencies(gsf.NewGrammaticalStructure(tree), extras);
                        SemanticGraph enhancedDeps         = SemanticGraphFactory.GenerateEnhancedDependencies(gsf.NewGrammaticalStructure(tree));
                        SemanticGraph enhancedPlusPlusDeps = SemanticGraphFactory.GenerateEnhancedPlusPlusDependencies(gsf.NewGrammaticalStructure(tree));
                        if (verbose)
                        {
                            log.Info("SDs:");
                            log.Info(deps.ToString(SemanticGraph.OutputFormat.List));
                        }
                        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);
                    }
                    first = false;
                }
            }
            if (trees.Count > 1)
            {
                sentence.Set(typeof(TreeCoreAnnotations.KBestTreesAnnotation), trees);
            }
        }
        /// <summary>Converts basic UD tree to enhanced++ UD graph.</summary>
        private static SemanticGraph ConvertBasicToEnhancedPlusPlus(SemanticGraph sg)
        {
            GrammaticalStructure gs = SemanticGraphToGrammaticalStructure(sg);

            return(SemanticGraphFactory.GenerateEnhancedPlusPlusDependencies(gs));
        }