Skip to content

Commit

Permalink
refactor: lint 1 script
Browse files Browse the repository at this point in the history
  • Loading branch information
maelle committed Oct 12, 2023
1 parent 6ece4cf commit 2b44d99
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions R/decompose-triple-pattern.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#' Get elements subject, verb, object of a triple pattern as a list.
#' @param triple_pattern the triple pattern statement (replaces arguments subject verb and object)
#' @param subject an anonymous variable (for instance, and by default, "?subject") or item (for instance "wd:Q456"))
#' @param triple_pattern the triple pattern statement
#' (replaces arguments subject verb and object)
#' @param subject an anonymous variable (for instance, and by default,
#' "?subject") or item (for instance "wd:Q456"))
#' @param verb the property (for instance "wdt:P190")
#' @param object an anonymous variable (for instance, and by default, "?object") or item (for instance "wd:Q456"))
#' @param object an anonymous variable (for instance, and by default, "?object")
#' or item (for instance "wd:Q456"))
#' @noRd
decompose_triple_pattern = function(triple_pattern, subject, verb, object){
decompose_triple_pattern = function(triple_pattern, subject, verb, object) {

if (is.null(triple_pattern)) {
elements = list(subject = subject,
Expand All @@ -14,14 +17,14 @@ decompose_triple_pattern = function(triple_pattern, subject, verb, object){
} else {
# if there is a trailing period
triple_pattern = sub("\\.$", "", triple_pattern)
if (str_detect(triple_pattern, "\\s*==\\s*")){
triple_pattern = str_replace(triple_pattern, "\\s*==\\s*"," == ")
if (str_detect(triple_pattern, "\\s*==\\s*")) {
triple_pattern = str_replace(triple_pattern, "\\s*==\\s*", " == ")
}

# if one part of triple_pattern is of the type 'Cristiano_Ronaldo'@en
if (str_detect(triple_pattern, "[\'\"].*[\'\"]")) {
part_pb = str_extract(triple_pattern, "[\'\"].*[\'\"]")
part_ok = str_replace_all(part_pb, "\\s","_")
part_ok = str_replace_all(part_pb, "\\s", "_")
triple_pattern = str_replace(triple_pattern, part_pb, part_ok)
}

Expand All @@ -38,8 +41,10 @@ decompose_triple_pattern = function(triple_pattern, subject, verb, object){
elements_interpreted = purrr::map(elements, interpret_svo)
elements_correct = purrr::map_lgl(elements_interpreted, is_svo_correct)

if(!all(elements_correct)) {
cli::cli_abort("Element {elements[!elements_correct][1]} is incorrectly stated.")
if (!all(elements_correct)) {
cli::cli_abort(
"Element {elements[!elements_correct][1]} is incorrectly stated."
)
}

elements_interpreted
Expand Down

0 comments on commit 2b44d99

Please sign in to comment.