public override Tree TransformTree(Tree t, Tree root)
        {
            // Perform tregex-powered annotations
            t = base.TransformTree(t, root);
            string cat = t.Value();

            //Add morphosyntactic features if this is a POS tag
            if (t.IsPreTerminal() && tagSpec != null)
            {
                if (!(t.FirstChild().Label() is CoreLabel) || ((CoreLabel)t.FirstChild().Label()).OriginalText() == null)
                {
                    throw new Exception(string.Format("%s: Term lacks morpho analysis: %s", this.GetType().FullName, t.ToString()));
                }
                string morphoStr = ((CoreLabel)t.FirstChild().Label()).OriginalText();
                Pair <string, string> lemmaMorph = MorphoFeatureSpecification.SplitMorphString(string.Empty, morphoStr);
                MorphoFeatures        feats      = tagSpec.StrToFeatures(lemmaMorph.Second());
                cat = feats.GetTag(cat);
            }
            //Update the label(s)
            t.SetValue(cat);
            if (t.IsPreTerminal() && t.Label() is IHasTag)
            {
                ((IHasTag)t.Label()).SetTag(cat);
            }
            return(t);
        }
예제 #2
0
        /// <summary>First map to the LDC short tags.</summary>
        /// <remarks>
        /// First map to the LDC short tags. Then map to the Universal POS. Then add
        /// morphological annotations.
        /// </remarks>
        public override string Map(string posTag, string terminal)
        {
            string rawTag   = posTag.Trim();
            string shortTag = tagsToEscape.Contains(rawTag) ? rawTag : tagMap[rawTag];

            if (shortTag == null)
            {
                System.Console.Error.Printf("%s: No LDC shortened tag for %s%n", this.GetType().FullName, rawTag);
                return(rawTag);
            }
            string universalTag = universalMap[shortTag];

            if (!universalMap.Contains(shortTag))
            {
                System.Console.Error.Printf("%s: No universal tag for LDC tag %s%n", this.GetType().FullName, shortTag);
                universalTag = shortTag;
            }
            MorphoFeatures feats         = new MorphoFeatures(morphoSpec.StrToFeatures(rawTag));
            string         functionalTag = feats.GetTag(universalTag);

            return(functionalTag);
        }