Exemplo n.º 1
0
        /// <summary>
        /// Gets a deep copy of this label
        /// </summary>
        /// <returns>Deep copy of this label</returns>
        public NomBankNodeLabel Copy()
        {
            NomBankNodeLabel copied = new NomBankNodeLabel(_type, _feature, _confidence);

            foreach (HyphenationIndex hyphenIndex in _hyphenIndexes)
            {
                copied.AddHyphenIndex(hyphenIndex);
            }

            return(copied);
        }
        /// <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);
                }
            }
        }