How to retrieve the categorical details in wikidata

自古美人都是妖i 提交于 2019-12-11 04:24:22

问题


I have a list of instances as follows.

myinstances = ['word2vec', 'tf-idf', 'dijkstra's algorithm']

For each myinstance in the above list, I want to find:

 1. What are the other instances of `myinstance`'s category (i.e. only one hop)
 2. What are the instances of `myinstance`'s category's category (i.e. two hops)

For example, if we consider myinstance = word2vec

  1. What are the other instances of myinstance's category (i.e. only one hop)? As shown in the figure below the other instances of its immediade ancestor is GloVe.

  2. What are the instances of myinstance's category's category (i.e. two hops)? In other words, what are the instances of embedding (which is two hops away from word2vec) as shown the below figure.

I am just wondering if such query searches can be performed in sparql?

My current code is as follows.

SELECT * {
    VALUES ?searchTerm { "word2vec" "tf-idf" "dijkstra's algorithm" }
    SERVICE wikibase:mwapi {
        bd:serviceParam wikibase:api "EntitySearch".
        bd:serviceParam wikibase:endpoint "www.wikidata.org".
        bd:serviceParam wikibase:limit 1 .
        bd:serviceParam mwapi:search ?searchTerm.
        bd:serviceParam mwapi:language "en".
        ?item wikibase:apiOutputItem mwapi:item.
        ?num wikibase:apiOrdinal true.
    }
    ?item (wdt:P279|wdt:P31) ?type
}

I am happy to provide more details if needed.

来源:https://stackoverflow.com/questions/55920836/how-to-retrieve-the-categorical-details-in-wikidata

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