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
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.What are the instances of
myinstance
's category's category (i.e. two hops)? In other words, what are the instances ofembedding
(which is two hops away fromword2vec
) 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.