You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by huang huiliang <hu...@live.cn> on 2014/09/09 09:07:37 UTC

答复: why does the addDomain method affect the domain's SuperClass?

Thank you for your suggestion ,Dave. I modify my code as you said.
Before p.addDomain(class2) ,the class2's SupClass is :
http://www.xxx.org.cn/standards/publishing/ontology/cores/class1.
But after p.addDomain(class2) execute ,class2's has two SupClasses.
http://www.w3.org/2000/01/rdf-schema#Resource is added to class2's
SupClasses.
Now the question is : why would addDomain(class2) add rdfs:Resouce to
class2's SupClasses.
Thanks for your attention.
-----邮件原件-----
发件人: Dave Reynolds [mailto:dave.e.reynolds@gmail.com] 
发送时间: 2014年9月9日 14:51
收件人: users@jena.apache.org
主题: Re: why does the addDomain method affect the domain's SuperClass?

On 09/09/14 07:40, huang huiliang wrote:
> I'm creating an ontology from excel files and I have some problems to 
> make my program work.
>
> The first problem I encounter is that I can't get the right superclass 
> .The simplest code example is below.
>
> Code begin:
>
> OntModel individuals = ModelFactory.createOntologyModel();
>
>        TreeMap<String, String> namespaces=new 
> TreeMap<String,String>();
>
>        namespaces.put("pubo",
> "http://www.xxx.org.cn/standards/publishing/ontology/cores/");
>
>        individuals.setNsPrefixes(namespaces);
>
>        OntClass
> class1=individuals.createClass(namespaces.get("pubo")+"class1");
>
>        class1.setLabel("class1", "en");
>
>        OntClass
> class2=individuals.createClass(namespaces.get("pubo")+"class2");
>
>        class2.setLabel("class2", "en");
>
> class2.setSuperClass(class1);
>
>        System.out.println(class2.getSuperClass().getURI());
>
>        DatatypeProperty p = 
> individuals.createDatatypeProperty(namespaces
>
>              .get("pubo") + "haha");
>
>        p.addDomain(class2);
>
>        System.out.println(class2.getSuperClass().getURI());
>
> Code end
>
> The first output is:
> <http://www.xxx.org.cn/standards/publishing/ontology/cores/class1>
> http://www.xxx.org.cn/standards/publishing/ontology/cores/class1
>
> The second output is : http://www.w3.org/2000/01/rdf-schema#Resource
>
> I have no idea why the two output are different? Have I done something 
> wrong? Any suggestions?

Mostly likely possibility is that getSuperClass is simply picking a
different random value from the set of super classes (see the javadoc). 
I don't know if getSuperClass is supposed to list only direct superclasses
but if you are getting rdfs:Resource then probably not.

Suggest using listSuperClasses(true) to find out what's going on.

Dave


答复: 答复: 答复: why does the addDomain method affect the domain's SuperClass?

Posted by huang huiliang <hu...@live.cn>.
Thanks, Dave. 
Suddenly it all makes sense. You are genius. Sorry for wasting your time on
this simple problem.
I'm can't be too grateful for your help.
So all I have to do is to manually eliminate the Rdfs:resource from
SuperClass.
Very helpful ,thanks again.

-----邮件原件-----
发件人: Dave Reynolds [mailto:dave.e.reynolds@gmail.com] 
发送时间: 2014年9月9日 15:44
收件人: users@jena.apache.org
主题: Re: 答复: 答复: why does the addDomain method affect the domain's
SuperClass?

On 09/09/14 08:19, huang huiliang wrote:
> All codes involved have been listed in my original post. It seems that 
> I just used the default . And individual model has nothing else.
> I don't know what's wrong.

OK if you don't need inference then use:

OntModel individuals =
ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);

That will make this go away.

If you do need inference then use OWL_MEM_MINI_RULE_INF.

What seems to be happening is that the default for OntModels is to specify
RDFS reasoning. In RDFS then everything is an rdfs:Resource and every class
is a subclass of rdfs:Resource so what it is saying is not wrong. The RDFS
reasoner doesn't know about owl:Class but does know about rdfs:domain so as
soon as you make the domain statement the reasoner works out a bunch of
stuff about class2 but not quite enough to know that class1 is also a
subClass of rdfs:Resource (and so remove rdfs:Resource from the direct
superclasses).

Dave

