Skip to content

Commit 1ba517d

Browse files
committed
resolve pid, qid equivalence from session
1 parent 7cc6706 commit 1ba517d

6 files changed

Lines changed: 22 additions & 40 deletions

File tree

R/copy_wikidata_item.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ copy_wikidata_item <- function(
9090
equivalence_property <- resolve_from_session("wikibase_api_url", equivalence_property, wikibase_session)
9191
classification_property <- resolve_from_session("wikibase_api_url", classification_property, wikibase_session)
9292
csrf <- resolve_from_session("csrf", csrf, wikibase_session)
93+
qid_equivalence_property <- resolve_from_session("qid_equivalence_property", qid_equivalence_property, wikibase_session)
94+
9395

9496
validate_copy_entity_args(
9597
language = language,

R/copy_wikidata_property.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ copy_wikidata_property <- function(
9393
wikibase_api_url <- resolve_from_session("wikibase_api_url", wikibase_api_url, wikibase_session)
9494
classification_property <- resolve_from_session("classification_property", classification_property, wikibase_session)
9595
equivalence_property <- resolve_from_session("equivalence_property", equivalence_property, wikibase_session)
96+
pid_equivalence_property <- resolve_from_session("pid_equivalence_property", pid_equivalence_property, wikibase_session)
9697

9798
csrf <- resolve_from_session("csrf", csrf, wikibase_session)
9899

R/create_property.R

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#' @param datatype A single character string defining the datatype of this
2121
#' property, for example, \code{"string"}, \code{"wikibase-item"},
2222
#' \code{"quantity"}, \code{"commonsMedia"}, \code{"url"}, \code{"external-id"},
23-
#' \code{"globe-coordinate"}.
23+
#' \code{"globe-coordinate"}, \code{"time"}, \code{"monolingualtext"}.
2424
#' @param equivalence_property An optional PID of a property already defined in
2525
#' the same Wikibase instance that records the equivalence of this new
2626
#' property with a property defined elsewhere, for example, on Wikidata or
@@ -105,7 +105,11 @@ create_property <- function(label,
105105
log_file_name <- resolve_from_session("log_file_name", log_file_name, wikibase_session)
106106
wikibase_api_url <- resolve_from_session("wikibase_api_url", wikibase_api_url, wikibase_session)
107107
equivalence_property <- resolve_from_session("wikibase_api_url", equivalence_property, wikibase_session)
108-
csrf <- resolve_from_session("csrf", csrf, wikibase_session)
108+
csrf <- resolve_from_session("csrf", csrf, wikibase_session)
109+
110+
if(!is_valid_wikibase_datatype(datatype)) {
111+
stop ("create_property(..., datatype): ", datatype, " is not a valid Wikibase property type.")
112+
}
109113

110114
validate_create_entity_args(
111115
label = label,
@@ -114,10 +118,15 @@ create_property <- function(label,
114118
wikibase_api_url = wikibase_api_url,
115119
equivalence_property = equivalence_property,
116120
equivalence_id = equivalence_id,
121+
classification_property = NA_character_, # not used in this function
122+
classification_id = NA_character_, # not used in this function
117123
csrf = csrf,
118124
data_curator = data_curator,
119125
validated_action = "create_property()"
120126
)
127+
128+
129+
121130
# Save the time of running the code
122131
action_time <- Sys.time()
123132
action_timestamp <- action_timestamp_create()

man/create_property.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-create_item.R

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,5 @@
1-
test_that("multiplication works", {
2-
expect_equal(2 * 2, 4)
1+
test_that("create_item() validates inputs", {
2+
expect_error(create_item(label=123, description="test"),
3+
regexp = "\\'label\\' must be a non-empty character string")
34
})
4-
library(keyring)
5-
jekyll_anna <- "Reprexba jekyll@MesterannaBot"
6-
jekyll_daniel <- "Reprexba jekyll@AntaldanielBot"
7-
agya_wikibase_api_url <- "https://reprexbase.eu/jekyll/api.php" # temporary
8-
my_csrf <- get_csrf(
9-
jekyll_daniel,
10-
password = key_get(
11-
service = agya_wikibase_api_url,
12-
username = jekyll_daniel,
13-
),
14-
agya_wikibase_api_url
15-
)
165

17-
18-
agya_wikibase_session <- list(
19-
csrf = my_csrf,
20-
wikibase_api_url = agya_wikibase_api_url,
21-
language = c("en", "sk", "hu", "de", "fr", "es", "ro"),
22-
data_curator = person("Daniel", "Antal"),
23-
pid_equivalence_property = "P2",
24-
qid_equivalence_property = "P35",
25-
log_path = here("not_included")
26-
)
27-
28-
digital_record_class <- create_item(
29-
label = "digital record",
30-
description = "a subclass of the record, a record in the collection of the Andrássy Gyula Foundation.",
31-
language = "en",
32-
classification_property = "P137", # subclass of
33-
classification_id = "Q584", # record
34-
wikibase_api_url = agya_wikibase_api_url,
35-
csrf = agya_wikibase_session$csrf,
36-
wikibase_session = agya_wikibase_session
37-
)
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1-
test_that("multiplication works", {
2-
expect_equal(2 * 2, 4)
1+
test_that("create_property() validates inputs", {
2+
expect_error(create_property(label="test", description="test",
3+
datatype = "chicken"),
4+
regexp = "is not a valid Wikibase property type")
35
})

0 commit comments

Comments
 (0)