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
Example_v1.owl
Description: application/rdf
Example_v2.owl
Description: application/rdf
