0
與RDF三元這樣的:dotnetrdf圖SPARQL查詢
<?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>
我怎樣才能查詢有關主語或賓語?
我的代碼:
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);
}
}
我的代碼下面我從查詢的所有答案。任何人都可以幫助我得到主題= fadi?
myGraph.BaseUri = NULL;在store.add(myGraph)正在工作之前.. 謝謝。 – 2013-05-04 08:53:50