> -----邮件原件-----
> 发件人: Dave Reynolds [mailto:dave.e.reynolds@gmail.com]
> 发送时间: 2014年9月9日 15:12
> 收件人: users@jena.apache.org
> 主题: Re: 答复: why does the addDomain method affect the domain's 
> SuperClass?
>
> Don't know.
>
> What reasoner configuration are you using?
>
> Is there any other data in the "individuals" model?
>
> Dave
>
> On 09/09/14 08:07, huang huiliang wrote:
>> Thank you for your suggestion ,Dave. I modify my code as you said.
>> Before p.addDomain(class2) ,the class2's SupClass is :
>> http://www.xxx.org.cn/standards/publishing/ontology/cores/class1.
>> But after p.addDomain(class2) execute ,class2's has two SupClasses.
>> http://www.w3.org/2000/01/rdf-schema#Resource is added to class2's 
>> SupClasses.
>> Now the question is : why would addDomain(class2) add rdfs:Resouce to 
>> class2's SupClasses.
>> Thanks for your attention.
>> -----邮件原件-----
>> 发件人: Dave Reynolds [mailto:dave.e.reynolds@gmail.com]
>> 发送时间: 2014年9月9日 14:51
>> 收件人: users@jena.apache.org
>> 主题: Re: why does the addDomain method affect the domain's SuperClass?
>>
>> On 09/09/14 07:40, huang huiliang wrote:
>>> I'm creating an ontology from excel files and I have some problems 
>>> to make my program work.
>>>
>>> The first problem I encounter is that I can't get the right 
>>> superclass .The simplest code example is below.
>>>
>>> Code begin:
>>>
>>> OntModel individuals = ModelFactory.createOntologyModel();
>>>
>>>          TreeMap<String, String> namespaces=new 
>>> TreeMap<String,String>();
>>>
>>>          namespaces.put("pubo",
>>> "http://www.xxx.org.cn/standards/publishing/ontology/cores/");
>>>
>>>          individuals.setNsPrefixes(namespaces);
>>>
>>>          OntClass
>>> class1=individuals.createClass(namespaces.get("pubo")+"class1");
>>>
>>>          class1.setLabel("class1", "en");
>>>
>>>          OntClass
>>> class2=individuals.createClass(namespaces.get("pubo")+"class2");
>>>
>>>          class2.setLabel("class2", "en");
>>>
>>> class2.setSuperClass(class1);
>>>
>>>          System.out.println(class2.getSuperClass().getURI());
>>>
>>>          DatatypeProperty p =
>>> individuals.createDatatypeProperty(namespaces
>>>
>>>                .get("pubo") + "haha");
>>>
>>>          p.addDomain(class2);
>>>
>>>          System.out.println(class2.getSuperClass().getURI());
>>>
>>> Code end
>>>
>>> The first output is:
>>> <http://www.xxx.org.cn/standards/publishing/ontology/cores/class1>
>>> http://www.xxx.org.cn/standards/publishing/ontology/cores/class1
>>>
>>> The second output is : http://www.w3.org/2000/01/rdf-schema#Resource
>>>
>>> I have no idea why the two output are different? Have I done 
>>> something wrong? Any suggestions?
>>
>> Mostly likely possibility is that getSuperClass is simply picking a 
>> different random value from the set of super classes (see the javadoc).
>> I don't know if getSuperClass is supposed to list only direct 
>> superclasses but if you are getting rdfs:Resource then probably not.
>>
>> Suggest using listSuperClasses(true) to find out what's going on.
>>
>> Dave
>>
>


Re: 答复: 答复: why does the addDomain method affect the domain's SuperClass?

Posted by Dave Reynolds <da...@gmail.com>.
On 09/09/14 08:19, huang huiliang wrote:
> All codes involved have been listed in my original post. It seems that I
> just used the default . And individual model has nothing else.
> I don't know what's wrong.

OK if you don't need inference then use:

OntModel individuals = 
ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);

That will make this go away.

If you do need inference then use OWL_MEM_MINI_RULE_INF.

What seems to be happening is that the default for OntModels is to 
specify RDFS reasoning. In RDFS then everything is an rdfs:Resource and 
every class is a subclass of rdfs:Resource so what it is saying is not 
wrong. The RDFS reasoner doesn't know about owl:Class but does know 
about rdfs:domain so as soon as you make the domain statement the 
reasoner works out a bunch of stuff about class2 but not quite enough to 
know that class1 is also a subClass of rdfs:Resource (and so remove 
rdfs:Resource from the direct superclasses).

Dave

