/// <summary>
        /// Gets a copy of this collection
        /// </summary>
        /// <returns>Copy of this collection</returns>
        public override LabeledNodeCollection Copy()
        {
            // create copy
            PropBankLabeledNodeCollection copy = new PropBankLabeledNodeCollection(new PropBankNodeLabel(_label.Type, _label.Feature, _label.Confidence));

            // add single nodes
            foreach (TreeBankNode singleNode in SingleNodes)
            {
                copy.AddSingleNode(singleNode);
            }

            // add split nodes
            foreach (List <TreeBankNode> splitNode in SplitNodes)
            {
                copy.AddSplitNode(splitNode);
            }

            return(copy);
        }
Пример #2
0
        /// <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);
        }