Search Multiple Queries from List in SPARQL

霸气de小男生 提交于 2019-12-08 19:01:27

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

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

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 .

   ...
}

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!