Search in sources :

Example 1 with Type

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

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

use of org.apache.uima.cas.Type in project lucene-solr by apache.

the class SampleWSTokenizerAnnotator method process.

@Override
public void process(JCas jCas) throws AnalysisEngineProcessException {
    Type sentenceType = jCas.getCas().getTypeSystem().getType(SENTENCE_TYPE);
    Type tokenType = jCas.getCas().getTypeSystem().getType(TOKEN_TYPE);
    int i = 0;
    for (String sentenceString : jCas.getDocumentText().split(lineEnd)) {
        // add the sentence
        AnnotationFS sentenceAnnotation = jCas.getCas().createAnnotation(sentenceType, i, sentenceString.length());
        jCas.addFsToIndexes(sentenceAnnotation);
        i += sentenceString.length();
    }
    // get tokens
    int j = 0;
    for (String tokenString : jCas.getDocumentText().split(WHITESPACE)) {
        int tokenLength = tokenString.length();
        AnnotationFS tokenAnnotation = jCas.getCas().createAnnotation(tokenType, j, j + tokenLength);
        jCas.addFsToIndexes(tokenAnnotation);
        j += tokenLength;
    }
}
Also used : AnnotationFS(org.apache.uima.cas.text.AnnotationFS) Type(org.apache.uima.cas.Type)

Example 4 with Type

use of org.apache.uima.cas.Type in project lucene-solr by apache.

the class UIMAAnnotationsTokenizer method initializeIterator.

@Override
protected void initializeIterator() throws IOException {
    try {
        analyzeInput();
    } catch (AnalysisEngineProcessException | ResourceInitializationException e) {
        throw new IOException(e);
    }
    finalOffset = correctOffset(cas.getDocumentText().length());
    Type tokenType = cas.getTypeSystem().getType(tokenTypeString);
    iterator = cas.getAnnotationIndex(tokenType).iterator();
}
Also used : Type(org.apache.uima.cas.Type) ResourceInitializationException(org.apache.uima.resource.ResourceInitializationException) IOException(java.io.IOException) AnalysisEngineProcessException(org.apache.uima.analysis_engine.AnalysisEngineProcessException)

Example 5 with Type

use of org.apache.uima.cas.Type in project lucene-solr by apache.

the class UIMATypeAwareAnnotationsTokenizer method initializeIterator.

@Override
protected void initializeIterator() throws IOException {
    try {
        analyzeInput();
    } catch (AnalysisEngineProcessException | ResourceInitializationException e) {
        throw new IOException(e);
    }
    featurePath = cas.createFeaturePath();
    try {
        featurePath.initialize(typeAttributeFeaturePath);
    } catch (CASException e) {
        featurePath = null;
        throw new IOException(e);
    }
    finalOffset = correctOffset(cas.getDocumentText().length());
    Type tokenType = cas.getTypeSystem().getType(tokenTypeString);
    iterator = cas.getAnnotationIndex(tokenType).iterator();
}
Also used : Type(org.apache.uima.cas.Type) ResourceInitializationException(org.apache.uima.resource.ResourceInitializationException) IOException(java.io.IOException) CASException(org.apache.uima.cas.CASException) AnalysisEngineProcessException(org.apache.uima.analysis_engine.AnalysisEngineProcessException)

Aggregations

Type (org.apache.uima.cas.Type)160 AnnotationFS (org.apache.uima.cas.text.AnnotationFS)112 JCas (org.apache.uima.jcas.JCas)75 ArrayList (java.util.ArrayList)72 Feature (org.apache.uima.cas.Feature)62 Test (org.junit.Test)59 Token (de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token)54 CAS (org.apache.uima.cas.CAS)47 AnnotationFeature (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)40 FeatureStructure (org.apache.uima.cas.FeatureStructure)39 CasUtil.getType (org.apache.uima.fit.util.CasUtil.getType)29 List (java.util.List)25 IOException (java.io.IOException)17 HashMap (java.util.HashMap)15 POS (de.tudarmstadt.ukp.dkpro.core.api.lexmorph.type.pos.POS)14 LinkedHashMap (java.util.LinkedHashMap)14 NamedEntity (de.tudarmstadt.ukp.dkpro.core.api.ner.type.NamedEntity)13 Map (java.util.Map)13 AnalysisEngineProcessException (org.apache.uima.analysis_engine.AnalysisEngineProcessException)13 ResourceInitializationException (org.apache.uima.resource.ResourceInitializationException)13