Search in sources :

Example 6 with SpanTypeEnum

use of org.apache.stanbol.enhancer.nlp.model.SpanTypeEnum in project stanbol by apache.

the class CorefFeatureSupport method parse.

@Override
public CorefFeature parse(ObjectNode jCoref, AnalysedText at) {
    JsonNode jIsRepresentative = jCoref.path(IS_REPRESENTATIVE_TAG);
    if (!jIsRepresentative.isBoolean()) {
        throw new IllegalStateException("Field 'isRepresentative' must have a true/false format");
    }
    JsonNode node = jCoref.path(MENTIONS_TAG);
    Set<Span> mentions = new HashSet<Span>();
    if (node.isArray()) {
        ArrayNode jMentions = (ArrayNode) node;
        for (int i = 0; i < jMentions.size(); i++) {
            JsonNode member = jMentions.get(i);
            if (member.isObject()) {
                ObjectNode jMention = (ObjectNode) member;
                SpanTypeEnum spanType = SpanTypeEnum.valueOf(jMention.path(MENTION_TYPE_TAG).getTextValue());
                int spanStart = jMention.path(MENTION_START_TAG).asInt();
                int spanEnd = jMention.path(MENTION_END_TAG).asInt();
                Span mentionedSpan = null;
                switch(spanType) {
                    case Chunk:
                        mentionedSpan = at.addChunk(spanStart, spanEnd);
                        break;
                    case Sentence:
                    case Text:
                    case TextSection:
                        break;
                    case Token:
                        mentionedSpan = at.addToken(spanStart, spanEnd);
                        break;
                }
                mentions.add(mentionedSpan);
            }
        }
    }
    return new CorefFeature(jIsRepresentative.asBoolean(), mentions);
}
Also used : CorefFeature(org.apache.stanbol.enhancer.nlp.coref.CorefFeature) SpanTypeEnum(org.apache.stanbol.enhancer.nlp.model.SpanTypeEnum) ObjectNode(org.codehaus.jackson.node.ObjectNode) JsonNode(org.codehaus.jackson.JsonNode) ArrayNode(org.codehaus.jackson.node.ArrayNode) Span(org.apache.stanbol.enhancer.nlp.model.Span) HashSet(java.util.HashSet)

Aggregations

SpanTypeEnum (org.apache.stanbol.enhancer.nlp.model.SpanTypeEnum)6 Span (org.apache.stanbol.enhancer.nlp.model.Span)5 JsonNode (org.codehaus.jackson.JsonNode)4 ObjectNode (org.codehaus.jackson.node.ObjectNode)3 ArrayList (java.util.ArrayList)2 Entry (java.util.Map.Entry)2 Graph (org.apache.clerezza.commons.rdf.Graph)2 IRI (org.apache.clerezza.commons.rdf.IRI)2 Language (org.apache.clerezza.commons.rdf.Language)2 TripleImpl (org.apache.clerezza.commons.rdf.impl.utils.TripleImpl)2 AnalysedText (org.apache.stanbol.enhancer.nlp.model.AnalysedText)2 NlpEngineHelper.getAnalysedText (org.apache.stanbol.enhancer.nlp.utils.NlpEngineHelper.getAnalysedText)2 SerializedString (org.codehaus.jackson.io.SerializedString)2 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 CorefFeature (org.apache.stanbol.enhancer.nlp.coref.CorefFeature)1 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 NIFHelper.writeSpan (org.apache.stanbol.enhancer.nlp.utils.NIFHelper.writeSpan)1