从SPARQL中的列表中搜索多个查询 [英] Search Multiple Queries from List in SPARQL

查看:295
本文介绍了从SPARQL中的列表中搜索多个查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用UK Land Registry数据库查找一组300个地址的销售数据.该数据库允许进行SPARQL查询,但是我对SPARQL完全陌生,并且不知道如何一次进行多个查询(例如,在一个SPARQL查询中搜索300个地址).

I want to find sales data for a set of 300 addresses using the UK Land Registry database. The database permits SPARQL queries, however I am completely new to SPARQL, and do not know how to make multiple queries at once (e.g. search for 300 addresses in one SPARQL query).

所以我有两个问题:

1)如何在一个查询中搜索多个地址?

1) How can I search for multiple addresses in one query?

2)有没有一种方法可以连接数据库地址列表以自动执行查询?

2) Is there a way to connect a database list of addresses to automate the query?

我们将非常感谢您的帮助和指导.

Help and direction will be hugely appreciated.

推荐答案

在示例查询中,WHERE子句中的前五个三元模式将结果与特定结果相关联.删除这些地址或用#注释掉,您将获得所选SPARQL端点已知的所有地址的列表:

In the example query, the first five triple patterns in the WHERE clause ties the result to a specific result. Delete these or comment out with a # and you will get a list of all addresses known to the chosen SPARQL endpoint:

prefix ...

SELECT  ?item ?ppd_propertyAddress ?ppd_hasTransaction ?ppd_pricePaid ? ppd_transactionCategory ?ppd_transactionDate ?ppd_transactionId ?ppd_estateType    ?ppd_newBuild ?ppd_propertyAddressCounty ?ppd_propertyAddressDistrict ?ppd_propertyAddressLocality ?ppd_propertyAddressPaon ?ppd_propertyAddressPostcode ?ppd_propertyAddressSaon ?ppd_propertyAddressStreet ?ppd_propertyAddressTown ?ppd_propertyType ?ppd_recordStatus
WHERE
{ #?ppd_propertyAddress text:query _:b0 .
  #_:b0 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> "paon: ( 12 )  AND street: ( PATTINSON AND DRIVE )" .
  #_:b0 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:b1 .
  #_:b1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> 3000000 .
  #_:b1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> .
  ?item ppd:propertyAddress ?ppd_propertyAddress .
  ?item ppd:hasTransaction ?ppd_hasTransaction .
  ?item ppd:pricePaid ?ppd_pricePaid .
  ?item ppd:transactionCategory ?ppd_transactionCategory .
  ?item ppd:transactionDate ?ppd_transactionDate .
  ?item ppd:transactionId ?ppd_transactionId
  OPTIONAL
  { ?item ppd:estateType ?ppd_estateType }
  OPTIONAL
  { ?item ppd:newBuild ?ppd_newBuild }
  OPTIONAL
  { ?ppd_propertyAddress lrcommon:county ?ppd_propertyAddressCounty }
  OPTIONAL
  { ?ppd_propertyAddress lrcommon:district ?ppd_propertyAddressDistrict }
  OPTIONAL
  { ?ppd_propertyAddress lrcommon:locality ?ppd_propertyAddressLocality }
  OPTIONAL
  { ?ppd_propertyAddress lrcommon:paon ?ppd_propertyAddressPaon }
  OPTIONAL
  { ?ppd_propertyAddress lrcommon:postcode ?ppd_propertyAddressPostcode }
  OPTIONAL
  { ?ppd_propertyAddress lrcommon:saon ?ppd_propertyAddressSaon }
  OPTIONAL
  { ?ppd_propertyAddress lrcommon:street ?ppd_propertyAddressStreet }
  OPTIONAL
  { ?ppd_propertyAddress lrcommon:town ?ppd_propertyAddressTown }
  OPTIONAL
  { ?item ppd:propertyType ?ppd_propertyType }
  OPTIONAL
  { ?item ppd:recordStatus ?ppd_recordStatus }
}
LIMIT   100

第二个问题尚不清楚,也许可以通过上述方法解决? IE.您不需要提交多个查询.

The second question is unclear and perhaps resolved by the above? I.e. you don't need to submit multiple queries.

如果要查询特定的地址列表,则可以使用SPARQL VALUES表达式,请参见

If you want to query for a specific list of addresses, then you could use a SPARQL VALUES expression, see VALUES: Providing inline data. A starting point may be the following (by inspection only - you'd have to check this against the data):

SELECT *
WHERE {
   VALUES ?addr {"address1" "paon: ( 12 )  AND street: ( PATTINSON AND DRIVE )" ...}
   ?ppd_propertyAddress text:query _:b0 .
   _:b0 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> ?addr .
   ?item ppd:propertyAddress ?ppd_propertyAddress .

   ...
}

请注意,VALUES?addr绑定到VALUES子句中大括号之间的列表中的每个字符串.然后在三元模式中使用?addr代替原始查询中的地址.

Note that VALUES binds ?addr to each string in the list between the braces in the VALUES clause. ?addr is then used in the triple pattern in place of the address in the original query.

这篇关于从SPARQL中的列表中搜索多个查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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