Search in sources :

Example 1 with TokenAnnotation

use of org.apache.uima.TokenAnnotation 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 2 with TokenAnnotation

use of org.apache.uima.TokenAnnotation 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 3 with TokenAnnotation

use of org.apache.uima.TokenAnnotation 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

TokenAnnotation (org.apache.uima.TokenAnnotation)3 Annotation (org.apache.uima.jcas.tcas.Annotation)3 DummySentimentAnnotation (org.apache.solr.uima.ts.DummySentimentAnnotation)1 EntityAnnotation (org.apache.solr.uima.ts.EntityAnnotation)1 Feature (org.apache.uima.cas.Feature)1 Type (org.apache.uima.cas.Type)1 AnnotationFS (org.apache.uima.cas.text.AnnotationFS)1