Exemple #1
0
        /// <summary>
        /// Gets descendant nodes by their feature
        /// </summary>
        /// <param name="feature">Feature of nodes to get</param>
        /// <returns>Nodes with given feature</returns>
        public List <PropBankNode> GetDescendants(PropBankNodeLabel.NodeFeature feature)
        {
            List <PropBankNode> nodes = new List <PropBankNode>();

            foreach (PropBankNode n in Descendants)
            {
                if (n.Label.Feature == feature)
                {
                    nodes.Add(n);
                }
            }

            return(nodes);
        }
        /// <summary>
        /// Gets a predicate tree for a PropBank propositions entry
        /// </summary>
        /// <param name="vi">VerbInfo specifying tree to look up</param>
        /// <returns>PropBankNode</returns>
        public PropBankNode GetPropBankTree(VerbInfo vi)
        {
            TreeBankNode parse    = GetParseTree(vi.File, vi.SentenceNumber);
            PropBankNode predTree = new PropBankNode(parse);

            predTree.Information = vi;

            // label information is space-delimited
            string[] labels = vi.LabeledNodeLocations.Split(' ');
            foreach (string label in labels)
            {
                // label columns are dash-delimited
                string[] labelCols = label.Split('-');

                // get label type
                PropBankNodeLabel.NodeType labelType = PropBankNodeLabel.GetNodeType(labelCols[1]);

                // get label feature if any
                PropBankNodeLabel.NodeFeature labelFeature = PropBankNodeLabel.NodeFeature.None;
                if (labelCols.Length > 2)
                {
                    // sometimes the feature is the actual preposition, so this might fail
                    string featureStr = labelCols[2];
                    if (!PropBankNodeLabel.TryGetNodeFeature(featureStr, out labelFeature))
                    {
                        // use PRP as the feature, which we have added for this case
                        featureStr   = "PRP";
                        labelFeature = PropBankNodeLabel.GetNodeFeature(featureStr);
                    }

                    if (labelCols.Length > 3)
                    {
                        throw new Exception("Missed feature");
                    }
                }

                // create new labeled node collection
                PropBankLabeledNodeCollection labeledNodes = new PropBankLabeledNodeCollection(new PropBankNodeLabel(labelType, labelFeature, 1));
                AddNodesToCollection(predTree, labelCols[0], labeledNodes);

                // add to root's list of nodes
                predTree.LabeledNodeCollections.Add(labeledNodes);
            }

            // make sure one of the predicate leaves has the leaf number from the propositions file entry
            bool foundMatch = false;

            foreach (PropBankNode predicateNode in predTree.PredicateNodes)
            {
                foreach (PropBankNode leaf in predicateNode.Leaves)
                {
                    if (leaf.LeafNumber == vi.LeafNumber)
                    {
                        foundMatch = true;
                        break;
                    }
                }

                if (foundMatch)
                {
                    break;
                }
            }

            if (!foundMatch)
            {
                throw new Exception("Mismatch between VerbInfo predicate leaf number and actual predicate leaf number");
            }

            return(predTree);
        }