use of org.apache.stanbol.enhancer.nlp.dependency.GrammaticalRelation in project stanbol by apache.
the class DependencyRelationSupport method parse.
@Override
public DependencyRelation parse(ObjectNode jDependencyRelation, AnalysedText at) {
JsonNode tag = jDependencyRelation.path(RELATION_TYPE_TAG);
if (!tag.isTextual()) {
throw new IllegalStateException("Unable to parse GrammaticalRelationTag. The value of the " + "'tag' field MUST have a textual value (json: " + jDependencyRelation + ")");
}
GrammaticalRelation grammaticalRelation = GrammaticalRelation.class.getEnumConstants()[jDependencyRelation.path(RELATION_STANBOL_TYPE_TAG).asInt()];
GrammaticalRelationTag gramRelTag = new GrammaticalRelationTag(tag.getTextValue(), grammaticalRelation);
JsonNode isDependent = jDependencyRelation.path(RELATION_IS_DEPENDENT_TAG);
if (!isDependent.isBoolean()) {
throw new IllegalStateException("Field 'isDependent' must have a true/false format");
}
Span partnerSpan = null;
String typeString = jDependencyRelation.path(RELATION_PARTNER_TYPE_TAG).getTextValue();
if (!typeString.equals(ROOT_TAG)) {
SpanTypeEnum spanType = SpanTypeEnum.valueOf(jDependencyRelation.path(RELATION_PARTNER_TYPE_TAG).getTextValue());
int spanStart = jDependencyRelation.path(RELATION_PARTNER_START_TAG).asInt();
int spanEnd = jDependencyRelation.path(RELATION_PARTNER_END_TAG).asInt();
switch(spanType) {
case Chunk:
partnerSpan = at.addChunk(spanStart, spanEnd);
break;
// break;
case Token:
partnerSpan = at.addToken(spanStart, spanEnd);
break;
}
}
return new DependencyRelation(gramRelTag, isDependent.asBoolean(), partnerSpan);
}
Aggregations