Exemplo n.º 1
0
        /// <summary>
        /// Removes a label from this node
        /// </summary>
        /// <param name="label">Label to remove</param>
        public void RemoveLabel(NomBankNodeLabel label)
        {
            _labels.Remove(label);

            // remove from root node collection if it is present
            NomBankLabeledNodeCollection nodes = GetLabeledNodeCollection(label, false);

            if (nodes != null && nodes.ContainsSingleNode(this))
            {
                nodes.RemoveSingleNode(this);
            }
        }
        /// <summary>
        /// Gets a copy of this collection
        /// </summary>
        /// <returns>Copy of this collection</returns>
        public override LabeledNodeCollection Copy()
        {
            // create copy
            NomBankLabeledNodeCollection copy = new NomBankLabeledNodeCollection(_label.Copy());

            // 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);
        }
Exemplo n.º 3
0
        /// <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 NomBankLabeledNodeCollection GetLabeledNodeCollection(NomBankNodeLabel label, bool createIfMissing)
        {
            // look for an existing collection with the given label
            foreach (NomBankLabeledNodeCollection nodeCollection in LabeledNodeCollections)
            {
                if (nodeCollection.Label == label)
                {
                    return(nodeCollection);
                }
            }

            if (!createIfMissing)
            {
                return(null);
            }

            // return new collection
            NomBankLabeledNodeCollection newCollection = new NomBankLabeledNodeCollection(label);

            LabeledNodeCollections.Add(newCollection);

            return(newCollection);
        }
Exemplo n.º 4
0
        /// <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);
        }