On 10/04/2017 04:58, Brill Lyle wrote:
It is very logical. You're right. I understand this now that I see it
built....
Ah, the key is the wdt:P276*/wdt:P131* wd:Q771.... That captures the Boston
and environs. This is great.
What does "BIND ('1' AS ?ma)" mean explicitly. I saw on the User Manual it
binds together location -- but I want to be able to customize this for the
various locales -- and be able to explain this to Heather so she can do it
herself as well....
Thanks so much! I really appreciate this help.
- Erika
So at the moment the query is looking for any of those columns to have a
value located in the state of Massachusetts (Q771). To change the
geographical requirement to anywhere else, simply change all the Q771
requirements to some other Q value.
The '?' in SPARQL is used to indicate what follows is a user-defined
variable -- the same way that '$' as in '$count' is used in some other
programming languages.
So '?ma' is simply a variable we are setting if one of the OPTIONAL{}
clauses has found a value in Massachusetts. It's our variable, so we
could change the name to whatever we like, eg '$local', '$in_state',
'$include', '$okay'... whatever, so long as the same change is made all
the way through.
BIND() is the SPARQL keyword to set the value of a variable -- so all
this line is doing is what in another programming language might be
LET $ma = 1
-- ie setting the value of our variable ?ma to 1 if we like what the
OPTIONAL{} clause has found.
Later the line
FILTER(bound(?ma))
is used to require that the variable ?ma has indeed been set to
something -- ie, in our case, that at least one of the OPTIONAL{}
clauses has found a value that means we want to include the line.
Here's one further version of the query:
http://tinyurl.com/l8eybae
which runs a little bit more quickly.
The difference is I have added a 'hint' to the geographic tests, so they
now read
?placeBirth wdt:P276*/wdt:P131* wd:Q771 .
hint:Prior hint:gearing "forward" .
The hint tells the query engine to check these conditions by starting at
the place of birth, and then going *forward* to find all the geographic
units that include that place of birth, and see if any of those include
the state of Massachusetts -- rather than starting at the state of
Massachusetts, then going backwards to find all the places that are
inside the state (a far bigger question), and seeing if any of those
places is the birth place.
Including these hints makes the query run about 4x more quickly.
Hope this helps,
All best regards,
James.
_______________________________________________
Wikidata mailing list
Wikidata@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/wikidata