Hi Martin,
assuming this constellation
- Proposition extends Annotation
- Conclusion extends Proposition
- Premise extends Proposition
then the following lines should all be valid:
- selectCovered(jcas, Annotation.class, 0, 100);
- selectCovered(jcas, Proposition.class, 0, 100);
- selectCovered(jcas, Conclusion.class, 0, 100);
- selectCovered(jcas, Premise.class, 0, 100);
more generically, this should also be valid:
<T extends Proposition> void doSomething(JCas jcas, Class<T> aClazz) {
selectCovered(jcas, aClazz, 0, 100);
}
If you can show a minimal example that doesn't work, I may be able to say more.
To me, so far it looks like a problem with the generics in your code, not with
uimaFIT.
Cheers,
-- Richard
On 31.07.2015, at 22:00, Martin Wunderlich <martin_wu@gmx.net> wrote:
> Hi all,
>
> I am currently developing some feature extractors in the DKPro framework and I have come
across a problem with the Class type in the following method in org.apache.uima.fit.util.JCasUtil:
>
> public static <T extends Annotation> List<T> selectCovered(JCas jCas, final
Class<T> type,
> int begin, int end) {
> return cast(CasUtil.selectCovered(jCas.getCas(), getType(jCas, type), begin, end));
> }
>
> In my type system I have a base type „Proposition" that extends „Annotation" and
two more types which are derived from the base type: „Conclusion“ and „Premise". If
I use the base type for the generic type parameter T in this method above, it works fine.
If I use one of the sub-types of the base type, I get the following error:
>
> - Bound mismatch: The generic method selectCovered(JCas, Class<T>, int, int) of
type JCasUtil is not applicable for the arguments (JCas, Class<Conclusion>, int, int).
The
> inferred type Conclusion is not a valid substitute for the bounded parameter <T
extends Annotation>
>
> Background is that I would like to use one abstract feature extractor for common code
which is parameterized with <T extends Proposition> and the two concrete sub-class
FE’s, which are parameterized with the two sub-types.
>
> Maybe I have some misunderstanding regarding the use of Generics here. Could it be that
in the definition of selectCovered() the clause <T extends Annotation> allows only direct
sub-types of Annotation? Interestingly enough, if I don’t parameterize the sub-class FEs,
I don’t get any errors.
> Thanks a lot.
>
> Cheers,
>
> Martin
|