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