2012-01-09 2 views
1

J'Interrogation fichier rdf en utilisant la bibliothèque rdfdotnetInterrogation RDF Fichier dans RDFDOTNET

Voici mon code

//Define your Graph here - it may be better to use a QueryableGraph if you plan 
//on making lots of Queries against this Graph as that is marginally more performant 
IGraph g = new Graph(); 

//Load some data into your Graph using the LoadFromFile() extension method 
g.LoadFromFile("C:/Users/admin/Desktop/current/Semantic/test.rdf"); 

//Use the extension method ExecuteQuery() to make the query against the Graph 
try 
{ 
    String q = " Prefix u:<http://localhost:49682/Semantic/test.rdf> SELECT * WHERE {?x1 u:age ?x2}"; 
     Object results = g.ExecuteQuery(q); 

     if (results is SparqlResultSet) 
     { 
      //SELECT/ASK queries give a SparqlResultSet 
      SparqlResultSet rset = (SparqlResultSet)results; 
      foreach (SparqlResult r in rset) 
      { 
       //Do whatever you want with each Result 
      } 
     } 
     else if (results is IGraph) 
     { 
      //CONSTRUCT/DESCRIBE queries give a IGraph 
      IGraph resGraph = (IGraph)results; 
      foreach (Triple t in resGraph.Triples) 
      { 
       //Do whatever you want with each Triple 
      } 
     } 
     else 
     { 
      //If you don't get a SparqlResutlSet or IGraph something went wrong 
      //but didn't throw an exception so you should handle it here 
      Console.WriteLine("ERROR"); 
     } 
    } 
    catch (VDS.RDF.Query.RdfQueryException queryEx) 
    { 
     //There was an error executing the query so handle it here 
     Console.WriteLine(queryEx.Message); 
    } 

Il donne une erreur quand j'exécute ma requête

[UriToken à la ligne 1 Colonne 10 à ligne 1 Colonne 52] Attendu un jeton de préfixe pour suivre le verbe PREFIX dans une requête

+0

voici le fichier rdf – user514596

Répondre

0

Quelle version de la bibliothèque utilisez-vous?

Les anciennes versions ont un bug où il devait y avoir un espace entre le préfixe - dans votre cas u: - et l'URI d'espace - dans votre cas <http://localhost:49682/Semantic/test.rdf>

Si vous utilisez la dernière version de la bibliothèque (0,5. 1) vous n'aurez plus cette question

Modifier

C'était fixe dans la version 0.5.0 (voir le numéro CORE-88) si vous êtes au moins deux versions derrière au moment de l'écriture si vous voyez cette erreur, comme je l'ai déjà répondu à la mise à niveau devrait résoudre le problème.