基于邮政编码第一部分的HM土地注册网站SPARQL查询

基于邮政编码第一部分的HM土地注册网站SPARQL查询,sparql,Sparql,我正试图通过HM土地注册处开放数据SPARQL查询找出一个邮编区域的平均房价数据,如果是针对一个邮编区域,例如GL52,那么最好的方法是什么 此处给出的“邮政编码中的交易”示例代码显示了如何搜索完整的邮政编码,我已尝试使用值上的STRSTARTS更改代码?邮政编码部分,但返回时出错 prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> prefix rdfs: <http://www.w3.org/2000/01/r

我正试图通过HM土地注册处开放数据SPARQL查询找出一个邮编区域的平均房价数据,如果是针对一个邮编区域,例如GL52,那么最好的方法是什么

此处给出的“邮政编码中的交易”示例代码显示了如何搜索完整的邮政编码,我已尝试使用值上的STRSTARTS更改代码?邮政编码部分,但返回时出错

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 ukhpi: <http://landregistry.data.gov.uk/def/ukhpi/>
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 using SPARQL 1.1's 'values' clause

SELECT ?paon ?saon ?street ?town ?county ?postcode ?amount ?date ?category
WHERE
{
  VALUES ?postcode STRSTARTS({"GL52"^^xsd:string}, {"GL52"^^xsd:string})

  ?addr lrcommon:postcode ?postcode.

  ?transx lrppi:propertyAddress ?addr ;
          lrppi:pricePaid ?amount ;
          lrppi:transactionDate ?date ;
          lrppi:transactionCategory/skos:prefLabel ?category.

  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
错误返回为 在第18行第20列遇到STRSTARTS STRSTARTS。 他期望: {


如果您有任何建议,我们将不胜感激!

恐怕您的语法是错误的。对于这种类型的查询,您将需要一个筛选器,如:

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 ukhpi: <http://landregistry.data.gov.uk/def/ukhpi/>
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 using SPARQL 1.1's 'values' clause

    SELECT ?paon ?saon ?street ?town ?county ?postcode ?amount ?date ?category
    WHERE
    {
      ?addr lrcommon:postcode ?postcode .
    
      ?transx lrppi:propertyAddress ?addr ;
              lrppi:pricePaid ?amount ;
              lrppi:transactionDate ?date ;
              lrppi:transactionCategory/skos:prefLabel ?category.
      FILTER(STRSTARTS(?postcode,"GL52")) #Difference is here
    
      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
现在,此端点不是最快的端点,因此此查询很遗憾将超时。您可以通过指定county是什么来帮助提高查询性能,并且以下查询也将生成您要查找的内容,而不会超时:

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 ukhpi: <http://landregistry.data.gov.uk/def/ukhpi/>
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 using SPARQL 1.1's 'values' clause

SELECT ?paon ?saon ?street ?town ?county ?postcode ?amount ?date ?category
WHERE
{
  #VALUES ?pc {"GL52"}

  ?addr lrcommon:postcode ?postcode ;
        lrcommon:county "GLOUCESTERSHIRE" .

  ?transx lrppi:propertyAddress ?addr ;
          lrppi:pricePaid ?amount ;
          lrppi:transactionDate ?date ;
          lrppi:transactionCategory/skos:prefLabel ?category.
  FILTER(STRSTARTS(?postcode,"GL52"))

  #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
现在,如果您想同时查看多个邮政编码,可以尝试以下方法:

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 ukhpi: <http://landregistry.data.gov.uk/def/ukhpi/>
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 using SPARQL 1.1's 'values' clause

SELECT ?paon ?saon ?street ?town ?county ?postcode ?amount ?date ?category
WHERE
{
  VALUES ?pc {"GL52" "GL51" "GL1 "}

  ?addr lrcommon:postcode ?postcode ;
        lrcommon:county "GLOUCESTERSHIRE" .

  ?transx lrppi:propertyAddress ?addr ;
          lrppi:pricePaid ?amount ;
          lrppi:transactionDate ?date ;
          lrppi:transactionCategory/skos:prefLabel ?category.
  FILTER(STRSTARTS(?postcode,?pc))

  #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

这是做同样的事情,但本质上是一个缩写。

恐怕您的语法是错误的。对于这种类型的查询,您需要一个过滤器,如:

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 ukhpi: <http://landregistry.data.gov.uk/def/ukhpi/>
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 using SPARQL 1.1's 'values' clause

    SELECT ?paon ?saon ?street ?town ?county ?postcode ?amount ?date ?category
    WHERE
    {
      ?addr lrcommon:postcode ?postcode .
    
      ?transx lrppi:propertyAddress ?addr ;
              lrppi:pricePaid ?amount ;
              lrppi:transactionDate ?date ;
              lrppi:transactionCategory/skos:prefLabel ?category.
      FILTER(STRSTARTS(?postcode,"GL52")) #Difference is here
    
      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
现在,此端点不是最快的端点,因此此查询很遗憾将超时。您可以通过指定county是什么来帮助提高查询性能,并且以下查询也将生成您要查找的内容,而不会超时:

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 ukhpi: <http://landregistry.data.gov.uk/def/ukhpi/>
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 using SPARQL 1.1's 'values' clause

SELECT ?paon ?saon ?street ?town ?county ?postcode ?amount ?date ?category
WHERE
{
  #VALUES ?pc {"GL52"}

  ?addr lrcommon:postcode ?postcode ;
        lrcommon:county "GLOUCESTERSHIRE" .

  ?transx lrppi:propertyAddress ?addr ;
          lrppi:pricePaid ?amount ;
          lrppi:transactionDate ?date ;
          lrppi:transactionCategory/skos:prefLabel ?category.
  FILTER(STRSTARTS(?postcode,"GL52"))

  #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
现在,如果您想同时查看多个邮政编码,可以尝试以下方法:

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 ukhpi: <http://landregistry.data.gov.uk/def/ukhpi/>
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 using SPARQL 1.1's 'values' clause

SELECT ?paon ?saon ?street ?town ?county ?postcode ?amount ?date ?category
WHERE
{
  VALUES ?pc {"GL52" "GL51" "GL1 "}

  ?addr lrcommon:postcode ?postcode ;
        lrcommon:county "GLOUCESTERSHIRE" .

  ?transx lrppi:propertyAddress ?addr ;
          lrppi:pricePaid ?amount ;
          lrppi:transactionDate ?date ;
          lrppi:transactionCategory/skos:prefLabel ?category.
  FILTER(STRSTARTS(?postcode,?pc))

  #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

这是做同样的事情,但本质上是一个缩写。

这太棒了,谢谢你解释和给出一些很好的例子!它看起来像是返回了完整的历史,你认为过滤过去两年的最佳方式是什么?试着用它作为过滤器:FILTERSTRSTARTS?邮政编码,GL52&&YEAR?date>2018。也不要这样做如果你认为答案能回答你的问题,请忘记接受答案。谢谢,我使用你的上一个示例测试了它,你可以查找多个邮政编码,但返回了一个错误,我想我一定是遗漏了什么?-FiltersTrstStarts?postcode,?pc&&YEAR?date>2018适合我…有什么错误?嗨,我刚刚发现我也有一个ust before&&这太棒了,谢谢你解释并给出了一些很好的例子!它看起来像是返回了完整的历史,你认为过滤过去两年的最佳方式是什么?试着用它作为你的过滤器:FILTERSTRSTARTS?邮编,GL52&&YEAR?date>2018。如果你认为它符合你的要求,也别忘了接受答案估计。谢谢,我用上一个例子测试了它,你可以查找多个邮政编码,但返回了一个错误,我想我一定是遗漏了什么?-FILTERSTRSTARTS?postcode,?pc&&YEAR?date>2018适合我…什么错误?嗨,我刚刚发现我也有一个邮政编码!就在之前&&