Skip to content

Commit 3dcd5a2

Browse files
committed
Version: 0.1.1053
Minor fixes that may have documentation problems
1 parent 20e18c8 commit 3dcd5a2

22 files changed

+281
-70
lines changed

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: wbdataset
22
Title: Making Datasets Truly Interoperable and Reusable in R with Wikibase
3-
Version: 0.1.1053
4-
Date: 2024-06-06
3+
Version: 0.1.1056
4+
Date: 2024-06-08
55
Authors@R:
66
c(person(given="Daniel", family="Antal",
77
email= "[email protected]",

R/add_id_statement.R

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#' @rdname add_statement
22
#' @description See
3-
#' \link[https://www.wikidata.org/w/api.php?action=help&modules=wbcreateclaim]{MediaWiki
3+
#' \href{https://www.wikidata.org/w/api.php?action=help&modules=wbcreateclaim}{MediaWiki
44
#' API help}
55
#' @param qid The QID of the item in the Wikibase instance that you use.
66
#' @param pid The PID of the equivalent Wikidata (or reference Wikibase) URI.
@@ -9,8 +9,8 @@
99
#' @param wikibase_api_url The full URL of the Wikibase API, which is the
1010
#' address that the \code{wbdataset} R client sends requests to when
1111
#' interacting with the knowledge base. For example,
12-
#' \code{'https://reprexbase.eu/demowiki/api.php'}. The URL must end with
13-
#' api.php.
12+
#' \code{'https://reprexbase.eu/demowiki/api.php'}.
13+
#' The URL must end with api.php.
1414
#' @param csrf The CSRF token of your session, received with
1515
#' \code{\link{get_csrf}}.
1616
#' @importFrom httr POST content
@@ -25,8 +25,14 @@ add_id_statement <- function(
2525
wikibase_api_url = "https://reprexbase.eu/demowiki/api.php",
2626
csrf) {
2727

28-
datavalue <- paste0('"', o, '"')
29-
datavalue
28+
format_claim_value <- function(value, datatype) {
29+
if (datatype %in% c("external-id", "string", "url")) {
30+
return(paste0('"', value, '"'))
31+
}
32+
stop("Unsupported datatype")
33+
}
34+
35+
datavalue <- format_claim_value(o, wikibase_type)
3036

3137
this_csrf_token <- get_csrf_token(csrf = csrf)
3238

@@ -67,21 +73,17 @@ add_id_statement <- function(
6773
return(data.frame(
6874
id = NA_character_,
6975
s = qid,
70-
o = NA_character_,
71-
p = NA_character_
76+
p = NA_character_,
77+
o = NA_character_
7278
))
7379
}
7480

7581
if (response$success == 1) {
7682
data.frame(
7783
id = response$claim$id,
7884
s = qid,
79-
o = pid,
80-
p = response$claim$mainsnak$datavalue$value
85+
p = pid,
86+
o = response$claim$mainsnak$datavalue$value
8187
)
8288
}
8389
}
84-
85-
86-
#' datavalue\":{\"value\":\"https://www.wikidata.org/wiki/Q43878\",\"type\":\"string\"},\"datatype\":\"external-id\"}'
87-
# api.php?action=wbcreateclaim&entity=Q4115189&property=P9003&snaktype=value&value={"entity-type":"item","numeric-id":1}

R/add_statement.R

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#' @title Add statements to an item
22
#' @description Adds a claim (statement) to a Wikibase item via `wbcreateclaim`.
33
#' See
4-
#' \link[https://www.wikidata.org/w/api.php?action=help&modules=wbcreateclaim]{MediaWiki
4+
#' \href{https://www.wikidata.org/w/api.php?action=help&modules=wbcreateclaim}{MediaWiki
55
#' API help}
66
#' @param qid The QID of the item in the Wikibase instance.
77
#' @param pid The PID of the property to be added.
@@ -14,7 +14,7 @@
1414
#' @export
1515
add_statement <- function(
1616
qid, pid, o,
17-
wikibase_type = c("item", "string", "numeric", "external-id"),
17+
wikibase_type = c("item", "string", "numeric", "external-id", "url"),
1818
wikibase_api_url = "https://reprexbase.eu/demowiki/api.php",
1919
csrf) {
2020

@@ -26,11 +26,12 @@ add_statement <- function(
2626
wikibase_type <- match.arg(wikibase_type,
2727
choices = c(
2828
"item", "string",
29-
"numeric", "external-id"
29+
"numeric", "external-id", "url"
3030
)
3131
)
3232

3333
if (wikibase_type == "external-id") wikibase_type <- "string"
34+
if (wikibase_type == "url") wikibase_type <- "string"
3435

3536
if (wikibase_type == "string") {
3637
add_id_statement(

R/check_existing_item.R

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,19 @@
1717
#' adhering to BCP 47 standards (e.g., `"en"` for English). Defaults to
1818
#' `"en"`. For more details, see \href{https://tools.ietf.org/html/bcp47}{BCP
1919
#' 47}.
20+
#' @param classification_property The instance of, or subclass of, or superclass
21+
#' of property. Defaults to \code{NA_character} when not used.
22+
#' @param classification_id The QID of the class. Defaults to
23+
#' \code{NA_character} when not used.
24+
#' @param equivalence_property An optional PID of a property already defined in
25+
#' the same Wikibase instance that records the equivalence of this new
26+
#' item with a property defined elsewhere, for example, on Wikidata or
27+
#' CIDOC-CRM. Defaults to \code{NA_character_}; if left missing, no
28+
#' equivalence relations is will be claimed.
29+
#' @param equivalence_id The identifier that uniquely identifies this item among
30+
#' another system's definitions. Defaults to
31+
#' \code{NA_character_}; if left missing, no equivalence relations is will be
32+
#' claimed.
2033
#' @param action A character string indicating the action being performed.
2134
#' Defaults to `"create_item"`.
2235
#' @param log_file_name A character string specifying the name of the log file.
@@ -42,18 +55,19 @@
4255
#' )
4356
#' @export
4457

45-
check_existing_item <- function(search_term,
46-
language = "en",
47-
equivalence_property = NA_character_,
48-
equivalence_id = NA_character_,
49-
classification_property = NA_character_,
50-
classification_id = NA_character_,
51-
action = "create_item",
52-
log_file_name = NA_character_,
53-
data_curator = person("Unknown", "Person"),
54-
wikibase_api_url = "https://www.wikidata.org/w/api.php",
55-
csrf = NULL,
56-
ambiguity_handling = "return_null") {
58+
check_existing_item <- function(
59+
search_term,
60+
language = "en",
61+
equivalence_property = NA_character_,
62+
equivalence_id = NA_character_,
63+
classification_property = NA_character_,
64+
classification_id = NA_character_,
65+
action = "create_item",
66+
log_file_name = NA_character_,
67+
data_curator = person("Unknown", "Person"),
68+
wikibase_api_url = "https://www.wikidata.org/w/api.php",
69+
csrf = NULL,
70+
ambiguity_handling = "return_null") {
5771
# Validate inputs
5872
if (!is.character(search_term) ||
5973
length(search_term) != 1 ||

R/check_existing_property.R

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,24 @@
66
#' action=wbsearchentities}.
77
#' @param search_term A character string specifying the label to search for. For
88
#' example, "instance of".
9+
#' @param action A name for the action performed by a function for the
10+
#' log file, defaults to \code{"create_property"}.
911
#' @param language A character string specifying the language code of the label,
1012
#' adhering to BCP 47 standards (e.g., `"en"` for English). Defaults to
1113
#' `"en"`.
14+
#' @param classification_property The instance of, or subclass of, or superclass
15+
#' of property. Defaults to \code{NA_character} when not used.
16+
#' @param classification_id The QID of the class. Defaults to
17+
#' \code{NA_character} when not used.
18+
#' @param equivalence_property An optional PID of a property already defined in
19+
#' the same Wikibase instance that records the equivalence of this new
20+
#' item with a property defined elsewhere, for example, on Wikidata or
21+
#' CIDOC-CRM. Defaults to \code{NA_character_}; if left missing, no
22+
#' equivalence relations is will be claimed.
23+
#' @param equivalence_id The identifier that uniquely identifies this item among
24+
#' another system's definitions. Defaults to
25+
#' \code{NA_character_}; if left missing, no equivalence relations is will be
26+
#' claimed.
1227
#' @param wikibase_api_url The full URL of the Wikibase API. Defaults to
1328
#' `'https://www.wikidata.org/w/api.php'`, which is Wikidata's API endpoint.
1429
#' @param csrf The CSRF token of your session, obtained with
@@ -19,6 +34,13 @@
1934
#' where multiple properties match the search term. Options are
2035
#' \code{"return_first"} (default) to return the first match, or
2136
#' \code{"return_null"} to return \code{NULL} when multiple matches are found.
37+
#' @param log_file_name An explicitly stated full path to a possible CSV log
38+
#' file, defaults to \code{NULL}. If the value is \code{NULL}, no log file
39+
#' will be created.
40+
#' @param data_curator The name of the data curator who runs the function and
41+
#' creates the log file, created with \link[utils]{person}.
42+
#' It is either given as a parameter or resolved from
43+
#' \code{wikibase_session}. If no curator
2244
#' @return A data frame containing details of the matching property, or
2345
#' \code{NULL} if no match is found or if multiple matches are found and
2446
#' \code{ambiguity_handling} is set to \code{"return_null"}.

R/copy_wikidata_property.R

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@
2323
#' of property. Defaults to \code{NA_character} when not used.
2424
#' @param classification_id The QID of the class. Defaults to
2525
#' \code{NA_character} when not used.
26+
#' @param equivalence_property An optional PID of a property already defined in
27+
#' the same Wikibase instance that records the equivalence of this new
28+
#' item with a property defined elsewhere, for example, on Wikidata or
29+
#' CIDOC-CRM. Defaults to \code{NA_character_}; if left missing, no
30+
#' equivalence relations is will be claimed.
31+
#' @param equivalence_id The identifier that uniquely identifies this item among
32+
#' another system's definitions. Defaults to
33+
#' \code{NA_character_}; if left missing, no equivalence relations is will be
34+
#' claimed.
2635
#' @param language Defaults to \code{c("en")}. A character string of
2736
#' the languages in which the users wants to receive the labels and
2837
#' descriptions of the property. The vector of languages must use \href{https://en.wikipedia.org/wiki/IETF_language_tag}{BCP

R/create_dual_item.R

Lines changed: 0 additions & 12 deletions
This file was deleted.

R/data-wikidata_countries_df.R

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
#' @description
33
#' A small dataset of countries, including sovereign states and autonomous
44
#' parts of federal states taken from Wikidata.
5-
#' @format ## `wikidata_countries_df`
6-
#' A data frame with 4 rows and 4 columns:
5+
#' @format A data frame with 4 rows and 4 columns:
76
#' \describe{
87
#' \item{qid}{QID of the item.}
98
#' \item{label}{Name label of the item.}

R/data.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#' @rdname wikidata_countries_df
2+
"wikidata_countries_df"

R/get_csrf.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@ get_csrf <- function(username, password, wikibase_api_url) {
144144
#' @importFrom httr handle GET POST content
145145
#' @export
146146
get_csrf_token <- function(csrf) {
147-
csrf_data <- httr::content(csrf, as = "parsed", type = "application/json")
147+
csrf_data <- httr::content(csrf, as = "parsed",
148+
type = "application/json")
148149
csrf_data
149150
csrf_token <- csrf_data$query$tokens$csrftoken
150151
if (nchar(csrf_token) < 10) stop("Error: get_csrf_token(csrf): Did not receive a valid token.")

0 commit comments

Comments
 (0)