bonjour,
je veux faire un requête sparql qui affiche les individus d'une classe (la liste des module affecter à chaque professeur
voici le contenu d'une ontologie créée en protégé
Code XML :Sélectionner tout -Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?xml version="1.0"?>
<rdf:RDF xmlns="http://www.semanticweb.org/pc/ontologies/2019/1/untitled-ontology-20#"
     xml:base="http://www.semanticweb.org/pc/ontologies/2019/1/untitled-ontology-20"
     xmlns:untitled-ontology-20="http://www.semanticweb.org/pc/ontologies/2019/1/untitled-ontology-20#"
     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
     xmlns:owl="http://www.w3.org/2002/07/owl#"
     xmlns<img src="images/smilies/icon_mad.gif" border="0" alt="" title=":x" class="inlineimg" />ml="http://www.w3.org/XML/1998/namespace"
     xmlns<img src="images/smilies/icon_mad.gif" border="0" alt="" title=":x" class="inlineimg" />sd="http://www.w3.org/2001/XMLSchema#"
     xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
    <owl:Ontology rdf:about="http://www.semanticweb.org/pc/ontologies/2019/1/untitled-ontology-20"/>
    <!-- <a href="http://www.semanticweb.org/pc/ontologies/2019/1/untitled-ontology-20#affecter_à" target="_blank">http://www.semanticweb.org/pc/ontolo...-20#affecter_à</a> -->
 
    <owl:ObjectProperty rdf:about="http://www.semanticweb.org/pc/ontologies/2019/1/untitled-ontology-20#affecter_à">
        <rdfs:domain rdf:resource="http://www.semanticweb.org/pc/ontologies/2019/1/untitled-ontology-20#professeur"/>
        <rdfs:range rdf:resource="http://www.semanticweb.org/pc/ontologies/2019/1/untitled-ontology-20#module"/>
    </owl:ObjectProperty>
 
 
    <!-- <a href="http://www.semanticweb.org/pc/ontologies/2019/1/untitled-ontology-20#codemodule" target="_blank">http://www.semanticweb.org/pc/ontolo...-20#codemodule</a> -->
 
    <owl<img src="images/smilies/icon_biggrin.gif" border="0" alt="" title=":D" class="inlineimg" />atatypeProperty rdf:about="http://www.semanticweb.org/pc/ontologies/2019/1/untitled-ontology-20#codemodule">
        <rdfs:domain rdf:resource="http://www.semanticweb.org/pc/ontologies/2019/1/untitled-ontology-20#module"/>
        <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    </owl<img src="images/smilies/icon_biggrin.gif" border="0" alt="" title=":D" class="inlineimg" />atatypeProperty>
 
    <!-- <a href="http://www.semanticweb.org/pc/ontologies/2019/1/untitled-ontology-20#firstname" target="_blank">http://www.semanticweb.org/pc/ontolo...y-20#firstname</a> -->
 
    <owl<img src="images/smilies/icon_biggrin.gif" border="0" alt="" title=":D" class="inlineimg" />atatypeProperty rdf:about="http://www.semanticweb.org/pc/ontologies/2019/1/untitled-ontology-20#firstname">
        <rdfs:domain rdf:resource="http://www.semanticweb.org/pc/ontologies/2019/1/untitled-ontology-20#personne"/>
        <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    </owl<img src="images/smilies/icon_biggrin.gif" border="0" alt="" title=":D" class="inlineimg" />atatypeProperty>
 
    <!-- <a href="http://www.semanticweb.org/pc/ontologies/2019/1/untitled-ontology-20#module" target="_blank">http://www.semanticweb.org/pc/ontolo...logy-20#module</a> -->
 
    <owl:Class rdf:about="http://www.semanticweb.org/pc/ontologies/2019/1/untitled-ontology-20#module"/>
 
 
    <!-- <a href="http://www.semanticweb.org/pc/ontologies/2019/1/untitled-ontology-20#personne" target="_blank">http://www.semanticweb.org/pc/ontolo...gy-20#personne</a> -->
 
    <owl:Class rdf:about="http://www.semanticweb.org/pc/ontologies/2019/1/untitled-ontology-20#personne"/>
 
