如何使用owlapi生成特定推断?

huangapple go评论49阅读模式
英文:

How to generate specific inference using owlapi?

问题

I am working on this project which requires to perform ontology reasoning in code, so far I have written this rule. I am implementing this in java with the help of owlapi, and clarkparsia.pellet.owlapiv3.PelletReasoner.

//dexpi:Pump(?pump) ^ swrlb:greaterThan(?value, "10.0"^^xsd:double) ^ rdl:datumValue(?pump, ?value) -> dexpi:EjectorPump(?pump)
// Rule created using SWRLClassAtoms and DataPropertyAtoms
ontologyManager.applyChange(new AddAxiom(ontology, rule1));

So this section of code adds the rule to the ontology. I know the rules are defined correctly, since I can see this rule in protege, but How do I update the ontology according to the rule, i.e. change class type of all Pump instances whose datumValue is greaterThan 10 to EjectorPump.

I have tried these approaches so far.

Approach-1

// These lines uses pellet reasoner to perform reasoning
PelletReasoner reasoner = PelletReasonerFactory.getInstance().createReasoner(ontology);		
InferredOntologyGenerator iog = new  InferredOntologyGenerator(reasoner);
iog.fillOntology(factory, ontology);		

Approach-2

List<InferredAxiomGenerator<? extends OWLAxiom>> gens = new ArrayList<>();
gens.add(new InferredClassAssertionAxiomGenerator());
InferredOntologyGenerator iog = new InferredOntologyGenerator(reasoner, gens);
iog.fillOntology(factory, ontology);

Both of the approaches works perfectly fine but the problem is when they generate inference there is too much information I just want reclassification to be done like this if possible (This one is generated by protege.
desired inference (generated by protege)

but instead, these codes reclassify like this
code generated inference

Additionally, if you can direct me on how I can generate and show an explanation of reasoning, it will be a huge help. Thank you.

英文:

I am working on this project which requires to perform ontology reasoning in code, so far I have written this rule. I am implementing this in java with the help of owlapi, and clarkparsia.pellet.owlapiv3.PelletReasoner.

//dexpi:Pump(?pump) ^ swrlb:greaterThan(?value, "10.0"^^xsd:double) ^ rdl:datumValue(?pump, ?value) -> dexpi:EjectorPump(?pump)
// Rule created using SWRLClassAtoms and DataPropertyAtoms
ontologyManager.applyChange(new AddAxiom(ontology, rule1));

So this section of code adds the rule to the ontology. I know the rules are defined correctly, since I can see this rule in protege, but How do I update the ontology according to the rule, i.e. change class type of all Pump instances whose datumValue is greaterThan 10 to EjectorPump.

I have tried these approaches so far.

Approach-1

// These lines uses pellet reasoner to perform reasoning
PelletReasoner reasoner = PelletReasonerFactory.getInstance().createReasoner(ontology);		
InferredOntologyGenerator iog = new  InferredOntologyGenerator(reasoner);
iog.fillOntology(factory, ontology);		

Approach-2

List<InferredAxiomGenerator<? extends OWLAxiom>> gens = new ArrayList<>();
gens.add(new InferredClassAssertionAxiomGenerator());
InferredOntologyGenerator iog = new InferredOntologyGenerator(reasoner, gens);
iog.fillOntology(factory, ontology);

Both of the approaches works perfectly fine but the problem is when they generate inference there is too much information I just want reclassification to be done like this if possible (This one is generated by protege.
desired inference (generated by protege)

but instead, these codes reclassify like this
code generated inference

Additionally, if you can direct me on how I can generate and show an explanation of reasoning, it will be a huge help. Thank you.

答案1

得分: 0

以下是翻译好的部分:

从上面的评论中延伸讨论:

Openllet 和 OWLAPI 版本:Openllet 的 2.6.5 版本是三年前发布的,我刚刚尝试了它与 OWLAPI 5.1.20(一年半前发布)的配合,没有收到任何错误。然而,我没有您的本体,所以这可能不是足够的测试。

无论使用哪种设置,您都可以通过编写自己的生成器来更有选择地生成公理。此示例引入了一个仅为一个类创建断言公理的生成器,即它不会为个体添加任何其他类型:

List<InferredAxiomGenerator<? extends OWLAxiom>> gens = new ArrayList<>();
gens.add(new InferredEntityAxiomGenerator<OWLClass, OWLClassAssertionAxiom>() {
    @Override
    protected Stream<OWLClass> getEntities(OWLOntology ont) {
        return Stream.of(factory.getOWLClass(IRI.create("urn:test:onto#A")));
    }

    @Override
    protected void addAxioms(OWLClass entity, OWLReasoner reasoner, OWLDataFactory dataFactory,
            Set<OWLClassAssertionAxiom> result) {
        reasoner.getInstances(entity).entities().map(x -> factory.getOWLClassAssertionAxiom(entity, x))
                .forEach(result::add);
    }

    @Override
    public String getLabel() {
        // TODO Auto-generated method stub
        return "Instances of A";
    }

});
InferredOntologyGenerator iog = new InferredOntologyGenerator(reasoner, gens);
iog.fillOntology(factory, ontology);

这种方法可以用于较旧的 OWLAPI 版本,但您需要调整它以正确编译使用您所使用的版本。

英文:

Extending the discussion from the comments above:

Openllet and OWLAPI versions: 2.6.5 of Openllet was released three years back, I have just tried it with OWLAPI 5.1.20 (released a year and a half ago) and got no errors. However, I do not have your ontology, so this might not be a sufficient test.

With either setup, you can be more selective about which axioms to generate by writing your own generator. This example introduces a generator that creates assertion axioms for only one class, i.e., it will not add any other type to individuals:

	List&lt;InferredAxiomGenerator&lt;? extends OWLAxiom&gt;&gt; gens = new ArrayList&lt;&gt;();
	gens.add(new InferredEntityAxiomGenerator&lt;OWLClass, OWLClassAssertionAxiom&gt;() {
		@Override
		protected Stream&lt;OWLClass&gt; getEntities(OWLOntology ont) {
			return Stream.of(factory.getOWLClass(IRI.create(&quot;urn:test:onto#A&quot;)));
		}

		@Override
		protected void addAxioms(OWLClass entity, OWLReasoner reasoner, OWLDataFactory dataFactory,
				Set&lt;OWLClassAssertionAxiom&gt; result) {
			reasoner.getInstances(entity).entities().map(x -&gt; factory.getOWLClassAssertionAxiom(entity, x))
					.forEach(result::add);
		}

		@Override
		public String getLabel() {
			// TODO Auto-generated method stub
			return &quot;Instances of A&quot;;
		}

	});
	InferredOntologyGenerator iog = new InferredOntologyGenerator(reasoner, gens);
	iog.fillOntology(factory, ontology);

The approach can be followed for older OWLAPI versions, but you will have to adjust it to compile correctly with whichever version you're using.

huangapple
  • 本文由 发表于 2023年7月31日 18:50:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/76802897.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定