private static void ReplacePOSTags(Tree tree) { IList <ILabel> yield = tree.Yield(); IList <ILabel> preYield = tree.PreTerminalYield(); System.Diagnostics.Debug.Assert(yield.Count == preYield.Count); MorphoFeatureSpecification spec = new FrenchMorphoFeatureSpecification(); for (int i = 0; i < yield.Count; i++) { // Morphological Analysis string morphStr = ((CoreLabel)yield[i]).OriginalText(); if (morphStr == null || morphStr.Equals(string.Empty)) { morphStr = preYield[i].Value(); // POS subcategory string subCat = ((CoreLabel)yield[i]).Category(); if (subCat != null && subCat != string.Empty) { morphStr += "-" + subCat + "--"; } else { morphStr += "---"; } } MorphoFeatures feats = spec.StrToFeatures(morphStr); if (feats.GetAltTag() != null && !feats.GetAltTag().Equals(string.Empty)) { CoreLabel cl = (CoreLabel)preYield[i]; cl.SetValue(feats.GetAltTag()); cl.SetTag(feats.GetAltTag()); } } }
private static void ReplacePOSTag(Tree t, MorphoFeatureSpecification morpho) { if (!t.IsPreTerminal()) { throw new ArgumentException("Can only operate on preterminals"); } if (!(t.Label() is CoreLabel)) { throw new ArgumentException("Only operates on CoreLabels"); } CoreLabel label = (CoreLabel)t.Label(); Tree child = t.Children()[0]; if (!(child.Label() is CoreLabel)) { throw new ArgumentException("Only operates on CoreLabels"); } CoreLabel childLabel = (CoreLabel)child.Label(); // Morphological Analysis string morphStr = childLabel.OriginalText(); if (morphStr == null || morphStr.Equals(string.Empty)) { morphStr = label.Value(); // POS subcategory string subCat = childLabel.Category(); if (subCat != null && subCat != string.Empty) { morphStr += "-" + subCat + "--"; } else { morphStr += "---"; } } MorphoFeatures feats = morpho.StrToFeatures(morphStr); if (feats.GetAltTag() != null && !feats.GetAltTag().Equals(string.Empty)) { label.SetValue(feats.GetAltTag()); label.SetTag(feats.GetAltTag()); } }