/// <summary> /// Constructor. WARNING: this will accept an instance of any class derived from TreeBankNode (e.g., PropBankNode), but /// will return a PropBankNode with only TreeBankNode members instantiated. /// </summary> /// <param name="treeBankNode">TreeBankNode from which to construct this PropBankNode</param> /// <param name="parent">Parent of this PropBank node</param> protected PropBankNode(TreeBankNode treeBankNode, PropBankNode parent) : base(treeBankNode, parent, new TreeBankNodeConstructor(PropBankChildConstructor)) { _label = null; _information = null; _labeledNodeCollections = new List <PropBankLabeledNodeCollection>(); }
/// <summary> /// Gets whether or not this PropBankNodeLabel equals another object /// </summary> /// <param name="obj">Object to compare this one with</param> /// <returns>True if the other object is a PropBankNodeLabel and is equal to this one, false otherwise</returns> public override bool Equals(object obj) { if (!(obj is PropBankNodeLabel)) { return(false); } PropBankNodeLabel label = obj as PropBankNodeLabel; return(_type == label.Type && _feature == label.Feature); }
/// <summary> /// Sets the label on this node /// </summary> /// <param name="label">Label to use</param> /// <param name="syncWithRootNodeCollection">Whether or not to add this node to the corresponding node collection on the root. The /// root collections are shortcut collections that allow quick searching for particular node types. Thus, the collections need to /// remain synchronized with the labels that are applied to the nodes. Passing true here will perform this synchronization. If you /// will do the synchronization on your own later, pass false.</param> public void SetLabel(PropBankNodeLabel label, bool syncWithRootNodeCollection) { // first remove current node from previous node collection if it is present if (_label != null) { PropBankLabeledNodeCollection nodes = GetLabeledNodeCollection(label, false); if (nodes != null && nodes.ContainsSingleNode(this)) { nodes.RemoveSingleNode(this); } } _label = label; // add node to root's collection if needed if (syncWithRootNodeCollection) { GetLabeledNodeCollection(_label, true).AddSingleNode(this); } }
/// <summary> /// Gets labeled node collection /// </summary> /// <param name="label">Label of node collection to get</param> /// <param name="createIfMissing">Whether or not to create and return a new node collection if none exists</param> /// <returns>Labeled node collection</returns> public PropBankLabeledNodeCollection GetLabeledNodeCollection(PropBankNodeLabel label, bool createIfMissing) { // look for an existing collection with the given label foreach (PropBankLabeledNodeCollection nodeCollection in LabeledNodeCollections) { if (nodeCollection.Label == label) { return(nodeCollection); } } if (!createIfMissing) { return(null); } // return new collection PropBankLabeledNodeCollection newCollection = new PropBankLabeledNodeCollection(label); LabeledNodeCollections.Add(newCollection); return(newCollection); }
/// <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); }
/// <summary> /// Constructor /// </summary> /// <param name="label">Label for this collection</param> public PropBankLabeledNodeCollection(PropBankNodeLabel label) { _label = label; }