retrieving the countries details from geonames using a sparql query

270 Views Asked by At

I am trying to get specific countries informations from geonames using "Linked Data HTW Chur sparql endpoint" (url: http://linkeddata.fh-htwchur.ch/lodestar/sparql ):

PREFIX gn: <http://www.geonames.org/ontology#>
PREFIX wgs84_pos: <http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX dcterms: <http://purl.org/dc/terms/>

select distinct ?country ?population ?lattitude ?longitude ?creationDate ?modificationDate
from <http://sws.geonames.org>
where { ?country gn:name ?country_name;
        gn:population ?population;
        wgs84_pos:lat ?lattitude;
        wgs84_pos:long ?longitude;
        dcterms:created ?creationDate;
        dcterms:modified ?modificationDate
}

The query works if I remove "dcterms:created" and "dctermes:modified" but I need both to extract the data item creation date and the last modification date

If someone could please help me

1

There are 1 best solutions below

0
Stefan - brox IT-Solutions On

You have to distinguish between the concept and the document about this concept.

Example for the United States:

  • https://sws.geonames.org/6252001/ (concept, i.e., the actual country)
  • https://sws.geonames.org/6252001/about.rdf (GeoNames document about this concept)

These URIs refer to each other via rdfs:isDefinedBy/foaf:primaryTopic.

The dcterms:created property gives the date when the document was created, not when the country was created. The same applies to dcterms:modified.


If you don’t need to refer to the "document about the concept" in your results, you could use property paths to get the values:

PREFIX gn: <http://www.geonames.org/ontology#>
PREFIX wgs84_pos: <http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

SELECT DISTINCT ?country ?population ?lattitude ?longitude ?creationDate ?modificationDate
WHERE {

?country gn:name ?country_name ;
         gn:population ?population ;
         wgs84_pos:lat ?lattitude ;
         wgs84_pos:long ?longitude ;
         rdfs:isDefinedBy/dcterms:created ?creationDate ;
         rdfs:isDefinedBy/dcterms:modified ?modificationDate .
}

Otherwise you can use another variable for it:

PREFIX gn: <http://www.geonames.org/ontology#>
PREFIX wgs84_pos: <http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

SELECT DISTINCT ?country ?population ?lattitude ?longitude ?creationDate ?modificationDate 
WHERE {

?country gn:name ?country_name ;
         gn:population ?population ;
         wgs84_pos:lat ?lattitude ;
         wgs84_pos:long ?longitude ;
         rdfs:isDefinedBy ?countryDocument .

?countryDocument dcterms:created ?creationDate ;
                 dcterms:modified ?modificationDate .
}