如何从 SPARQL 查询访问土地注册处住宅类型 [英] How to access the Land Registry dwelling type from a SPARQL query

查看:36
本文介绍了如何从 SPARQL 查询访问土地注册处住宅类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 SPARQL 查询从英国土地注册处检索住宅类型.

I'm trying to retrieve the type of dwelling from the UK Land Registry using a SPARQL query.

API 显示它称为属性类型,并显示有四种类型:独立式、公寓式、半独立式、露台式.API 在这里:http://landregistry.data.gov.uk/def/common?_page=1.

The API shows it's called property-types and shows there are four types: Detached, Flat-maisonette, Semi-detached, Terraced. API is here: http://landregistry.data.gov.uk/def/common?_page=1.

查询是:

PREFIX xsd:     <http://www.w3.org/2001/XMLSchema#>
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 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/>

SELECT ?propertytype ?paon ?saon ?street ?town ?county ?locality ?district ?postcode ?    amount ?date
WHERE
{    
SERVICE <http://landregistry.data.gov.uk/landregistry/sparql>
{ 
    ?transx  lrppi:pricePaid ?amount .
    ?transx   lrppi:transactionDate ?date .
    ?transx   lrppi:propertyAddress ?addr.

    ?addr lrcommon:district "MALVERN HILLS"^^xsd:string .

    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 .}
    OPTIONAL {?addr lrcommon:locality ?locality .}
    OPTIONAL {?addr lrcommon:postcode  ?postcode .}
}
}
ORDER BY ?postcode ?amount
LIMIT 1000

这将检索我期望的数据(速度限制为 1000),但我想提取显示它是否已分离、梯田等的数据.

This retrieves the data I'm expecting (limited to 1000 for speed), but I'd like to pull out the data showing whether it's Detached, Terraced etc.

非常感谢任何帮助!

推荐答案

答案

你只需要添加三重

The answer

You just need to add the triple

?transx lrppi:propertyType ?propertytype .

您的查询.例如,这是一个基于您的查询:

to your query. For instance, here's a query based on yours:

PREFIX xsd:     <http://www.w3.org/2001/XMLSchema#>
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 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/>

SELECT ?propertytype ?paon ?saon ?street ?town ?county ?locality ?district ?postcode ?amount ?date
WHERE {
    ?transx lrppi:pricePaid ?amount ;
            lrppi:transactionDate ?date ;
            lrppi:propertyAddress ?addr ;
            lrppi:propertyType ?propertytype .

    ?addr lrcommon:district "MALVERN HILLS"^^xsd:string .

    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 .}
    OPTIONAL {?addr lrcommon:locality ?locality .}
    OPTIONAL {?addr lrcommon:postcode  ?postcode .}
}
ORDER BY ?postcode ?amount
LIMIT 10

您可以将其复制并粘贴到端点并获得结果.(不幸的是,似乎没有直接链接到结果的方法.)

You can copy and paste that into the endpoint and get the results. (Unfortunately, it doesn't appear that there's a way to link to the results directly.)

这是我如何找到该属性的.端点有一些示例查询,其中之一是列出正在使用的 RDF 类型":

Here's how I found that property. The endpoint has some sample queries, one of which is "list the RDF types in use":

PREFIX rdf:      <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs:     <http://www.w3.org/2000/01/rdf-schema#>

# Get labels for types used in the data.
SELECT  ?type ?name
WHERE {
    ?type rdfs:label ?name .
     FILTER EXISTS {  ?something rdf:type ?type . }
}

该查询的结果包括

---------------------------------------------------------------------------------------------------------------------------------------------
| type                                                                           | name                                                     |
=============================================================================================================================================
| <http://landregistry.data.gov.uk/def/common/PropertyTypeConcept>               | "Property type concept"@en                               |
---------------------------------------------------------------------------------------------------------------------------------------------

既然我们现在关于类型 我们可以要求它的实例:

Since we now now about the type <http://landregistry.data.gov.uk/def/common/PropertyTypeConcept> we can ask for instances of it:

PREFIX rdf:      <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs:     <http://www.w3.org/2000/01/rdf-schema#>

