我想使用OWL API将xls文件中的RDF三元组添加到OWL RDF/XML本体中。我遵循这个topic并设法使用OWL API v 3.4来做到这点,但是我无法用v4.3来做到这一点(并且我所有的程序都使用了v4.3)。在OWL API中添加RDF三元组(OWL API 4.3.0)
这里是话题上面的3.4版本使用的代码:
import java.io.Reader;
import org.coode.owlapi.rdfxml.parser.OWLRDFConsumer;
import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.OWLDataFactory;
import org.semanticweb.owlapi.model.OWLDataProperty;
import org.semanticweb.owlapi.model.OWLEntity;
import org.semanticweb.owlapi.model.OWLNamedIndividual;
import org.semanticweb.owlapi.model.OWLObjectProperty;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyCreationException;
import org.semanticweb.owlapi.model.OWLOntologyLoaderConfiguration;
import org.semanticweb.owlapi.model.OWLOntologyManager;
import org.semanticweb.owlapi.model.OWLOntologyStorageException;
import uk.ac.manchester.cs.owl.owlapi.turtle.parser.TurtleParser;
public class ExampleOWLRDFConsumer {
public static void main(String[] args) throws OWLOntologyCreationException, OWLOntologyStorageException {
// Create an ontology.
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLDataFactory factory = manager.getOWLDataFactory();
OWLOntology ontology = manager.createOntology();
// Create some named individuals and an object property.
String ns = "http://example.org/";
OWLNamedIndividual tom = factory.getOWLNamedIndividual(IRI.create(ns + "Tom"));
OWLObjectProperty likes = factory.getOWLObjectProperty(IRI.create(ns + "likes"));
OWLDataProperty age = factory.getOWLDataProperty(IRI.create(ns + "age"));
OWLNamedIndividual anna = factory.getOWLNamedIndividual(IRI.create(ns + "Anna"));
// Add the declarations axioms to the ontology so that the triples involving
// these are understood (otherwise the triples will be ignored).
for (OWLEntity entity : new OWLEntity[] {tom, likes, age, anna}) {
manager.addAxiom(ontology, factory.getOWLDeclarationAxiom(entity));
}
// Print the the ontology to see that the entities are declared.
// The important result is
// <NamedIndividual rdf:about="http://example.org/Tom"/>
// with no properties
manager.saveOntology(ontology, System.out);
// Create an OWLRDFConsumer for the ontology.
OWLRDFConsumer consumer = new OWLRDFConsumer(ontology, new TurtleParser((Reader) null), new OWLOntologyLoaderConfiguration());
// The consumer handles (IRI,IRI,IRI) and (IRI,IRI,OWLLiteral) triples.
consumer.handle(tom.getIRI(), likes.getIRI(), anna.getIRI());
consumer.handle(tom.getIRI(), age.getIRI(), factory.getOWLLiteral(35));
// Print the ontology to see the new object and data property assertions. The import contents is
// still Tom:
// <NamedIndividual rdf:about="http://example.org/Tom">
// <example:age rdf:datatype="http://www.w3.org/2001/XMLSchema#integer">35</example:age>
// <example:likes rdf:resource="http://example.org/Anna"/>
// </NamedIndividual>
manager.saveOntology(ontology, System.out);
}
}
我知道有些Packages changed from v3.X to 4.X,并似乎TurtleParser是不再一个AnonymousNodeChecker?在这个例子中,消费者不会处理v4.3中的2 RDF-Triple。 如果有人设法运行这个例子并打印这两个关系(OWLObjectProperty/OWLDataproperty),那很好=)。我的依赖:
<parent>
<artifactId>owlapi-parent</artifactId>
<groupId>net.sourceforge.owlapi</groupId>
<version>4.3.0</version>
</parent>
<dependency>
<groupId>net.sourceforge.owlapi</groupId>
<artifactId>owlapi-compatibility</artifactId>
<version>4.3.0</version>
</dependency>
非常感谢。
P.S. :我是法语的,对不起,如果我的语法不完美
为了澄清我的问题,我希望把我的三倍,其中所有类和关系,定义了目标本体。此外,我不知道我想添加的三元组的类型(ClassAssertion,DataPropertyAxiom,ObjectPropertyAxiom)。这就是为什么我认为RDFConsumer和Parser可以帮助我。 –