Ejemplo n.º 1
0
        /// <summary>
        /// Given a
        /// <c>Tree</c>
        /// node
        /// <paramref name="t"/>
        /// , attempts to
        /// return a list of nodes to which node
        /// <paramref name="t"/>
        /// has this
        /// grammatical relation, with
        /// <paramref name="t"/>
        /// as the governor.
        /// </summary>
        /// <param name="t">Target for finding dependents of t related by this GR</param>
        /// <param name="root">The root of the Tree</param>
        /// <returns>A Collection of dependent nodes to which t bears this GR</returns>
        public virtual ICollection <TreeGraphNode> GetRelatedNodes(TreeGraphNode t, TreeGraphNode root, IHeadFinder headFinder)
        {
            ICollection <TreeGraphNode> nodeList = new ArraySet <TreeGraphNode>();

            foreach (TregexPattern p in targetPatterns)
            {
                // cdm: I deleted: && nodeList.isEmpty()
                // Initialize the TregexMatcher with the HeadFinder so that we
                // can use the same HeadFinder through the entire process of
                // building the dependencies
                TregexMatcher m = p.Matcher(root, headFinder);
                while (m.FindAt(t))
                {
                    TreeGraphNode target = (TreeGraphNode)m.GetNode("target");
                    if (target == null)
                    {
                        throw new AssertionError("Expression has no target: " + p);
                    }
                    nodeList.Add(target);
                    if (Debug)
                    {
                        log.Info("found " + this + "(" + t + "-" + t.HeadWordNode() + ", " + m.GetNode("target") + "-" + ((TreeGraphNode)m.GetNode("target")).HeadWordNode() + ") using pattern " + p);
                        foreach (string nodeName in m.GetNodeNames())
                        {
                            if (nodeName.Equals("target"))
                            {
                                continue;
                            }
                            log.Info("  node " + nodeName + ": " + m.GetNode(nodeName));
                        }
                    }
                }
            }
            return(nodeList);
        }
 /// <summary>Just for testing.</summary>
 public static void Main(string[] args)
 {
     try
     {
         ITreeReader tr = new PennTreeReader(new StringReader("(S (NP (NNP Sam)) (VP (VBD died) (NP (NN today))))"), new LabeledScoredTreeFactory());
         Tree        t  = tr.ReadTree();
         System.Console.Out.WriteLine(t);
         TreeGraphNode tgn = new TreeGraphNode(t, (TreeGraphNode)null);
         System.Console.Out.WriteLine(tgn.ToPrettyString(0));
         EnglishGrammaticalStructure gs = new EnglishGrammaticalStructure(tgn);
         System.Console.Out.WriteLine(tgn.ToPrettyString(0));
         tgn.PercolateHeads(new SemanticHeadFinder());
         System.Console.Out.WriteLine(tgn.ToPrettyString(0));
     }
     catch (Exception e)
     {
         log.Error("Horrible error: " + e);
         log.Error(e);
     }
 }
 public GraphLessGrammaticalStructure(IList <TypedDependency> projectiveDependencies, TreeGraphNode root)
     : base(projectiveDependencies, root)
 {
 }
 public virtual GrammaticalStructure Build(IList <TypedDependency> projectiveDependencies, TreeGraphNode root)
 {
     return(new GraphLessGrammaticalStructure(projectiveDependencies, root));
 }