Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce distinct language parameters for search and response #9

Merged
merged 1 commit into from
May 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions R/gets.R
Original file line number Diff line number Diff line change
Expand Up @@ -156,16 +156,16 @@ get_example <- function(example_name){
#'@aliases find_item find_property
#'@rdname find_item
#'@export
find_item <- function(search_term, language = "en", limit = 10, ...){
res <- searcher(search_term, language, limit, "item")
find_item <- function(search_term, language = "en", limit = 10, response_language = "en", ...){
res <- searcher(search_term, language, limit, response_language, "item")
class(res) <- "find_item"
return(res)
}

#'@rdname find_item
#'@export
find_property <- function(search_term, language = "en", limit = 10){
res <- searcher(search_term, language, limit, "property")
find_property <- function(search_term, language = "en", response_language = "en", limit = 10){
res <- searcher(search_term, language, limit, response_language, "property")
class(res) <- "find_property"
return(res)
}
Expand All @@ -174,7 +174,9 @@ find_property <- function(search_term, language = "en", limit = 10){
#'@title Convert an input to a item QID
#'@description Convert an input string to the most likely item QID
#'@param search_term a term to search for.
#'@param language the language to return the labels and descriptions in; this should
#'@param language the language to conduct the search in; this should
#'consist of an ISO language code. Set to "en" by default.
#'@param response_language the language to return the labels and descriptions in; this should
#'consist of an ISO language code. Set to "en" by default.
#'@param limit the number of results to return; set to 10 by default.
#'@param type type of wikidata object to return (default = "item")
Expand All @@ -190,12 +192,13 @@ find_property <- function(search_term, language = "en", limit = 10){
#'# if input string matches a single unique label
#'as_qid("Douglas Adams and the question of arterial blood pressure in mammals")
#'@export
searcher <- function(search_term, language, limit, type, ...){
searcher <- function(search_term, language, limit, response_language, type, ...){
result <- WikipediR::query(url = "https://www.wikidata.org/w/api.php", out_class = "list", clean_response = FALSE,
query_param = list(
action = "wbsearchentities",
type = type,
language = language,
uselang = response_language,
limit = limit,
search = search_term
),
Expand Down
15 changes: 13 additions & 2 deletions man/find_item.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions man/searcher.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.