-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
0.1.1020 initalise_logfile, add classification id and property to ite…
…m creation
- Loading branch information
1 parent
54f17d4
commit 9002120
Showing
15 changed files
with
217 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
Package: wbdataset | ||
Title: Making Datasets Truly Interoperable and Reusable in R with Wikibase | ||
Version: 0.1.1019 | ||
Date: 2024-02-24 | ||
Version: 0.1.1020 | ||
Date: 2024-03-02 | ||
Authors@R: | ||
c(person(given="Daniel", family="Antal", | ||
email= "[email protected]", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#' @rdname add_statement | ||
#' @inheritParams add_statement | ||
#' @param wikibase_type Defaults to \code{'item'}. | ||
#' @param o The item to be added to the statement as an object in the semantic triple. | ||
#' @export | ||
|
||
add_item_statement <- function(qid, pid, o, | ||
wikibase_type = "item", | ||
wikibase_api_url=NULL, | ||
csrf) { | ||
|
||
# api.php?action=wbcreateclaim&entity=Q4115189&property=P9003&snaktype=value&value={"entity-type":"item","numeric-id":1} | ||
|
||
assertthat::assert_that(!is.null(wikibase_api_url), | ||
msg="No wikibase_api_url is given") | ||
|
||
csrf_token <- get_csrf_token(csrf = csrf) | ||
|
||
base_string <- '{"entity-type":"item","numeric-id":numid}' | ||
new_numeric_id <- gsub("Q", "", o) | ||
datavalue <- gsub('numid', new_numeric_id, base_string) | ||
datavalue | ||
|
||
claim_body <- list( | ||
action = "wbcreateclaim", | ||
entity = qid, | ||
property = pid, | ||
snaktype = "value", | ||
value = datavalue, | ||
# '"datavalue":{"value":"https://www.wikidata.org/wiki/Q43878","type":"string"}}', | ||
token = csrf_token, | ||
format = "json") | ||
|
||
new_claim <- httr::POST( | ||
wikibase_api_url, | ||
body = list( | ||
action = "wbcreateclaim", | ||
entity = qid, | ||
property = pid, | ||
snaktype = "value", | ||
value = datavalue, | ||
# '"datavalue":{"value":"https://www.wikidata.org/wiki/Q43878","type":"string"}}', | ||
token = csrf_token, | ||
format = "json"), | ||
encode = "form", | ||
handle = csrf | ||
) | ||
|
||
response <- httr::content(new_claim, as = "parsed", type = "application/json") | ||
|
||
if ("error" %in% names(response)) { | ||
#invalid snak error at type mismatch | ||
warning_message <- glue::glue("Error in 'wbcreateclaim' wrapper add_item_statement():\n", response$error$code, ": ", response$error$info) | ||
warning(warning_message) | ||
|
||
return(data.frame( | ||
id = NA_character_, | ||
s = qid, | ||
o = NA_character_, | ||
p = NA_character_ | ||
)) | ||
} | ||
|
||
if (response$success == 1) { | ||
data.frame( | ||
id = response$claim$id, | ||
s = qid, | ||
o = pid, | ||
p = response$claim$mainsnak$datavalue$value$id | ||
) | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.