/// <summary> /// Gets the set of roles not filled. Numbers in the set correspond to the argument positions in the frame file for the /// current verbal predicate. Only valid for root nodes. /// </summary> /// <param name="considerNullElementNodes">Whether or not to consider null-element nodes when checking whether a role is filled</param> public Set <int> GetUnfilledRoles(bool considerNullElementNodes) { if (!IsRoot) { throw new Exception("Not valid for non-root nodes"); } Set <int> unfilledRoles = new Set <int>(); /* check for a node that fills each role in the set. some annotations in propbank don't * have a role set specified, so we can't determine which roles are unfilled.*/ if (RoleSet != null) { foreach (Role role in RoleSet) { bool filled = false; PropBankNodeLabel.NodeType argType = (PropBankNodeLabel.NodeType)Enum.Parse(typeof(PropBankNodeLabel.NodeType), "Arg" + role.Number); foreach (PropBankNode node in GetDescendants(argType)) { if (!node.IsNullElement || considerNullElementNodes) { filled = true; break; } } if (!filled) { unfilledRoles.Add(role.Number); } } } return(unfilledRoles); }
/// <summary> /// Gets descendant nodes by their type /// </summary> /// <param name="type">Type of node to get</param> /// <returns>Descendant nodes</returns> public List <PropBankNode> GetDescendants(PropBankNodeLabel.NodeType type) { List <PropBankNode> nodes = new List <PropBankNode>(); foreach (PropBankNode n in Descendants) { if (n.Label != null && n.Label.Type == type) { 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); }