Skip to content

Commit

Permalink
arg config for get_dbpedia_uris() to address #37
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreas Blätte authored and Andreas Blätte committed Feb 26, 2024
1 parent 99a5c44 commit 12d01fc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
13 changes: 9 additions & 4 deletions R/dbpedia.R
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ setGeneric("get_dbpedia_uris", function(x, ...) standardGeneric("get_dbpedia_uri
#' types = "Company",
#' api = "http://api.dbpedia-spotlight.org/en/annotate"
#' )
setMethod("get_dbpedia_uris", "character", function(x, language = getOption("dbpedia.lang"), max_len = 5600L, confidence = 0.35, api = getOption("dbpedia.endpoint"), types = character(), support = 20, verbose = TRUE){
setMethod("get_dbpedia_uris", "character", function(x, language = getOption("dbpedia.lang"), max_len = 5600L, confidence = 0.35, api = getOption("dbpedia.endpoint"), types = character(), support = 20, config = list(), verbose = TRUE){

if (nchar(x) > max_len){
if (verbose) cli_alert_warning(
Expand All @@ -381,6 +381,7 @@ setMethod("get_dbpedia_uris", "character", function(x, language = getOption("dbp
else
list(types = paste(types, collapse = ","))
),
config = config,
httr::add_headers('Accept' = 'application/json')
)

Expand Down Expand Up @@ -463,6 +464,7 @@ setMethod("get_dbpedia_uris", "AnnotatedPlainTextDocument", function(x, language
#' vector is empty (default), no restrictions are applied.
#' @param support The number of indegrees at Wikidata. Useful for limiting the
#' the number of results by excluding insignificant entities.
#' @param config Configuration settings passed into `httr::GET()`.
#' @param verbose A `logical` value - whether to display messages.
#' @param progress A `logical` value - whether to show progress.
#' @param s_attribute A length-one `character` vector indicating a s-attribute.
Expand Down Expand Up @@ -702,12 +704,13 @@ setMethod("get_dbpedia_uris", "subcorpus_bundle", function(x, language = getOpti
#' # example code
#'
#' # Process quanteda corpus
#' \donttest{
#' library(quanteda)
#' uritab <- data_char_ukimmig2010 |>
#' corpus() |>
#' get_dbpedia_uris(verbose = FALSE)
#' }
#' get_dbpedia_uris(
#' verbose = FALSE,
#' config = httr::config(http_version = 1.1)
#' )
#'
#' @rdname get_dbpedia_uris
setMethod(
Expand All @@ -721,6 +724,7 @@ setMethod(
api = getOption("dbpedia.endpoint"),
types = character(),
support = 20,
config = list(),
verbose = TRUE,
progress = FALSE
){
Expand Down Expand Up @@ -755,6 +759,7 @@ setMethod(
api = api,
types = types,
support = support,
config = config,
verbose = if (progress) FALSE else verbose
)[, "doc" := docname]
}
Expand Down
11 changes: 8 additions & 3 deletions man/get_dbpedia_uris.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 12d01fc

Please sign in to comment.