代码之家  ›  专栏  ›  技术社区  ›  timguy

Wikidata SPARQL-国家及其(仍然存在的)邻国

  •  2
  • timguy  · 技术社区  · 6 年前

    this :

    SELECT ?country ?countryLabel WHERE { 
      ?country wdt:P47 wd:Q183 . 
      FILTER NOT EXISTS{ ?country wdt:P576 ?date } # don't count dissolved country - at least filters German Democratic Republic
      SERVICE wikibase:label {
            bd:serviceParam wikibase:language "en" .
        }
    }
    

    我的问题是,例如,在这个德国邻国的例子中,仍然有一些国家不再存在,比如:

    • 丹麦王国或
    • 萨尔地区。

    已经试过了

    我已经可以把这个数字减少 FILTER 声明。

    问题

    • (陆上和海上也可以分开)

    1 回复  |  直到 6 年前
        1
  •  2
  •   Stanislav Kralin kenwenzel    6 年前

    wd:Q133346 wd:Q12413618 (“国际边界”):

    SELECT ?border ?borderLabel ?country1Label ?country2Label ?isLandBorder ?isMaritimeBorder ?constraint {
      VALUES (?country1) {(wd:Q183)}
      ?border wdt:P31 wd:Q12413618 ;
              wdt:P17 ?country1 , ?country2 .
      FILTER (?country1 != ?country2)
      BIND (EXISTS {?border wdt:P31 wd:Q15104814} AS ?isLandBorder)
      BIND (EXISTS {?border wdt:P31 wd:Q3089219} AS ?isMaritimeBorder)
      BIND ((?isLandBorder || ?isMaritimeBorder) AS ?constraint)
      SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
      } ORDER BY ?country1Label
    

    Try it!

    从某种意义上说,记录是重复的:对于阿富汗-努兹别克斯坦边界,清单包含了这两个方面 (?country1=Afganistan,?country2=Uzbekistan) (?country1=Uzbekistan,?country2=Afganistan) .


    • 一个数据库或列表或准备好的哈希图与世界上所有有邻国的国家

    你可以继续问 https://opendata.stackexchange.com .