0

with rdf triples like this:

<?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:nss="http://www.example.org/startTime"
     xmlns:nse="http://www.example.org/endTime">

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

  <rdf:Description rdf:about="I">
    <ns1:love xmlns:ns1="http://example.org/">You</ns1:love>
    <nss:startTime>00:05:35</nss:startTime>
    <nse:endTime>00:06:39</nse:endTime>
  </rdf:Description>
</rdf:RDF>

how can i query about subject or object?

my code:

Graph myGraph = new Graph();
FileLoader.Load(myGraph, "C:\\Users\\hasoOn\\Desktop\\tt.rdf");                

TripleStore store = new TripleStore();
store.Add(myGraph);

SparqlParameterizedString queryString = new SparqlParameterizedString();
queryString.CommandText = "PREFIX ex: <http://example.org/> SELECT * WHERE { { ex:fadi ?p ?o } UNION { GRAPH ?g { ?s ?p ?o } } } ";
SparqlQueryParser parser = new SparqlQueryParser();
SparqlQuery query = parser.ParseFromString(queryString.CommandText);
SparqlResultSet results = (SparqlResultSet)store.ExecuteQuery(query);

if (results is SparqlResultSet)
{
    SparqlResultSet rset = (SparqlResultSet)results;
    foreach (SparqlResult result in rset)
    {
        Console.WriteLine(result);   
    }
} 

with my code below i get all answers from the query. can anyone help me to get for just subject = fadi?

4

1 回答 1

3

union 的第二部分负责结果:您从商店中的所有图表中查询所有三元组,因为没有绑定任何变量。第一部分实际上什么也不返回。

您在这里有两个解决方案:

1)您将图形添加到默认数据集中:

myGraph.baseUri = null

在添加 store.add(myGraph) 语句之前 然后查询 SELECT * { ex:Fadi ?p ?o } 应该足够了

2)您将查询更改为:

Select * from _yourGraphUriHere { ex:Fadi ?p ?o}

那应该可以得到你想要的。

顺便说一句,请记住 Uris 区分大小写,因此 ex:fadi 不是您要查询的内容,而是 ex:Fadi

于 2013-05-04T07:03:36.687 回答