You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by 卢思佳 <lu...@tju.edu.cn> on 2011/04/18 07:45:32 UTC

some question

Now I am learning Jena;

I read a entity in a RDF file and i found the properties .
but when i try to find the datatyperange and the objectrang of the property , it fail.
I don't know how to do about it .

my code:

ExtendedIterator rangIterator=property.listRange();
   while (rangIterator.hasNext()){
    OntClass rangClass=(OntClass)rangIterator.next();
    if(rangClass.isUnionClass()){
     System.out.println("data****************");
     UnionClass unionClass=rangClass.asUnionClass();
     rangClassIterator=unionClass.listOperands();
    }
    else{
     rangClassIterator=property.listRange();
    }
   } 
while(rangClassIterator.hasNext()){
    OntClass itemClass=(OntClass)rangClassIterator.next(); 
    if(itemClass.isDatatypeProperty()){
     System.out.println("   datarangClass:"+itemClass.getLocalName()); 
    }
    else{
     System.out.println("   objectrangClass:"+itemClass.getLocalName()); 
    }


it does't work.

thank you !!

lusijia

Re: some question

Posted by Dave Reynolds <da...@gmail.com>.
Hi Lusijia,

Could you gives us a little more information on exactly how it doesn't
work ...

Do you get an error or just not see the output your were expecting?

If you get an error, what is the error?

Does your RDF file definitely have the range statements in and have you
read in the fine successfully?

On Mon, 2011-04-18 at 13:45 +0800, 卢思佳 wrote: 
> Now I am learning Jena;
> 
> I read a entity in a RDF file and i found the properties .
> but when i try to find the datatyperange and the objectrang of the property , it fail.
> I don't know how to do about it .
> 
> my code:
> 
> ExtendedIterator rangIterator=property.listRange();
>    while (rangIterator.hasNext()){
>     OntClass rangClass=(OntClass)rangIterator.next();
>     if(rangClass.isUnionClass()){
>      System.out.println("data****************");
>      UnionClass unionClass=rangClass.asUnionClass();
>      rangClassIterator=unionClass.listOperands();
>     }
>     else{
>      rangClassIterator=property.listRange();
>     }
>    } 

Unless I'm miss-counting '}' then you have now closed the first while
loop. This means that the next loop only runs for the final setting of
rangClassIterator. I suspect you meant to have the next loop embedded
inside this loop.

> while(rangClassIterator.hasNext()){
>     OntClass itemClass=(OntClass)rangClassIterator.next(); 
>     if(itemClass.isDatatypeProperty()){
>      System.out.println("   datarangClass:"+itemClass.getLocalName()); 
>     }
>     else{
>      System.out.println("   objectrangClass:"+itemClass.getLocalName()); 
>     }


> 
> it does't work.
> 
> thank you !!
> 
> lusijia

Dave