Carry a a verbosity default already in the connection object
Change-Id: I8b0b0cb3ebbf5d92be8442366b5aaf6643e9431c
diff --git a/R/KorAPConnection.R b/R/KorAPConnection.R
index 84aec06..a890d3f 100644
--- a/R/KorAPConnection.R
+++ b/R/KorAPConnection.R
@@ -10,25 +10,26 @@
#'
#' @export
-KorAPConnection <- setClass("KorAPConnection", slots=c(KorAPUrl="character", apiVersion="character", apiUrl="character"))
+KorAPConnection <- setClass("KorAPConnection", slots=c(KorAPUrl="character", apiVersion="character", apiUrl="character", verbose="logical"))
#' @param .Object KorAPConnection object
#' @param KorAPUrl the URL of the KorAP server instance you want to access.
#' @param apiVersion which version of KorAP's API you want to connect to.
#' @param apiUrl URL of the KorAP web service.
+#' @param verbose logical decides wether following operations will default to be verbose
#' @return \code{\link{KorAPConnection}} object that can be used e.g. with \code{\link{corpusQuery}}
#'
#' @examples
-#' kcon <- new("KorAPConnection")
+#' kcon <- new("KorAPConnection", verbose = TRUE)
#' kq <- corpusQuery(kcon, "Ameisenplage")
-#' kq <- fetchAll(kq, verbose=TRUE)
+#' kq <- fetchAll(kq)
#'
#' @note Currently it is not possible to authenticate the client
#'
#' @rdname KorAPConnection-class
#' @export
setMethod("initialize", "KorAPConnection",
- function(.Object, KorAPUrl = "https://korap.ids-mannheim.de/", apiVersion = 'v1.0', apiUrl) {
+ function(.Object, KorAPUrl = "https://korap.ids-mannheim.de/", apiVersion = 'v1.0', apiUrl, verbose = FALSE) {
.Object <- callNextMethod()
m <- regexpr("https?://[^?]+", KorAPUrl, perl = TRUE)
.Object@KorAPUrl <- regmatches(KorAPUrl, m)
@@ -41,6 +42,7 @@
.Object@apiUrl = apiUrl
}
.Object@apiVersion = apiVersion
+ .Object@verbose = verbose
.Object
})
diff --git a/R/KorAPCorpusStats.R b/R/KorAPCorpusStats.R
index dc60133..f1b98e8 100644
--- a/R/KorAPCorpusStats.R
+++ b/R/KorAPCorpusStats.R
@@ -18,6 +18,7 @@
#' Fetch information about a (virtual) corpus
#' @param kco \code{\link{KorAPConnection}} object (obtained e.g. from \code{new("KorAPConnection")}
#' @param vc string describing the virtual corpus. An empty string (default) means the whole corpus, as far as it is license-wise accessible.
+#' @param verbose logical. If \code{TRUE}, additional diagnostics are printed.
#' @return \code{KorAPCorpusStats} object with the slots \code{documents}, \code{tokens}, \code{sentences}, \code{paragraphs}
#'
#' @examples
@@ -28,9 +29,15 @@
#'
#' @aliases corpusStats
#' @export
-setMethod("corpusStats", "KorAPConnection", function(kco, vc="") {
+setMethod("corpusStats", "KorAPConnection", function(kco, vc="", verbose = kco@verbose) {
url <- paste0(kco@apiUrl, 'statistics?cq=', URLencode(vc, reserved=TRUE))
+ if (verbose) {
+ cat("Calculating size of corpus \"", vc,"\"", sep="")
+ }
res <- fromJSON(url)
+ if (verbose) {
+ cat("\n")
+ }
new("KorAPCorpusStats", vc = vc, documents = res$documents, tokens = res$tokens, sentences = res$sentences, paragraphs = res$paragraphs)
})
diff --git a/R/KorAPQuery.R b/R/KorAPQuery.R
index 1ca8123..28c508e 100644
--- a/R/KorAPQuery.R
+++ b/R/KorAPQuery.R
@@ -129,7 +129,7 @@
#' @export
setMethod("corpusQuery", "KorAPConnection",
function(kco, query, vc="", KorAPUrl, metadataOnly = TRUE, ql = "poliqarp", fields = defaultFields,
- accessRewriteFatal = TRUE, verbose=FALSE) {
+ accessRewriteFatal = TRUE, verbose = kco@verbose) {
defaultFields <- c("corpusSigle", "textSigle", "pubDate", "pubPlace",
"availability", "textClass", "snippet")
contentFields <- c("snippet")