|
2 | 2 | #' @description Receive the label and description of a property on the basis of |
3 | 3 | #' its PID from a Wikibase instance. It will not add further statements about |
4 | 4 | #' the property. |
5 | | -#' @details Currently the languages choose a default, "en", for cases where the |
6 | | -#' user-chosen language return empty labels and descriptions. This feature may |
7 | | -#' be elaborated or changed later. The function receives aliases (alternative |
8 | | -#' labels), too, but does not return them; the format of aliases needs to be |
9 | | -#' decided in view of how other functions will use them, as aliases themselves |
10 | | -#' can break the tidiness of the returned data. |
| 5 | +#' @details Currently the language has a choose a default, \code{"en"}, for |
| 6 | +#' cases where the user-chosen language return empty labels and descriptions. |
| 7 | +#' This feature may be elaborated or changed later. The function receives |
| 8 | +#' aliases (alternative labels), too, but does not return them; the format of |
| 9 | +#' aliases needs to be decided in view of how other functions will use them, |
| 10 | +#' as aliases themselves can break the tidiness of the returned data. |
11 | 11 | #' @param pid The PID of the property in the Wikibase instance (or Wikidata |
12 | 12 | #' itself). |
13 | | -#' @param languages Defaults to \code{c("en", "nl", "hu")}. A character string |
14 | | -#' of the languages in which the users wants to receive the labels and |
15 | | -#' descriptions of the property. The vector of languages must use BCP |
16 | | -#' 47-compliant language tags (e.g., "en" for English, "nl" for Dutch and "hu" |
17 | | -#' ofr Hungarian.) |
18 | 13 | #' @param wikibase_api_url Defaults to |
19 | 14 | #' \code{"https://www.wikidata.org/w/api.php"}, may be replaced with a similar |
20 | 15 | #' API address of a Wikibase instance. Private instances may require an |
|
33 | 28 | #' @examples |
34 | 29 | #' # Receive a data.frame for further use |
35 | 30 | #' get_property_definition(pid = "P2047", return_type = "data.frame") |
| 31 | +#' |
36 | 32 | #' # Receive JSON for copying with wbeditidentiy |
37 | 33 | #' get_property_definition(pid = "P2047", languages = c("en", "hu")) |
38 | 34 | #' @export |
39 | 35 |
|
40 | 36 | get_property_definition <- function( |
41 | 37 | pid, |
42 | | - languages = c("en", "nl", "hu"), |
| 38 | + language = c("en", "nl", "hu"), |
43 | 39 | wikibase_api_url = "https://www.wikidata.org/w/api.php", |
44 | 40 | return_type = "JSON") { |
45 | 41 | ## Ensure that the pid is a character string starting with P followed by |
@@ -116,15 +112,15 @@ get_property_definition <- function( |
116 | 112 |
|
117 | 113 | ## We must determine which labels, descriptions, aliases actually exist |
118 | 114 | ## in the languages requested by the user. |
119 | | - labels_present <- languages[which(languages %in% names(response$entities[[1]]$labels))] |
120 | | - labels_missing <- languages[which(!languages %in% names(response$entities[[1]]$labels))] |
| 115 | + labels_present <- language[which(language %in% names(response$entities[[1]]$labels))] |
| 116 | + labels_missing <- language[which(!language %in% names(response$entities[[1]]$labels))] |
121 | 117 |
|
122 | | - descriptions_present <- languages[which(languages %in% names(response$entities[[1]]$descriptions))] |
123 | | - descriptions_missing <- languages[which(!languages %in% names(response$entities[[1]]$descriptions))] |
| 118 | + descriptions_present <- language[which(language %in% names(response$entities[[1]]$descriptions))] |
| 119 | + descriptions_missing <- language[which(!language %in% names(response$entities[[1]]$descriptions))] |
124 | 120 |
|
125 | 121 | # We do not work with the aliases now, but they may be used later. |
126 | | - aliases_present <- languages[which(languages %in% names(response$entities[[1]]$aliases))] |
127 | | - aliases_missing <- languages[which(!languages %in% names(response$entities[[1]]$aliases))] |
| 122 | + aliases_present <- language[which(language %in% names(response$entities[[1]]$aliases))] |
| 123 | + aliases_missing <- language[which(!language %in% names(response$entities[[1]]$aliases))] |
128 | 124 |
|
129 | 125 | ## Set a default later, this is now hard coded to English but could be a parameter. |
130 | 126 |
|
|
0 commit comments