3 ms·
Here-in lies the problem for me: select * { wd:Q9682 (wdt:P25|wdt:P22)* ?p . ?p wdt:P25|wdt:P22 ?q } - I am extremely motivated to learn how to use this:
by simonw 5y ago
Here-in lies the problem for me:
select * { wd:Q9682 (wdt:P25|wdt:P22)* ?p . ?p wdt:P25|wdt:P22 ?q } -
I am extremely motivated to learn how to use this: I have a deep desire to extract data from Wikipedia, and I'm fascinated by graph databases.
And yet, despite trying on several previous occasions, SPARQL has completely failed to stick in my brain.
This is partly my own failing: I'm confident that if I really dedicated myself to it I could get over this hump.
But it's also a sign that the learning curve here really is tremendously steep, which I think indicates a problem with the design of the technology.
- mmarx 5y agoA few days ago, the Wikidata Query Builder[0] was deployed. It provides a visual interface to generate simple SPARQL queries, and you can show the generated queries. Maybe this can help you in understanding how SPARQL patterns work? [0] https://query.wikidata.org/querybuilder/ https://query.wikidata.org/querybuilder/
- simonw 5y agoThat does look like a big step forward. It could really benefit from some linked examples on that page though - I stared at the interface for quite a while, unable to figure out how to use it for anything - then I dug around for an example link and it started to make sense to me. https://query.wikidata.org/querybuilder/?query=%7B%22conditions%22%3A%5B%7B%22propertyId%22%3A%22P1435%22%2C%22propertyDataType%22%3A%22wikibase-item%22%2C%22propertyValueRelation%22%3A%22matching%22%2C%22referenceRelation%22%3A%22regardless%22%2C%22value%22%3A%22Q10729054%22%2C%22subclasses%22%3Afalse%2C%22conditionRelation%22%3Anull%2C%22negate%22%3Afalse%7D%2C%7B%22propertyId%22%3A%22P131%22%2C%22propertyDataType%22%3A%22wikibase-item%22%2C%22propertyValueRelation%22%3A%22regardless-of-value%22%2C%22referenceRelation%22%3A%22regardless%22%2C%22value%22%3A%22%22%2C%22subclasses%22%3Atrue%2C%22conditionRelation%22%3A%22and%22%2C%22negate%22%3Afalse%7D%5D%2C%22limit%22%3A100%2C%22useLimit%22%3Atrue%2C%22omitLabels%22%3Afalse%7D https://query.wikidata.org/querybuilder/?query=%7B%22conditi...
- dmitriid 5y agoOr use something like https://github.com/zverok/wikipedia_ql https://github.com/zverok/wikipedia_ql that uses Mediawiki API
- bawolff 5y agoI find it helps to translate the syntax into english: > select * Show all variables starting with ? > wd:Q9682 Find item Q9682 (Queen Elizabeth 2) > (wdt:P25|wdt:P22)* Follow edges that are either P22 (father) or P25 (mother) zero-or more times Everytime you follow one of those edges, add the new item to ?p. Keep following these edges until you can't anymore. > ?p wdt:P25|wdt:P22 ?q For every ?p follow a mother/father edge precisely once, call the item it points to ?q (if there is no such edge we get rid of the p) The end result, is we have a list of rows containing pairs of (an ancestor of elizabeth, one of that ancestor's direct parents). ---- I feel like one of the reasons that sparql is confusing is because people use their intuitions from SQL which is wrong - since the underlying data model is different but the syntax looks vaugely sql-like which leads to misunderstandings.
- freeone3000 5y agoWhere do you end up with the translations from wdt:P25 to "mother"? That's the most incomprehensible part. It feels like I need a reverse dictionary lookup to write a single query.
- tasogare 5y agoYep. Not only this but in the sample "wd:Q9682" is a lie. wd is a namespace shortcut which is expended to an URI, and the prefix to URI mapping has to be defined as part of the query, otherwise it won't work. Notice how the sample use two of those prefixes (wd and wdt): data is segregated in different namespace that one have to search for and remember each time they want to make a query. And I mean remembering the prefix value, ie a partial URI, not the little cute prefix like wd that semweb sample always use.
- bawolff 5y agoThe sparql endpoint that is typically used with wikidata has some namespaces implicitly predefined, including wdt and wd. You do not need to declare the wd: prefix if you are using the endpoint at https://query.wikidata.org https://query.wikidata.org I think its safe to assume in context that the newbie sparql user is not setting up their own sparql endpoint but using the official wikidata endpoint.