我是RDF和SPARQL的新手,正在为正确的语法而苦苦挣扎。当我在网络上查找示例时,它看起来相当简单,但是当我尝试应用它并进行练习时,它根本不起作用。
当前,我必须制作一个包含三列的列表,其中包含欧盟国家,人口规模(从大到小排列)以及该国拥有的政府类型。
我尝试了许多PREFIX和几乎所有可以想象的文本(请参见下文),但是没有任何效果。
PREFIX dbc: <dbc:Member_states_of_the_European_Union>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX schema: <http://schema.org/Country>
SELECT ?populationsize
WHERE
{
?populationsize dbo:populationTotal ?number
}
答案 0 :(得分:1)
就我个人而言,这还不是很清楚,但这可行!
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX yago: <http://dbpedia.org/class/yago/>
PREFIX dbp: <http://dbpedia.org/property/>
PREFIX dct: <http://purl.org/dc/terms/>
SELECT DISTINCT *
WHERE
{ ?country dct:subject
<http://dbpedia.org/resource/Category:Member_states_of_the_European_Union> ;
dbo:populationTotal ?populationTotal;
dbo:governmentType ?governmentType
}
ORDER BY DESC(?populationTotal)
答案 1 :(得分:1)
请注意,your revised query未使用,因此您无需包括yago:
或dct:
前缀。我还为类别添加了另一个前缀。
PREFIX dbc: <http://dbpedia.org/resource/Category:>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dct: <http://purl.org/dc/terms/>
SELECT DISTINCT *
WHERE
{ ?country dct:subject dbc:Member_states_of_the_European_Union ;
dbo:populationTotal ?populationTotal ;
dbo:governmentType ?governmentType
}
ORDER BY DESC(?populationTotal)
这是相同的查询,根本没有PREFIX
-
SELECT DISTINCT *
WHERE
{ ?country http://purl.org/dc/terms/subject http://dbpedia.org/resource/Category:Member_states_of_the_European_Union ;
http://dbpedia.org/ontology/populationTotal ?populationTotal ;
http://dbpedia.org/ontology/governmentType ?governmentType
}
ORDER BY DESC(?populationTotal)
所需标签只是当前正在检索的URI的属性。标签以多种语言存在,因此我在此处添加了FILTER
,以仅获取标记为英语的标签。
PREFIX dbc: <http://dbpedia.org/resource/Category:>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dct: <http://purl.org/dc/terms/>
SELECT DISTINCT *
WHERE
{ ?country dct:subject dbc:Member_states_of_the_European_Union ;
dbo:populationTotal ?populationTotal ;
dbo:governmentType ?governmentType .
OPTIONAL { ?country rdfs:label ?countryLabel .
FILTER ( lang(?countryLabel)="en" ) }
OPTIONAL { ?governmentType rdfs:label ?governmentTypeLabel .
FILTER ( lang(?governmentTypeLabel)="en" ) }
}
ORDER BY DESC(?populationTotal)
我知道您既不希望使用文字类型也不希望使用langtags,所以这里还有一个调整使所有输出变得简单-
PREFIX dbc: <http://dbpedia.org/resource/Category:>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dct: <http://purl.org/dc/terms/>
SELECT DISTINCT ( STR(?populationTotal) AS ?Population )
( STR(?countryLabel) AS ?Country )
( STR(?governmentTypeLabel) AS ?Government )
WHERE
{ ?country dct:subject dbc:Member_states_of_the_European_Union ;
dbo:populationTotal ?populationTotal ;
dbo:governmentType ?governmentType .
OPTIONAL { ?country rdfs:label ?countryLabel .
FILTER ( LANG(?countryLabel) = "en" ) }
OPTIONAL { ?governmentType rdfs:label ?governmentTypeLabel .
FILTER ( LANG(?governmentTypeLabel) = "en" ) }
}
ORDER BY DESC(?populationTotal)