> -----邮件原件-----
> 发件人: Dave Reynolds [mailto:dave.e.reynolds@gmail.com]
> 发送时间: 2014年9月9日 15:12
> 收件人: users@jena.apache.org
> 主题: Re: 答复: why does the addDomain method affect the domain's
> SuperClass?
>
> Don't know.
>
> What reasoner configuration are you using?
>
> Is there any other data in the "individuals" model?
>
> Dave
>
> On 09/09/14 08:07, huang huiliang wrote:
>> Thank you for your suggestion ,Dave. I modify my code as you said.
>> Before p.addDomain(class2) ,the class2's SupClass is :
>> http://www.xxx.org.cn/standards/publishing/ontology/cores/class1.
>> But after p.addDomain(class2) execute ,class2's has two SupClasses.
>> http://www.w3.org/2000/01/rdf-schema#Resource is added to class2's
>> SupClasses.
>> Now the question is : why would addDomain(class2) add rdfs:Resouce to
>> class2's SupClasses.
>> Thanks for your attention.
>> -----邮件原件-----
>> 发件人: Dave Reynolds [mailto:dave.e.reynolds@gmail.com]
>> 发送时间: 2014年9月9日 14:51
>> 收件人: users@jena.apache.org
>> 主题: Re: why does the addDomain method affect the domain's SuperClass?
>>
>> On 09/09/14 07:40, huang huiliang wrote:
>>> I'm creating an ontology from excel files and I have some problems to
>>> make my program work.
>>>
>>> The first problem I encounter is that I can't get the right
>>> superclass .The simplest code example is below.
>>>
>>> Code begin:
>>>
>>> OntModel individuals = ModelFactory.createOntologyModel();
>>>
>>>          TreeMap<String, String> namespaces=new
>>> TreeMap<String,String>();
>>>
>>>          namespaces.put("pubo",
>>> "http://www.xxx.org.cn/standards/publishing/ontology/cores/");
>>>
>>>          individuals.setNsPrefixes(namespaces);
>>>
>>>          OntClass
>>> class1=individuals.createClass(namespaces.get("pubo")+"class1");
>>>
>>>          class1.setLabel("class1", "en");
>>>
>>>          OntClass
>>> class2=individuals.createClass(namespaces.get("pubo")+"class2");
>>>
>>>          class2.setLabel("class2", "en");
>>>
>>> class2.setSuperClass(class1);
>>>
>>>          System.out.println(class2.getSuperClass().getURI());
>>>
>>>          DatatypeProperty p =
>>> individuals.createDatatypeProperty(namespaces
>>>
>>>                .get("pubo") + "haha");
>>>
>>>          p.addDomain(class2);
>>>
>>>          System.out.println(class2.getSuperClass().getURI());
>>>
>>> Code end
>>>
>>> The first output is:
>>> <http://www.xxx.org.cn/standards/publishing/ontology/cores/class1>
>>> http://www.xxx.org.cn/standards/publishing/ontology/cores/class1
>>>
>>> The second output is : http://www.w3.org/2000/01/rdf-schema#Resource
>>>
>>> I have no idea why the two output are different? Have I done
>>> something wrong? Any suggestions?
>>
>> Mostly likely possibility is that getSuperClass is simply picking a
>> different random value from the set of super classes (see the javadoc).
>> I don't know if getSuperClass is supposed to list only direct
>> superclasses but if you are getting rdfs:Resource then probably not.
>>
>> Suggest using listSuperClasses(true) to find out what's going on.
>>
>> Dave
>>
>


答复: 答复: why does the addDomain method affect the domain's SuperClass?

Posted by huang huiliang <hu...@live.cn>.
All codes involved have been listed in my original post. It seems that I
just used the default . And individual model has nothing else. 
I don't know what's wrong. 

-----邮件原件-----
发件人: Dave Reynolds [mailto:dave.e.reynolds@gmail.com] 
发送时间: 2014年9月9日 15:12
收件人: users@jena.apache.org
主题: Re: 答复: why does the addDomain method affect the domain's
SuperClass?

Don't know.

What reasoner configuration are you using?

Is there any other data in the "individuals" model?

Dave

