DBpedia SPARQL查询美国大学 [英] DBpedia SPARQL Query US Universities

查看:205
本文介绍了DBpedia SPARQL查询美国大学的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个SPARQL查询,该查询正在 DBpedia SNORQL SPARQL端点上运行。该查询的目的是获取美国大学或学院的列表,包括其经度,纬度和天赋。该查询似乎正在工作,但似乎缺少一些记录和/或属性。因此,例如,即使存在其 DBpedia记录,并且该结果不存在,哈佛大学也不会显示在结果中属性应与我的查询匹配。我不确定为什么没有显示该记录。另一个示例是马萨诸塞州波士顿大学,它作为查询结果出现,但没有得到结果经度和纬度属性,即使记录包含这些属性也是如此。这是SPARQL查询:

I created a SPARQL query that I'm running on the DBpedia SNORQL SPARQL endpoint. The purpose of the query is to get a list of universities or colleges in the United States, including their longitude, latitude, and endowment. The query seems to be working but seems to be missing some records and/or attributes. So, for example, Harvard University doesn't show up in the result, even though its DBpedia record exists and the attributes should match my query. I'm not sure why that record doesn't show up. Another example is University of Massachusetts Boston, which comes up as a query result, but the result doesn't get the longitude and latitude attributes, even though the record contains those attributes. Here's the SPARQL Query:

PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX d: <http://dbpedia.org/ontology/>

SELECT ?uni ?link ?lat ?long ?endowment
WHERE {
?s foaf:homepage ?link ;
   rdf:type <http://schema.org/CollegeOrUniversity> ;
rdfs:label ?uni
OPTIONAL {?s geo:lat ?lat ;
             geo:long ?long . 
          ?s d:endowment ?endowment . }
FILTER (LANGMATCHES(LANG(?uni), 'en'))

{?s dbpedia2:country "U.S."@en . }
UNION
{?s dbpedia2:country "U.S." . }
UNION
{?s d:country :United_States . }

}
ORDER BY ?s


推荐答案

您发布的查询将仅选择具有 foaf:homepage 哈佛大学没有一个。 (也就是说,资源没有 foaf:homepage 属性。显然,大学确实有主页。)马萨诸塞州波士顿与可选模式不匹配-

The query you posted will only select entities with a foaf:homepage and Harvard University does not have one. (That is, the resource does not have a foaf:homepage property. Obviously the university does have a homepage.) UMass Boston doesn't match the optional pattern --

OPTIONAL {?s geo:lat ?lat ;
             geo:long ?long . 
          ?s d:endowment ?endowment . }

-因为该模式仅在?s 具有 geo:lat geo:long d:捐赠。尽管该模式是可选的,但整个模式必须匹配或不匹配。您不会得到部分匹配。

-- because that pattern only matches when ?s has a geo:lat, a geo:long, and a d:endowment. Though the pattern is optional, the whole pattern must either match or not; you do not get partial matches.

这是您的查询,经过重新整理后可以使用 DBPedia SPARQL端点当前支持的内置名称空间(该列表可能会随着时间的变化而变化),其中 OPTIONAL 部分已损坏必要时向下移动,然后移至末尾。 (将它们移到末尾只是出于美学考虑。)我尝试了各种限制,有趣的是,只有32所大学的 dbpprop:country US @en ,但有273个 dbpprop:country美国 @en 。总共有7620个结果。

Here's your query, reworked to use the built-in namespaces that the DBPedia SPARQL endpoint currently supports (that list is subject to change over time), with the OPTIONAL parts broken down as necessary, and moved to the end. (Moving them to the end is just an aesthetic consideration.) I tried some various constraints, and it is interesting to note that only 32 universities have the dbpprop:country "U.S."@en, but 273 have dbpprop:country "United States"@en. There are 7620 results in total.

PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>
PREFIX dbpedia: <http://dbpedia.org/resource/>
PREFIX dbpprop: <http://dbpedia.org/property/>

SELECT ?label ?homepage ?lat ?long ?endowment
WHERE {
  ?school a <http://schema.org/CollegeOrUniversity> 
  { ?school dbpedia-owl:country dbpedia:United_States }
  UNION
  { ?school dbpprop:country dbpedia:United_States }
  UNION 
  { ?school dbpprop:country "U.S."@en }
  UNION 
  { ?school dbpprop:country "United States"@en }

  OPTIONAL { ?school rdfs:label ?label .
             FILTER (LANGMATCHES(LANG(?label), 'en')) }
  OPTIONAL { ?school foaf:homepage ?homepage }
  OPTIONAL { ?school geo:lat ?lat ; geo:long ?long }
  OPTIONAL { ?school dbpedia-owl:endowment ?endowment }
}

SPARQL结果

这篇关于DBpedia SPARQL查询美国大学的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