最新文章請前去 http://xjtushilei.com 裏的http://xjtushilei.com/2012/11/04/sparql%E5%AD%A6%E4%B9%A0sparql%E7%A4%BA%E4%BE%8B-dbpedia%E5%9C%A8%E7%BA%BF%E9%AA%8C%E8%AF%81/
select的第2個
問題:中國的首都是什麼?
select distinct ?c where
{
<http://dbpedia.org/resource/China> <http://dbpedia.org/property/capital> ?c
}
------------------------------------------------------
select的第2個
問題:韓國比較大的城市有哪些?
select distinct ?c where
{
<http://dbpedia.org/resource/Korea> <http://dbpedia.org/property/largestCity> ?c
}
------------------------------------------------------
ask第1個
問題:北京人口是否超過了1千萬?
prefix xsdt: <http://www.w3.org/2001/XMLSchema#>
ask where
{
<http://dbpedia.org/resource/Beijing> <http://dbpedia.org/property/populationTotal> ?total.
filter(?total >"10000000"^^xsdt:integer )
}
--------------------------------------------------------
ask第2個
問題:姚明是90後嗎?
prefix xsdt: <http://www.w3.org/2001/XMLSchema#>
ask where
{
<http://dbpedia.org/resource/Yao_Ming> <http://dbpedia.org/ontology/birthDate> ?date.
filter(?date>"1990-01-01"^^xsdt:date )
}
--------------------------------------------------------------------
第1個describe(說明:The DESCRIBE query result clause allows the server to return whatever RDF it wants that describes the given resource(s).)
問題:返回“哈希表”這個實體的所有內容
describe ?a
{?a <http://www.w3.org/2000/01/rdf-schema#label> "哈希表"@zh}
----------------------------------------------------------------------
describe第2個
問題:返回“數據結構”類別下的所有實體內容
describe ?a
{?a <http://purl.org/dc/terms/subject> <http://dbpedia.org/resource/Category:Data_structures>}
----------------------------------------------------------------------
filter的第1個
問題:請隨意列舉出生在中國的20個人
select distinct ?name where
{
?a <http://www.w3.org/2000/01/rdf-schema#label> ?name.
?a <http://dbpedia.org/property/birthPlace> ?country.
filter regex(str(?country), "China")
}limit 20
----------------------------------------------------------------------
filter第2個
問題:2008年之後的美國災難電影有哪些?
PREFIX dbpprop:<http://dbpedia.org/property/>
prefix xsdt: <http://www.w3.org/2001/XMLSchema#>
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX category: <http://dbpedia.org/resource/Category:>
SELECT ?filmname {
?film dcterms:subject category:American_disaster_films.
?film dbpprop:name ?filmname.
?film dbpprop:released ?date.
FILTER (?date > "2008-01-01T00:00:00"^^xsdt:dateTime)
}
-------------------------------------------------------
filter第3個
問題:名字中包含'Republic'的且在1920年之前成立的國家有哪些?
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX type: <http://dbpedia.org/class/yago/>
PREFIX prop: <http://dbpedia.org/property/>
SELECT ?lbl ?est
WHERE {
?country rdfs:label ?lbl .
FILTER(bif:contains(?lbl, "Republic")) .
?country prop:establishedDate ?est .
FILTER(?est < "1920-01-01"^^xsd:date) .
}
-------------------------------------------------------
filter第4個
問題:1990到1993年出生的NBA球員有哪些有哪些?
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
SELECT ?name
WHERE {
?a <http://dbpedia.org/property/name> ?name.
?a <http://dbpedia.org/property/league> <http://dbpedia.org/resource/National_Basketball_Association>.
?a <http://dbpedia.org/ontology/birthDate> ?date.
filter(?date>"1990-01-01"^^xsd:date &&
?date<"1993-01-01"^^xsd:date )
}
bound的第1個
問題:1970年前出生的NBA球員中,沒有上過大學的人有誰?(這個問題和下一個問題形成對比)
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
SELECT distinct ?name ?college
WHERE {
?a <http://dbpedia.org/property/name> ?name.
?a <http://dbpedia.org/property/league> <http://dbpedia.org/resource/National_Basketball_Association>.
?a <http://dbpedia.org/ontology/birthDate> ?date.
filter(?date<"1970-01-01"^^xsd:date )
optional
{
?a <http://dbpedia.org/ontology/college> ?college
}
filter(!bound(?college))
}
------------------------------------------------------
bound的第2個
問題:1970年前出生的NBA球員中,上過大學的人有誰?
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
SELECT distinct ?name ?college
WHERE {
?a <http://dbpedia.org/property/name> ?name.
?a <http://dbpedia.org/property/league> <http://dbpedia.org/resource/National_Basketball_Association>.
?a <http://dbpedia.org/ontology/birthDate> ?date.
filter(?date<"1970-01-01"^^xsd:date )
optional
{
?a <http://dbpedia.org/ontology/college> ?college
}
filter(bound(?college))
}
------------------------------------------------------
not exists的第1個
問題:NBA球員中,法國出生但是不在法國的“Saint”城市出生的人有誰?
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
SELECT ?name ?country
WHERE {
?a <http://dbpedia.org/property/name> ?name.
?a <http://dbpedia.org/property/league> <http://dbpedia.org/resource/National_Basketball_Association>.
?a <http://dbpedia.org/property/birthPlace> ?country.
filter regex(str(?country), "France")
filter not exists{
{
?a <http://dbpedia.org/property/name> ?name.
?a <http://dbpedia.org/property/league> <http://dbpedia.org/resource/National_Basketball_Association>.
?a <http://dbpedia.org/property/birthPlace> ?country.
filter regex(str(?country), "Saint")
}
}
}
------------------------------------------------------
not exists的第2個
問題:出生在西安的名人有哪些?但是這些人不在1970年後出生的人當中
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
SELECT ?name
WHERE {
?a <http://dbpedia.org/property/name> ?name.
?a <http://dbpedia.org/property/birthPlace> <http://dbpedia.org/resource/Xi'an>.
filter not exists{
?a <http://dbpedia.org/ontology/birthYear> ?date.
filter(?date>"1970-01-01"^^xsd:date )
}
}
------------------------------------------------------------------------
in第一個(in是限制條件,a in(a,b,c,d)表示返回成功,e in(a,b,c,d)返回失敗)
問題:北京的城市人口和總人口是多少?(沒有這項指標則忽略)
SELECT ?b ?number
WHERE
{
<http://dbpedia.org/resource/Beijing> ?b ?number.
filter( ?b in(<http://dbpedia.org/property/populationUrban>,<http://dbpedia.org/property/populationTotal>) )
}
------------------------------------------------------------------------
in第一個(in是限制條件,a in(a,b,c,d)表示返回成功,e in(a,b,c,d)返回失敗)
問題:姚明的出生日期和死亡日期是什麼時候?如果有數據才返回結果,沒有就忽略。
SELECT ?b ?date
WHERE
{
<http://dbpedia.org/resource/Yao_Ming> ?b ?date.
filter( ?b in(<http://dbpedia.org/ontology/birthDate>,<http://dbpedia.org/ontology/deathDate>) )
}
---------------------------------------------------------------------------
regex的第1個
問題:NBA球員中,法國出生的有誰?
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
SELECT ?name ?country
WHERE {
?a <http://dbpedia.org/property/name> ?name.
?a <http://dbpedia.org/property/league> <http://dbpedia.org/resource/National_Basketball_Association>.
?a <http://dbpedia.org/property/birthPlace> ?country.
filter regex(str(?country), "France")
}
------------------------------------------------------
regex的第2個
問題:NBA球員中,名字中有“Jason”的人都有誰?
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
SELECT ?name
WHERE {
?a <http://dbpedia.org/property/name> ?name.
?a <http://dbpedia.org/property/league> <http://dbpedia.org/resource/National_Basketball_Association>.
filter(regex(?name,"Jason"))
}
------------------------------------------------------
minus(主要就是排除功能)的第1個
問題:美國浪漫主義電影裏,除去2000年以前的電影,還剩下什麼電影?
PREFIX dbpprop:<http://dbpedia.org/property/>
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX category: <http://dbpedia.org/resource/Category:>
SELECT ?filmname{
?film dcterms:subject category:Romantic_epic_films.
?film dbpprop:name ?filmname.
MINUS{?film dbpprop:released ?date.
FILTER (?date < 2000 )}
}
------------------------------------------------------
minus(主要就是排除功能)的第2個
問題:NBA隊員裏,除去出生在美國的,還有哪些人?
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
SELECT ?name
WHERE {
?a <http://dbpedia.org/property/name> ?name.
?a <http://dbpedia.org/property/league> <http://dbpedia.org/resource/National_Basketball_Association>.
?a <http://dbpedia.org/ontology/birthDate> ?date.
minus{
?a <http://dbpedia.org/property/birthPlace> ?country.
filter regex(str(?country), "American")
}
}
-------------------------------------------
union(主要進行合併操作)第1個
問題:中國和韓國的領導人有哪些?
SELECT ?people
where{
{
<http://dbpedia.org/resource/China> <http://dbpedia.org/ontology/leader> ?people.
}
union
{
<http://dbpedia.org/resource/Korea> <http://dbpedia.org/property/leaderName> ?people.
}
}
-------------------------------------------
union(主要進行合併操作)第2個
問題:浪漫主義電影和美國災難片這兩種類型的電影有哪些?
PREFIX dbpprop:<http://dbpedia.org/property/>
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX category: <http://dbpedia.org/resource/Category:>
SELECT ?filmname{
{
?film dcterms:subject category:Romantic_epic_films.
?film dbpprop:name ?filmname.
}
union{
?film dcterms:subject category:American_disaster_films.
?film dbpprop:name ?filmname.
}
}
--------------------------------------------------
optional 第1個
問題:NBA球員中,出生在1950年以前的人的名字叫什麼,如果數據庫中有出生地點,也列舉出來,沒有的話就不用管(備註:其實這也是optional的作用)
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
SELECT distinct ?name ?birthPlace
WHERE {
?a <http://dbpedia.org/property/name> ?name.
?a <http://dbpedia.org/property/league> <http://dbpedia.org/resource/National_Basketball_Association>.
?a <http://dbpedia.org/ontology/birthDate> ?date.
filter(?date<"1950-01-01"^^xsd:date )
optional {
?a <http://dbpedia.org/property/birthPlace> ?birthPlace
}
}
--------------------------------------------------------------------------------------
optional 第2個
問題:NBA球員中,出生在1970年以前的人的名字叫什麼,如果上過大學,請列出大學。(結果中看到有部分人沒有大學信息)
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
SELECT distinct ?name ?college
WHERE {
?a <http://dbpedia.org/property/name> ?name.
?a <http://dbpedia.org/property/league> <http://dbpedia.org/resource/National_Basketball_Association>.
?a <http://dbpedia.org/ontology/birthDate> ?date.
filter(?date<"1970-01-01"^^xsd:date )
optional {
?a <http://dbpedia.org/ontology/college> ?college
}
}