2017-05-09 1 views
0
public class Main { 

public static void main(String args[]){ 



    //read an ontology 

    String filename = "IOTOntology.owl"; 
    Model model = ModelFactory.createDefaultModel(); 
    OntModel model1 = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM); 

    //over 

    // Waits for the device ID 
    System.out.print("Enter name of man: "); 

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 
    String devID = null; 
    try { 
     devID = br.readLine(); 
     } catch (IOException ioe) { 
     System.out.println("IO error trying to read device ID!"); 
     System.exit(1); 
     } 


    try { 
      File file=new File(filename); 
      FileInputStream reader=new FileInputStream(file); 
      System.out.println("The absolute path of the file is:"+ file.getAbsolutePath()); 

      model.read(reader, "RDF/XML"); 


      // Create a SPARQL query from the given string. 
      String queryString = "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> "+ 
      "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> "+ 
      "PREFIX owl: <http://www.w3.org/2002/07/owl#>" + 
      "PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>" + 
      //"PREFIX act: <http://www.semanticweb.org/project/ontologies/2016/0/Actor#>" + 
      "select ?name "+ 
      "where { "+ 
      " ?User a rdf:name"+ 
      "} \n "; 

      Query query = QueryFactory.create(queryString); 

      try (// Execute the query and obtain results 
       QueryExecution qe = QueryExecutionFactory.create(query, model)) { 
       ResultSet results = qe.execSelect(); 

       // Output query results 
       ResultSetFormatter.out(System.out, results, query); 
       qe.close(); 

      } 
      model.close(); 
     } catch(Exception e) { 
      System.out.println(e.getMessage()); 
     }  
    } 
} 

J'ai un problème parce que ma table est vide, il écrit dans la ligne de commande seulement ceci:Quelqu'un peut-il me dire comment lister tous les utilisateurs de l'ontologie dans eclipse?

-------- 
| name | 
======== 
-------- 

et c'est le lien vers mon ontologie: https://github.com/isidoramalkata/IOTOntology.git

Répondre

1

Je pense que vous devez lire un peu plus sur RDF et SPARQL premier ...

Votre requête est

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> 
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> 
PREFIX owl: <http://www.w3.org/2002/07/owl#> 
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> 
PREFIX act: <http://www.semanticweb.org/project/ontologies/2016/0/Actor#> 
select ?name where { 
    ?User a rdf:name 
} 

Cela ne fait aucun sens:

  • Vous sélectionnez une ?name variable qui ne se produit pas dans la requête
  • vous utilisez a comme prédicat qui est un raccourci pour rdf:type propriété, qui, en fait, attribue des ressources aux classes, donc, vous AAK des ressources qui sont d'un type rdf:name
  • qui d'ailleurs n'existent pas dans votre ontologie

Jetez un oeil à la structure triple:

utilisateur un rdf: nommer

Vos données sont

<owl:NamedIndividual rdf:about="file://SHOnt.owl#UserIsidora"> 
     <rdf:type rdf:resource="file://SHOnt.owl#User"/> 
     <SHOnt:phoneNumber rdf:datatype="http://www.w3.org/2001/XMLSchema#string">0605222024</SHOnt:phoneNumber> 
     <SHOnt:name rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Isidora</SHOnt:name> 
     <SHOnt:email rdf:datatype="http://www.w3.org/2001/XMLSchema#string">[email protected]</SHOnt:email> 
</owl:NamedIndividual> 

Il n'y a pas trois dans vos données correspondant à ce modèle. RDF moyens triple

subject predicate object

à savoir

@prefix shont: <file://SHOnt.owl#> . 
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> . 
shont:UserIsidora shont:name "Isidora"^^xsd:string . 

Ceci est la syntaxe tortue qui est ce que SPARQL est basé sur, par conséquent, il est toujours bon d'avoir un oeil à vos données dans cette syntaxe.

requête SPARQL:

prefix shont: <file://SHOnt.owl#> 
prefix xsd: <http://www.w3.org/2001/XMLSchema#> 
select ?name where { 
     ?User shont:name ?name 
} 

Comme je l'ai dit, vous devriez vraiment lire d'abord un tutoriel RDF.