Search in sources :

Example 1 with Annotation

use of org.apache.uima.jcas.tcas.Annotation in project lucene-solr by apache.

the class SampleEntityAnnotator method process.

@Override
public void process(JCas jcas) throws AnalysisEngineProcessException {
    Type type = jcas.getCas().getTypeSystem().getType(TYPE_NAME);
    Feature entityFeature = type.getFeatureByBaseName(ENTITY_FEATURE);
    Feature nameFeature = type.getFeatureByBaseName(NAME_FEATURE);
    for (Annotation annotation : jcas.getAnnotationIndex(TokenAnnotation.type)) {
        String tokenPOS = ((TokenAnnotation) annotation).getPosTag();
        if (NP.equals(tokenPOS) || NPS.equals(tokenPOS)) {
            AnnotationFS entityAnnotation = jcas.getCas().createAnnotation(type, annotation.getBegin(), annotation.getEnd());
            entityAnnotation.setStringValue(entityFeature, annotation.getCoveredText());
            // "OTHER" makes no sense. In practice, "PERSON", "COUNTRY", "E-MAIL", etc.
            String name = "OTHER";
            if (annotation.getCoveredText().equals("Apache"))
                name = "ORGANIZATION";
            entityAnnotation.setStringValue(nameFeature, name);
            jcas.addFsToIndexes(entityAnnotation);
        }
    }
}
Also used : TokenAnnotation(org.apache.uima.TokenAnnotation) AnnotationFS(org.apache.uima.cas.text.AnnotationFS) Type(org.apache.uima.cas.Type) Feature(org.apache.uima.cas.Feature) Annotation(org.apache.uima.jcas.tcas.Annotation) TokenAnnotation(org.apache.uima.TokenAnnotation)

Example 2 with Annotation

use of org.apache.uima.jcas.tcas.Annotation in project lucene-solr by apache.

the class SamplePoSTagger method process.

@Override
public void process(JCas jcas) throws AnalysisEngineProcessException {
    Type type = jcas.getCas().getTypeSystem().getType(TYPE_NAME);
    Feature posFeature = type.getFeatureByBaseName(FEATURE_NAME);
    for (Annotation annotation : jcas.getAnnotationIndex(type)) {
        String text = annotation.getCoveredText();
        String pos = extractPoS(text);
        annotation.setStringValue(posFeature, pos);
    }
}
Also used : Type(org.apache.uima.cas.Type) Feature(org.apache.uima.cas.Feature) Annotation(org.apache.uima.jcas.tcas.Annotation)

Example 3 with Annotation

use of org.apache.uima.jcas.tcas.Annotation in project lucene-solr by apache.

the class DummySentimentAnnotator method process.

@Override
public void process(JCas jcas) throws AnalysisEngineProcessException {
    for (Annotation annotation : jcas.getAnnotationIndex(TokenAnnotation.type)) {
        String tokenPOS = ((TokenAnnotation) annotation).getPosTag();
        if ("jj".equals(tokenPOS)) {
            if (Arrays.asList(positiveAdj).contains(annotation.getCoveredText())) {
                DummySentimentAnnotation dummySentimentAnnotation = createSentimentAnnotation(jcas, annotation);
                dummySentimentAnnotation.setMood("positive");
                dummySentimentAnnotation.addToIndexes();
            } else if (Arrays.asList(negativeAdj).contains(annotation.getCoveredText())) {
                DummySentimentAnnotation dummySentimentAnnotation = createSentimentAnnotation(jcas, annotation);
                dummySentimentAnnotation.setMood("negative");
                dummySentimentAnnotation.addToIndexes();
            }
        }
    }
}
Also used : TokenAnnotation(org.apache.uima.TokenAnnotation) DummySentimentAnnotation(org.apache.solr.uima.ts.DummySentimentAnnotation) Annotation(org.apache.uima.jcas.tcas.Annotation) DummySentimentAnnotation(org.apache.solr.uima.ts.DummySentimentAnnotation) TokenAnnotation(org.apache.uima.TokenAnnotation)

Example 4 with Annotation

use of org.apache.uima.jcas.tcas.Annotation in project lucene-solr by apache.

the class UIMAToSolrMapper method map.

