Once you have the Type object you can get all and index to all the annotations
in the case using:
AnnotationIndex<Annotation> mySentenceIndex =
jcas.getAnnotationIndex(mySentenceTypeObj);
Then you can get an iterator over the index using:
FSIterator<Annotation> mySentenceIterator = mySentenceIndex.iterator();
or you could just use the iterator loop syntax in Java such as:
for(Annotation sentence : mySentenceIndex) {
/** Do something cool **/
}
The AnnotationLibrarian class in the Leo framework provides some pretty
convenient methods for this as well such as:
Collection<Sentence> sentenceList =
AnnotationLibrarian.getAllAnnotationsOfType(jcas, mySentenceTypeObj);
which returns a list of Sentence annotation types. You can find more
information about the Leo framework at the following URL:
http://decipher.chpc.utah.edu/sites/gov.va.vinci/leo/2014.01.8/
Thanks,
Thomas Ginter
801-448-7676
[email protected]
On Feb 14, 2014, at 2:50 AM, Richard Eckart de Castilho <[email protected]> wrote:
> On 14.02.2014, at 09:50, hannes schantl <[email protected]> wrote:
>
>> thanks for the answers.
>>
>> Is there also a way to get a Type from a String, which can be used as
>> argument for the JCasUtil.select method?
>
> The JCasUtil methods assume that you have access to JCas classes, e.g.
>
> import mypackage.AnnotationType;
> JCasUtil.select(jcas, AnnotationType.class)
>
> If you want to select based on names/types, not on JCas-classes, you could
> consider using the CasUtil methods:
>
> CAS cas = jcas.getCas(); // Or use inherit from CasAnnotator_ImplBase
> Type annotationType = CasUtil.getType(cas, "mypackage.AnnotationType");
> CasUtil.select(cas, annotationType);
>
> Of course, you could also use reflection to get the class for your annotation
> type and pass it to JCasUtil - but that would be redundant and would require
> handling various exceptions:
>
> JCasUtil.select(jcas, Class.forName("mypackage.AnnotationType"))
>
>> I want to use the type object to get all Annotations of type Sentence from
>> the Cas. And further extract all Annotations within this
>> sentence. There for sure other ways to solve this issue without using
>> JCasUtil, but it seems JCasUtil provide an easy way to do this by using the
>> methods
>> JCasUtil.select and JCasUtil.selectCovered.
>
> CasUtil largely mirrors the functionality of JCasUtil. In fact, JCasUtil calls
> out to CasUtil for most of the grunt work.
>
> Cheers,
>
> -- Richard
>
>> greetings Hannes
>>
>>
>> Am 13.02.2014 22:11, schrieb Thomas Ginter:
>>
>> There are a couple of different ways to get a pointer to specific Type
>> object.
>>
>> jcas.getRequiredType("mypackage.AnnotationType");
>> (cas|jcas).getTypeSystem.getType("mypackage.AnnotationType");
>>
>> The question is what do you want to do with the Type object once you have it.
>>
>> Thanks,
>>
>> Thomas [email protected]
>>
>> On Feb 13, 2014, at 6:03 AM, hannes schantl
>> <[email protected]> <[email protected]> wrote:
>>
>>
>> Hi,
>>
>> Is there a way to get an annotation Type from the cas(or Jcas) from a
>> string.
>> For example, i am looking for something like that:
>> jcas.getCasType("AnnotationName")
>>
>> greetings Hannes
>