uima-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Martin Wunderlich <martin...@gmx.net>
Subject Re: Question on JCasUtil's selectCovered(...)
Date Sat, 01 Aug 2015 21:06:18 GMT
Yes, I think you might be right, Richard, and that the problem is with the use of Generics.


This would be the concrete FE class: 

public class StartingPositionOfPremiseUFE<Premise> extends StartingPositionOfPropositionUFE
{
    
    public static String FN_STARTINGPOSITIONOFPROPOSITION = "StartingPositionOfPremise";

	@Override
	List<Premise> getPropositions(JCas jcas, int start, int end) {
		return JCasUtil.selectCovered(jcas, Premise.class, start, end);
	}
}

The call to selectCovered(…) gives the described error. The method getPropositions(…)
is defined as abstract in the super-class, which looks like this: 


abstract public class StartingPositionOfPropositionUFE<T extends Proposition> extends
FeatureExtractorResource_ImplBase implements ClassificationUnitFeatureExtractor{
	...
    public List<Feature> extract(JCas jcas, TextClassificationUnit classificationUnit)
{
    	List<? extends Proposition> props = (List<? extends Proposition>) getPropositions(jcas,
start, end);
        if( props != null && props.size() > 0) {
        	Proposition firstProposition = props.get(0);
        	startingPos = firstProposition.getBegin();
        }
        
	List<Feature> featList = new ArrayList<Feature>();
        featList.add(new Feature(FN_STARTINGPOSITIONOFPROPOSITION, startingPos));
        
        return featList;
    }

    abstract List<?> getPropositions(JCas jcas, int start, int end);
}

I’ve removed the irrelevant bits to make it more concise. 

Cheers, 

Martin
 

> Am 01.08.2015 um 16:14 schrieb Richard Eckart de Castilho <rec@apache.org>:
> 
> 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
> 


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message