在SPARQL中搜索列表中的多个查询

时间:2016-04-22 14:35:15

标签: sparql linked-data

我想使用英国土地注册数据库查找一组300个地址的销售数据。数据库允许SPARQL查询,但我是SPARQL的新手,并且不知道如何一次进行多个查询(例如,在一个SPARQL查询中搜索300个地址)。

This is an example land registry query表示单个地址。

所以我有两个问题:

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

2)有没有办法连接数据库地址列表以自动化查询?

非常感谢帮助和指导。

1 个答案:

答案 0 :(得分:1)

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

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

第二个问题不清楚,或许可以通过以上解决?即您不需要提交多个查询。

如果要查询特定的地址列表,可以使用SPARQL VALUES表达式,请参阅VALUES: Providing inline 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代替原始查询中的地址。