/**
   * map features of a certain UIMA type to corresponding Solr fields based on the mapping
   *
   * @param typeName             name of UIMA type to map
   */
void map(String typeName, Map<String, MapField> featureFieldsmapping) throws FieldMappingException {
    try {
        Type type = cas.getTypeSystem().getType(typeName);
        for (FSIterator<FeatureStructure> iterator = cas.getFSIndexRepository().getAllIndexedFS(type); iterator.hasNext(); ) {
            FeatureStructure fs = iterator.next();
            for (String featureName : featureFieldsmapping.keySet()) {
                MapField mapField = featureFieldsmapping.get(featureName);
                String fieldNameFeature = mapField.getFieldNameFeature();
                String fieldNameFeatureValue = fieldNameFeature == null ? null : fs.getFeatureValueAsString(type.getFeatureByBaseName(fieldNameFeature));
                String fieldName = mapField.getFieldName(fieldNameFeatureValue);
                if (log.isInfoEnabled()) {
                    log.info("mapping {}@{} to {}", new Object[] { typeName, featureName, fieldName });
                }
                String featureValue;
                if (fs instanceof Annotation && "coveredText".equals(featureName)) {
                    featureValue = ((Annotation) fs).getCoveredText();
                } else {
                    featureValue = fs.getFeatureValueAsString(type.getFeatureByBaseName(featureName));
                }
                if (log.isDebugEnabled()) {
                    log.debug("writing {} in {}", new Object[] { featureValue, fieldName });
                }
                document.addField(fieldName, featureValue);
            }
        }
    } catch (Exception e) {
        throw new FieldMappingException(e);
    }
}
Also used : FeatureStructure(org.apache.uima.cas.FeatureStructure) Type(org.apache.uima.cas.Type) Annotation(org.apache.uima.jcas.tcas.Annotation) MapField(org.apache.solr.uima.processor.SolrUIMAConfiguration.MapField)

Example 5 with Annotation

use of org.apache.uima.jcas.tcas.Annotation in project lucene-solr by apache.

the class DummyEntityAnnotator method process.

@Override
public void process(JCas jcas) throws AnalysisEngineProcessException {
    for (Annotation annotation : jcas.getAnnotationIndex(TokenAnnotation.type)) {
        String tokenPOS = ((TokenAnnotation) annotation).getPosTag();
        if ("np".equals(tokenPOS) || "nps".equals(tokenPOS)) {
            EntityAnnotation entityAnnotation = new EntityAnnotation(jcas);
            entityAnnotation.setBegin(annotation.getBegin());
            entityAnnotation.setEnd(annotation.getEnd());
            String entityString = annotation.getCoveredText();
            entityAnnotation.setEntity(entityString);
            // "OTHER" makes no sense. In practice, "PERSON", "COUNTRY", "E-MAIL", etc.
            String name = "OTHER";
            if (entityString.equals("Apache"))
                name = "ORGANIZATION";
            entityAnnotation.setName(name);
            entityAnnotation.addToIndexes();
        }
    }
}
Also used : TokenAnnotation(org.apache.uima.TokenAnnotation) EntityAnnotation(org.apache.solr.uima.ts.EntityAnnotation) Annotation(org.apache.uima.jcas.tcas.Annotation) TokenAnnotation(org.apache.uima.TokenAnnotation) EntityAnnotation(org.apache.solr.uima.ts.EntityAnnotation)

Aggregations

Annotation (org.apache.uima.jcas.tcas.Annotation)6 Type (org.apache.uima.cas.Type)4 TokenAnnotation (org.apache.uima.TokenAnnotation)3 Feature (org.apache.uima.cas.Feature)2 ArrayList (java.util.ArrayList)1 MapField (org.apache.solr.uima.processor.SolrUIMAConfiguration.MapField)1 DummySentimentAnnotation (org.apache.solr.uima.ts.DummySentimentAnnotation)1 EntityAnnotation (org.apache.solr.uima.ts.EntityAnnotation)1 Feature (org.apache.stanbol.commons.caslight.Feature)1 FeatureStructure (org.apache.stanbol.commons.caslight.FeatureStructure)1 FeatureStructure (org.apache.uima.cas.FeatureStructure)1 AnnotationFS (org.apache.uima.cas.text.AnnotationFS)1