SELECT  ?x 
WHERE { ?x a <http://landregistry.data.gov.uk/def/common/PropertyTypeConcept> }
LIMIT 10 

----------------------------------------------------------------
| x                                                            |
================================================================
| <http://landregistry.data.gov.uk/def/common/detached>        |
| <http://landregistry.data.gov.uk/def/common/semi-detached>   |
| <http://landregistry.data.gov.uk/def/common/flat-maisonette> |
| <http://landregistry.data.gov.uk/def/common/terraced>        |
----------------------------------------------------------------

现在我们可以看到与其中之一相关的内容,以及哪些属性.例如

Now we can see what's related to one of those, and by what properties. For instance

PREFIX rdf:      <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs:     <http://www.w3.org/2000/01/rdf-schema#>

SELECT  ?x ?y
WHERE { ?x ?y <http://landregistry.data.gov.uk/def/common/detached> }
LIMIT 10 

----------------------------------------------------------------------------------------------------------------------------------------------------------------------
| x                                                                                                         | y                                                      |
======================================================================================================================================================================
| <http://landregistry.data.gov.uk/data/ppi/transaction/C7AE071D-242D-4825-9162-97BBF3B71840/2009-02-27233> | <http://landregistry.data.gov.uk/def/ppi/propertyType> |
| <http://landregistry.data.gov.uk/data/ppi/transaction/D0CDBC03-5147-4D93-BCE5-176AF007E391/2009-02-10191> | <http://landregistry.data.gov.uk/def/ppi/propertyType> |
| <http://landregistry.data.gov.uk/data/ppi/transaction/E37CAA33-CEF5-4162-8E07-918394B3C8AF/2009-02-00643> | <http://landregistry.data.gov.uk/def/ppi/propertyType> |
| <http://landregistry.data.gov.uk/data/ppi/transaction/E37CAA33-CEF5-4162-8E07-918394B3C8AF/2009-03-32825> | <http://landregistry.data.gov.uk/def/ppi/propertyType> |
| <http://landregistry.data.gov.uk/data/ppi/transaction/22276002-0030-4748-A7F6-C20F125DAC1C/2009-02-47264> | <http://landregistry.data.gov.uk/def/ppi/propertyType> |
| <http://landregistry.data.gov.uk/data/ppi/transaction/FA525F65-CC8E-4617-A682-F8B267319445/2009-02-38989> | <http://landregistry.data.gov.uk/def/ppi/propertyType> |
| <http://landregistry.data.gov.uk/data/ppi/transaction/3BFA438C-47AE-4B47-87AD-5DC365977619/2009-02-37729> | <http://landregistry.data.gov.uk/def/ppi/propertyType> |
| <http://landregistry.data.gov.uk/data/ppi/transaction/A5BED22B-F54B-4459-9BF9-18920B8CDBAA/2009-02-21721> | <http://landregistry.data.gov.uk/def/ppi/propertyType> |
| <http://landregistry.data.gov.uk/data/ppi/transaction/DDAAE7E0-B07F-49FF-AAB6-A2B96D8D4DE3/2009-02-11020> | <http://landregistry.data.gov.uk/def/ppi/propertyType> |
| <http://landregistry.data.gov.uk/data/ppi/transaction/5168D986-FAA2-42E8-B2C8-A04981C8BD0F/2009-02-09080> | <http://landregistry.data.gov.uk/def/ppi/propertyType> |
----------------------------------------------------------------------------------------------------------------------------------------------------------------------

然后我们看到我们想要的属性是,可以简写为lrppi:propertyType 使用您定义的前缀.它似乎将交易与属性类型相关联,并且由于您查询中的交易是 ?transx,我们添加

and we see that the property we want is <http://landregistry.data.gov.uk/def/ppi/propertyType>, which can be shortened to lrppi:propertyType using the prefixes that you have defined. It seems to relate transactions to property types, and since the transaction in your query was ?transx, we add

?transx lrppi:propertyType ?propertyType

这篇关于如何从 SPARQL 查询访问土地注册处住宅类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