Rogan Creswick wrote:
> On Sat, Sep 5, 2009 at 8:43 PM, Marshall Schor <[email protected]> wrote:
>
>> The method JCasRegistry.getClassForIndex... returns a Java
>> cover class corresponding to a particular CAS type.
>> As previously discussed, there can be multiple definitions for
>> these.
>>
>
> How do you map from one to the other, or how do you make use of the
> annotation types that come out of a PEAR if they are different
> CAS/cover types (I'm still a bit fuzzy on that distinction) than those
> the invoking code is aware of?
The actual data is contained inside the CAS. Within the PEAR, the
PEAR's JCas cover classes are used. Outside of the PEAR, the outside
JCas cover classes are used.
So, imagine that inside the PEAR, it created an instance of a CAS type
FOO and set the feature FooFeature to some value, all using the PEAR's
JCas cover classes.
Now, when the CAS is passed out of the PEAR, it can be accessed with the
JCas cover classes being used there. So, outside the PEAR, the CAS has
the same FOO instance, with FooFeature set, and it can be accessed.
> The definition for the cover class
> that is used to annotate the content is contained within the pear (as
> a jar that reside's in the PEARs lib dir, and on the pear's
> classpath), so the calling code (the 'core' module in my case) can't
> see that definition.
>
True, but it shouldn't need to. It *can* see the actual data in the
CAS, accessed via its own cover classes.
> I could treat it as an Annotation instance, but then I can't access
> the data I need -- nor can I filter the types that way. Since the
> type id isn't a compile-time constant, I can't store that somewhere
> that core can access, so filtering based on that is out too. I could
> possibly filter with the Type from
> jcas.getTypeSystem.getType(canonicalName), but that would require a
> magic string somewhere that would have to be maintained along side the
> definition of Redaction (without access to the Redaction class file, I
> can't use the Redaction.class.getCanonicalName() trick below).
>
I confess to not quite following what the issue is. It seems something
along the lines: the PEAR puts something into the CAS, and now the
"core" wants to iterate over it, but doesn't have a direct way of
knowing what the PEAR put into the CAS - is that right?
If so, then a simple solution may be to have the PEAR put into the CAS
in some agreed-upon FeatureStructure the name of the CAS type the PEAR
created.
>
>> Rogan Creswick wrote:
>>
>>> a true function. It seems like there are at least two parallel ways
>>> to retrieve types, and in my experience, they don't return the same
>>> results--at least when getting filtered annotation indices. (The ways
>>> being: JCasRegistry.getClassForIndex(MyAnnotationType.type) and
>>> aJCas.getTypeSystem().getTypeByName(MyAnnotationType.class.getType())
>>>
>>>
>> The second form I think is written incorrectly - it won't compile for me
>>
>
> My apologies, I was being lazy and I didn't look up the actual line of code.
>
> Here's the actual method -- with both approaches to getting an
> AnnotationIndex:
>
> /**
> * Collects the Redaction annotations on the JCas and creates a list of
> * Violations from them.
> *
> * @param jcas The JCas with annotations.
> * @return A list of Violations on the document.
> */
> private ImmutableList<Violation> extractViolations(final JCas jcas) {
> Builder<Violation> builder = ImmutableList.builder();
>
> // First approach: (used in tutorial code, most obvious)
> // This delegates to JCasRegistry.getClassForIndex(int)
> //
> // AnnotationIndex index = jcas.getAnnotationIndex(Redaction.type);
>
This looks fine, assuming the definition of the Redaction type is the
underlying CAS type.you want to iterate over.
> // Second approach: uses the canonical class name to extract a
> // type from the JCAS's type system:
> Type redactionType =
> jcas.getTypeSystem().getType(Redaction.class.getCanonicalName());
> AnnotationIndex index = jcas.getAnnotationIndex(redactionType);
>
This looks fine too. I don't understand what isn't working here. If
these are getting different values out of the CAS, then something very
strange is going on, I think. If this is true, do you have any idea
what the different underlying CAS types are, that are being fetched via
the iteration?
-Marshall
> // the returned index from jcas is restricted based on the
> // Redaction.type passed in. See API docs at:
> //
> http://incubator.apache.org/uima/downloads/releaseDocs/2.2.2-incubating/docs/api/org/apache/uima/jcas/JCas.html#getAnnotationIndex(int)
> @SuppressWarnings("unchecked")
> Iterator<Redaction> itr = index.iterator();
>
> while (itr.hasNext()) {
> Redaction r = itr.next();
> int start = r.getBegin();
> int end = r.getEnd();
>
> Set<IRestriction> restrictions =
> parseRestrictions(r.getRestrictions());
>
> builder.add(new Violation(start, end, restrictions));
> }
>
> return builder.build();
> }
>
>
> Thanks for taking the time to help!
>
> --Rogan
>
>