You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Brice Sommacal <br...@gmail.com> on 2013/07/19 16:54:21 UTC
Running transitive inference in a OntModel
Hello everyone,
In the past, I was able to execute inference engine to retrieve transitive
values like the following:
// model intialisation
Model typesModel = ModelFactory.createDefaultModel();
typesModel.read(inStream, "RDF");
//function to run inference:
public void applyInference(Model model) throws FileNotFoundException{
Model modelTemp = model;
Reasoner reasoner = ReasonerRegistry.getOWLMicroReasoner();
reasoner = reasoner.bindSchema(ev6Model);
InfModel infmodel = ModelFactory.createInfModel(reasoner, model);
Model modelTemp2 = ModelFactory.createDefaultModel();
Property prop21 = ev6Model.getProperty(ns+"#parentsType");
for (StmtIterator sti = infmodel.listStatements(null, prop21, (RDFNode)
null);
sti.hasNext(); ) {
Statement stmt = sti.nextStatement();
modelTemp2.add(stmt);
}
modelTemp.add(modelTemp2);
}
Actually, I'm working on a other project which deal with OntModel like the
following:
public static OntModel readOntology(File ontoFile) throws
FileNotFoundException
{
Model myModel = null;
FileInputStream inStream = new FileInputStream(ontoFile);
myModel = ModelFactory.createDefaultModel();
myModel.read(inStream, "");
OntModel sourceModel =
ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, myModel);
return sourceModel;
}
I have 2 transitive properties in my model. When I make a call to the
function which deal with inference, the transitive values are not returned.
Here is how my inference engine is initialized:
Reasoner reasoner = ReasonerRegistry.getTransitiveReasoner();
reasoner = reasoner.bindSchema(srcModel);
InfModel infmodel = ModelFactory.createInfModel(reasoner, kbModel);
I have tried several way to make it works, but I din't figure out yet:
- Modify the inference engine intialization with Model instead of OntModel
- Modify the specification with OntModelSpec.OWL_DL_MEM_RULE_INF instead
of OntModelSpec.OWL_MEM
- Modify the reasonner from getTransitiveReasonner to getOwlMicro
I have been using Jena 2.7 and jena 2.6.3.
Do you have any ideas about what I'm doing wrong?
Regards,
Brice
Re: Running transitive inference in a OntModel
Posted by Dave Reynolds <da...@gmail.com>.
Hi,
That's not a complete, minimal example - there's not enough info there
to create something we can test. There's nothing in that snippet that
shows any transitive inference is possible since we can't see the 3 and
4 other individuals you are referring to and can't see what properties
they have to start the inference.
If you can create something more complete so we can see an minimal
example then we might be able to help.
One oddity which might be cut/paste issues in your email or might mean
there's a namespace problem ...
In parts of your example you show:
<#TcClass.RBFParamDef>
and in other parts
<http://seamless.pco-innovation.com/energy/common/software/tcua#TcClass.RBFParamDef>
Unless you have an explicit @base declaration in that Turtle file then
those are two different resources.
Dave
On 22/07/13 15:12, Brice Sommacal wrote:
> Hi again,
>
> The transitive properties are well-defined in my ontology:
>
> <owl:ObjectProperty rdf:about="#allparents">
> <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#TransitiveProperty
> "/>
> <rdfs:range rdf:resource="#TCCLASS"/>
> <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
> >allparents</rdfs:label>
> <owl:inverseOf rdf:resource="#allchilds"/>
> <rdfs:domain rdf:resource="#TCCLASS"/>
> <rdfs:comment rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
> >parentClassName</rdfs:comment>
> </owl:ObjectProperty>
>
> <owl:ObjectProperty rdf:ID="allchilds">
> <rdfs:range rdf:resource="#TCCLASS"/>
> <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#TransitiveProperty
> "/>
> <rdfs:domain rdf:resource="#TCCLASS"/>
> <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
> >allchilds</rdfs:label>
> <owl:inverseOf>
> <owl:ObjectProperty rdf:ID="allparents"/>
> </owl:inverseOf>
> </owl:ObjectProperty>
>
>
> Here are extract from the infModel :
>
> <#TcClass.RBFParamDef>
> a pco:BMIDE , owl:Thing , rdfs:Resource , _:b1 , pco:TCCLASS ;
> pco:allchilds <
> http://seamless.pco-innovation.com/energy/common/software/tcua#TcClass.RBFOutput>
> , <
> http://seamless.pco-innovation.com/energy/common/software/tcua#TcClass.RBFExpression>
> ;
> pco:childClassName <
> http://seamless.pco-innovation.com/energy/common/software/tcua#TcClass.RBFOutput>
> , <
> http://seamless.pco-innovation.com/energy/common/software/tcua#TcClass.RBFExpression>
> ;
> owl:sameAs <#TcClass.RBFParamDef> .
>
> <
> http://seamless.pco-innovation.com/energy/common/software/tcua#TcClass.RBFParamDef
>>
> a pco:BMIDE , owl:Thing , rdfs:Resource , _:b1 , pco:TCCLASS ;
> pco:allparents <#TcClass.BusinessElement> ;
> pco:className "RBFParamDef" ;
> pco:custo "False" ;
> pco:description "" ;
> pco:isExportable "false"^^xsd:boolean ;
> pco:isUninheritable "false"^^xsd:boolean ;
> pco:isUninstantiable
> "false"^^xsd:boolean ;
> pco:parentClassName <#TcClass.BusinessElement> ;
> owl:sameAs <
> http://seamless.pco-innovation.com/energy/common/software/tcua#TcClass.RBFParamDef>
> .
>
>
>
> I expect 3 individuals in pco:allparents and 4 individuals in
> pco:allchilds.
>
> Initially, pco:allchilds is populated from pco:childclassname.
> Same for pco:allparents with pco:parentClassName.
>
> As you can see, the inferred type values are well retrived. But nothing
> about the inference on transitive properties.
>
> Regards,
>
>
> Brice
>
>
>
> 2013/7/22 Dave Reynolds <da...@gmail.com>
>
>> Hi Brice,
>>
>> Using Models with an explicit reasoner or an OntModel with a suitable
>> OntModelSpec should result in exactly the same inferences.
>>
>> This list doesn't accept attachments. The thing to do is to cut your
>> ontology down a minimal complete test case with you then either post inline
>> or use a pastebin type service.
>>
>> Cutting the ontology down to a test case may reveal the answer anyway :)
>>
>> Dave
>>
>>
>> On 22/07/13 14:29, Brice Sommacal wrote:
>>
>>> Hello Dave,
>>>
>>> Thank you for your answer. However, I didn't figure out why it was not
>>> working.
>>>
>>> You were right, I was meaning owl:TransitiveProperty.
>>> My first code fragment was using Model while the second piece of code
>>> was using OntModel. I was thinking that this 2 differents Model may have
>>> incidences on the inference engine.
>>>
>>> Updating the OntModelSpec to OWL_DL_MEM_RULE___INF didn't change
>>>
>>> anything in the output file. I am able to see the infered type, but
>>> nothing about my transitive properties.
>>>
>>> See ontology.owl attached.
>>>
>>> Regards,
>>>
>>>
>>> Brice
>>>
>>>
>>>
>>>
>>> 2013/7/19 Dave Reynolds <dave.e.reynolds@gmail.com
>>> <mailto:dave.e.reynolds@gmail.**com <da...@gmail.com>>>
>>>
>>>
>>> On 19/07/13 15:54, Brice Sommacal wrote:
>>>
>>> Hello everyone,
>>>
>>> In the past, I was able to execute inference engine to retrieve
>>> transitive
>>> values like the following:
>>>
>>> // model intialisation
>>> Model typesModel = ModelFactory.__**createDefaultModel();
>>>
>>> typesModel.read(inStream, "RDF");
>>>
>>> //function to run inference:
>>> public void applyInference(Model model) throws
>>> FileNotFoundException{
>>>
>>> Model modelTemp = model;
>>> Reasoner reasoner = ReasonerRegistry.__**
>>> getOWLMicroReasoner();
>>>
>>> reasoner = reasoner.bindSchema(ev6Model);
>>> InfModel infmodel =
>>> ModelFactory.createInfModel(__**reasoner, model);
>>>
>>> Model modelTemp2 = ModelFactory.__**createDefaultModel();
>>> Property prop21 = ev6Model.getProperty(ns+"#__**
>>> parentsType");
>>>
>>> for (StmtIterator sti = infmodel.listStatements(null,
>>> prop21, (RDFNode)
>>> null);
>>> sti.hasNext(); ) {
>>> Statement stmt = sti.nextStatement();
>>> modelTemp2.add(stmt);
>>> }
>>> modelTemp.add(modelTemp2);
>>> }
>>>
>>>
>>> By "transitive" I assume you mean as in owl:TransitiveProperty?
>>>
>>>
>>> Actually, I'm working on a other project which deal with
>>> OntModel like the
>>> following:
>>>
>>> public static OntModel readOntology(File ontoFile) throws
>>> FileNotFoundException
>>> {
>>> Model myModel = null;
>>> FileInputStream inStream = new FileInputStream(ontoFile);
>>>
>>> myModel = ModelFactory.__**createDefaultModel();
>>>
>>> myModel.read(inStream, "");
>>>
>>> OntModel sourceModel =
>>> ModelFactory.__**createOntologyModel(__**OntModelSpec.OWL_MEM,
>>> myModel);
>>>
>>>
>>> return sourceModel;
>>> }
>>>
>>> I have 2 transitive properties in my model. When I make a call
>>> to the
>>> function which deal with inference, the transitive values are
>>> not returned.
>>>
>>> Here is how my inference engine is initialized:
>>>
>>> Reasoner reasoner = ReasonerRegistry.__**getTransitiveReasoner();
>>> reasoner = reasoner.bindSchema(srcModel);
>>> InfModel infmodel = ModelFactory.createInfModel(__**reasoner,
>>>
>>> kbModel);
>>>
>>>
>>> Can't see how this code fragment relates to the above code fragment.
>>> I'll assume that srcModel is the result of a call to readOntology.
>>>
>>> The problem is that the TransitiveReasoner only does transitive
>>> closure (and reduction) of the the subClassOf/subPropertyOf
>>> hierarchies. Despite the name it doesn't handle
>>> owl:TransitiveProperty.
>>>
>>> You want OWL_MICRO (or better).
>>>
>>>
>>> I have tried several way to make it works, but I din't figure
>>> out yet:
>>> - Modify the inference engine intialization with Model
>>> instead of OntModel
>>>
>>>
>>> Should not make any difference.
>>>
>>>
>>> - Modify the specification with
>>> OntModelSpec.OWL_DL_MEM_RULE__**_INF instead
>>>
>>> of OntModelSpec.OWL_MEM
>>>
>>>
>>> In readOntology? That should work, though then you don't need the
>>> second InfModel wrapper.
>>>
>>>
>>> - Modify the reasonner from getTransitiveReasonner to
>>> getOwlMicro
>>>
>>>
>>> That should also work.
>>>
>>> I would start with the simplest standalone test which just creates
>>> an OntModel and use OntModelSpec.OWL_MEM_MICRO___**RULE_INF. No
>>>
>>> separate InfModel wrappers.
>>>
>>> If that works then you can repackage to separate out a readOntology
>>> function however you wish.
>>>
>>> If it doesn't work then that suggests a problem with the ontology or
>>> the test code. [Or a bug in the reasoner but if you have had the
>>> same case work before then hopefully that's not the case.]
>>>
>>> Dave
>>>
>>>
>>>
>>
>
Re: Running transitive inference in a OntModel
Posted by Brice Sommacal <br...@gmail.com>.
Hi again,
The transitive properties are well-defined in my ontology:
<owl:ObjectProperty rdf:about="#allparents">
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#TransitiveProperty
"/>
<rdfs:range rdf:resource="#TCCLASS"/>
<rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
>allparents</rdfs:label>
<owl:inverseOf rdf:resource="#allchilds"/>
<rdfs:domain rdf:resource="#TCCLASS"/>
<rdfs:comment rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
>parentClassName</rdfs:comment>
</owl:ObjectProperty>
<owl:ObjectProperty rdf:ID="allchilds">
<rdfs:range rdf:resource="#TCCLASS"/>
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#TransitiveProperty
"/>
<rdfs:domain rdf:resource="#TCCLASS"/>
<rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
>allchilds</rdfs:label>
<owl:inverseOf>
<owl:ObjectProperty rdf:ID="allparents"/>
</owl:inverseOf>
</owl:ObjectProperty>
Here are extract from the infModel :
<#TcClass.RBFParamDef>
a pco:BMIDE , owl:Thing , rdfs:Resource , _:b1 , pco:TCCLASS ;
pco:allchilds <
http://seamless.pco-innovation.com/energy/common/software/tcua#TcClass.RBFOutput>
, <
http://seamless.pco-innovation.com/energy/common/software/tcua#TcClass.RBFExpression>
;
pco:childClassName <
http://seamless.pco-innovation.com/energy/common/software/tcua#TcClass.RBFOutput>
, <
http://seamless.pco-innovation.com/energy/common/software/tcua#TcClass.RBFExpression>
;
owl:sameAs <#TcClass.RBFParamDef> .
<
http://seamless.pco-innovation.com/energy/common/software/tcua#TcClass.RBFParamDef
>
a pco:BMIDE , owl:Thing , rdfs:Resource , _:b1 , pco:TCCLASS ;
pco:allparents <#TcClass.BusinessElement> ;
pco:className "RBFParamDef" ;
pco:custo "False" ;
pco:description "" ;
pco:isExportable "false"^^xsd:boolean ;
pco:isUninheritable "false"^^xsd:boolean ;
pco:isUninstantiable
"false"^^xsd:boolean ;
pco:parentClassName <#TcClass.BusinessElement> ;
owl:sameAs <
http://seamless.pco-innovation.com/energy/common/software/tcua#TcClass.RBFParamDef>
.
I expect 3 individuals in pco:allparents and 4 individuals in
pco:allchilds.
Initially, pco:allchilds is populated from pco:childclassname.
Same for pco:allparents with pco:parentClassName.
As you can see, the inferred type values are well retrived. But nothing
about the inference on transitive properties.
Regards,
Brice
2013/7/22 Dave Reynolds <da...@gmail.com>
> Hi Brice,
>
> Using Models with an explicit reasoner or an OntModel with a suitable
> OntModelSpec should result in exactly the same inferences.
>
> This list doesn't accept attachments. The thing to do is to cut your
> ontology down a minimal complete test case with you then either post inline
> or use a pastebin type service.
>
> Cutting the ontology down to a test case may reveal the answer anyway :)
>
> Dave
>
>
> On 22/07/13 14:29, Brice Sommacal wrote:
>
>> Hello Dave,
>>
>> Thank you for your answer. However, I didn't figure out why it was not
>> working.
>>
>> You were right, I was meaning owl:TransitiveProperty.
>> My first code fragment was using Model while the second piece of code
>> was using OntModel. I was thinking that this 2 differents Model may have
>> incidences on the inference engine.
>>
>> Updating the OntModelSpec to OWL_DL_MEM_RULE___INF didn't change
>>
>> anything in the output file. I am able to see the infered type, but
>> nothing about my transitive properties.
>>
>> See ontology.owl attached.
>>
>> Regards,
>>
>>
>> Brice
>>
>>
>>
>>
>> 2013/7/19 Dave Reynolds <dave.e.reynolds@gmail.com
>> <mailto:dave.e.reynolds@gmail.**com <da...@gmail.com>>>
>>
>>
>> On 19/07/13 15:54, Brice Sommacal wrote:
>>
>> Hello everyone,
>>
>> In the past, I was able to execute inference engine to retrieve
>> transitive
>> values like the following:
>>
>> // model intialisation
>> Model typesModel = ModelFactory.__**createDefaultModel();
>>
>> typesModel.read(inStream, "RDF");
>>
>> //function to run inference:
>> public void applyInference(Model model) throws
>> FileNotFoundException{
>>
>> Model modelTemp = model;
>> Reasoner reasoner = ReasonerRegistry.__**
>> getOWLMicroReasoner();
>>
>> reasoner = reasoner.bindSchema(ev6Model);
>> InfModel infmodel =
>> ModelFactory.createInfModel(__**reasoner, model);
>>
>> Model modelTemp2 = ModelFactory.__**createDefaultModel();
>> Property prop21 = ev6Model.getProperty(ns+"#__**
>> parentsType");
>>
>> for (StmtIterator sti = infmodel.listStatements(null,
>> prop21, (RDFNode)
>> null);
>> sti.hasNext(); ) {
>> Statement stmt = sti.nextStatement();
>> modelTemp2.add(stmt);
>> }
>> modelTemp.add(modelTemp2);
>> }
>>
>>
>> By "transitive" I assume you mean as in owl:TransitiveProperty?
>>
>>
>> Actually, I'm working on a other project which deal with
>> OntModel like the
>> following:
>>
>> public static OntModel readOntology(File ontoFile) throws
>> FileNotFoundException
>> {
>> Model myModel = null;
>> FileInputStream inStream = new FileInputStream(ontoFile);
>>
>> myModel = ModelFactory.__**createDefaultModel();
>>
>> myModel.read(inStream, "");
>>
>> OntModel sourceModel =
>> ModelFactory.__**createOntologyModel(__**OntModelSpec.OWL_MEM,
>> myModel);
>>
>>
>> return sourceModel;
>> }
>>
>> I have 2 transitive properties in my model. When I make a call
>> to the
>> function which deal with inference, the transitive values are
>> not returned.
>>
>> Here is how my inference engine is initialized:
>>
>> Reasoner reasoner = ReasonerRegistry.__**getTransitiveReasoner();
>> reasoner = reasoner.bindSchema(srcModel);
>> InfModel infmodel = ModelFactory.createInfModel(__**reasoner,
>>
>> kbModel);
>>
>>
>> Can't see how this code fragment relates to the above code fragment.
>> I'll assume that srcModel is the result of a call to readOntology.
>>
>> The problem is that the TransitiveReasoner only does transitive
>> closure (and reduction) of the the subClassOf/subPropertyOf
>> hierarchies. Despite the name it doesn't handle
>> owl:TransitiveProperty.
>>
>> You want OWL_MICRO (or better).
>>
>>
>> I have tried several way to make it works, but I din't figure
>> out yet:
>> - Modify the inference engine intialization with Model
>> instead of OntModel
>>
>>
>> Should not make any difference.
>>
>>
>> - Modify the specification with
>> OntModelSpec.OWL_DL_MEM_RULE__**_INF instead
>>
>> of OntModelSpec.OWL_MEM
>>
>>
>> In readOntology? That should work, though then you don't need the
>> second InfModel wrapper.
>>
>>
>> - Modify the reasonner from getTransitiveReasonner to
>> getOwlMicro
>>
>>
>> That should also work.
>>
>> I would start with the simplest standalone test which just creates
>> an OntModel and use OntModelSpec.OWL_MEM_MICRO___**RULE_INF. No
>>
>> separate InfModel wrappers.
>>
>> If that works then you can repackage to separate out a readOntology
>> function however you wish.
>>
>> If it doesn't work then that suggests a problem with the ontology or
>> the test code. [Or a bug in the reasoner but if you have had the
>> same case work before then hopefully that's not the case.]
>>
>> Dave
>>
>>
>>
>
Re: Running transitive inference in a OntModel
Posted by Dave Reynolds <da...@gmail.com>.
Hi Brice,
Using Models with an explicit reasoner or an OntModel with a suitable
OntModelSpec should result in exactly the same inferences.
This list doesn't accept attachments. The thing to do is to cut your
ontology down a minimal complete test case with you then either post
inline or use a pastebin type service.
Cutting the ontology down to a test case may reveal the answer anyway :)
Dave
On 22/07/13 14:29, Brice Sommacal wrote:
> Hello Dave,
>
> Thank you for your answer. However, I didn't figure out why it was not
> working.
>
> You were right, I was meaning owl:TransitiveProperty.
> My first code fragment was using Model while the second piece of code
> was using OntModel. I was thinking that this 2 differents Model may have
> incidences on the inference engine.
>
> Updating the OntModelSpec to OWL_DL_MEM_RULE___INF didn't change
> anything in the output file. I am able to see the infered type, but
> nothing about my transitive properties.
>
> See ontology.owl attached.
>
> Regards,
>
>
> Brice
>
>
>
>
> 2013/7/19 Dave Reynolds <dave.e.reynolds@gmail.com
> <ma...@gmail.com>>
>
> On 19/07/13 15:54, Brice Sommacal wrote:
>
> Hello everyone,
>
> In the past, I was able to execute inference engine to retrieve
> transitive
> values like the following:
>
> // model intialisation
> Model typesModel = ModelFactory.__createDefaultModel();
> typesModel.read(inStream, "RDF");
>
> //function to run inference:
> public void applyInference(Model model) throws
> FileNotFoundException{
>
> Model modelTemp = model;
> Reasoner reasoner = ReasonerRegistry.__getOWLMicroReasoner();
> reasoner = reasoner.bindSchema(ev6Model);
> InfModel infmodel =
> ModelFactory.createInfModel(__reasoner, model);
>
> Model modelTemp2 = ModelFactory.__createDefaultModel();
> Property prop21 = ev6Model.getProperty(ns+"#__parentsType");
> for (StmtIterator sti = infmodel.listStatements(null,
> prop21, (RDFNode)
> null);
> sti.hasNext(); ) {
> Statement stmt = sti.nextStatement();
> modelTemp2.add(stmt);
> }
> modelTemp.add(modelTemp2);
> }
>
>
> By "transitive" I assume you mean as in owl:TransitiveProperty?
>
>
> Actually, I'm working on a other project which deal with
> OntModel like the
> following:
>
> public static OntModel readOntology(File ontoFile) throws
> FileNotFoundException
> {
> Model myModel = null;
> FileInputStream inStream = new FileInputStream(ontoFile);
>
> myModel = ModelFactory.__createDefaultModel();
> myModel.read(inStream, "");
>
> OntModel sourceModel =
> ModelFactory.__createOntologyModel(__OntModelSpec.OWL_MEM, myModel);
>
> return sourceModel;
> }
>
> I have 2 transitive properties in my model. When I make a call
> to the
> function which deal with inference, the transitive values are
> not returned.
>
> Here is how my inference engine is initialized:
>
> Reasoner reasoner = ReasonerRegistry.__getTransitiveReasoner();
> reasoner = reasoner.bindSchema(srcModel);
> InfModel infmodel = ModelFactory.createInfModel(__reasoner,
> kbModel);
>
>
> Can't see how this code fragment relates to the above code fragment.
> I'll assume that srcModel is the result of a call to readOntology.
>
> The problem is that the TransitiveReasoner only does transitive
> closure (and reduction) of the the subClassOf/subPropertyOf
> hierarchies. Despite the name it doesn't handle owl:TransitiveProperty.
>
> You want OWL_MICRO (or better).
>
>
> I have tried several way to make it works, but I din't figure
> out yet:
> - Modify the inference engine intialization with Model
> instead of OntModel
>
>
> Should not make any difference.
>
>
> - Modify the specification with
> OntModelSpec.OWL_DL_MEM_RULE___INF instead
> of OntModelSpec.OWL_MEM
>
>
> In readOntology? That should work, though then you don't need the
> second InfModel wrapper.
>
>
> - Modify the reasonner from getTransitiveReasonner to getOwlMicro
>
>
> That should also work.
>
> I would start with the simplest standalone test which just creates
> an OntModel and use OntModelSpec.OWL_MEM_MICRO___RULE_INF. No
> separate InfModel wrappers.
>
> If that works then you can repackage to separate out a readOntology
> function however you wish.
>
> If it doesn't work then that suggests a problem with the ontology or
> the test code. [Or a bug in the reasoner but if you have had the
> same case work before then hopefully that's not the case.]
>
> Dave
>
>
Re: Running transitive inference in a OntModel
Posted by Brice Sommacal <br...@gmail.com>.
Hello Dave,
Thank you for your answer. However, I didn't figure out why it was not
working.
You were right, I was meaning owl:TransitiveProperty.
My first code fragment was using Model while the second piece of code was
using OntModel. I was thinking that this 2 differents Model may have
incidences on the inference engine.
Updating the OntModelSpec to OWL_DL_MEM_RULE_**INF didn't change anything
in the output file. I am able to see the infered type, but nothing about my
transitive properties.
See ontology.owl attached.
Regards,
Brice
2013/7/19 Dave Reynolds <da...@gmail.com>
> On 19/07/13 15:54, Brice Sommacal wrote:
>
>> Hello everyone,
>>
>> In the past, I was able to execute inference engine to retrieve transitive
>> values like the following:
>>
>> // model intialisation
>> Model typesModel = ModelFactory.**createDefaultModel();
>> typesModel.read(inStream, "RDF");
>>
>> //function to run inference:
>> public void applyInference(Model model) throws FileNotFoundException{
>>
>> Model modelTemp = model;
>> Reasoner reasoner = ReasonerRegistry.**getOWLMicroReasoner();
>> reasoner = reasoner.bindSchema(ev6Model);
>> InfModel infmodel = ModelFactory.createInfModel(**reasoner, model);
>>
>> Model modelTemp2 = ModelFactory.**createDefaultModel();
>> Property prop21 = ev6Model.getProperty(ns+"#**parentsType");
>> for (StmtIterator sti = infmodel.listStatements(null, prop21,
>> (RDFNode)
>> null);
>> sti.hasNext(); ) {
>> Statement stmt = sti.nextStatement();
>> modelTemp2.add(stmt);
>> }
>> modelTemp.add(modelTemp2);
>> }
>>
>
> By "transitive" I assume you mean as in owl:TransitiveProperty?
>
>
> Actually, I'm working on a other project which deal with OntModel like the
>> following:
>>
>> public static OntModel readOntology(File ontoFile) throws
>> FileNotFoundException
>> {
>> Model myModel = null;
>> FileInputStream inStream = new FileInputStream(ontoFile);
>>
>> myModel = ModelFactory.**createDefaultModel();
>> myModel.read(inStream, "");
>>
>> OntModel sourceModel =
>> ModelFactory.**createOntologyModel(**OntModelSpec.OWL_MEM, myModel);
>>
>> return sourceModel;
>> }
>>
>> I have 2 transitive properties in my model. When I make a call to the
>> function which deal with inference, the transitive values are not
>> returned.
>>
>> Here is how my inference engine is initialized:
>>
>> Reasoner reasoner = ReasonerRegistry.**getTransitiveReasoner();
>> reasoner = reasoner.bindSchema(srcModel);
>> InfModel infmodel = ModelFactory.createInfModel(**reasoner, kbModel);
>>
>
> Can't see how this code fragment relates to the above code fragment. I'll
> assume that srcModel is the result of a call to readOntology.
>
> The problem is that the TransitiveReasoner only does transitive closure
> (and reduction) of the the subClassOf/subPropertyOf hierarchies. Despite
> the name it doesn't handle owl:TransitiveProperty.
>
> You want OWL_MICRO (or better).
>
>
> I have tried several way to make it works, but I din't figure out yet:
>> - Modify the inference engine intialization with Model instead of
>> OntModel
>>
>
> Should not make any difference.
>
>
> - Modify the specification with OntModelSpec.OWL_DL_MEM_RULE_**INF
>> instead
>> of OntModelSpec.OWL_MEM
>>
>
> In readOntology? That should work, though then you don't need the second
> InfModel wrapper.
>
>
> - Modify the reasonner from getTransitiveReasonner to getOwlMicro
>>
>
> That should also work.
>
> I would start with the simplest standalone test which just creates an
> OntModel and use OntModelSpec.OWL_MEM_MICRO_**RULE_INF. No separate
> InfModel wrappers.
>
> If that works then you can repackage to separate out a readOntology
> function however you wish.
>
> If it doesn't work then that suggests a problem with the ontology or the
> test code. [Or a bug in the reasoner but if you have had the same case work
> before then hopefully that's not the case.]
>
> Dave
>
>
Re: Running transitive inference in a OntModel
Posted by Dave Reynolds <da...@gmail.com>.
On 19/07/13 15:54, Brice Sommacal wrote:
> Hello everyone,
>
> In the past, I was able to execute inference engine to retrieve transitive
> values like the following:
>
> // model intialisation
> Model typesModel = ModelFactory.createDefaultModel();
> typesModel.read(inStream, "RDF");
>
> //function to run inference:
> public void applyInference(Model model) throws FileNotFoundException{
>
> Model modelTemp = model;
> Reasoner reasoner = ReasonerRegistry.getOWLMicroReasoner();
> reasoner = reasoner.bindSchema(ev6Model);
> InfModel infmodel = ModelFactory.createInfModel(reasoner, model);
>
> Model modelTemp2 = ModelFactory.createDefaultModel();
> Property prop21 = ev6Model.getProperty(ns+"#parentsType");
> for (StmtIterator sti = infmodel.listStatements(null, prop21, (RDFNode)
> null);
> sti.hasNext(); ) {
> Statement stmt = sti.nextStatement();
> modelTemp2.add(stmt);
> }
> modelTemp.add(modelTemp2);
> }
By "transitive" I assume you mean as in owl:TransitiveProperty?
> Actually, I'm working on a other project which deal with OntModel like the
> following:
>
> public static OntModel readOntology(File ontoFile) throws
> FileNotFoundException
> {
> Model myModel = null;
> FileInputStream inStream = new FileInputStream(ontoFile);
>
> myModel = ModelFactory.createDefaultModel();
> myModel.read(inStream, "");
>
> OntModel sourceModel =
> ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, myModel);
>
> return sourceModel;
> }
>
> I have 2 transitive properties in my model. When I make a call to the
> function which deal with inference, the transitive values are not returned.
>
> Here is how my inference engine is initialized:
>
> Reasoner reasoner = ReasonerRegistry.getTransitiveReasoner();
> reasoner = reasoner.bindSchema(srcModel);
> InfModel infmodel = ModelFactory.createInfModel(reasoner, kbModel);
Can't see how this code fragment relates to the above code fragment.
I'll assume that srcModel is the result of a call to readOntology.
The problem is that the TransitiveReasoner only does transitive closure
(and reduction) of the the subClassOf/subPropertyOf hierarchies. Despite
the name it doesn't handle owl:TransitiveProperty.
You want OWL_MICRO (or better).
> I have tried several way to make it works, but I din't figure out yet:
> - Modify the inference engine intialization with Model instead of OntModel
Should not make any difference.
> - Modify the specification with OntModelSpec.OWL_DL_MEM_RULE_INF instead
> of OntModelSpec.OWL_MEM
In readOntology? That should work, though then you don't need the second
InfModel wrapper.
> - Modify the reasonner from getTransitiveReasonner to getOwlMicro
That should also work.
I would start with the simplest standalone test which just creates an
OntModel and use OntModelSpec.OWL_MEM_MICRO_RULE_INF. No separate
InfModel wrappers.
If that works then you can repackage to separate out a readOntology
function however you wish.
If it doesn't work then that suggests a problem with the ontology or the
test code. [Or a bug in the reasoner but if you have had the same case
work before then hopefully that's not the case.]
Dave