예제 #1
0
 /// <summary>
 /// Copies particular labels from the current node to corresponding nodes in another tree
 /// </summary>
 /// <param name="n">Tree to which to copy labels</param>
 /// <param name="labels">Labels to copy</param>
 public void CopyLabelsTo(NomBankNode n, params NomBankNodeLabel[] labels)
 {
     foreach (NomBankNodeLabel label in labels)
     {
         foreach (NomBankNode fromNode in GetDescendants(label))
         {
             int         startToken = fromNode.FirstToken.TokenNumber;
             int         endToken   = fromNode.LastToken.TokenNumber;
             NomBankNode toNode     = n.GetLowestCommonAncestorOfTokens(startToken, endToken) as NomBankNode;
             toNode.AddLabel(label.Copy(), true);
         }
     }
 }
        /// <summary>
        /// Applies the current type to a node, or does nothing if the node already has the type
        /// </summary>
        /// <param name="n">Node to apply type to</param>
        private void ApplyType(NomBankNode n)
        {
            // don't reapply type
            if (n.HasLabel(_label))
            {
                return;
            }

            // add label without hyphen indexes, and don't bother synching with root collection (this collection will be added to the root)
            NomBankNodeLabel label = _label.Copy();

            label.HyphenIndexes.Clear();
            n.AddLabel(label, false);

            // only apply hyphen indexes to text with a hyphen or slash
            string nodeText = n.SurfaceText;

            char[] hyphenSlash = new char[] { '-', '/' };
            if (nodeText.IndexOfAny(hyphenSlash) == -1)
            {
                return;
            }

            // try to apply each hyphen index
            foreach (NomBankNodeLabel.HyphenationIndex hyphenIndex in _label.HyphenIndexes)
            {
                int numParts = nodeText.Split(hyphenSlash, StringSplitOptions.RemoveEmptyEntries).Length;

                // get numeric hyphen index
                int index = int.Parse(hyphenIndex.ToString().Substring(1));

                // add index to node's label if applicable
                if (index < numParts)
                {
                    if (_appliedIndexes.Contains(hyphenIndex))
                    {
                        throw new Exception("Hyphen index applied more than once");
                    }

                    label.AddHyphenIndex(hyphenIndex);
                    _appliedIndexes.Add(hyphenIndex);
                }
            }
        }