use of edu.stanford.nlp.international.morph.MorphoFeatures in project CoreNLP by stanfordnlp.
the class SplitCanditoTrees method replacePOSTags.
private static void replacePOSTags(Tree tree) {
List<Label> yield = tree.yield();
List<Label> preYield = tree.preTerminalYield();
assert yield.size() == preYield.size();
MorphoFeatureSpecification spec = new FrenchMorphoFeatureSpecification();
for (int i = 0; i < yield.size(); i++) {
// Morphological Analysis
String morphStr = ((CoreLabel) yield.get(i)).originalText();
if (morphStr == null || morphStr.equals("")) {
morphStr = preYield.get(i).value();
// POS subcategory
String subCat = ((CoreLabel) yield.get(i)).category();
if (subCat != null && subCat != "") {
morphStr += "-" + subCat + "--";
} else {
morphStr += "---";
}
}
MorphoFeatures feats = spec.strToFeatures(morphStr);
if (feats.getAltTag() != null && !feats.getAltTag().equals("")) {
CoreLabel cl = (CoreLabel) preYield.get(i);
cl.setValue(feats.getAltTag());
cl.setTag(feats.getAltTag());
}
}
}
use of edu.stanford.nlp.international.morph.MorphoFeatures in project CoreNLP by stanfordnlp.
the class FrenchMorphoFeatureSpecification method strToFeatures.
@Override
public MorphoFeatures strToFeatures(String spec) {
MorphoFeatures feats = new MorphoFeatures();
//Usually this is the boundary symbol
if (spec == null || spec.equals(""))
return feats;
boolean isOtherActive = isActive(MorphoFeatureType.OTHER);
if (spec.startsWith("ADV")) {
feats.setAltTag("ADV");
if (spec.contains("int")) {
if (isOtherActive) {
feats.addFeature(MorphoFeatureType.OTHER, "advint");
}
feats.setAltTag("ADVWH");
}
} else if (spec.startsWith("A")) {
feats.setAltTag("ADJ");
if (spec.contains("int")) {
if (isOtherActive) {
feats.addFeature(MorphoFeatureType.OTHER, "adjint");
}
feats.setAltTag("ADJWH");
}
addPhiFeatures(feats, spec);
} else if (spec.equals("CC") || spec.equals("C-C")) {
if (isOtherActive) {
feats.addFeature(MorphoFeatureType.OTHER, "Cc");
}
feats.setAltTag("CC");
} else if (spec.equals("CS") || spec.equals("C-S")) {
if (isOtherActive) {
feats.addFeature(MorphoFeatureType.OTHER, "Cs");
}
feats.setAltTag("CS");
} else if (spec.startsWith("CL")) {
feats.setAltTag("CL");
if (spec.contains("suj") || spec.equals("CL-S-3fp")) {
//"CL-S-3fp" is equivalent to suj
if (isOtherActive) {
feats.addFeature(MorphoFeatureType.OTHER, "Sbj");
}
feats.setAltTag("CLS");
} else if (spec.contains("obj")) {
if (isOtherActive) {
feats.addFeature(MorphoFeatureType.OTHER, "Obj");
}
feats.setAltTag("CLO");
} else if (spec.contains("refl")) {
if (isOtherActive) {
feats.addFeature(MorphoFeatureType.OTHER, "Rfl");
}
feats.setAltTag("CLR");
}
addPhiFeatures(feats, spec);
} else if (spec.startsWith("D")) {
feats.setAltTag("DET");
if (spec.contains("int")) {
if (isOtherActive) {
feats.addFeature(MorphoFeatureType.OTHER, "dint");
}
feats.setAltTag("DETWH");
}
addPhiFeatures(feats, spec);
} else if (spec.startsWith("N")) {
//TODO These are usually N-card...make these CD?
feats.setAltTag("N");
if (spec.contains("P")) {
if (isOtherActive) {
feats.addFeature(MorphoFeatureType.OTHER, "Np");
}
feats.setAltTag("NPP");
} else if (spec.contains("C")) {
if (isOtherActive) {
feats.addFeature(MorphoFeatureType.OTHER, "Nc");
}
feats.setAltTag("NC");
}
addPhiFeatures(feats, spec);
} else if (spec.startsWith("PRO")) {
feats.setAltTag("PRO");
if (spec.contains("int")) {
if (isOtherActive) {
feats.addFeature(MorphoFeatureType.OTHER, "Ni");
}
feats.setAltTag("PROWH");
} else if (spec.contains("rel")) {
if (isOtherActive) {
feats.addFeature(MorphoFeatureType.OTHER, "Nr");
}
feats.setAltTag("PROREL");
}
addPhiFeatures(feats, spec);
} else if (spec.startsWith("V")) {
feats.setAltTag("V");
if (spec.contains("Y")) {
if (isOtherActive) {
feats.addFeature(MorphoFeatureType.OTHER, "Vp");
}
feats.setAltTag("VIMP");
} else if (spec.contains("W")) {
if (isOtherActive) {
feats.addFeature(MorphoFeatureType.OTHER, "Vf");
}
feats.setAltTag("VINF");
} else if (spec.contains("S") || spec.contains("T")) {
if (isOtherActive) {
feats.addFeature(MorphoFeatureType.OTHER, "Vs");
}
feats.setAltTag("VS");
} else if (spec.contains("K")) {
if (isOtherActive) {
feats.addFeature(MorphoFeatureType.OTHER, "Vp");
}
feats.setAltTag("VPP");
} else if (spec.contains("G")) {
if (isOtherActive) {
feats.addFeature(MorphoFeatureType.OTHER, "Vr");
}
feats.setAltTag("VPR");
}
addPhiFeatures(feats, spec);
} else if (spec.equals("P") || spec.equals("I")) {
feats.setAltTag(spec);
}
return feats;
}
use of edu.stanford.nlp.international.morph.MorphoFeatures in project CoreNLP by stanfordnlp.
the class UniversalPOSMapper method map.
/**
* First map to the LDC short tags. Then map to the Universal POS. Then add
* morphological annotations.
*/
@Override
public String map(String posTag, String terminal) {
String rawTag = posTag.trim();
String shortTag = tagsToEscape.contains(rawTag) ? rawTag : tagMap.get(rawTag);
if (shortTag == null) {
System.err.printf("%s: No LDC shortened tag for %s%n", this.getClass().getName(), rawTag);
return rawTag;
}
String universalTag = universalMap.get(shortTag);
if (!universalMap.containsKey(shortTag)) {
System.err.printf("%s: No universal tag for LDC tag %s%n", this.getClass().getName(), shortTag);
universalTag = shortTag;
}
MorphoFeatures feats = new MorphoFeatures(morphoSpec.strToFeatures(rawTag));
String functionalTag = feats.getTag(universalTag);
return functionalTag;
}
use of edu.stanford.nlp.international.morph.MorphoFeatures in project CoreNLP by stanfordnlp.
the class FrenchTreebankParserParams method transformTree.
@Override
public Tree transformTree(Tree t, Tree root) {
// Perform tregex-powered annotations
t = super.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() instanceof CoreLabel) || ((CoreLabel) t.firstChild().label()).originalText() == null)
throw new RuntimeException(String.format("%s: Term lacks morpho analysis: %s", this.getClass().getName(), t.toString()));
String morphoStr = ((CoreLabel) t.firstChild().label()).originalText();
Pair<String, String> lemmaMorph = MorphoFeatureSpecification.splitMorphString("", morphoStr);
MorphoFeatures feats = tagSpec.strToFeatures(lemmaMorph.second());
cat = feats.getTag(cat);
}
//Update the label(s)
t.setValue(cat);
if (t.isPreTerminal() && t.label() instanceof HasTag)
((HasTag) t.label()).setTag(cat);
return t;
}
use of edu.stanford.nlp.international.morph.MorphoFeatures in project CoreNLP by stanfordnlp.
the class ArabicTreebankParserParams method transformTree.
@Override
public Tree transformTree(Tree t, Tree root) {
String baseCat = t.value();
StringBuilder newCategory = new StringBuilder();
//Add manual state splits
for (Pair<TregexPattern, Function<TregexMatcher, String>> e : activeAnnotations) {
TregexMatcher m = e.first().matcher(root);
if (m.matchesAt(t))
newCategory.append(e.second().apply(m));
}
//Add morphosyntactic features if this is a POS tag
if (t.isPreTerminal() && tagSpec != null) {
if (!(t.firstChild().label() instanceof CoreLabel) || ((CoreLabel) t.firstChild().label()).originalText() == null)
throw new RuntimeException(String.format("%s: Term lacks morpho analysis: %s", this.getClass().getName(), t.toString()));
String morphoStr = ((CoreLabel) t.firstChild().label()).originalText();
MorphoFeatures feats = tagSpec.strToFeatures(morphoStr);
baseCat = feats.getTag(baseCat);
}
//Update the label(s)
String newCat = baseCat + newCategory.toString();
t.setValue(newCat);
if (t.isPreTerminal() && t.label() instanceof HasTag)
((HasTag) t.label()).setTag(newCat);
return t;
}
Aggregations