Add a triple pattern statement to a query
Arguments
- .query
query
- .triple_pattern
the triple pattern statement (replaces arguments subject verb and object)
- .subject
an anonymous variable (for instance, and by default, "?subject") or item (for instance "wd:Q456"))
- .verb
the property (for instance "wdt:P190")
- .object
an anonymous variable (for instance, and by default, "?object") or item (for instance "wd:Q456"))
- .prefixes
Custom prefixes
- .required
whether the existence of a value for the triple is required or not (defaults to TRUE). If set to FALSE, then other triples in the query are returned even if this particular triple is missing)
- .label
See
spq_label().- .within_box
if provided, rectangular bounding box for the triple query. Provided as list(southwest=c(long=...,lat=...),northeast=c(long=...,lat=...))
- .within_distance
if provided, circular bounding box for the triple query. Provided as list(center=c(long=...,lat=...), radius=...), with radius in kilometers. The center can also be provided as a variable (for instance, "?location") for the center coordinates to be retrieved directly from the query.
- .filter
Filter for the triple. Only use this with
.required=FALSE- .sibling_triple_pattern
Triple this triple is to be grouped with, especially (only?) useful if the sibling triple is optional.
Details
The arguments .subject, .verb, .object are most useful for programmatic
usage, they are actually used within glitter code itself.
Examples
# find the cities
spq_init() %>%
spq_add("?city wdt:P31/wdt:P279* wd:Q486972") %>%
spq_label(city) %>%
spq_mutate(coords = wdt::P625(city),
.within_distance=list(center=c(long=4.84,lat=45.76),
radius=5)) %>%
spq_perform()
# find the individuals of the species
spq_init() %>%
spq_add("?mayor wdt:P31 ?species") %>%
# dog, cat or chicken
spq_set(species = c('wd:Q144','wd:Q146', 'wd:Q780')) %>%
# who occupy the function
spq_add("?mayor p:P39 ?node") %>%
# of mayor
spq_add("?node ps:P39 wd:Q30185") %>%
# of some places
spq_add("?node pq:P642 ?place") %>%
spq_perform()
