Return the first lines of results
Subsetting
spq_offset()
and spq_head()
are only useful when used with
spq_arrange()
that makes the order of results predictable.
Examples
# Return the default of 5 items
spq_init() %>%
spq_add("?item wdt:P31 wd:Q5") %>%
spq_label(item) %>%
spq_add("?item wdt:P19/wdt:P131* wd:Q60") %>%
spq_add("?item wikibase:sitelinks ?linkcount") %>%
spq_arrange(desc(linkcount)) %>%
spq_head()
#> PREFIX wd: <http://www.wikidata.org/entity/>
#> PREFIX wdt: <http://www.wikidata.org/prop/direct/>
#> PREFIX wikibase: <http://wikiba.se/ontology#>
#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
#> SELECT ?item (COALESCE(?item_labell,'') AS ?item_label) ?linkcount
#> WHERE {
#>
#> ?item wdt:P31 wd:Q5.
#> OPTIONAL {
#> ?item rdfs:label ?item_labell.
#> FILTER(lang(?item_labell) IN ('en'))
#> }
#>
#> ?item wdt:P19/wdt:P131* wd:Q60.
#> ?item wikibase:sitelinks ?linkcount.
#>
#> }
#> ORDER BY DESC(?linkcount)
#> LIMIT 5
# Return 42 items
spq_init() %>%
spq_add("?item wdt:P31 wd:Q5") %>%
spq_label(item) %>%
spq_add("?item wdt:P19/wdt:P131* wd:Q60") %>%
spq_add("?item wikibase:sitelinks ?linkcount") %>%
spq_arrange(desc(linkcount)) %>%
spq_head(42)
#> PREFIX wd: <http://www.wikidata.org/entity/>
#> PREFIX wdt: <http://www.wikidata.org/prop/direct/>
#> PREFIX wikibase: <http://wikiba.se/ontology#>
#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
#> SELECT ?item (COALESCE(?item_labell,'') AS ?item_label) ?linkcount
#> WHERE {
#>
#> ?item wdt:P31 wd:Q5.
#> OPTIONAL {
#> ?item rdfs:label ?item_labell.
#> FILTER(lang(?item_labell) IN ('en'))
#> }
#>
#> ?item wdt:P19/wdt:P131* wd:Q60.
#> ?item wikibase:sitelinks ?linkcount.
#>
#> }
#> ORDER BY DESC(?linkcount)
#> LIMIT 42