Title: | Get Facts and Data from Wikipedia and Wikidata |
---|---|
Description: | Query Wikidata and get facts from current and historic Wikipedia main pages. |
Authors: | Keith McNulty [aut, cre] |
Maintainer: | Keith McNulty <[email protected]> |
License: | CC0 |
Version: | 0.4.2.9999 |
Built: | 2025-03-11 02:44:09 UTC |
Source: | https://github.com/keithmcnulty/wikifacts |
'wiki_define()' displays plaintext extract(s) of the given term(s) from ' the Wikipedia article(s).
wiki_define(term = NULL, sentences = 5L)
wiki_define(term = NULL, sentences = 5L)
term |
A non-empty character string or vector giving the name(s) of the term to be searched |
sentences |
An integer (or whole number) giving the number of sentences to return |
An extract from the Wikipedia article
wiki_define('R (programming language)') animals <- data.frame(name = c("dog", "cat")) animals$definition <- wiki_define(animals$name, sentences = 1) print(animals)
wiki_define('R (programming language)') animals <- data.frame(name = c("dog", "cat")) animals$definition <- wiki_define(animals$name, sentences = 1) print(animals)
‘wiki_didyouknow()' generates ’did you know' facts from the Wikipedia main page on a specified date.
wiki_didyouknow( n_facts = 1L, date = sample(seq(as.Date("2015-01-01"), Sys.Date() - 1, by = "day"), 1), bare_fact = FALSE )
wiki_didyouknow( n_facts = 1L, date = sample(seq(as.Date("2015-01-01"), Sys.Date() - 1, by = "day"), 1), bare_fact = FALSE )
n_facts |
An integer determining the number of facts that will be generated, up to a limit of the maximum facts for the date specified. |
date |
A date string of the form YYYY-MM-DD. Default value is a random date since 1 January 2015. |
bare_fact |
Logical. Determining whether the fact should be quoted as is or surrounded by a preamble and courtesy statement. |
A vector of strings with random 'did you know' facts from Wikipedia's main page if it exists for the date specified - otherwise "I got nothin'"
wiki_didyouknow(n_facts = 2, date = '2020-05-02')
wiki_didyouknow(n_facts = 2, date = '2020-05-02')
'wiki_inthenews()' generates news items from the Wikipedia main page on a specified date.
wiki_inthenews( n_facts = 1L, date = sample(seq(as.Date("2015-01-01"), Sys.Date() - 1, by = "day"), 1), bare_fact = FALSE )
wiki_inthenews( n_facts = 1L, date = sample(seq(as.Date("2015-01-01"), Sys.Date() - 1, by = "day"), 1), bare_fact = FALSE )
n_facts |
An integer determining the number of facts that will be generated, up to a limit of the maximum facts for the date specified. |
date |
A date string of the form YYYY-MM-DD. Default value is a random date since 1 January 2015. |
bare_fact |
Logical. Determining whether the fact should be quoted as is or surrounded by a preamble and courtesy statement. |
A vector of strings with random 'in the news' items from Wikipedia's main page, if it exists for the date specified - otherwise "I got nothin'"
wiki_inthenews(n_facts = 1, date = '2020-05-02')
wiki_inthenews(n_facts = 1, date = '2020-05-02')
‘wiki_onthisday()' generates ’on this day' facts from the Wikipedia main page on a specified date.
wiki_onthisday( n_facts = 1L, date = sample(seq(as.Date("2015-01-01"), Sys.Date() - 1, by = "day"), 1), bare_fact = FALSE )
wiki_onthisday( n_facts = 1L, date = sample(seq(as.Date("2015-01-01"), Sys.Date() - 1, by = "day"), 1), bare_fact = FALSE )
n_facts |
An integer determining the number of facts that will be generated, up to a limit of the maximum facts for the date specified. |
date |
A date string of the form YYYY-MM-DD. Default value is a random date since 1 January 2015. |
bare_fact |
Logical. Determining whether the fact should be quoted as is or surrounded by a preamble and courtesy statement. |
A vector of strings with random 'on this day' facts from Wikipedia's main page if it exists for the date specified - otherwise "I got nothin'"
wiki_onthisday(date = '2020-05-02')
wiki_onthisday(date = '2020-05-02')
'wiki_query()' sends a SPARQL query to Wikidata and collects the results in a dataframe
wiki_query(qry)
wiki_query(qry)
qry |
A character string representing a SPARQL query to be sent to Wikidata |
A dataframe of results
# List five diseases query <- 'SELECT ?itemLabel WHERE { ?item wdt:P31 wd:Q12136. #instance of disease SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } } LIMIT 5' wiki_query(query)
# List five diseases query <- 'SELECT ?itemLabel WHERE { ?item wdt:P31 wd:Q12136. #instance of disease SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } } LIMIT 5' wiki_query(query)
'wiki_randomfact()' generates random facts from Wikipedia main pages after 1 January 2015.
wiki_randomfact( n_facts = 1L, fact = c("any", "didyouknow", "onthisday", "inthenews"), bare_fact = FALSE, repeats = TRUE )
wiki_randomfact( n_facts = 1L, fact = c("any", "didyouknow", "onthisday", "inthenews"), bare_fact = FALSE, repeats = TRUE )
n_facts |
An integer determining the number of facts that will be generated. |
fact |
String to determine the type of fact to be randomly generated - "any" will generate a random selection. |
bare_fact |
Logical. Determining whether the fact should be quoted as is or surrounded by a preamble and courtesy statement. |
repeats |
Logical. Determining if repeat facts should be permitted. If FALSE the number of facts may be less than requested. |
A vector of strings with random items from Wikipedia's main page - otherwise "I got nothin'"
wiki_randomfact()
wiki_randomfact()
'wiki_search()' displays the results of a Wikipedia search in the browser.
wiki_search(term = NULL, browser = getOption("browser"))
wiki_search(term = NULL, browser = getOption("browser"))
term |
A non-empty character string giving the name of the term to be searched |
browser |
A non-empty character string passed to [browseURL()] to determine the browser used. |
A display of the results of the search in the browser.
wiki_search('R (programming language)')
wiki_search('R (programming language)')