Example #1
0
        /// <summary>TODO: figure out how to specify where in the sentence this node goes.</summary>
        /// <remarks>
        /// TODO: figure out how to specify where in the sentence this node goes.
        /// TODO: determine if we should be copying an IndexedWord, or working just with a FeatureLabel.
        /// TODO: bombproof if this gov, dep, and reln already exist.
        /// </remarks>
        public override void Evaluate(SemanticGraph sg, SemgrexMatcher sm)
        {
            IndexedWord govNode  = sm.GetNode(govNodeName);
            IndexedWord newNode  = new IndexedWord(newNodePrototype);
            int         newIndex = SemanticGraphUtils.LeftMostChildVertice(govNode, sg).Index();

            // cheap En-specific hack for placing copula (beginning of governing phrase)
            newNode.SetDocID(govNode.DocID());
            newNode.SetIndex(newIndex);
            newNode.SetSentIndex(govNode.SentIndex());
            sg.AddVertex(newNode);
            sg.AddEdge(govNode, newNode, relation, weight, false);
        }
Example #2
0
        public override void Evaluate(SemanticGraph sg, SemgrexMatcher sm)
        {
            IndexedWord rootNode = this.GetNamedNode(rootName, sm);
            ICollection <IndexedWord> subgraphNodeSet = sg.GetSubgraphVertices(rootNode);

            if (!sg.IsDag(rootNode))
            {
                /* Check if there is a cycle going back to the root. */
                foreach (IndexedWord child in sg.GetChildren(rootNode))
                {
                    ICollection <IndexedWord> reachableSet = sg.GetSubgraphVertices(child);
                    if (reachableSet.Contains(rootNode))
                    {
                        throw new ArgumentException("Subtree cannot contain cycle leading back to root node!");
                    }
                }
            }
            IList <IndexedWord> sortedSubgraphNodes = Generics.NewArrayList(subgraphNodeSet);

            sortedSubgraphNodes.Sort();
            IndexedWord newNode = new IndexedWord(rootNode.DocID(), rootNode.SentIndex(), rootNode.Index());

            /* Copy all attributes from rootNode. */
            foreach (Type key in newNode.BackingLabel().KeySet())
            {
                newNode.Set(key, rootNode.Get(key));
            }
            newNode.SetValue(StringUtils.Join(sortedSubgraphNodes.Stream().Map(null), " "));
            newNode.SetWord(StringUtils.Join(sortedSubgraphNodes.Stream().Map(null), " "));
            newNode.SetLemma(StringUtils.Join(sortedSubgraphNodes.Stream().Map(null), " "));
            if (sg.GetRoots().Contains(rootNode))
            {
                sg.GetRoots().Remove(rootNode);
                sg.AddRoot(rootNode);
            }
            foreach (SemanticGraphEdge edge in sg.IncomingEdgeIterable(rootNode))
            {
                sg.AddEdge(edge.GetGovernor(), newNode, edge.GetRelation(), edge.GetWeight(), edge.IsExtra());
            }
            foreach (IndexedWord node in sortedSubgraphNodes)
            {
                sg.RemoveVertex(node);
            }
        }
Example #3
0
            private static Pair <IndexedWord, GrammaticalRelation> GetGovAndReln(int govIdx, int copyCount, IndexedWord word, string relationName, IList <IndexedWord> sortedTokens)
            {
                IndexedWord         gov;
                GrammaticalRelation reln;

                if (relationName.Equals("root"))
                {
                    reln = GrammaticalRelation.Root;
                }
                else
                {
                    reln = GrammaticalRelation.ValueOf(Language.UniversalEnglish, relationName);
                }
                if (govIdx == 0)
                {
                    gov = new IndexedWord(word.DocID(), word.SentIndex(), 0);
                    gov.SetValue("ROOT");
                }
                else
                {
                    gov = CoNLLUDocumentReader.SentenceProcessor.GetToken(sortedTokens, govIdx, copyCount);
                }
                return(Generics.NewPair(gov, reln));
            }