I am trying to get some data from land registry API (http://landregistry.data.gov.uk/app/hpi/qonsole) and it uses SPARQL query. I am new to sparql queries and not sure what to pass in my param.query object and how to pass prefixes required.
//myCode
var req = {
method: 'GET',
url: 'http://landregistry.data.gov.uk/landregistry/query',
headers: { 'Content-type' : 'application/x-www-form-urlencoded',
'Accept' : 'application/sparql-results+json' },
params: {
query :"select ?paon ?saon ?street ?town ?county ?postcode ?amount ?date where {?addr lrcommon:postcode "PL6 8RU"} limit 10",
format: "json"
}
};
console.log(req)
// SparQL Query
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix owl: <http://www.w3.org/2002/07/owl#>
prefix xsd: <http://www.w3.org/2001/XMLSchema#>
prefix sr: <http://data.ordnancesurvey.co.uk/ontology/spatialrelations/>
prefix lrhpi: <http://landregistry.data.gov.uk/def/hpi/>
prefix lrppi: <http://landregistry.data.gov.uk/def/ppi/>
prefix skos: <http://www.w3.org/2004/02/skos/core#>
prefix lrcommon: <http://landregistry.data.gov.uk/def/common/>
#-- Returns the Price Paid data from the default graph for each transaction record having
#-- an address with the given postcode.
#-- The postcode to query is set in the line - ?address_instance common:postcode "PL6 8RU"^^xsd:string .
SELECT ?paon ?saon ?street ?town ?county ?postcode ?amount ?date
WHERE
{
?transx lrppi:pricePaid ?amount ;
lrppi:transactionDate ?date ;
lrppi:propertyAddress ?addr.
?addr lrcommon:postcode "PL6 8RU"^^xsd:string.
?addr lrcommon:postcode ?postcode.
OPTIONAL {?addr lrcommon:county ?county}
OPTIONAL {?addr lrcommon:paon ?paon}
OPTIONAL {?addr lrcommon:saon ?saon}
OPTIONAL {?addr lrcommon:street ?street}
OPTIONAL {?addr lrcommon:town ?town}
}
ORDER BY ?amount