uima-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thilo Götz <twgo...@gmx.de>
Subject Re: printing features values
Date Tue, 09 Nov 2010 15:42:40 GMT
On 11/9/2010 16:04, Andrea Turbati wrote:
>  Hi all,
> I'm trying to make a simple function which take an annotation and a Type and
> print all the value associated with all the feature present in the Type.
> This is the recursive function:
> 
> public void printTypeSystem(Type uimaType, Annotation annotation, int level){
>         String levelString="\t";
>         for (int i=0; i<level; ++i)
>             levelString += "\t";
>         List <Feature> feauturesList = uimaType.getFeatures();
>         if(level == 1)
>             System.out.println("T.S. = "+uimaType.getName());
>         for(int i=0; i<feauturesList.size(); ++i){
>             Feature feature = (Feature) feauturesList.get(i);
>             String nameFeat = feature.getName();
>             if(!nameFeat.startsWith("uima.")){
>                 Type typeRange = feature.getRange();
>                 if(typeRange.isPrimitive()){
>                     String value = annotation.getFeatureValueAsString(feature);
>                     System.out.println(levelString+"F: "+nameFeat+" = "+" V:
> "+value);
>                 }
>                 else{
>                     System.out.println(levelString+"F: "+nameFeat+" = "+" TS:
> "+typeRange.getName());
>                     printTypeSystem(typeRange, annotation, level+1);

Here's your problem (I think).  You're calling printTypeSystem recursively,
but with the original annotation as parameter, not the feature value.  This
line should be something like (again, typing from memory, so please verify):

     printTypeSystem(typeRange, annotation.getFeatureValue(feature), level+1);

Also, I'm not sure you want to provide the type of the annotation/FS
explicitly like you're doing.  Better to obtain with annotation.getType().
The actual type of the annotation may be more specific than the range type
of the feature.  Your code would also be more general if you used
FeatureStructure instead of Annotation.

Finally, check the UIMA source code.  You can either just use the
FeatureStructure.toString() method to do what you want, or you can adapt
the source code in FeatureStructureImpl.java.

--Thilo

>                 }
>             }
>         }
>     }
> 
> 
> The problem is that I'm able to print only the values associated with the "first
> level" of features (when they are primitive). If for example a Type has a
> feature that as a value as another Type (the else in the source code) when I do
> annotation.getFeatureValueAsString(feature) to print the values associated with
> the feature of this "inside" Type all I get is an empty String (not an error or
> a null value).
> 
> Is there a problem in my code or the error is somewhere else?
> 
> Thanks
> 
> Andrea Turbati
> 

Mime
View raw message