6.Graph Graph patterns

须知

1.SPARQL 查询是建立在RDF 数据集上。
2.一个 RDF数据集包含一个默认graph, 和0个或者多个被URI指定的graph
3.关键字——GRAPH让一个被URI指定的graph成为当前被使用的graph,用于模式匹配。

Data structure

---Default Graph
dbpedia:Mount_Etna rdfs:seeAlso . 
dbpedia:Mount_Baker rdfs:seeAlso . 
http://example.org/d1 
dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ; 
                   rdfs:label "Etna" . 
http://example.org/d2 
dbpedia:Mount_Baker rdf:type umbel-sc:Volcano . 
http://example.org/d3 
dbpedia:Beerenberg rdf:type umbel-sc:Volcano ; 
                   rdfs:label ”Beerenberg“@en

1.问题:在graph1 中有哪些火山的名字?

QUERY

SELECT ?v WHERE {  
   GRAPH  { 
         ?v rdf:type umbel-sc:Volcano . 
} 
}

返回:

dbpedia:Mount_Etna

2.问题:在所有图中,有哪些火山?

QUERY

SELECT ?v WHERE { 
GRAPH ?g {
     ?v rdf:type umbel-sc:Volcano .
}
}

返回:

dbpedia:Mount_Etna
dbpedia:Mount_Baker
dbpedia:Beerenberg

3.问题:在默认graph中有哪些火山?

QUERY

SELECT ?v WHERE { 
_:x rdfs:seeAlso ?g 
GRAPH ?g { 
 ?v rdf:type umbel-sc:Volcano . 
  } 
}

返回:

dbpedia:Mount_Etna
dbpedia:Mount_Baker

4.问题:不在默认graph中有哪些火山

QUERY

SELECT ?g WHERE { 
     GRAPH ?g { 
         ?v rdf:type umbel-sc:Volcano ;
            rdfs:label ?name 
    }
     OPTIONAL { ?v rdfs:seeAlso ?r }
     Filter (! BOUND(?r) )
}

返回:

dbpedia:Beerenberg

你可能感兴趣的:(6.Graph Graph patterns)