What are values starting with “t” and how to ignore them for counting

喜你入骨 提交于 2019-12-06 15:09:39

Values starting with t are "skolemized" unknown values (see, e.g., Q2423351 for a person of unknown sex or gender).

In order to improve performance, I suggest you to divide your query into three parts:

  1. All "normal" genders:

    SELECT ?rid (COUNT(?qid) AS ?count) 
    WHERE {
       ?qid wdt:P31 wd:Q5.
       ?qid wdt:P21 ?rid.
       ?rid wdt:P31 wd:Q48264 
    } GROUP BY ?rid ORDER BY DESC(?count)
    

    Please note that, according Wikidata, wd:Q746411 is a subclass of wd:Q48270, etc.

  2. All "non-normal" genders:

    SELECT ?rid (COUNT(?qid) AS ?count) 
    WHERE {
       ?qid wdt:P31 wd:Q5.
       ?qid wdt:P21 ?rid.
       FILTER (?rid NOT IN
               (
                wd:Q6581097,
                wd:Q6581072,
                wd:Q1052281,
                wd:Q2449503,
                wd:Q48270,
                wd:Q746411,
                wd:Q189125,
                wd:Q1399232,
                wd:Q3277905
               )
              ).
       FILTER (isURI(?rid))
    } GROUP BY ?rid ORDER BY DESC(?count)
    

    I do not use FILTER NOT EXISTS {?rid wdt:P31 wd:Q48264 } due to performance reasons.

  3. All (i.e. 1) "unknown" genders:

    SELECT (COUNT(?qid) AS ?count) 
    WHERE {
       ?qid wdt:P31 wd:Q5.
       ?qid wdt:P21 ?rid.
       FILTER (!isURI(?rid))
    } 
    

In fact, it is not very important in your case — to count distinct wd:Q5 or count them not distinct — but the latter is preferable due to performance reasons.

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