2014-10-23 2 views
0

Следующий запрос будет искать совпадающие предметы на основе списка свойств и на заданном расстоянии. Они ранжируются по количеству подходящих свойств (? NumProperties), который выводится как число. Как я могу также напечатать каждое из свойств, которые соответствуют?Печать подходящих свойств в запросе DBpedia

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 

ответ

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

+1

Очень красиво, и очень быстро! Благодаря! :) –