Package org.apache.stanbol.enhancer.nlp.morpho

Examples of org.apache.stanbol.enhancer.nlp.morpho.MorphoFeatures


                        }
                    }
                }
            }
            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){
View Full Code Here


        expectedTokens.put(enhancer, "enhancer");
        enhancer.addAnnotation(NlpAnnotations.POS_ANNOTATION, Value.value(
            new PosTag("PN", Pos.ProperNoun),0.95));
        enhancer.addAnnotation(NlpAnnotations.POS_ANNOTATION, Value.value(
            new PosTag("N", LexicalCategory.Noun),0.87));
        MorphoFeatures morpho = new MorphoFeatures("enhance");
        morpho.addCase(new CaseTag("test-case-1",Case.Comitative));
        morpho.addCase(new CaseTag("test-case-2",Case.Abessive));
        morpho.addDefinitness(Definitness.Definite);
        morpho.addPerson(Person.First);
        morpho.addPos(new PosTag("PN", Pos.ProperNoun));
        morpho.addGender(new GenderTag("test-gender", Gender.Masculine));
        morpho.addNumber(new NumberTag("test-number", NumberFeature.Plural));
        morpho.addTense(new TenseTag("test-tense", Tense.Present));
        morpho.addVerbForm(new VerbMoodTag("test-verb-mood", VerbMood.ConditionalVerb));
        enhancer.addAnnotation(NlpAnnotations.MORPHO_ANNOTATION, Value.value(morpho));

        //create a chunk
        Chunk stanbolEnhancer = analysedTextWithData.addChunk(stanbol.getStart(), enhancer.getEnd());
        expectedChunks.put(stanbolEnhancer, "Stanbol enhancer");
View Full Code Here

        JsonNode jLemma = jMorpho.path("lemma");
        if(!jLemma.isTextual()){
            throw new IllegalStateException("Field 'lemma' MUST provide a String value (parsed JSON: "
                +jMorpho);
        }
        MorphoFeatures morpho = new MorphoFeatures(jLemma.asText());
        JsonNode node = jMorpho.path("case");
        if(node.isArray()){
            ArrayNode jCases = (ArrayNode)node;
            for(int i=0;i<jCases.size();i++){
                JsonNode member = jCases.get(i);
                if(member.isObject()){
                    ObjectNode jCase = (ObjectNode)member;
                    JsonNode tag = jCase.path("tag");
                    if(tag.isTextual()){
                        EnumSet<Case> type = JsonUtils.parseEnum(jCase, "type", Case.class);
                        if(type.isEmpty()){
                            morpho.addCase(new CaseTag(tag.getTextValue()));
                        } else {
                            morpho.addCase(new CaseTag(tag.getTextValue(),type.iterator().next()));
                        }
                    } else {
                        log.warn("Unable to parse CaseTag becuase 'tag' value is "
                            + "missing or is not a String (json: "+jCase.toString()+")");
                    }
                } else {
                    log.warn("Unable to parse CaseTag from "+member.toString());
                }
            }
        } else if(!node.isMissingNode()) {
            log.warn("Unable to parse CaseTags (Json Array expected as value for field 'case' but was "
                + node);
        }
        if(jMorpho.has("definitness")){
            for(Definitness d : JsonUtils.parseEnum(jMorpho, "definitness", Definitness.class)){
                morpho.addDefinitness(d);
            }
        }
        node = jMorpho.path("gender");
        if(node.isArray()){
            ArrayNode jGenders = (ArrayNode)node;
            for(int i=0;i<jGenders.size();i++){
                JsonNode member = jGenders.get(i);
                if(member.isObject()){
                    ObjectNode jGender = (ObjectNode)member;
                    JsonNode tag = jGender.path("tag");
                    if(tag.isTextual()){
                        EnumSet<Gender> type = JsonUtils.parseEnum(jGender, "type", Gender.class);
                        if(type.isEmpty()){
                            morpho.addGender(new GenderTag(tag.getTextValue()));
                        } else {
                            morpho.addGender(new GenderTag(tag.getTextValue(),type.iterator().next()));
                        }
                    } else {
                        log.warn("Unable to parse GenderTag becuase 'tag' value is "
                                + "missing or is not a String (json: "+jGender.toString()+")");
                    }
                } else {
                    log.warn("Unable to parse GenderTag from "+member.toString());
                }
            }
        } else if(!node.isMissingNode()) {
            log.warn("Unable to parse GenderTag (Json Array expected as value for field 'case' but was "
                    + node);
        }
       
        node = jMorpho.path("number");
        if(node.isArray()){
            ArrayNode jNumbers = (ArrayNode)node;
            for(int i=0;i<jNumbers.size();i++){
                JsonNode member = jNumbers.get(i);
                if(member.isObject()){
                    ObjectNode jNumber = (ObjectNode)member;
                    JsonNode tag = jNumber.path("tag");
                    if(tag.isTextual()){
                        EnumSet<NumberFeature> type = JsonUtils.parseEnum(jNumber, "type", NumberFeature.class);
                        if(type.isEmpty()){
                            morpho.addNumber(new NumberTag(tag.getTextValue()));
                        } else {
                            morpho.addNumber(new NumberTag(tag.getTextValue(),type.iterator().next()));
                        }
                    } else {
                        log.warn("Unable to parse NumberTag becuase 'tag' value is "
                                + "missing or is not a String (json: "+jNumber.toString()+")");
                    }
                } else {
                    log.warn("Unable to parse NumberTag from "+member.toString());
                }
            }
        } else if(!node.isMissingNode()) {
            log.warn("Unable to parse NumberTag (Json Array expected as value for field 'case' but was "
                    + node);
        }
       
        if(jMorpho.has("person")){
            for(Person p : JsonUtils.parseEnum(jMorpho, "person", Person.class)){
                morpho.addPerson(p);
            }
        }

        node = jMorpho.path("pos");
        if(node.isArray()){
            ArrayNode jPosTags = (ArrayNode)node;
            for(int i=0;i<jPosTags.size();i++){
                JsonNode member = jPosTags.get(i);
                if(member.isObject()){
                    ObjectNode jPosTag = (ObjectNode)member;
                    morpho.addPos(getPosTagParser().parse(jPosTag, at));
                } else {
                    log.warn("Unable to parse PosTag from "+member.toString());
                }
            }
        } else if(!node.isMissingNode()){
            log.warn("Unable to parse PosTag (Json Array expected as value for field 'case' but was "
                    + node);
        }
       
        node = jMorpho.path("tense");
        if(node.isArray()){
            ArrayNode jTenses = (ArrayNode)node;
            for(int i=0;i<jTenses.size();i++){
                JsonNode member = jTenses.get(i);
                if(member.isObject()){
                    ObjectNode jTense = (ObjectNode)member;
                    JsonNode tag = jTense.path("tag");
                    if(tag.isTextual()){
                        EnumSet<Tense> type = JsonUtils.parseEnum(jTense, "type", Tense.class);
                        if(type.isEmpty()){
                            morpho.addTense(new TenseTag(tag.getTextValue()));
                        } else {
                            morpho.addTense(new TenseTag(tag.getTextValue(),type.iterator().next()));
                        }
                    } else {
                        log.warn("Unable to parse TenseTag becuase 'tag' value is "
                                + "missing or is not a String (json: "+jTense.toString()+")");
                    }
                } else {
                    log.warn("Unable to parse TenseTag from "+member.toString());
                }
            }
        } else if(!node.isMissingNode()) {
            log.warn("Unable to parse TenseTag (Json Array expected as value for field 'case' but was "
                    + node);
        }
       
        node = jMorpho.path("verb-mood");
        if(node.isArray()){
            ArrayNode jVerbMoods = (ArrayNode)node;
            for(int i=0;i<jVerbMoods.size();i++){
                JsonNode member = jVerbMoods.get(i);
                if(member.isObject()){
                    ObjectNode jVerbMood = (ObjectNode)member;
                    JsonNode tag = jVerbMood.path("tag");
                    if(tag.isTextual()){
                        EnumSet<VerbMood> type = JsonUtils.parseEnum(jVerbMood, "type", VerbMood.class);
                        if(type.isEmpty()){
                            morpho.addVerbForm(new VerbMoodTag(tag.getTextValue()));
                        } else {
                            morpho.addVerbForm(new VerbMoodTag(tag.getTextValue(),type.iterator().next()));
                        }
                    } else {
                        log.warn("Unable to parse VerbMoodTag becuase 'tag' value is "
                                + "missing or is not a String (json: "+jVerbMood.toString()+")");
                    }
View Full Code Here

                        nerList.add(ner);
                    }
                    ner.end = offset.endOffset();
                }
                BaseFormAttribute baseFormAttr = tokenStream.addAttribute(BaseFormAttribute.class);
                MorphoFeatures morpho = null;
                if(baseFormAttr != null && baseFormAttr.getBaseForm() != null){
                  morpho = new MorphoFeatures(baseFormAttr.getBaseForm());
                  morpho.addPos(posTag); //and add the posTag
                }
                InflectionAttribute inflectionAttr = tokenStream.addAttribute(InflectionAttribute.class);
                inflectionAttr.getInflectionForm();
                inflectionAttr.getInflectionType();
                if(morpho != null){ //if present add the morpho
View Full Code Here

        }
        List<Value<MorphoFeatures>> morphoAnnotations = token.getAnnotations(NlpAnnotations.MORPHO_ANNOTATION);
        if(selectedPosTag == null){ //no POS information ... use the first morpho annotation
            morpho = morphoAnnotations.isEmpty() ? null : morphoAnnotations.get(0).value();
        } else { //select the correct morpho annotation based on the POS tag
            MorphoFeatures mf = null;
            selectMorphoFeature :
            for(Value<MorphoFeatures> morphoAnnotation : morphoAnnotations){
                for(PosTag posTag : morphoAnnotation.value().getPosList()){
                    if(!disjoint(selectedPosTag.getCategories(),posTag.getCategories())){
                        mf = morphoAnnotation.value();
View Full Code Here

        JsonNode jLemma = jMorpho.path("lemma");
        if(!jLemma.isTextual()){
            throw new IllegalStateException("Field 'lemma' MUST provide a String value (parsed JSON: "
                +jMorpho);
        }
        MorphoFeatures morpho = new MorphoFeatures(jLemma.asText());
        JsonNode node = jMorpho.path("case");
        if(node.isArray()){
            ArrayNode jCases = (ArrayNode)node;
            for(int i=0;i<jCases.size();i++){
                JsonNode member = jCases.get(i);
                if(member.isObject()){
                    ObjectNode jCase = (ObjectNode)member;
                    JsonNode tag = jCase.path("tag");
                    if(tag.isTextual()){
                        EnumSet<Case> type = JsonUtils.parseEnum(jCase, "type", Case.class);
                        if(type.isEmpty()){
                            morpho.addCase(new CaseTag(tag.getTextValue()));
                        } else {
                            morpho.addCase(new CaseTag(tag.getTextValue(),type.iterator().next()));
                        }
                    } else {
                        log.warn("Unable to parse CaseTag becuase 'tag' value is "
                            + "missing or is not a String (json: "+jCase.toString()+")");
                    }
                } else {
                    log.warn("Unable to parse CaseTag from "+member.toString());
                }
            }
        } else if(!node.isMissingNode()) {
            log.warn("Unable to parse CaseTags (Json Array expected as value for field 'case' but was "
                + node);
        }
        if(jMorpho.has("definitness")){
            for(Definitness d : JsonUtils.parseEnum(jMorpho, "definitness", Definitness.class)){
                morpho.addDefinitness(d);
            }
        }
        node = jMorpho.path("gender");
        if(node.isArray()){
            ArrayNode jGenders = (ArrayNode)node;
            for(int i=0;i<jGenders.size();i++){
                JsonNode member = jGenders.get(i);
                if(member.isObject()){
                    ObjectNode jGender = (ObjectNode)member;
                    JsonNode tag = jGender.path("tag");
                    if(tag.isTextual()){
                        EnumSet<Gender> type = JsonUtils.parseEnum(jGender, "type", Gender.class);
                        if(type.isEmpty()){
                            morpho.addGender(new GenderTag(tag.getTextValue()));
                        } else {
                            morpho.addGender(new GenderTag(tag.getTextValue(),type.iterator().next()));
                        }
                    } else {
                        log.warn("Unable to parse GenderTag becuase 'tag' value is "
                                + "missing or is not a String (json: "+jGender.toString()+")");
                    }
                } else {
                    log.warn("Unable to parse GenderTag from "+member.toString());
                }
            }
        } else if(!node.isMissingNode()) {
            log.warn("Unable to parse GenderTag (Json Array expected as value for field 'case' but was "
                    + node);
        }
       
        node = jMorpho.path("number");
        if(node.isArray()){
            ArrayNode jNumbers = (ArrayNode)node;
            for(int i=0;i<jNumbers.size();i++){
                JsonNode member = jNumbers.get(i);
                if(member.isObject()){
                    ObjectNode jNumber = (ObjectNode)member;
                    JsonNode tag = jNumber.path("tag");
                    if(tag.isTextual()){
                        EnumSet<NumberFeature> type = JsonUtils.parseEnum(jNumber, "type", NumberFeature.class);
                        if(type.isEmpty()){
                            morpho.addNumber(new NumberTag(tag.getTextValue()));
                        } else {
                            morpho.addNumber(new NumberTag(tag.getTextValue(),type.iterator().next()));
                        }
                    } else {
                        log.warn("Unable to parse NumberTag becuase 'tag' value is "
                                + "missing or is not a String (json: "+jNumber.toString()+")");
                    }
                } else {
                    log.warn("Unable to parse NumberTag from "+member.toString());
                }
            }
        } else if(!node.isMissingNode()) {
            log.warn("Unable to parse NumberTag (Json Array expected as value for field 'case' but was "
                    + node);
        }
       
        if(jMorpho.has("person")){
            for(Person p : JsonUtils.parseEnum(jMorpho, "person", Person.class)){
                morpho.addPerson(p);
            }
        }

        node = jMorpho.path("pos");
        if(node.isArray()){
            ArrayNode jPosTags = (ArrayNode)node;
            for(int i=0;i<jPosTags.size();i++){
                JsonNode member = jPosTags.get(i);
                if(member.isObject()){
                    ObjectNode jPosTag = (ObjectNode)member;
                    morpho.addPos(getPosTagParser().parse(jPosTag));
                } else {
                    log.warn("Unable to parse PosTag from "+member.toString());
                }
            }
        } else if(!node.isMissingNode()){
            log.warn("Unable to parse PosTag (Json Array expected as value for field 'case' but was "
                    + node);
        }
       
        node = jMorpho.path("tense");
        if(node.isArray()){
            ArrayNode jTenses = (ArrayNode)node;
            for(int i=0;i<jTenses.size();i++){
                JsonNode member = jTenses.get(i);
                if(member.isObject()){
                    ObjectNode jTense = (ObjectNode)member;
                    JsonNode tag = jTense.path("tag");
                    if(tag.isTextual()){
                        EnumSet<Tense> type = JsonUtils.parseEnum(jTense, "type", Tense.class);
                        if(type.isEmpty()){
                            morpho.addTense(new TenseTag(tag.getTextValue()));
                        } else {
                            morpho.addTense(new TenseTag(tag.getTextValue(),type.iterator().next()));
                        }
                    } else {
                        log.warn("Unable to parse TenseTag becuase 'tag' value is "
                                + "missing or is not a String (json: "+jTense.toString()+")");
                    }
                } else {
                    log.warn("Unable to parse TenseTag from "+member.toString());
                }
            }
        } else if(!node.isMissingNode()) {
            log.warn("Unable to parse TenseTag (Json Array expected as value for field 'case' but was "
                    + node);
        }
       
        node = jMorpho.path("verb-mood");
        if(node.isArray()){
            ArrayNode jVerbMoods = (ArrayNode)node;
            for(int i=0;i<jVerbMoods.size();i++){
                JsonNode member = jVerbMoods.get(i);
                if(member.isObject()){
                    ObjectNode jVerbMood = (ObjectNode)member;
                    JsonNode tag = jVerbMood.path("tag");
                    if(tag.isTextual()){
                        EnumSet<VerbMood> type = JsonUtils.parseEnum(jVerbMood, "type", VerbMood.class);
                        if(type.isEmpty()){
                            morpho.addVerbForm(new VerbMoodTag(tag.getTextValue()));
                        } else {
                            morpho.addVerbForm(new VerbMoodTag(tag.getTextValue(),type.iterator().next()));
                        }
                    } else {
                        log.warn("Unable to parse VerbMoodTag becuase 'tag' value is "
                                + "missing or is not a String (json: "+jVerbMood.toString()+")");
                    }
View Full Code Here

        expectedTokens.put(enhancer, "enhancer");
        enhancer.addAnnotation(NlpAnnotations.POS_ANNOTATION, Value.value(
            new PosTag("PN", Pos.ProperNoun),0.95));
        enhancer.addAnnotation(NlpAnnotations.POS_ANNOTATION, Value.value(
            new PosTag("N", LexicalCategory.Noun),0.87));
        MorphoFeatures morpho = new MorphoFeatures("enhance");
        morpho.addCase(new CaseTag("test-case-1",Case.Comitative));
        morpho.addCase(new CaseTag("test-case-2",Case.Abessive));
        morpho.addDefinitness(Definitness.Definite);
        morpho.addPerson(Person.First);
        morpho.addPos(new PosTag("PN", Pos.ProperNoun));
        morpho.addGender(new GenderTag("test-gender", Gender.Masculine));
        morpho.addNumber(new NumberTag("test-number", NumberFeature.Plural));
        morpho.addTense(new TenseTag("test-tense", Tense.Present));
        morpho.addVerbForm(new VerbMoodTag("test-verb-mood", VerbMood.ConditionalVerb));
        enhancer.addAnnotation(NlpAnnotations.MORPHO_ANNOTATION, Value.value(morpho));

        //create a chunk
        Chunk stanbolEnhancer = analysedTextWithData.addChunk(stanbol.getStart(), enhancer.getEnd());
        expectedChunks.put(stanbolEnhancer, "Stanbol enhancer");
View Full Code Here

                        }
                    }
                }
            }
            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){
View Full Code Here

            }
            List<Value<MorphoFeatures>> morphoAnnotations = token.getAnnotations(NlpAnnotations.MORPHO_ANNOTATION);
            if(selectedPosTag == null){ //no POS information ... use the first morpho annotation
                morpho = morphoAnnotations.isEmpty() ? null : morphoAnnotations.get(0).value();
            } else { //select the correct morpho annotation based on the POS tag
                MorphoFeatures mf = null;
                selectMorphoFeature :
                for(Value<MorphoFeatures> morphoAnnotation : morphoAnnotations){
                    for(PosTag posTag : morphoAnnotation.value().getPosList()){
                        if(!disjoint(selectedPosTag.getCategories(),posTag.getCategories())){
                            mf = morphoAnnotation.value();
View Full Code Here

TOP

Related Classes of org.apache.stanbol.enhancer.nlp.morpho.MorphoFeatures

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.