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")
diff --git a/man/KorAPConnection-class.Rd b/man/KorAPConnection-class.Rd
index 2c4c60e..54f6468 100644
--- a/man/KorAPConnection-class.Rd
+++ b/man/KorAPConnection-class.Rd
@@ -10,7 +10,7 @@
\usage{
\S4method{initialize}{KorAPConnection}(.Object,
KorAPUrl = "https://korap.ids-mannheim.de/", apiVersion = "v1.0",
- apiUrl)
+ apiUrl, verbose = FALSE)
\S4method{show}{KorAPConnection}(object)
}
@@ -23,6 +23,8 @@
\item{apiUrl}{URL of the KorAP web service.}
+\item{verbose}{logical decides wether following operations will default to be verbose}
+
\item{object}{KorAPConnection object}
}
\value{
@@ -36,8 +38,8 @@
Currently it is not possible to authenticate the client
}
\examples{
-kcon <- new("KorAPConnection")
+kcon <- new("KorAPConnection", verbose = TRUE)
kq <- corpusQuery(kcon, "Ameisenplage")
-kq <- fetchAll(kq, verbose=TRUE)
+kq <- fetchAll(kq)
}
diff --git a/man/corpusQuery-KorAPConnection-method.Rd b/man/corpusQuery-KorAPConnection-method.Rd
index 3f0d791..9d3da95 100644
--- a/man/corpusQuery-KorAPConnection-method.Rd
+++ b/man/corpusQuery-KorAPConnection-method.Rd
@@ -8,7 +8,7 @@
\usage{
\S4method{corpusQuery}{KorAPConnection}(kco, query, vc = "", KorAPUrl,
metadataOnly = TRUE, ql = "poliqarp", fields = defaultFields,
- accessRewriteFatal = TRUE, verbose = FALSE)
+ accessRewriteFatal = TRUE, verbose = kco@verbose)
}
\arguments{
\item{kco}{\code{\link{KorAPConnection}} object (obtained e.g. from \code{new("KorAPConnection")}}
diff --git a/man/corpusStats-KorAPConnection-method.Rd b/man/corpusStats-KorAPConnection-method.Rd
index 6a4ccc2..486ee1c 100644
--- a/man/corpusStats-KorAPConnection-method.Rd
+++ b/man/corpusStats-KorAPConnection-method.Rd
@@ -6,12 +6,15 @@
\alias{corpusStats}
\title{Fetch information about a (virtual) corpus}
\usage{
-\S4method{corpusStats}{KorAPConnection}(kco, vc = "")
+\S4method{corpusStats}{KorAPConnection}(kco, vc = "",
+ verbose = kco@verbose)
}
\arguments{
\item{kco}{\code{\link{KorAPConnection}} object (obtained e.g. from \code{new("KorAPConnection")}}
\item{vc}{string describing the virtual corpus. An empty string (default) means the whole corpus, as far as it is license-wise accessible.}
+
+\item{verbose}{logical. If \code{TRUE}, additional diagnostics are printed.}
}
\value{
\code{KorAPCorpusStats} object with the slots \code{documents}, \code{tokens}, \code{sentences}, \code{paragraphs}