Basic graph pattern (BGP) 是一个三元组的集合(带有变量的RDF 三元组),变量名都带有前缀 ‘?’or ‘$’(e.g. ?v, $v)
Turtle 语法和 N3 类似,是一种语法糖。
格式如下:
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX umbel-sc: <http://umbel.org/umbel/sc/>
SELECT ?name
WHERE {
?v rdf:type umbel-sc:Volcano .
rdfs:label ?name .
}
举例:
-- Data
dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ;
rdfs:label "Etna".
dbpedia:Mount_Baker rdf:type umbel-sc:Volcano.
dbpedia:Beerenberg rdf:type umbel-sc:Volcano,
umbel-sc:NaturalElevation ;
rdfs:label "Beerenberg“@en ;
rdfs:label "Бееренберг"@ru .
提问:所有已知火山的名字是什么?
--Query
SELECT ?name WHERE {
?v rdf:type umbel-sc:Volcano ;
rdfs:label ?name .
}
经过模式匹配后,我们得到:
"Etna"
"Beerenberg“@en
"Бееренберг"@ru
又如问题:列出所有叫做Beerenberg的火山
SELECT ?type WHERE {
?v rdf:type ?type ;
rdfs:label ''Beerenberg''. }
经过匹配后,我们得到:
umbel-sc:Volcano,
umbel-sc:NaturalElevation ;
复杂一点的Data结构:
dbpedia:Mount_Baker rdf:type umbel-sc:Volcano ;
p:location dbpedia:United_States .
dbpedia:United_States rdfs:label "United States";
问题:已知的火山位于哪里?
SELECT ?name WHERE {
_:x rdf:type umbel-sc:Volcano ;
p:location [ rdfs:label ?name ] . }
经过匹配后,我们得到:
"United States"
更更复杂的Data结构:
dbpedia:Mount_Baker rdf:type umbel-sc:Volcano ;
p:location [ rdfs:label "United States"@en , "États-Unis"@fr ] .
dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ;
p:location [ rdfs:label "Italy" ]
问题: 所有已知火山的位置?
SELECT ?name WHERE {
?v rdf:type umbel-sc:Volcano ;
p:location ?l .
?l rdfs:label ?name .
}
经过匹配后,我们得到:
"United States"@en
"États-Unis"@fr
"Italy"