Hi, has anyone any experience of SPARQL and the potential of consuming queries within Ebase:?:
http://landregistry.data.gov.uk/app/qonsole#
Thanks
SPARQL
Moderators: Jon, Steve, Ian, Dave
-
- Ebase User
- Posts: 331
- Joined: Mon Mar 10, 2014 8:34 am
I got a reply direct from the Land Registry. It is actually farily straightforward once you have the select statement (which will be most of the issue). Ebase doesn't encode # as %23 so I did this via a text replace and have reported it via the portal.
I've since built an appropriate query in Ebase.
http://landregistry.data.gov.uk/landreg ... %20?amount
To do this you need to access the SPARQL endpoint using a HTTP get request, there are a number of ways you can achieve this,
You can access the data under both unix and windows platforms.
As an example within unix you can use wget to issue a query to the SPARQL end point.
wget http://landregistry.data.gov.uk/landreg ... ry="SELECT DISTINCT * {?s ?a ?c } LIMIT 1"
You need to ensure you are pointing to the land registry sparql endpoint which in this case is everything before the ?query.
i.e. http://landregistry.data.gov.uk/landregistry/query
Further information on the SPARQL protocol and how to access the data in the triple store via the API can be viewed here. It includes details of how to use HTTP GET and how to format the data retrieved.
http://www.w3.org/TR/sparql11-protocol/
Also attached is an example of HTTP get using ruby N.B. The SPARQL query is for illustrative purposes.
Code: Select all
require 'capybara'
require 'capybara/dsl'
require 'selenium-webdriver'
require 'thread'
require 'net/http'
require 'json'
driver = Selenium::WebDriver.for :firefox
class Sparqlresult
def initialize(json_data)
# Instance variables
@json_data = json_data
end
def display
@json_data["results"]["bindings"].each do |child|
puts "text = #{(child["ppd_pricePaid"]["value"])}"
end
end
def avgeDetached
i = 0
sum = 0
average= 0
@json_data["results"]["bindings"].each do |child|
if (child["ppd_propertyType"]["value"]) == "http://landregistry.data.gov.uk/def/common/detached"
sum = sum + (child["ppd_pricePaid"]["value"]).to_i
puts sum
i = i + 1
end
end
average = sum / i
return(average)
end
end
postcode = "DT*"
county1 = "DEVON"
# Define the query we want to run. We can add as many lines as we
# want to between the EOF markers
test_query = <<EOF
prefix rdf: <http>
prefix rdfs: <http>
prefix owl: <http>
prefix xsd: <http>
prefix sr: <http>
prefix lrhpi: <http>
prefix lrppi: <http>
prefix skos: <http>
prefix lrcommon: <http>
PREFIX text: <http>
PREFIX ppd: <http>
PREFIX lrcommon: <http>
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> "county: ( :county1 )" .
_:b0 <http> _:b1 .
_:b1 <http> 3000000 .
_:b1 <http> <http> .
?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 }
FILTER ( ?ppd_transactionDate >= "2015-01-01"^^xsd:date )
}
LIMIT 100
EOF
# Specify the host server
#sparql_endpoint = "http://landregistry.data.gov.uk/landregistry/query"
# HTTP encode the query
encoded_query = URI.encode_www_form( query: test_query )
# construct the URI object
uri = URI( sparql_endpoint )
uri.query = encoded_query
# show the URL we are about to call, for debugging only
puts uri.inspect
# now send the query
response = Net::HTTP.get_response(uri)
puts "Response code #{response.code}"
puts response.body
puts "here we go"
json = JSON.parse( response.body )
#s = json["results"]["bindings"][0]["s"]["value"]
#puts "s = #{s}"
data_hash = JSON.parse(response.body)
#data_hash["results"]["bindings"].each do |child|
# puts "text = #{(child["ppd_pricePaid"]["value"])}"
testObject = Sparqlresult.new(data_hash)
testObject.display
value = testObject.avgeDetached
puts value
#end
I've since built an appropriate query in Ebase.
http://landregistry.data.gov.uk/landreg ... %20?amount
0 x
Who is online
Users browsing this forum: No registered users and 18 guests