<!-- <a href="http://www.semanticweb.org/pc/ontologies/2019/1/untitled-ontology-20#professeur" target="_blank">http://www.semanticweb.org/pc/ontolo...-20#professeur</a> -->
 
    <owl:Class rdf:about="http://www.semanticweb.org/pc/ontologies/2019/1/untitled-ontology-20#professeur">
        <rdfs:subClassOf rdf:resource="http://www.semanticweb.org/pc/ontologies/2019/1/untitled-ontology-20#personne"/>
    </owl:Class>
    <!-- <a href="http://www.semanticweb.org/pc/ontologies/2019/1/untitled-ontology-20#carla" target="_blank">http://www.semanticweb.org/pc/ontolo...ology-20#carla</a> -->
 
    <owl:NamedIndividual rdf:about="http://www.semanticweb.org/pc/ontologies/2019/1/untitled-ontology-20#carla">
        <rdf:type rdf:resource="http://www.semanticweb.org/pc/ontologies/2019/1/untitled-ontology-20#professeur"/>
        <affecter_à rdf:resource="http://www.semanticweb.org/pc/ontologies/2019/1/untitled-ontology-20#mathe105"/>
        <firstname>carla</firstname>
    </owl:NamedIndividual>
        <!-- <a href="http://www.semanticweb.org/pc/ontologies/2019/1/untitled-ontology-20#jack" target="_blank">http://www.semanticweb.org/pc/ontolo...tology-20#jack</a> -->
 
    <owl:NamedIndividual rdf:about="http://www.semanticweb.org/pc/ontologies/2019/1/untitled-ontology-20#jack">
        <rdf:type rdf:resource="http://www.semanticweb.org/pc/ontologies/2019/1/untitled-ontology-20#professeur"/>
        <firstname>jack</firstname>
    </owl:NamedIndividual>
    <!-- <a href="http://www.semanticweb.org/pc/ontologies/2019/1/untitled-ontology-20#mathe105" target="_blank">http://www.semanticweb.org/pc/ontolo...gy-20#mathe105</a> -->
 
    <owl:NamedIndividual rdf:about="http://www.semanticweb.org/pc/ontologies/2019/1/untitled-ontology-20#mathe105">
        <rdf:type rdf:resource="http://www.semanticweb.org/pc/ontologies/2019/1/untitled-ontology-20#module"/>
        <affecter_à rdf:resource="http://www.semanticweb.org/pc/ontologies/2019/1/untitled-ontology-20#jack"/>
        <codemodule>mathe105</codemodule>
    </owl:NamedIndividual>
</rdf:RDF>



cette ontologie contient deux classe:personne ,module
une sous classe de personne appelée: professeur,
une relation: affecter à entre le module et le professeur,

le code java que le fait:
Code :Sélectionner tout -Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
public class J {
	  static final String inputFileName = "C:/TEST.owl";
 
	public static void main(String[] args) {
		  Model model = ModelFactory.createDefaultModel();
 
		  InputStream in = FileManager.get().open(inputFileName);
		   if (in == null) {
		    throw new IllegalArgumentException( "File: " + inputFileName + " not found");
		        }
 
 
		  model.read( in, "", "RDF/XML" );       
		  String queryString = 
				  	"PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> " +
		  					"PREFIX owl: <http://www.w3.org/2002/07/owl#> " +
		  					"SELECT ?professeur" +
		  				  	"WHERE {" +
		  				  	"?x rdf:affecter_à ?module"+		  
		  				  "      }";
 
		  				  Query query = QueryFactory.create(queryString);
 
		  				  QueryExecution qe = QueryExecutionFactory.create(query, model);
		  				  ResultSet results = qe.execSelect();
 
		  				  ResultSetFormatter.out(System.out, results, query);
 
		  				  qe.close();
 
	}
}