Search code examples
sparqldbpedia

Get data about attractions and point of interest from DBpedia using SPARQL


I don't know how to use DBpedia or SPARQL.

Could you please help me in finding data list of attractions and point of interest from DBpedia.

Actually I want Hotels and Tourist Places from all Cities/Country with Latitude, Longitude, attraction Name, Location Name, City, State, continents, etc.

Please Help me to get data using Query of SPARQL.

If you have any other suggestion then please guide me..


Solution

  • This is the endpoint: http://dbpedia.org/sparql/

    To get all the hotels in Syria:

    select * where {
    ?hotel a <http://dbpedia.org/ontology/Hotel> .
    ?hotel dbo:location dbr:Syria
    }
    

    This answer is just to give you an idea how to query DBPedia

    Update

    After you comment Suppose I want to get all Tourist Places or point-of-interest for Mumbai City only

    You should define what those "Tourist Places* are? In the below query, I gave you an example, assuming the tourist places are museums, towers, parks, churches, Skyscrapers,

    select ?thing ?type ?typeName where {
    
    VALUES ?city {<http://dbpedia.org/resource/London>}
    
    ?thing dbo:location ?city.
    
    optional 
    {
    ?thing a ?type .
    VALUES ?type {<http://dbpedia.org/ontology/Hotel>}
    BIND( "Hotel" as ?typeName )
    }
    
    optional
    {
    ?thing a ?type.
    VALUES ?type {dbo:Museum}
    BIND( "Museum" as ?typeName )
    }
    optional
    {
    ?thing a ?type.
    VALUES ?type {dbo:Pyramid}
    BIND( "Pyramid" as ?typeName )
    }
    
    optional
    {
    ?thing a ?type.
    VALUES ?type {yago:Skyscraper104233124}
    BIND( "Skyscraper" as ?typeName )
    }
    
    optional
    {
    ?thing a ?type.
    VALUES ?type {dbo:Park}
    BIND( "Park" as ?typeName )
    }
    
    optional
    {
    ?thing a ?type.
    VALUES ?type {yago:Church103028079}
    BIND( "Church" as ?typeName )
    }
    
    {
    ?thing a dbo:Place
    }
    
    filter (BOUND (?type))
    
    }
    

    If you get the idea you can extend it

    Update 2

    You wanted to show long, lat and country. Here you go:

    select ?thing ?type ?typeName ?long ?lat ?country where {
    
    VALUES ?city {<http://dbpedia.org/resource/London>}
    
    optional {
    ?city dbo:country ?country
    }
    
    ?thing dbo:location ?city.
    
    optional 
    {
    ?thing a ?type .
    VALUES ?type {<http://dbpedia.org/ontology/Hotel>}
    BIND( "Hotel" as ?typeName )
    }
    
    optional
    {
    ?thing a ?type.
    VALUES ?type {dbo:Museum}
    BIND( "Museum" as ?typeName )
    }
    optional
    {
    ?thing a ?type.
    VALUES ?type {dbo:Pyramid}
    BIND( "Pyramid" as ?typeName )
    }
    
    optional
    {
    ?thing a ?type.
    VALUES ?type {yago:Skyscraper104233124}
    BIND( "Skyscraper" as ?typeName )
    }
    
    optional
    {
    ?thing a ?type.
    VALUES ?type {dbo:Park}
    BIND( "Park" as ?typeName )
    }
    
    optional
    {
    ?thing a ?type.
    VALUES ?type {yago:Church103028079}
    BIND( "Church" as ?typeName )
    }
    
    optional
    {
    ?thing geo:long ?long.
    ?thing geo:lat ?lat
    }
    
    
    {
    ?thing a dbo:Place
    }
    
    filter (BOUND (?type))
    
    }