我使用的是来自Maven的HermiT»1.3.8.1和来自Maven的OWL API 5.0.2。我试了将近2天来得到推论。我检查了所有的例子,没有一个适合我。有这么多版本的推理器和api真是令人沮丧。'
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
File file = new File(PATH_MODEL_ALL_OWL);
OWLOntology ontology = manager.loadOntologyFromOntologyDocument(file);
OWLReasonerFactory reasonerFactory = new StructuralReasonerFactory();
OWLReasonerConfiguration config = new SimpleConfiguration();
OWLReasoner reasoner = reasonerFactory.createReasoner(ontology, config);
reasoner.precompute();
private void printIndividualsByclass(OWLOntology ontology, OWLReasoner reasoner, String owlClass) {
for (OWLClass c : ontology.getClassesInSignature()) {
if (c.getIRI().getShortForm().equals(owlClass)) {
NodeSet<OWLNamedIndividual> instances = reasoner.getInstances(c, false);
System.out.println("Class : " + c.getIRI().getShortForm());
for (OWLNamedIndividual i : instances.getFlattened()) {
System.out.println(i.getIRI().getShortForm());
}
}
}
我有3个具有等价关系的类:A,B,C。A包含4个人,C包含2个人。如果我要求这个方法返回B的所有实例,它应该在这些类中的任何一个中返回6个实例。我做了一个实验,让B的子类C和等价的B A用推理逻辑得到了A和C的所有实例。但是等价在某种程度上对隐士不起作用。非常感谢你的帮助!
edit: i see i not use Hermit reasoner by call reasoner reasoner = new reasoner。我找不到一个例子,给出所有个人从一个特定的类,也推论(等效,子类)。请提供您正在使用的hermit版本或任何其他原因的owl api版本。一个有依赖关系的pom文件也很棒。这只是一个使用pom的工作示例。我真的很沮丧,没有一个例子对我有用。
My pom file:
`<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>Exporter</groupId>
<artifactId>Exporter</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>net.sourceforge.owlapi</groupId>
<artifactId>owlapi-distribution</artifactId>
<version>5.0.2</version>
</dependency>
<dependency>
<groupId>net.sourceforge.owlapi</groupId>
<artifactId>org.semanticweb.hermit</artifactId>
<version>1.3.8.500</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.github.ansell.pellet/pellet-owlapiv3 -->
<dependency>
<groupId>net.sourceforge.owlapi</groupId>
<artifactId>owlapi-apibinding</artifactId>
<version>5.0.2</version>
</dependency>
<dependency>
<groupId>net.sourceforge.owlapi</groupId>
<artifactId>owlapi-api</artifactId>
<version>5.0.2</version>
</dependency>
</dependencies>
</project>`
HermiT 1.3.8.1不兼容owlapi 5。maven上有一个兼容的版本,版本1.3.8.500。它是主HermiT代码库的一个分支,更新1.3.8。