Pregunta

Given This RDF:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE rdf:RDF [<!ENTITY rdf 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'>
<!ENTITY rdfs 'http://www.w3.org/2000/01/rdf-schema#'>
<!ENTITY xsd 'http://www.w3.org/2001/XMLSchema#'>]>
<rdf:RDF xmlns:xsd="http://www.w3.org/2001/XMLSchema#" 
         xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
         xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
     xmlns:dnr="http://www.dotnetrdf.org/configuration#"
         xml:base="http://www.example.org/"
         xmlns:ns1="http://www.example.org/startTime"
     xmlns:ns2="http://www.example.org/endTime">

  <rdf:Description rdf:about="Fadi">
    <ns0:eat xmlns:ns0="http://example.org/">Apple</ns0:eat>
    <ns1:startTime>00:01:38</ns1:startTime>
    <ns2:endTime>00:01:39</ns2:endTime>
  </rdf:Description>
</rdf:RDF>

i am trying to make sparql query, but when i make this query:

SELECT * WHERE { { ?s ?p ?o } UNION { GRAPH ?g { ?s ?p ?o } } }

i get the Answers. but when i tried this:

SELECT * WHERE { ?s ?p ?o . FILTER (regex(?o, 'Apple','i')) }

i get nothn.

i need to get the startTime and endTime with query, how can i write it?!

Including code from OPs comments

Graph myGraph = new Graph();
FileLoader.Load(myGraph, "C:\\Users\\hasoOn\\Desktop\\tt.RDF");
TripleStore store = new TripleStore();
store.Add(myGraph);
SparqlQueryParser parser = new SparqlQueryParser();
SparqlQuery q = parser.ParseFromString("PREFIX ex: <example.org/>; SELECT * WHERE { ex:Fadi ?p ?o }");
SparqlResultSet results = (SparqlResultSet)store.ExecuteQuery(q);
¿Fue útil?

Solución

Assuming based on your previous question that this also relates to dotNetRDF you aren't querying the data you think you are, to quote from the Querying with SPARQL documentation:

A common error with making queries is that queries by default typically operate only over the unnamed default graph in the store (depending on your query processor). Therefore executing queries may yield no results depending on what graphs your data is in and whether you configured your dataset correctly. Please see the SPARQL Datasets page for discussions of configuring different kinds of dataset. You can also look at Debugging SPARQL Queries for a method to debug what is happening with your query when using the in-memory SPARQL engine.

I have added the emphasis, the first query you mention selects everything regardless of what graph it is in hence why it returns a result.

Your second query is only querying the default graph which likely contains no data and thus returns nothing, please refer to the linked documentation for more information on how to configure your datasets appropriately.

Either modify your query to use GRAPH clauses so it actually accesses the named graphs in your data or show the code you use to make a query so that I can give you pointers on how to modify it appropriately so your second query works.

Edit

Having now seen your code you are indeed not querying your data, a TripleStore when using for SPARQL queries has an implicit unnamed graph which is the default graph that you are querying. To query your data you can change your code in several ways:

  1. Set g.BaseUri = null; prior to adding the graph to the TripleStore instance so that your data is treated as the default graph
  2. Use a ISparqlDataset and LeviathanQueryProcessor per the documentation so that you can configure your dataset to make your graph the default graph more flexibly
  3. As already suggested modify your query to use GRAPH clauses so you query the named graphs in your store rather than the default graph
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top