Пример #1
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);
            }
        }
Пример #2
0
        public virtual void TestLemma()
        {
            SemanticGraph graph = SemanticGraph.ValueOf("[ate subj>Bill dobj>[muffins compound>blueberry]]");

            foreach (IndexedWord word in graph.VertexSet())
            {
                word.SetLemma(word.Word());
            }
            RunTest("{lemma:ate}", graph, "ate");
            Tree tree = Tree.ValueOf("(ROOT (S (NP (PRP I)) (VP (VBP love) (NP (DT the) (NN display))) (. .)))");

            graph = SemanticGraphFactory.GenerateCCProcessedDependencies(tree);
            foreach (IndexedWord word_1 in graph.VertexSet())
            {
                word_1.SetLemma(word_1.Word());
            }
            // This set of three tests also provides some coverage for a
            // bizarre error a user found where multiple copies of the same
            // IndexedWord were created
            RunTest("{}=Obj <dobj {lemma:love}=Pred", graph, "display/NN");
            RunTest("{}=Obj <dobj {}=Pred", graph, "display/NN");
            RunTest("{lemma:love}=Pred >dobj {}=Obj ", graph, "love/VBP");
        }