On 09/09/14 08:07, huang huiliang wrote:
> Thank you for your suggestion ,Dave. I modify my code as you said.
> Before p.addDomain(class2) ,the class2's SupClass is :
> http://www.xxx.org.cn/standards/publishing/ontology/cores/class1.
> But after p.addDomain(class2) execute ,class2's has two SupClasses.
> http://www.w3.org/2000/01/rdf-schema#Resource is added to class2's 
> SupClasses.
> Now the question is : why would addDomain(class2) add rdfs:Resouce to 
> class2's SupClasses.
> Thanks for your attention.
> -----邮件原件-----
> 发件人: Dave Reynolds [mailto:dave.e.reynolds@gmail.com]
> 发送时间: 2014年9月9日 14:51
> 收件人: users@jena.apache.org
> 主题: Re: why does the addDomain method affect the domain's SuperClass?
>
> On 09/09/14 07:40, huang huiliang wrote:
>> I'm creating an ontology from excel files and I have some problems to 
>> make my program work.
>>
>> The first problem I encounter is that I can't get the right 
>> superclass .The simplest code example is below.
>>
>> Code begin:
>>
>> OntModel individuals = ModelFactory.createOntologyModel();
>>
>>         TreeMap<String, String> namespaces=new 
>> TreeMap<String,String>();
>>
>>         namespaces.put("pubo",
>> "http://www.xxx.org.cn/standards/publishing/ontology/cores/");
>>
>>         individuals.setNsPrefixes(namespaces);
>>
>>         OntClass
>> class1=individuals.createClass(namespaces.get("pubo")+"class1");
>>
>>         class1.setLabel("class1", "en");
>>
>>         OntClass
>> class2=individuals.createClass(namespaces.get("pubo")+"class2");
>>
>>         class2.setLabel("class2", "en");
>>
>> class2.setSuperClass(class1);
>>
>>         System.out.println(class2.getSuperClass().getURI());
>>
>>         DatatypeProperty p =
>> individuals.createDatatypeProperty(namespaces
>>
>>               .get("pubo") + "haha");
>>
>>         p.addDomain(class2);
>>
>>         System.out.println(class2.getSuperClass().getURI());
>>
>> Code end
>>
>> The first output is:
>> <http://www.xxx.org.cn/standards/publishing/ontology/cores/class1>
>> http://www.xxx.org.cn/standards/publishing/ontology/cores/class1
>>
>> The second output is : http://www.w3.org/2000/01/rdf-schema#Resource
>>
>> I have no idea why the two output are different? Have I done 
>> something wrong? Any suggestions?
>
> Mostly likely possibility is that getSuperClass is simply picking a 
> different random value from the set of super classes (see the javadoc).
> I don't know if getSuperClass is supposed to list only direct 
> superclasses but if you are getting rdfs:Resource then probably not.
>
> Suggest using listSuperClasses(true) to find out what's going on.
>
> Dave
>


Re: 答复: why does the addDomain method affect the domain's SuperClass?

Posted by Dave Reynolds <da...@gmail.com>.
Don't know.

What reasoner configuration are you using?

Is there any other data in the "individuals" model?

Dave

On 09/09/14 08:07, huang huiliang wrote:
> Thank you for your suggestion ,Dave. I modify my code as you said.
> Before p.addDomain(class2) ,the class2's SupClass is :
> http://www.xxx.org.cn/standards/publishing/ontology/cores/class1.
> But after p.addDomain(class2) execute ,class2's has two SupClasses.
> http://www.w3.org/2000/01/rdf-schema#Resource is added to class2's
> SupClasses.
> Now the question is : why would addDomain(class2) add rdfs:Resouce to
> class2's SupClasses.
> Thanks for your attention.
> -----邮件原件-----
> 发件人: Dave Reynolds [mailto:dave.e.reynolds@gmail.com]
> 发送时间: 2014年9月9日 14:51
> 收件人: users@jena.apache.org
> 主题: Re: why does the addDomain method affect the domain's SuperClass?
>
> On 09/09/14 07:40, huang huiliang wrote:
>> I'm creating an ontology from excel files and I have some problems to
>> make my program work.
>>
>> The first problem I encounter is that I can't get the right superclass
>> .The simplest code example is below.
>>
>> Code begin:
>>
>> OntModel individuals = ModelFactory.createOntologyModel();
>>
>>         TreeMap<String, String> namespaces=new
>> TreeMap<String,String>();
>>
>>         namespaces.put("pubo",
>> "http://www.xxx.org.cn/standards/publishing/ontology/cores/");
>>
>>         individuals.setNsPrefixes(namespaces);
>>
>>         OntClass
>> class1=individuals.createClass(namespaces.get("pubo")+"class1");
>>
>>         class1.setLabel("class1", "en");
>>
>>         OntClass
>> class2=individuals.createClass(namespaces.get("pubo")+"class2");
>>
>>         class2.setLabel("class2", "en");
>>
>> class2.setSuperClass(class1);
>>
>>         System.out.println(class2.getSuperClass().getURI());
>>
>>         DatatypeProperty p =
>> individuals.createDatatypeProperty(namespaces
>>
>>               .get("pubo") + "haha");
>>
>>         p.addDomain(class2);
>>
>>         System.out.println(class2.getSuperClass().getURI());
>>
>> Code end
>>
>> The first output is:
>> <http://www.xxx.org.cn/standards/publishing/ontology/cores/class1>
>> http://www.xxx.org.cn/standards/publishing/ontology/cores/class1
>>
>> The second output is : http://www.w3.org/2000/01/rdf-schema#Resource
>>
>> I have no idea why the two output are different? Have I done something
>> wrong? Any suggestions?
>
> Mostly likely possibility is that getSuperClass is simply picking a
> different random value from the set of super classes (see the javadoc).
> I don't know if getSuperClass is supposed to list only direct superclasses
> but if you are getting rdfs:Resource then probably not.
>
> Suggest using listSuperClasses(true) to find out what's going on.
>
> Dave
>