微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

仅获取英语财产价值

如何解决仅获取英语财产价值

我正在尝试列出包含英文简称的国家/地区:

# get a list countries with the corresponding ISO code
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wikibase: <http://wikiba.se/ontology#>
SELECT ?country ?countryLabel ?shortName (MAX(?pop) as ?population) ?coord ?isocode
WHERE 
{
  # instance of country
  ?country wdt:P31 wd:Q3624078.
  OPTIONAL {
     ?country rdfs:label ?countryLabel filter (lang(?countryLabel) = "en").
   }
  OPTIONAL {
    # https://www.wikidata.org/wiki/Property:P1813
    ?country wdt:P1813 ?shortName.
  }   
  OPTIONAL { 
    # get the population
     # https://www.wikidata.org/wiki/Property:P1082
     ?country wdt:P1082 ?pop. 
  }
  # get the iso countryCode
  { ?country wdt:P297 ?isocode }.
  # get the coordinate
  OPTIONAL { ?country wdt:P625 ?coord }.
} 
GROUP BY ?country ?countryLabel ?shortName ?population ?coord ?isocode 
ORDER BY ?countryLabel

try it!

不幸的是,还会返回标志和“ shortName”的非英语版本。我尝试使用子查询,但是超时。我想避免使用Wikibase标签服务,因为我需要在my local wikidata copy which uses Apache Jena

上运行查询

我如何获取国家/地区的英文缩写?例如。 People's republic of china的中国和United States of America的美国?

解决方法

这里有两个问题:

  1. 我们只需要过滤英文短名称,即我们需要在第二个filter (lang(?shortName) = "en")模式内使用OPTIONAL子句
  2. 出于某种原因,有些标志带有英语标记,因此我们必须以某种方式忽略它们-很好,这里有一个语句限定符可以帮助您:实例({ {3}})与Wikidata实体 emoji标志序列P31
  3. 的关系

因此,总的来说,我们取代

OPTIONAL {
    # https://www.wikidata.org/wiki/Property:P1813
    ?country wdt:P1813 ?shortName.
} 

作者

OPTIONAL {
  ?country p:P1813 ?shortNameStmt. # get the short name statement
  ?shortNameStmt ps:P1813 ?shortName # the the short name value from the statement
  filter (lang(?shortName) = "en") # filter for English short names only
  filter not exists {?shortNameStmt pq:P31 wd:Q28840786} # ignore flags (aka emojis)
}

不过,由于多个缩写,某些国家/地区会有多个条目。解决此问题的一种方法是使用一些汇总函数,例如samplemin/max并在每个国家/地区仅选择一个短名称。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?