You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@uima.apache.org by hannes schantl <jo...@gmail.com> on 2014/02/13 14:03:26 UTC

uima jcas get annotation type from string

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

Re: uima jcas get annotation type from string

Posted by Marshall Schor <ms...@schor.com>.
On 2/13/2014 8:13 AM, Peter Klügl wrote:
> maybe something like
>
> cas.getTypeSystem().getType("my.package.AnnotationName")

+1.  See the Javadocs for TypeSystem:

http://uima.apache.org/d/uimaj-2.5.0/apidocs/org/apache/uima/cas/TypeSystem.html

-Marshall
>
> Best,
>
> Peter
>
> Am 13.02.2014 14:03, schrieb hannes schantl:
>> 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
>>
>


Re: uima jcas get annotation type from string

Posted by Peter Klügl <pk...@uni-wuerzburg.de>.
maybe something like

cas.getTypeSystem().getType("my.package.AnnotationName")

Best,

Peter

Am 13.02.2014 14:03, schrieb hannes schantl:
> 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
>


Re: uima jcas get annotation type from string

Posted by Thomas Ginter <th...@utah.edu>.
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
thomas.ginter@utah.edu




On Feb 14, 2014, at 2:50 AM, Richard Eckart de Castilho <re...@apache.org> wrote:

> On 14.02.2014, at 09:50, hannes schantl <jo...@gmail.com> 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 Ginter801-448-7676thomas.ginter@utah.edu
>> 
>> On Feb 13, 2014, at 6:03 AM, hannes schantl
>> <jo...@gmail.com> <jo...@gmail.com> 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
> 


Re: uima jcas get annotation type from string

Posted by Richard Eckart de Castilho <re...@apache.org>.
On 14.02.2014, at 09:50, hannes schantl <jo...@gmail.com> 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 Ginter801-448-7676thomas.ginter@utah.edu
> 
> On Feb 13, 2014, at 6:03 AM, hannes schantl
> <jo...@gmail.com> <jo...@gmail.com> 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


Re: uima jcas get annotation type from string

Posted by hannes schantl <jo...@gmail.com>.
 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?

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.

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 Ginter801-448-7676thomas.ginter@utah.edu




On Feb 13, 2014, at 6:03 AM, hannes schantl
<jo...@gmail.com> <jo...@gmail.com> 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

Re: uima jcas get annotation type from string

Posted by Thomas Ginter <th...@utah.edu>.
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 Ginter
801-448-7676
thomas.ginter@utah.edu




On Feb 13, 2014, at 6:03 AM, hannes schantl <jo...@gmail.com> 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