Duplicated results from Wikidata

元气小坏坏 提交于 2019-12-10 18:39:47

问题


I created the following SPARQL query to Wikidata. And the result of this query are records related to states in Germany. But as you can see, results are occurring four times in a row (you can test it here: https://query.wikidata.org/). I supposed that there is a problem with geo coordinates and languages but I can't resolve it anyway. What is wrong with this query and how can I fix it to receive a result without repetition?

PREFIX  p:    <http://www.wikidata.org/prop/>
PREFIX  schema: <http://schema.org/>
PREFIX  psv:  <http://www.wikidata.org/prop/statement/value/>
PREFIX  wdt:  <http://www.wikidata.org/prop/direct/>
PREFIX  wikibase: <http://wikiba.se/ontology#>
PREFIX  rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX  wd:   <http://www.wikidata.org/entity/>

SELECT DISTINCT  ?subject ?featureCode ?countryCode ?name ?latitude ?longitude ?description ?iso31662
WHERE
  { ?subject  wdt:P31     wd:Q1221156 ;
              rdfs:label  ?name ;
              wdt:P17     ?countryClass .
    ?countryClass
              wdt:P297    ?countryCode .
    ?subject wdt:P31/(wdt:P279)* ?adminArea .
    ?adminArea  wdt:P2452  "A.ADM1" ;
              wdt:P2452  ?featureCode .
    ?subject  wdt:P300   ?iso31662
    OPTIONAL
      { ?subject  schema:description  ?description
        FILTER ( lang(?description) = "en" )
        ?subject  p:P625                ?coordinate .
        ?coordinate  psv:P625           ?coordinateNode .
        ?coordinateNode
                  wikibase:geoLatitude  ?latitude ;
                  wikibase:geoLongitude  ?longitude
      }
    FILTER ( lang(?name) = "en" )
    FILTER EXISTS { ?subject  wdt:P300  ?iso31662 }
  }
ORDER BY lcase(?name)
OFFSET  0
LIMIT   200

回答1:


In short, "9.0411111111111"^^xsd:double and "9.0411111111111"^^xsd:decimal are distinct, though they might be equal in some sense.

Check this:

SELECT DISTINCT ?subject ?featureCode ?countryCode ?name ?description ?iso31662
    (datatype(?latitude) AS ?lat)
    (datatype(?longitude) AS ?long)  

and this:

SELECT DISTINCT ?subject ?featureCode ?countryCode ?name ?description ?iso31662
    (xsd:decimal(?latitude) AS ?lat)
    (xsd:decimal(?longitude) AS ?long)  


来源:https://stackoverflow.com/questions/49012872/duplicated-results-from-wikidata

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!