Search code examples
rdfsparqlwikipediadbpedia

How to query coordinates of companies from wikipedia using SPARQL?


Following is the query that I am executing at SPARQL Endpoint:

SELECT DISTINCT ?name  ?location  ?products WHERE{
    ?name  rdf:type   <http://dbpedia.org/class/yago/Company108058098>.
    ?name  dbpedia:locationCity ?location.
    ?name  dbpedia:product          ?products.
} LIMIT  20

This query is executing as per my requirements but now I also want to get the coordinates (latitude/longtiude) for each of these companies. How should I construct the query to get coordinates for each of these companies?


Solution

  • To find our if they have this property I've used this request:

    SELECT DISTINCT *
    WHERE{
        ?name  rdf:type   <http://dbpedia.org/class/yago/Company108058098>.
        ?name ?p ?o .
    } LIMIT 2000
    

    Then i was able to scroll down (on 2nd page) to check that they have lat and long property. I don't know prefix for them, so i've used full property name (decoded from url)

    Here's request:

    SELECT DISTINCT 
    ?name ?lat ?long
    WHERE{
        ?name  rdf:type   <http://dbpedia.org/class/yago/Company108058098>.
        ?name  <http://www.w3.org/2003/01/geo/wgs84_pos#lat> ?lat.
        ?name  <http://www.w3.org/2003/01/geo/wgs84_pos#long> ?long.
    } LIMIT 20
    

    If you want that one with products:

    SELECT DISTINCT 
    ?name ?lat ?long
    (GROUP_CONCAT(?product; separator = ",") as ?products)
    WHERE{
        ?name  rdf:type   <http://dbpedia.org/class/yago/Company108058098>.
        ?name  dbpedia:product      ?product.
        ?name  <http://www.w3.org/2003/01/geo/wgs84_pos#lat> ?lat.
        ?name  <http://www.w3.org/2003/01/geo/wgs84_pos#long> ?long.
    } GROUP BY ?name ?lat ?long LIMIT 20