Search in sources :

Example 1 with GrammaticalRelation

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);
}
Also used : SpanTypeEnum(org.apache.stanbol.enhancer.nlp.model.SpanTypeEnum) GrammaticalRelation(org.apache.stanbol.enhancer.nlp.dependency.GrammaticalRelation) JsonNode(org.codehaus.jackson.JsonNode) GrammaticalRelationTag(org.apache.stanbol.enhancer.nlp.dependency.GrammaticalRelationTag) Span(org.apache.stanbol.enhancer.nlp.model.Span) DependencyRelation(org.apache.stanbol.enhancer.nlp.dependency.DependencyRelation)

Aggregations

DependencyRelation (org.apache.stanbol.enhancer.nlp.dependency.DependencyRelation)1 GrammaticalRelation (org.apache.stanbol.enhancer.nlp.dependency.GrammaticalRelation)1 GrammaticalRelationTag (org.apache.stanbol.enhancer.nlp.dependency.GrammaticalRelationTag)1 Span (org.apache.stanbol.enhancer.nlp.model.Span)1 SpanTypeEnum (org.apache.stanbol.enhancer.nlp.model.SpanTypeEnum)1 JsonNode (org.codehaus.jackson.JsonNode)1