OLS APIを使用して、xlsファイルからRDFトリプルをOWL RDF/XMLオントロジーに追加したいと思います。私はこのtopicに従い、OWL API v 3.4でそれを行うことができますが、私はv4.3(そして私のプログラムの残りの部分はv4.3を使用しています)ではできません。ここでRDF-tripleをowlオントロジーに追加する(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を処理しません。 誰かがこの例を実行して2つのリレーション(OWLObjectProperty/OWLDataproperty)を印刷するとnice =)になります。私の依存:
<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が私を助けてくれると思ったのです。 –