Je voudrais ajouter un triple RDF d'un fichier xls dans une ontologie OWL RDF/XML en utilisant l'API OWL. Je suis ce topic et réussi à le faire avec OWL API v 3.4 mais je ne peux pas le faire avec v4.3 (et tout le reste de mon programme utilise v4.3).Ajout d'une ontologie RDF-triple dans owl (OWL API 4.3.0)
Voici le code du sujet ci-dessus travaillant pour la version 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);
}
}
Je sais que certains Packages changed from v3.X to 4.X et il semble que le TurtleParser n'est plus un AnonymousNodeChecker? Dans cet exemple, le consommateur ne gère pas le 2 RDF-Triple dans la v4.3. Si quelqu'un parvient à exécuter cet exemple et à imprimer les deux relations (OWLObjectProperty/OWLDataproperty), ce serait sympa =). Ma dépendance:
<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>
Merci beaucoup.
P.S. : Je suis français, désolé si ma syntaxe n'est pas parfaite
Pour clarifier mon problème, je veux mettre mon triple dans une ontologie cible dans laquelle toute la classe et la relation sont définies. De plus, je ne connais pas à l'avance le type de triplet que je souhaite ajouter (ClassAssertion, DataPropertyAxiom, ObjectPropertyAxiom). C'est pourquoi je pensais que le RDFConsumer et un Parser pouvaient m'aider. –