Page MenuHomePhabricator

Wikidata Query Service sometimes removes trailing slashes from Geonames URIs
Open, Needs TriagePublic

Description

Ethan Gruber reported on Twitter that this query incorrectly returns a Geonames URI without a trailing slash:

CONSTRUCT {
  ?place a skos:Concept; 
  		   skos:prefLabel ?placeLabel;
           skos:exactMatch ?osgeo;
           skos:exactMatch ?tgn;
           skos:exactMatch ?geonames ;
           skos:exactMatch ?pleiades ;
           dct:coverage ?coord .
}
WHERE {
  ?place wdt:P1667 "7015539" .
  OPTIONAL {?place wdt:P3120 ?osgeoid .
  	BIND (uri(concat("http://data.ordnancesurvey.co.uk/id/", ?osgeoid)) as ?osgeo)
  }
  OPTIONAL {?place wdt:P1667 ?tgnid .
  	BIND (uri(concat("http://vocab.getty.edu/tgn/", ?tgnid)) as ?tgn)}
  OPTIONAL {?place wdt:P1566 ?geonamesid .
  	BIND (uri(concat("http://sws.geonames.org/", ?geonamesid, "/")) as ?geonames)}
  OPTIONAL {?place wdt:P1584 ?pleiadesid .
  	BIND (uri(concat("https://pleiades.stoa.org/places/", ?pleiadesid)) as ?pleiades)}
  OPTIONAL {?place p:P625/ps:P625 ?coord}
  SERVICE wikibase:label {
	bd:serviceParam wikibase:language "en"
  }
}

Note that he explicitly concatenates a "/" to it, yet it’s still not in the result:

subjectpredicateobject
wd:Q931172rdf:typeskos:Concept
wd:Q931172skos:prefLabelVulci
wd:Q931172skos:exactMatchhttp://vocab.getty.edu/tgn/7015539
wd:Q931172skos:exactMatchhttp://sws.geonames.org/3163940
wd:Q931172skos:exactMatchhttps://pleiades.stoa.org/places/413393
wd:Q931172http://purl.org/dc/terms/coveragePoint(11.631666666 42.418888888)

I managed to reduce it to this shorter query:

SELECT ?g {
  BIND(<http://sws.geonames.org/1/> AS ?g)
  OPTIONAL { BIND("" AS ?_) }
}

If the BIND is removed, or made non-optional, the bug doesn’t occur. It also doesn’t happen if you change anything in the domain part of the URI.

I assume this is related to the TrailingSlashRemovingInlineUriHandler that we register for Geonames URIs, though I’m not sure why it only seems to remove the slash in combination with an optional bind.

Event Timeline

Restricted Application added a project: Wikidata. · View Herald TranscriptOct 23 2019, 12:30 PM
Restricted Application added a subscriber: Aklapper. · View Herald Transcript

VIAF IDs are also affected:

SELECT ?g {
  BIND(<http://viaf.org/viaf/1/> AS ?g)
  OPTIONAL { BIND("" AS ?_) }
}

VIAF and Geonames seem to be the only cases where we use this TrailingSlashRemovingInlineUriHandler, though.

And note Ethan's assertion: The scheme for Geonames URIs requires a trailing forward slash.