在DBpedia查询中打印匹配属性

时间:2014-10-23 19:12:08

标签: properties rdf sparql matching dbpedia

以下查询将根据属性列表并在给定距离内搜索匹配的主题。它们按匹配属性的数量(?numProperties)排序,它作为数字输出。如何打印每个匹配的属性?

Run query

select ?subject (count ( distinct ?property) as ?numProperties) ?label ?lat ?long where {
values ?property { dbpedia-owl:crosses dbpedia-owl:vehicle dbpedia-owl:reopened dbpedia-owl:years dbpedia-owl:access dbpedia-owl:third dbpedia-owl:time dbpedia-owl:construction dbpedia-owl:anniversary dbpedia-owl:series dbpedia-owl:length dbpprop:suspension dbpprop:bridge dbpprop:crosses dbpprop:City dbpprop:connecting dbpprop:last dbpprop:three dbpprop:suspension dbpprop:bridges dbpprop:built } 
?subject ?property ?object .
?subject rdfs:label ?label .
?subject geo:lat ?lat .
?subject geo:long ?long .
FILTER (?long > -74.490898 && ?long <  -73.490898 && ?lat >  40.207222  && ?lat <  41.207222  ) .
FILTER(langMatches(lang(?label),"EN")) .
} 
group by ?subject ?label ?lat ?long
order by desc(?numProperties) 
limit 15

1 个答案:

答案 0 :(得分:2)

#-- I took the liberty of tidying up your query a bit.
#-- The key is to use the GROUP_CONCAT aggregate function.
select
  ?subject
  (count(distinct ?property) as ?numProperties)
  ?label
  ?lat
  ?long
  #-- concatenate distinct properties into a ', ' separated string
  (group_concat(distinct ?property;separator=', ') as ?properties)
where {
  values ?property {
    dbpedia-owl:crosses dbpedia-owl:vehicle dbpedia-owl:reopened
    dbpedia-owl:years dbpedia-owl:access dbpedia-owl:third
    dbpedia-owl:time dbpedia-owl:construction dbpedia-owl:anniversary
    dbpedia-owl:series dbpedia-owl:length dbpprop:suspension
    dbpprop:bridge dbpprop:crosses dbpprop:City dbpprop:connecting
    dbpprop:last dbpprop:three dbpprop:suspension
    dbpprop:bridges dbpprop:built
  } 
  ?subject ?property ?object ;
           rdfs:label ?label ;
           geo:lat ?lat ;geo:long ?long .
  FILTER ( -74.490898 < ?long && ?long < -73.490898 &&
            40.207222 < ?lat  && ?lat  <  41.207222 )
  FILTER(langMatches(lang(?label),"EN"))
} 
group by ?subject ?label ?lat ?long
order by desc(?numProperties) 
limit 15

SPARQL results