I'd figure out what could be the problem in the function. Actually I wouldn't say that to be a problem. Because since properties of owl:Thing are listed (you were right about that) few of such properties had their range as same as domain or some other class in its super class hierarchy, according to my code, since I am parsing the tree in top down fashion.. It results in a closed loop.
On Tue, Jan 7, 2014 at 1:55 PM, Dave Reynolds <[email protected]>wrote: > On 07/01/14 06:09, Dibyanshu Jaiswal wrote: > >> Dave, >> I'm sorry for injecting a different question in the thread of my >> original question. But I have tried a lot of to solve the problem with >> different perspectives an so have eneded up with more unanswered doubts >> >> To my observation since I have started working with Jena and having >> tried again as per your suggesstion: >> >> ExtendedIterator<OntProperty> i = cls.listDeclaredProperties(false); >> >> Always lists all/most the declared properties in the ontology, which may >> or may not be related to the ontclass in concern. >> > > That's likely to be due to properties which have unconstrained domain > (i.e. domain of owl:Thing) which, by definition of listDeclaredProperties > are applicable to instances of any class. > > Note that this whole notion of treating OWL as if it were an object-like > system with properties associated with classes and inheritance is > fundamentally doomed to failure. OWL is not like that. > > If you haven't already read it then the critical documentation which > explains how Jena tries to ease this pain is: > http://jena.apache.org/documentation/notes/rdf-frames.html > > > Using my function >> findDatatypePropOf("NS:C") >> results in an iinfinite loop. >> > > That would be a problem with your function :) > > > I have tried this with some different ontology as well (which has no >> relation to the current working ontology), but the results were same. >> Instead if the same code is executed in inference mode, the results are >> good and as expected. >> > > Dave > > On Fri, Jan 3, 2014 at 4:38 PM, Dave Reynolds <[email protected] >> <mailto:[email protected]>> wrote: >> >> 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.loa.istc.cnr.it/ontologies/DUL.owl> >> http://www.w3.org/2005/__Incubator/ssn/ssnx/ssn.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# >> <http://www.w3.org/2001/XMLSchema#>> . >> @prefix owl: <http://www.w3.org/2002/07/__owl# >> <http://www.w3.org/2002/07/owl#>> . >> @prefix rdf: <http://www.w3.org/1999/02/22-__rdf-syntax-ns# >> <http://www.w3.org/1999/02/22-rdf-syntax-ns#>> . >> @prefix rdfs: <http://www.w3.org/2000/01/__rdf-schema# >> >> <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]> >> <mailto:dave.e.reynolds@gmail.__com >> >> <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 >> >> >> >> >> >> >> -- >> _Dibyanshu Jaiswal_ >> Mb: +91 9038304989 >> >> >> > -- *Dibyanshu Jaiswal* Mb: +91 9038304989
