The issue is with the way you are declaring domains, it is not a bug in Jena.

In your sample ontology you have things like:

<owl:ObjectProperty rdf:about="#AhasOP">
        <rdfs:range  rdf:resource="#AOP"/>
        <rdfs:domain rdf:resource="#A"/>
        <rdfs:domain rdf:resource="#C"/>
</owl:ObjectProperty>

[I've shortened the URIs and reordered to make it more readable.]

If you supply two domain statements like that then the OWL semantics means that the domain of #AhasOP is now the intersection of #A and #C, so it is a "declared property" of neither of them but only of the intersection. If you mean that the property could be used on either #A or #C then you would need to specify the domain as the union of #A and #C.

However, you don't need to do that here. Properties automatically "inherit" the way you want anyway. If you simply have:

<owl:ObjectProperty rdf:about="#AhasOP">
        <rdfs:range  rdf:resource="#AOP"/>
        <rdfs:domain rdf:resource="#A"/>
</owl:ObjectProperty>

and then declare #C as a sub class of #A then #AhasOP will apply to #C. So will show up in the listDeclaredProperties listing. Similarly for #BhasOP.

Then you have a second problem which is that you are restricting your listings to only show "direct" properties, which isn't helpful if you are trying to show "inherited" properties. So you also need to change

   Iterator it = oc.listDeclaredProperties(true);

to

   Iterator it = oc.listDeclaredProperties(false);

or equivalently:

   Iterator it = oc.listDeclaredProperties();

Dave

On 03/01/14 06:29, Dibyanshu Jaiswal wrote:
In my ontology I have two different classes /*A */and /*B */as
subclasses of /*S*/.
A and B both have ObjectProperties /*AhasOP*/ and /*BhasOP*/ respectively.


I intend to take a user input of class *S *by listing all the
datatypeProperties of S specific to each class using the code as follows:


public static void parseFromGivenRoot(String classUri, OntModel om){
         OntClass oc =
om.getOntClass(classUri);//AppProperties.getBaseIRI()+"Power");
         System.out.println("Parsing :"+ oc.getLocalName());
         TryMain.findDatatypePropOf(classUri, om, 0);

System.out.println("---------------------------------------------------------------------------------");
         ExtendedIterator<OntClass> it = oc.listSubClasses(false);
         while(it.hasNext()){
             OntClass toc = it.next();
             TryMain.parseFromGivenRoot(toc.getURI(), om);
         }
     }

public static void findDatatypePropOf(String classUri, OntModel om, int
level){
         OntClass oc = om.getOntClass(classUri);
         OntClass temp;
         Iterator it = oc.listDeclaredProperties(true);
             while(it.hasNext()){
             String tab="";
             OntProperty op = (OntProperty) it.next();


                 for(int i=0;i<level;i++)tab+="\t"; // just ofr
hierarchical text formatting

                 if(op.getDomain()==null){
                     System.out.println("Found a NULL DOMIAN :
"+op.getLocalName());
                     continue;
                 }
                 if(op.getRange()==null){
                     System.out.println("Found a NULL RANGE :
"+op.getLocalName());
                     continue;
                 }

             if(op.isDatatypeProperty()){

                 System.out.println(tab+op.getDomain().getLocalName()+"
has DatatypeProp "+op.getLocalName()+" with Range :
"+op.getRange().getLocalName());

             }
             if(op.isObjectProperty()){

                 ExtendedIterator rangeIt = op.listRange();
                 while(rangeIt.hasNext()){

                     OntClass toc = (OntClass) rangeIt.next();

System.out.println(tab+op.getDomain().getLocalName()+" has OBJProp
"+op.getLocalName()+" with Range- "+toc.getLocalName());

                     findDatatypePropOf(toc.getURI(), om, level+1);

                 }
             }

            }
      }


The functions are invoked using
TryMain.parseFromGivenRoot("NameSpace#S", om); //om is the OntModel
variable read in OntModelSpec.OWL_MEM mode.

The owl file corresponding is enclosed in attacment : Example_v1.owl
Till here All works fine as expected. to give the following output.


Parsing :S
---------------------------------------------------------------------------------
Parsing :B
B has OBJProp BhasOP with Range- BOP
     BOP has DatatypeProp BhasDP with Range : string
---------------------------------------------------------------------------------
Parsing :A
A has OBJProp AhasOP with Range- AOP
     AOP has DatatypeProp AhasDP with Range : string
---------------------------------------------------------------------------------



The problem I face is as follows: When i intend to add a new class/*C*/
which is supposed to be a subclass of both*A* and *B*, such that *C* has
objectProperty of both *A* and *B*, i.e. I have made the domain class
of*AhasOP* as *A*, *C* and *BhasOP*  as *B*, *C* as shown in
Example_v2.owl (attachment). and run the same program. I get the output
as follows:


Parsing :S
---------------------------------------------------------------------------------
Parsing :B
---------------------------------------------------------------------------------
Parsing :C
C has OBJProp AhasOP with Range- AOP
     AOP has DatatypeProp AhasDP with Range : string
C has OBJProp BhasOP with Range- BOP
     BOP has DatatypeProp BhasDP with Range : string
---------------------------------------------------------------------------------
Parsing :A
---------------------------------------------------------------------------------
Parsing :C
C has OBJProp AhasOP with Range- AOP
     AOP has DatatypeProp AhasDP with Range : string
C has OBJProp BhasOP with Range- BOP
     BOP has DatatypeProp BhasDP with Range : string
---------------------------------------------------------------------------------


Here I fail to find AhasOP and BhasOP to bi listed with clasess A and B,
and insted are listed with C. I can manage the duplicate entries listed
for C as C is subclass of A and B, but Why isnt't the object properties
are not getting listed with classes A and B??

Firstly I was using jena 2.6, and thought it must be bug, so switched to
jena 2.11. But the problem still persists.

I am looking for an expected output as follows:
Parsing :S
---------------------------------------------------------------------------------
Parsing :B
B has OBJProp BhasOP with Range- BOP
     BOP has DatatypeProp BhasDP with Range : string
---------------------------------------------------------------------------------
Parsing :A
A has OBJProp AhasOP with Range- AOP
     AOP has DatatypeProp AhasDP with Range : string
---------------------------------------------------------------------------------
Parsing :C
C has OBJProp AhasOP with Range- AOP
     AOP has DatatypeProp AhasDP with Range : string
C has OBJProp BhasOP with Range- BOP
     BOP has DatatypeProp BhasDP with Range : string
---------------------------------------------------------------------------------

after i mange to eliminate the 2nd listing of the same class i.e class C.

--
_Dibyanshu Jaiswal_
Mb: +91 9038304989



Reply via email to