On 03/01/14 10:42, Dibyanshu Jaiswal wrote:
Thanks Dave! the answer is really helpfull. I know that inferenceing
leads to inherit properties as well. But I had to switch to this
approach, because in my actual working ontology when i load the ontology
in in inferencing mode using OntModelSpec.OWL_MEM_RULE_INF; or using
some externam reasoner like Pellet, the program doesnt runs successfully
and ends up with an error after a while(10-15mins) :
Exception in thread "main" java.lang.OutOfMemoryError: GC overhead limit
exceeded
at java.util.HashMap.newKeyIterator(HashMap.java:972)
at java.util.HashMap$KeySet.iterator(HashMap.java:1006)
at java.util.HashSet.iterator(HashSet.java:170)
..
..
Troubleshooting this, I Increased the memory alloted for JVM to 1GB, but
still the results are same. During the idle time the CPU statistics goes
high to 100% and computer hangs sometimes. For the ontologies like
Example_v1 and v2, as in above attachments, the OWL_MEM_RULE_INF works
fine. But i really need the Inferencing mechanism to work for my actual
ontology. It will solve a lot of trouble for me. My working Ontology is
an extension of two ontologies combined and downloaded from:
http://www.loa.istc.cnr.it/ontologies/DUL.owl
http://www.w3.org/2005/Incubator/ssn/ssnx/ssn.owl
where ssn.owl imports DUL.owl
Even without adding much entities to my owl the Inference still fails.
Below I have provided all the 3 owls, where Trial.owl is my additions
importing ssn.owl directly and DUL.owl indirectly.
Inferencing really needed!!
I wish/hope you have a solution to this too!!
There's two separate issues here - listing declared properties (your
original question) and inference costs.
For your original question you don't need explicit inference to make
that work:
[[[
public void temp() throws Exception {
Model model = FileManager.get().loadModel("data/temp.ttl");
OntModel ont =
ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, model);
check(ont, "http://example.com/A");
check(ont, "http://example.com/B");
check(ont, "http://example.com/C");
}
private void check(OntModel ont, String uri) {
OntClass cls = ont.getOntClass(uri);
if (cls == null) {
System.out.println("Can't find " + uri);
} else {
System.out.println("Properties of " + uri);
ExtendedIterator<OntProperty> i =
cls.listDeclaredProperties(false);
while (i.hasNext()) {
System.out.println(" - " + i.next());
}
}
}
]]]
(Note, no inference)
where temp.ttl is:
[[[
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix eg: <http://example.com/> .
eg:S a owl:Class .
eg:A a owl:Class; rdfs:subClassOf eg:S .
eg:B a owl:Class; rdfs:subClassOf eg:S .
eg:C a owl:Class; rdfs:subClassOf eg:A, eg:B .
eg:pa a owl:DatatypeProperty; rdfs:domain eg:A .
eg:pb a owl:DatatypeProperty; rdfs:domain eg:B .
]]]
Produces
[[[
Properties of http://example.com/A
- http://example.com/pa
Properties of http://example.com/B
- http://example.com/pb
Properties of http://example.com/C
- http://example.com/pb
- http://example.com/pa
]]]
As to your new question ... use OntModelSpec.OWL_MEM_MICRO_RULE_INF if
you possibly can, it's a much better trade-off of performance v.s.
completeness than OWL_MEM_RULE_INF.
If that doesn't do the job, and if Pellet is also too slow then I'm
afraid you are out of options for OWL inference under jena!
Dave
On Fri, Jan 3, 2014 at 1:30 PM, Dave Reynolds <[email protected]
<mailto:[email protected]>> wrote:
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
--
_Dibyanshu Jaiswal_
Mb: +91 9038304989