Compose query parts for triplets with subject verb object.

add_triplets(
  query = NA,
  subject,
  verb,
  object,
  optional = FALSE,
  label = NA,
  limit = NA,
  within_box = c(NA, NA),
  within_distance = c(NA, NA)
)

Arguments

subject

an anonymous variable (for instance, and by default, "?subject") or item (for instance "Q456"))

verb

the property (for instance "wdt:P190")

object

an anonymous variable (for instance, and by default, "?object") or item (for instance "Q456"))

optional

whether the triplet is optional (other results are sent back even if this particular triplet is missing)

label

a vector of variables for which to include a label column (defaults to NA)

limit

the max number of items sent back

within_box

if provided, rectangular bounding box for the triplet query. Provided as list(southwest=c(long=...,lat=...),northeast=c(long=...,lat=...))

within_distance

if provided, circular bounding box for the triplet 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.

Examples

add_triplets(subject="?city", verb="wdt:P31/wdt:P279*", object="wd:Q515", label=c("?city"), limit=10) %>% add_triplets(subject="?city", verb="wdt:P1082",object="?pop", optional=TRUE) %>% add_triplets(subject="?city", verb="wdt:P625",object="?coords", within_box=list(southwest=c(3,43), northeast=c(7,47))) %>% build_sparql() %>% send_sparql()
#> # A tibble: 10 x 4 #> city cityLabel pop coords #> <chr> <chr> <dbl> <chr> #> 1 http://www.wikidata.org/entity/… Avignon 91729 Point(4.808333333 43.94861… #> 2 http://www.wikidata.org/entity/… Nîmes 149633 Point(4.36 43.836944444) #> 3 http://www.wikidata.org/entity/… Nîmes 149633 Point(4.36 43.836944444) #> 4 http://www.wikidata.org/entity/… Nîmes 149633 Point(4.36 43.836944444) #> 5 http://www.wikidata.org/entity/… Nîmes 149633 Point(4.36 43.836944444) #> 6 http://www.wikidata.org/entity/… Nîmes 149633 Point(4.36 43.836944444) #> 7 http://www.wikidata.org/entity/… Nîmes 149633 Point(4.36 43.836944444) #> 8 http://www.wikidata.org/entity/… Nîmes 149633 Point(4.36 43.836944444) #> 9 http://www.wikidata.org/entity/… Nîmes 149633 Point(4.36 43.836944444) #> 10 http://www.wikidata.org/entity/… Nîmes 149633 Point(4.36 43.836944444)