英文:
OWL API, Hermit materialization
问题
- OWL API的推理器是什么?是Hermit吗?
所以当我有:
OWLReasonerFactory reasoner_factory = new ReasonerFactory();
OWLReasoner reasoner = reasoner_factory.createReasoner(ontology);
调用了哪个推理器?
- 当我执行材料化时,对于任何个体a、b,ABox中都会出现断言:
owl:topObjectProperty(a,b)
,这是真的,但也是多余的,会使知识库的大小急剧增加。
那么我应该如何防止这种情况发生?
我使用的方法如下:
public static Ontology materialization(Ontology ontology, File inferredOntologyFile) throws OWLOntologyStorageException, IOException, OWLOntologyCreationException {
Configuration config = new Configuration();
OntologyManager manager = OntManagers.createManager();
Ontology inf_ontology = manager.loadOntologyFromOntologyDocument(inferredOntologyFile);
OutputStream outputStream = new FileOutputStream(inferredOntologyFile);
OWLDataFactory data_factory = ontology.getOWLOntologyManager().getOWLDataFactory();
OWLReasonerFactory reasoner_factory = new ReasonerFactory();
OWLReasoner reasoner = reasoner_factory.createReasoner(ontology);
if (reasoner.isConsistent() == false) {
System.out.println("INCONSISTENT ONTOLOGY!");
}
InferredOntologyGenerator inference = new InferredOntologyGenerator(reasoner);
inference.fillOntology(data_factory, ontology);
manager.saveOntology(ontology, new NTriplesDocumentFormat(), outputStream);
return ontology;
}
owlapi-distribution版本:5.1.14
Hermit版本:1.3.8.510
此外,材料化后的一个非常简单的测试本体可以在以下链接找到:
https://drive.google.com/file/d/1EKm8uD1zuMfIjstCAZMperZFFv4-kCtD/view?usp=sharing
或者你也可以在下面看到它的内容。
英文:
I have two questions:
- What is the reasoner of OWL API? Is it Hermit?
So when I have:
OWLReasonerFactory reasoner_factory = new ReasonerFactory();
OWLReasoner reasoner = reasoner_factory.createReasoner(ontology);
Which reasoner is called?
- When I perform materialization I also get for any individuals a, b appearing the the ABox the assertion:
owl:topObjectProperty(a,b)
, which is true, but also redundant, and explodes the size of the KB.
So how can I prevent this from happening?
The method I used is as follows:
public static Ontology materialization(Ontology ontology, File inferredOntologyFile) throws OWLOntologyStorageException, IOException, OWLOntologyCreationException {
Configuration config=new Configuration();
OntologyManager manager= OntManagers.createManager();
Ontology inf_ontology = manager.loadOntologyFromOntologyDocument(inferredOntologyFile);
OutputStream outputStream=new FileOutputStream(inferredOntologyFile);
OWLDataFactory data_factory = ontology.getOWLOntologyManager().getOWLDataFactory();
OWLReasonerFactory reasoner_factory = new ReasonerFactory();
OWLReasoner reasoner = reasoner_factory.createReasoner(ontology);
if (reasoner.isConsistent() == false) {
System.out.println("INCONSISTENT ONTOLOGY!");
}
InferredOntologyGenerator inference = new InferredOntologyGenerator(reasoner);
inference.fillOntology(data_factory, ontology);
manager.saveOntology(ontology, new NTriplesDocumentFormat(), outputStream);
return ontology;
}
owlapi-distribution version: 5.1.14
Hermit version: 1.3.8.510
Also a very simple test ontology after materialization is here:
https://drive.google.com/file/d/1EKm8uD1zuMfIjstCAZMperZFFv4-kCtD/view?usp=sharing
or you can see it below:
<http://www.semanticweb.org/savtr/ontologies/2023/6/untitled-ontology-9> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Ontology> .
<http://www.semanticweb.org/savtr/ontologies/2023/6/untitled-ontology-9#c> <http://www.w3.org/2002/07/owl#topObjectProperty> <http://www.semanticweb.org/savtr/ontologies/2023/6/untitled-ontology-9#c> .
<http://www.semanticweb.org/savtr/ontologies/2023/6/untitled-ontology-9#c> <http://www.w3.org/2002/07/owl#topObjectProperty> <http://www.semanticweb.org/savtr/ontologies/2023/6/untitled-ontology-9#b> .
<http://www.semanticweb.org/savtr/ontologies/2023/6/untitled-ontology-9#c> <http://www.w3.org/2002/07/owl#topObjectProperty> <http://www.semanticweb.org/savtr/ontologies/2023/6/untitled-ontology-9#a> .
<http://www.semanticweb.org/savtr/ontologies/2023/6/untitled-ontology-9#c> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#NamedIndividual> .
<http://www.semanticweb.org/savtr/ontologies/2023/6/untitled-ontology-9#c> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Thing> .
<http://www.semanticweb.org/savtr/ontologies/2023/6/untitled-ontology-9#r> <http://www.w3.org/2000/01/rdf-schema#subPropertyOf> <http://www.w3.org/2002/07/owl#topObjectProperty> .
<http://www.semanticweb.org/savtr/ontologies/2023/6/untitled-ontology-9#r> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#ObjectProperty> .
<http://www.semanticweb.org/savtr/ontologies/2023/6/untitled-ontology-9#a> <http://www.w3.org/2002/07/owl#topObjectProperty> <http://www.semanticweb.org/savtr/ontologies/2023/6/untitled-ontology-9#b> .
<http://www.semanticweb.org/savtr/ontologies/2023/6/untitled-ontology-9#a> <http://www.w3.org/2002/07/owl#topObjectProperty> <http://www.semanticweb.org/savtr/ontologies/2023/6/untitled-ontology-9#a> .
<http://www.semanticweb.org/savtr/ontologies/2023/6/untitled-ontology-9#a> <http://www.w3.org/2002/07/owl#topObjectProperty> <http://www.semanticweb.org/savtr/ontologies/2023/6/untitled-ontology-9#c> .
<http://www.semanticweb.org/savtr/ontologies/2023/6/untitled-ontology-9#a> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#NamedIndividual> .
<http://www.semanticweb.org/savtr/ontologies/2023/6/untitled-ontology-9#a> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Thing> .
<http://www.semanticweb.org/savtr/ontologies/2023/6/untitled-ontology-9#A> <http://www.w3.org/2000/01/rdf-schema#subClassOf> <http://www.w3.org/2002/07/owl#Thing> .
<http://www.semanticweb.org/savtr/ontologies/2023/6/untitled-ontology-9#A> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Class> .
<http://www.semanticweb.org/savtr/ontologies/2023/6/untitled-ontology-9#b> <http://www.w3.org/2002/07/owl#topObjectProperty> <http://www.semanticweb.org/savtr/ontologies/2023/6/untitled-ontology-9#c> .
<http://www.semanticweb.org/savtr/ontologies/2023/6/untitled-ontology-9#b> <http://www.w3.org/2002/07/owl#topObjectProperty> <http://www.semanticweb.org/savtr/ontologies/2023/6/untitled-ontology-9#b> .
<http://www.semanticweb.org/savtr/ontologies/2023/6/untitled-ontology-9#b> <http://www.w3.org/2002/07/owl#topObjectProperty> <http://www.semanticweb.org/savtr/ontologies/2023/6/untitled-ontology-9#a> .
<http://www.semanticweb.org/savtr/ontologies/2023/6/untitled-ontology-9#b> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#NamedIndividual> .
<http://www.semanticweb.org/savtr/ontologies/2023/6/untitled-ontology-9#b> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Thing> .
<http://www.semanticweb.org/savtr/ontologies/2023/6/untitled-ontology-9#B> <http://www.w3.org/2000/01/rdf-schema#subClassOf> <http://www.w3.org/2002/07/owl#Thing> .
<http://www.semanticweb.org/savtr/ontologies/2023/6/untitled-ontology-9#B> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Class> .
<http://www.w3.org/2002/07/owl#topObjectProperty> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#ReflexiveProperty> .
<http://www.w3.org/2002/07/owl#topObjectProperty> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#SymmetricProperty> .
<http://www.w3.org/2002/07/owl#topObjectProperty> <http://www.w3.org/2002/07/owl#inverseOf> <http://www.w3.org/2002/07/owl#topObjectProperty> .
<http://www.w3.org/2002/07/owl#topObjectProperty> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#ObjectProperty> .
<http://www.semanticweb.org/savtr/ontologies/2023/6/untitled-ontology-9#q> <http://www.w3.org/2000/01/rdf-schema#subPropertyOf> <http://www.w3.org/2002/07/owl#topObjectProperty> .
<http://www.semanticweb.org/savtr/ontologies/2023/6/untitled-ontology-9#q> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#ObjectProperty> .
答案1
得分: 1
两个建议:我建议您更新您正在使用的版本,因为它们已经过时,而且似乎存在您的输入本体中的问题。
建议的版本更新:使用OWLAPI 5.1.20和HermiT 1.4.5.519(它们不直接影响此问题,但它们是比您正在使用的版本更新的版本)。
示例Maven配置:
<dependencies>
<dependency>
<groupId>net.sourceforge.owlapi</groupId>
<artifactId>owlapi-distribution</artifactId>
<version>5.1.20</version>
</dependency>
<dependency>
<groupId>net.sourceforge.owlapi</groupId>
<artifactId>org.semanticweb.hermit</artifactId>
<version>1.4.5.519</version>
<exclusions>
<exclusion>
<groupId>net.sourceforge.owlapi</groupId>
<artifactId>owlapi-distribution</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
关于您的输入本体,如果我按照您显示的代码原样进行处理(在删除不相关于问题的ONTAPI引用后,我不是专家),我会得到以下代码来复制问题:
package teststack;
import java.io.*;
import org.semanticweb.HermiT.ReasonerFactory;
import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.formats.NTriplesDocumentFormat;
import org.semanticweb.owlapi.io.StringDocumentSource;
import org.semanticweb.owlapi.model.*;
import org.semanticweb.owlapi.reasoner.*;
import org.semanticweb.owlapi.util.*;
public class Check {
static OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
static OWLDataFactory data_factory = manager.getOWLDataFactory();
public static void main(String[] args)
throws OWLOntologyCreationException, OWLOntologyStorageException, IOException {
String notWorking = "<urn:test:onto> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Ontology> .\n"
+ "<urn:test:onto#c> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#NamedIndividual> .\n"
+ "<urn:test:onto#c> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Thing> .\n"
+ "<urn:test:onto#r> <http://www.w3.org/2000/01/rdf-schema#subPropertyOf> <http://www.w3.org/2002/07/owl#topObjectProperty> .\n"
+ "<urn:test:onto#r> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#ObjectProperty> .\n"
+ "<urn:test:onto#a> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#NamedIndividual> .\n"
+ "<urn:test:onto#a> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Thing> .\n"
+ "<urn:test:onto#A> <http://www.w3.org/2000/01/rdf-schema#subClassOf> <http://www.w3.org/2002/07/owl#Thing> .\n"
+ "<urn:test:onto#A> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Class> .\n"
+ "<urn:test:onto#b> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#NamedIndividual> .\n"
+ "<urn:test:onto#b> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Thing> .\n"
+ "<urn:test:onto#B> <http://www.w3.org/2000/01/rdf-schema#subClassOf> <http://www.w3.org/2002/07/owl#Thing> .\n"
+ "<urn:test:onto#B> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Class> .\n"
+ "<urn:test:onto#q> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#ObjectProperty> .\n";
OWLOntology o = manager.loadOntologyFromOntologyDocument(new StringDocumentSource(
notWorking,
IRI.create("urn:test:onto"), new NTriplesDocumentFormat(), null));
materialization(o, new File("result.txt"));
}
public static OWLOntology materialization(OWLOntology ontology, File inferredOntologyFile)
throws OWLOntologyStorageException, IOException, OWLOntologyCreationException {
OutputStream outputStream = new FileOutputStream(inferredOntologyFile);
OWLReasonerFactory reasoner_factory = new ReasonerFactory();
OWLReasoner reasoner = reasoner_factory.createReasoner(ontology);
if (reasoner.isConsistent() == false) {
System.out.println("INCONSISTENT ONTOLOGY!");
}
InferredOntologyGenerator inference = new InferredOntologyGenerator(reasoner);
inference.fillOntology(data_factory, ontology);
manager.saveOntology(ontology, new NTriplesDocumentFormat(), outputStream);
return ontology;
}
}
注意:我从本体中删除了所有与topObjectProperty相关的个体相关的公理。这些公理由代码复制。
然而,如果移除声明属性为topObjectProperty的类型断言,问题就会消失。由于这些声明是多余的,看起来它们存在于本体中会使推理器生成这些公理。这些不必要的声明应该被忽略,所以这可能是一个bug。但是,对您来说的解决方法是从输入文件中筛选掉任
英文:
Two items: I recommend updating the versions you're using because they are old, and it seems there is an issue in your input ontology.
Suggested version updates: use OWLAPI 5.1.20 and HermiT 1.4.5.519 (they don't directly affect this issue but they're more recent versions than the ones you're using.
Example Maven config:
<dependencies>
<dependency>
<groupId>net.sourceforge.owlapi</groupId>
<artifactId>owlapi-distribution</artifactId>
<version>5.1.20</version>
</dependency>
<dependency>
<groupId>net.sourceforge.owlapi</groupId>
<artifactId>org.semanticweb.hermit</artifactId>
<version>1.4.5.519</version>
<exclusions>
<exclusion>
<groupId>net.sourceforge.owlapi</groupId>
<artifactId>owlapi-distribution</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
Regarding your input ontology, if I feed it as is in the code you show (after amending to remove ONTAPI references, which are not relevant to the problem and in which I'm not an expert), I have the following code replicating the problem:
package teststack;
import java.io.*;
import org.semanticweb.HermiT.ReasonerFactory;
import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.formats.NTriplesDocumentFormat;
import org.semanticweb.owlapi.io.StringDocumentSource;
import org.semanticweb.owlapi.model.*;
import org.semanticweb.owlapi.reasoner.*;
import org.semanticweb.owlapi.util.*;
public class Check {
static OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
static OWLDataFactory data_factory = manager.getOWLDataFactory();
public static void main(String[] args)
throws OWLOntologyCreationException, OWLOntologyStorageException, IOException {
String notWorking="<urn:test:onto> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Ontology> .\n"
+ "<urn:test:onto#c> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#NamedIndividual> .\n"
+ "<urn:test:onto#c> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Thing> .\n"
+ "<urn:test:onto#r> <http://www.w3.org/2000/01/rdf-schema#subPropertyOf> <http://www.w3.org/2002/07/owl#topObjectProperty> .\n"
+ "<urn:test:onto#r> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#ObjectProperty> .\n"
+ "<urn:test:onto#a> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#NamedIndividual> .\n"
+ "<urn:test:onto#a> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Thing> .\n"
+ "<urn:test:onto#A> <http://www.w3.org/2000/01/rdf-schema#subClassOf> <http://www.w3.org/2002/07/owl#Thing> .\n"
+ "<urn:test:onto#A> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Class> .\n"
+ "<urn:test:onto#b> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#NamedIndividual> .\n"
+ "<urn:test:onto#b> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Thing> .\n"
+ "<urn:test:onto#B> <http://www.w3.org/2000/01/rdf-schema#subClassOf> <http://www.w3.org/2002/07/owl#Thing> .\n"
+ "<urn:test:onto#B> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Class> .\n"
+ "<urn:test:onto#q> <http://www.w3.org/2000/01/rdf-schema#subPropertyOf> <http://www.w3.org/2002/07/owl#topObjectProperty> .\n"
+ "<urn:test:onto#q> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#ObjectProperty> .\n";
OWLOntology o = manager.loadOntologyFromOntologyDocument(new StringDocumentSource(
notWorking,
IRI.create("urn:test:onto"), new NTriplesDocumentFormat(), null));
materialization(o, new File("result.txt"));
}
public static OWLOntology materialization(OWLOntology ontology, File inferredOntologyFile)
throws OWLOntologyStorageException, IOException, OWLOntologyCreationException {
OutputStream outputStream = new FileOutputStream(inferredOntologyFile);
OWLReasonerFactory reasoner_factory = new ReasonerFactory();
OWLReasoner reasoner = reasoner_factory.createReasoner(ontology);
if (reasoner.isConsistent() == false) {
System.out.println("INCONSISTENT ONTOLOGY!");
}
InferredOntologyGenerator inference = new InferredOntologyGenerator(reasoner);
inference.fillOntology(data_factory, ontology);
manager.saveOntology(ontology, new NTriplesDocumentFormat(), outputStream);
return ontology;
}
}
Note: I've removed all axioms relating individuals with topObjectProperty from this ontology. These axioms are replicated by the code.
However, removing the type assertions that state the properties are subproperties of topObjectProperties, the problem goes away. As the declarations are redundant, it looks like them being in the ontology tricks the reasoner into generating those axioms. Such unnecessary declarations should be ignored, so this might be a bug. However, workaround for you is to filter out any declaration axioms where the type is topObjectProperty from your input file.
<urn:test:onto> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Ontology> .
<urn:test:onto#c> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#NamedIndividual> .
<urn:test:onto#c> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Thing> .
<urn:test:onto#r> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#ObjectProperty> .
<urn:test:onto#a> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#NamedIndividual> .
<urn:test:onto#a> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Thing> .
<urn:test:onto#A> <http://www.w3.org/2000/01/rdf-schema#subClassOf> <http://www.w3.org/2002/07/owl#Thing> .
<urn:test:onto#A> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Class> .
<urn:test:onto#b> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#NamedIndividual> .
<urn:test:onto#b> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Thing> .
<urn:test:onto#B> <http://www.w3.org/2000/01/rdf-schema#subClassOf> <http://www.w3.org/2002/07/owl#Thing> .
<urn:test:onto#B> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Class> .
<urn:test:onto#q> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#ObjectProperty> .
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论