只提取邮政编码和lsoa代码 - sparkql

时间:2016-03-07 16:07:13

标签: r sparql rdf semantic-web

我正在尝试编写一些sparkql来提取邮政编码数据和行进lsoa代码。 我到目前为止提取的所有邮政编码和lsoa代码的网址,当我想要最后一个单位时。我如何才能获得最后的元素?

query <- "PREFIX pc: <http://data.ordnancesurvey.co.uk/ontology/postcode/>
      PREFIX geo: <http://opendatacommunities.org/def/geography#>
      SELECT * WHERE { 
      ?postcodeUnit
      a pc:PostcodeUnit;
      geo:lsoa ?lsoa .
      }
      limit 10"

   endpoint <- "http://opendatacommunities.org/sparql"
   resultList <- SPARQL(endpoint,query)
   head(resultList)

当我开始工作时,我也很担心,R studio会超时,我是否需要从Web服务器运行它?请

提前致谢

1 个答案:

答案 0 :(得分:1)

如果生成URI的方式是标准的,您可以将结果转换为字符串,然后只采用所需的部分:

PREFIX pc: <http://data.ordnancesurvey.co.uk/ontology/postcode/>
PREFIX geo: <http://opendatacommunities.org/def/geography#>
SELECT ?postcode ?lsoa
WHERE { 
  ?URI_postcodeUnit
  a pc:PostcodeUnit;
  geo:lsoa ?URI_lsoa .
BIND (STRAFTER((STR(?URI_postcodeUnit)),"postcodeunit/") as ?postcode)
BIND (STRAFTER((STR(?URI_lsoa)),"lsoa/") as ?lsoa)
  }
  limit 10