I have developed my own ontology (I defined my classes, properties, etc.) and I want to interrogate my ontology with sparql.
in protégé 2000 (open-source ontology editor) everything works fine, but when I want to implement my request sparql in python I encountered some problems.
I did it in Java and it worked but it's not what I want, I wanted to it do with pyjnius
(A Python module to access Java classes as Python classes) but nothing worked also.
How I can use sparql to interrogate my ontology? Is there any way to use jena in Python?
that's how i did it with java :
try{
Model model = ModelFactory.createDefaultModel();
String FName = "C:\\Users\\p\\Desktop\\protégé project jour\\jour.owl";
InputStream inStr = FileManager.get().open(FName);
if (inStr == null) { throw new IllegalArgumentException("Fichier non trouvé");}
// Lire le fichier RDF vers le modèle précédemment créé.
model.read(inStr, "");
//****************************
String requete =
//***=====This is the query that works good in the ontology with properties between classes
"PREFIX OntoJO:<http://www.owl-ontologies.com/Ontology1400008538.owl#>" +
"SELECT ?path " +
"WHERE { "
+ " ?n OntoJO:signee_par '"+choixsignrech1.getText()+"' ."
+ " ?s OntoJO:mot_cle '"+choixclrech1.getText()+"' ."
+ " ?m OntoJO:secteur '"+choixsecrech1.getSelectedItem()+"' ."
+ " ?f OntoJO:ministere '"+choixminisrech1.getSelectedItem()+"' ."
+ " ?r OntoJO:synonymes '"+choixsyrech1.getText()+"' ."
+ "?n OntoJO:a_un_chemin ?y . "
+ "?s OntoJO:a_un_chemin ?y . "
+ "?m OntoJO:a_un_chemin ?y . "
+ "?f OntoJO:a_un_chemin ?y . "
+ "?r OntoJO:a_un_chemin ?y . "
+ "?y OntoJO:chemin ?path . }";
Query query = QueryFactory.create(requete);
QueryExecution qexec = QueryExecutionFactory.create(query, model);
try {
ResultSet results = qexec.execSelect();
while (results.hasNext()){
QuerySolution soln = results.nextSolution();
RDFNode name = soln.get("path");
System.out.println(name);
javax.swing.JOptionPane.showMessageDialog(this,soln.get("path"));
}
} finally
{
qexec.close();
}
the properties are: signee_par, mot_cle, secteur, ministere etc ..... ( in french ), the sqarql request is based on these properties
i wanna do it with python, anyone know how i can ?!