查询英文的城市/州/国家摘要 [英] Query city/state/country abstracts in English
问题描述
我正在尝试从DBpedia用英语查询城市,州和国家/地区的摘要,但结果混合。
I am trying to query city, state and country abstracts in English from DBpedia with mixed results. It seems to work well with City and Country but not with State.
SELECT * WHERE {
?x rdfs:label "France"@en.
?x dbpedia-owl:abstract ?abstract.
FILTER (LANG(?abstract) = 'en')
}
或
SELECT * WHERE {
?x rdfs:label "Boston"@en.
?x dbpedia-owl:abstract ?abstract.
FILTER (LANG(?abstract) = 'en')
}
但是,这些查询找不到任何结果:
However, these queries don't find any results:
SELECT * WHERE {
?x rdfs:label "Sao Paulo"@en.
?x dbpedia-owl:abstract ?abstract.
FILTER (LANG(?abstract) = 'en')
}
SELECT * WHERE {
?x rdfs:label "Massachusetts"@en.
?x dbpedia-owl:abstract ?abstract.
FILTER (LANG(?abstract) = 'en')
}
首先,如何将搜索过滤到仅城市,州或国家/地区?其次,如何找到法国的马萨诸塞州或罗纳州?
First, how can I filter the search to only Cities, States or Countries? Second, how can I find states such as Massachusetts or Rhone in France?
推荐答案
SPARQL查询(不包括可选
)仅返回可以匹配所有三重模式的结果。对于不返回结果的查询,这意味着以下有关资源?x的一个或多个语句不可用:
SPARQL queries (without OPTIONAL
) only return results for which all triple patterns can be matched. For your queries that do not return results, this means one or more of the following statements about a resource ?x are not available:
- 有是
rdfs:label
圣保罗 - 标签圣保罗是带有语言标签的英语
- 有一个
rdfs:abstract
- 摘要是带有语言标签的英语
- there is a
rdfs:label
"Sao Paulo" - the label "Sao Paulo" is language-tagged English
- there is an
rdfs:abstract
- the abstract is language-tagged English
在此示例中,您可能想找到< http://dbpedia.org/resource/Sao_Paulo>
。此资源的标签不是圣保罗,而是圣保罗。
In this example, you probably wanted to find <http://dbpedia.org/resource/Sao_Paulo>
. The label for this resource is not "Sao Paulo", but "São Paulo".
第二个查询对我来说很有效(马萨诸塞州),但花了一些时间才能完成。
The second query worked (Massachusetts) for me, but took some time to complete.
要将结果限制为某种类型的资源(如城市,州或国家/地区),您需要指定类型。在RDF中,使用 rdf:type
指定资源的类型(或类)。您可以通过相同的方式查询该问题:
To restrict your results to resources of a certain type (like City, State or Country), you need to specify the type. In RDF, a type (or rather 'class') of a resource is specified using rdf:type
. You can query that in the same way:
SELECT * WHERE {
?x rdfs:label "São Paulo"@en.
?x rdf:type dbpedia-owl:Settlement.
?x dbpedia-owl:abstract ?abstract.
FILTER (LANGMATCHES(LANG(?abstract), 'en'))
}
您可以使用速记 a
代替 rdf:type
,您可以将其理解为?x 是?y。
另外, LANGMATCHES(LANG(?abstract),'en')
可能更有效评估比 LANG(?abstract)='en')
。
Instead of rdf:type
you can use the shorthand a
, which you can read as "?x is a ?y".
Also, LANGMATCHES(LANG(?abstract), 'en')
may be more efficient to evaluate than LANG(?abstract) = 'en')
.
请注意,此资源 dbpedia:São_Paulo
不是DBpedia中的 dbpedia-owl:City
,因为它是Wikipedia上的自治市: http://en.wikipedia.org/wiki/S%C3%A3o_Paulo 。同样, dbpedia:Massachusetts
也未定义为州。两者都是 dbpedia-owl:PopulatedPlace s。
Note that this resource dbpedia:São_Paulo
is not a dbpedia-owl:City
in DBpedia, because it is a municipality on Wikipedia: http://en.wikipedia.org/wiki/S%C3%A3o_Paulo. Similarly, dbpedia:Massachusetts
is not defined as a state. Both are dbpedia-owl:PopulatedPlaces, though.
这篇关于查询英文的城市/州/国家摘要的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!