continue; //ignore terms without readings
}
//Add the LexicalEntry as Token to the Text. NOTE that if a
//Token with the same start/end positions already exist this
//Method returns the existing instance
Token token = at.addToken(term.getFrom(), term.getTo());
//Now try to get POS annotations for the Token
for(Value<PosTag> posAnno : token.getAnnotations(NlpAnnotations.POS_ANNOTATION)){
if(posAnno.value().isMapped()){
for(LexicalCategory cat :posAnno.value().getCategories()){
if(!tokenLexCats.containsKey(cat)){ //do not override with lover prob
tokenLexCats.put(cat, posAnno.probability());
}
}
}
}
for(Reading reading : term.getTermReadings()){
MorphoFeatures mf = CeliMorphoFeatures.parseFrom(reading, language);
//add the readings (MorphoFeatures)
if(mf != null){
//use the POS tags of the morpho analysis and compare it
//with existing POS tags.
double posProbability = -1;
Set<LexicalCategory> mfCats = EnumSet.noneOf(LexicalCategory.class);
for(PosTag mfPos : mf.getPosList()){
mfCats.addAll(mfPos.getCategories());
}
for(LexicalCategory mfCat : mfCats){
Double prob = tokenLexCats.get(mfCat);
if(prob != null && posProbability < prob){
posProbability = prob;
}
}
//add the morpho features with the posProbabiliy
Value<MorphoFeatures> value = Value.value(mf,
posProbability < 0 ? Value.UNKNOWN_PROBABILITY : posProbability);
token.addAnnotation(NlpAnnotations.MORPHO_ANNOTATION, value);
}
}
}
}