private void getTbSentences_Click(object sender, EventArgs e) { ClearList(); string mrgFile = null; try { mrgFile = mrgFileCombo.Text; mrgFile = mrgFile.Substring(0, mrgFile.IndexOf(' ')); mrgFile = _treeBankEngine.GetFullMrgPath(mrgFile); } catch (Exception) { MessageBox.Show("Invalid MRG file"); return; } try { foreach (int sentNum in _treeBankEngine.GetSentenceNumbers(mrgFile)) { AppendOutput(_treeBankEngine.GetParseTree(mrgFile, sentNum)); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
/// <summary> /// Marks argument nodes from the current node in the corresponding parse from a different TreeBank. This is used when /// transferring PropBank annotations to parse trees other than those distributed in the TreeBank (e.g., those produced /// by an automatic syntactic parser). /// </summary> /// <param name="treeBankEngine">Initialized TreeBank engine from which to pull the parse tree to mark PropBank arguments within</param> /// <returns>PropBank node, or null if all arguments couldn't be minimally transferred to the other parse tree. An argument /// is minimally transferred if the corresponding node in the other parse tree subsumes precisely the same text as the node in the /// current parse tree. Sometimes this is not possible due to parse errors.</returns> public PropBankNode MarkArgumentNodesIn(TreeBankEngine treeBankEngine) { if (!IsRoot) { throw new Exception("Attempted to transform non-root node"); } // get mrg file in other tree bank string treeBankMrgFile = treeBankEngine.GetFullMrgPath(MrgFile.Substring(MrgFile.LastIndexOf(Path.DirectorySeparatorChar) + 1)); // need a PropBank root to mark arguments within PropBankNode pbRoot = new PropBankNode(treeBankEngine.GetParseTree(treeBankMrgFile, SentenceNumber)); // make sure we got the right sentence if (pbRoot.SurfaceText != SurfaceText) { throw new Exception("Failed to convert root to Charniak-parsed version"); } // Add information to root. Ignore leaf number and argument info for now - we'll set them at the end. treeBankMrgFile = treeBankMrgFile.Substring(treeBankEngine.MrgPath.Length); VerbInfo pbInfo = Information; pbRoot.Information = new VerbInfo(pbInfo.Verb, treeBankMrgFile, pbInfo.SentenceNumber, -1, pbInfo.Tagger, pbInfo.RoleSetId, pbInfo.VForm, pbInfo.VTense, pbInfo.VAspect, pbInfo.VPerson, pbInfo.VVoice, ""); // transfer all argument node lists foreach (PropBankLabeledNodeCollection nodeCollection in LabeledNodeCollections) { // new node collection PropBankLabeledNodeCollection otherNodeCollection = new PropBankLabeledNodeCollection(new PropBankNodeLabel(nodeCollection.Label.Type, nodeCollection.Label.Feature, nodeCollection.Label.Confidence)); // get single nodes foreach (PropBankNode singleNode in nodeCollection.SingleNodes) { if (!singleNode.IsNullElement) { // get argument node from other parse tree PropBankNode otherArgNode = (PropBankNode)pbRoot.GetMinimallySubsumingNode(singleNode.FirstToken, singleNode.LastToken); if (otherArgNode == null) { return(null); } otherNodeCollection.AddSingleNode(otherArgNode); } } // get split arguments foreach (List <TreeBankNode> splitArg in nodeCollection.SplitNodes) { List <TreeBankNode> otherSplitArg = new List <TreeBankNode>(); // get each node in the split argument foreach (PropBankNode splitArgNode in splitArg) { if (!splitArgNode.IsNullElement) { // get split node in other tree PropBankNode otherSplitArgNode = (PropBankNode)pbRoot.GetMinimallySubsumingNode(splitArgNode.FirstToken, splitArgNode.LastToken); if (otherSplitArgNode == null) { return(null); } otherSplitArg.Add(otherSplitArgNode); } } // if only one node of the split arg was non-null, at that node as a single if (otherSplitArg.Count == 1) { otherNodeCollection.AddSingleNode(otherSplitArg.First()); } // otherwise, add the split arg normally else if (otherSplitArg.Count >= 2) { otherNodeCollection.AddSplitNode(otherSplitArg); } } // add coref list if we found non-null nodes if (otherNodeCollection.SingleNodes.Count > 0 || otherNodeCollection.SplitNodes.Count > 0) { pbRoot.LabeledNodeCollections.Add(otherNodeCollection); } } // return null if we didn't find any argument node lists with non-null nodes if (pbRoot.LabeledNodeCollections.Count == 0) { return(null); } // set leaf number and argument information pbRoot.Information.LeafNumber = pbRoot.PredicateNodes.First().Leaves[0].LeafNumber; pbRoot.Information.LabeledNodeLocations = pbRoot.LabeledNodeLocations; return(pbRoot); }
/// <summary> /// Marks argument nodes from the current node in the corresponding parse from a different TreeBank. This is used when /// transferring NomBank annotations to parse trees other than those distributed in the TreeBank (e.g., those produced /// by an automatic syntactic parser). /// </summary> /// <param name="treeBankEngine">Initialized TreeBank engine from which to pull the parse tree to mark NomBank arguments within</param> /// <returns>NomBank node, or null if all arguments couldn't be minimally transferred to the other parse tree. An argument /// is minimally transferred if the corresponding node in the other parse tree subsumes precisely the same text as the node /// in the current parse tree. Sometimes this is not possible due to parse errors.</returns> public NomBankNode MarkArgumentNodesIn(TreeBankEngine treeBankEngine) { // make sure we're marking arguments using a root node if (!IsRoot) { throw new Exception("Must pass root node"); } // get mrg file in other tree bank string treeBankMrgFile = treeBankEngine.GetFullMrgPath(MrgFile); // need a NomBank root to mark arguments within NomBankNode nbRoot = new NomBankNode(treeBankEngine.GetParseTree(treeBankMrgFile, SentenceNumber)); // make sure we got the right sentence if (nbRoot.SurfaceText != SurfaceText) { throw new Exception("Failed to get same parse tree"); } // Add information to root. Ignore leaf number and argument information - we'll set them at the end. treeBankMrgFile = treeBankMrgFile.Substring(treeBankEngine.MrgPath.Length).Trim(Path.DirectorySeparatorChar); NounInfo currInfo = Information; nbRoot.Information = new NounInfo(currInfo.Noun, treeBankMrgFile, currInfo.SentenceNumber, -1, currInfo.RoleSetId, ""); // transfer all argument node lists foreach (NomBankLabeledNodeCollection corefList in LabeledNodeCollections) { // new node list NomBankLabeledNodeCollection otherCorefList = new NomBankLabeledNodeCollection(corefList.Label.Copy()); // get single nodes foreach (NomBankNode singleNode in corefList.SingleNodes) { if (!singleNode.IsNullElement) { // get argument node from other parse tree NomBankNode otherArgNode = nbRoot.GetMinimallySubsumingNode(singleNode.FirstToken, singleNode.LastToken) as NomBankNode; if (otherArgNode == null) { return(null); } otherCorefList.AddSingleNode(otherArgNode); } } // get split arguments foreach (List <TreeBankNode> splitNode in corefList.SplitNodes) { List <TreeBankNode> otherSplitArg = new List <TreeBankNode>(); // get each node in the split argument foreach (NomBankNode node in splitNode) { if (!node.IsNullElement) { // get split node in other tree NomBankNode otherSplitArgNode = nbRoot.GetMinimallySubsumingNode(node.FirstToken, node.LastToken) as NomBankNode; if (otherSplitArgNode == null) { return(null); } otherSplitArg.Add(otherSplitArgNode); } } // if only one node of the split arg was non-null, at that node as a single if (otherSplitArg.Count == 1) { otherCorefList.AddSingleNode(otherSplitArg.First()); } // otherwise, add the split arg normally else if (otherSplitArg.Count >= 2) { otherCorefList.AddSplitNode(otherSplitArg); } } // make sure all hyphen indexes were applied if (otherCorefList.Label.HyphenIndexes.Count != otherCorefList.AppliedIndexes.Count) { throw new Exception("Not all hyphen indexes were applied"); } // add coref list if we found non-null nodes if (otherCorefList.SingleNodes.Count > 0 || otherCorefList.SplitNodes.Count > 0) { nbRoot.LabeledNodeCollections.Add(otherCorefList); } } // return null if we didn't find any argument node lists with non-null nodes if (nbRoot.LabeledNodeCollections.Count == 0) { return(null); } // set leaf number and argument locations in the information object nbRoot.Information.LeafNumber = nbRoot.PredicateNode.Leaves[0].LeafNumber; nbRoot.Information.LabeledNodeLocations = nbRoot.LabeledNodeLocations; return(nbRoot); }