♻️💄 simplify KorAPConnection class instantiations to modern syntax
Update all class instantiations from `new("KorAPConnection")` to `KorAPConnection()`.
This is possible with R >= 4.0.
Change-Id: I01131fb32045e084cafbb9e05cd8ba99f8f20f1b
diff --git a/tests/testthat/test-KorAPConnection.R b/tests/testthat/test-KorAPConnection.R
index 0755b08..42e3fd6 100644
--- a/tests/testthat/test-KorAPConnection.R
+++ b/tests/testthat/test-KorAPConnection.R
@@ -1,32 +1,32 @@
test_that("KorAPConnection fails gracefully on unresolvable host", {
- expect_message(new("KorAPConnection", accessToken = NULL, apiUrl="http://xxx.asdhsahdsadhvgas.org"), "No internet|Could not resolve")
+ expect_message(KorAPConnection(accessToken = NULL, apiUrl="http://xxx.asdhsahdsadhvgas.org"), "No internet|Could not resolve")
})
test_that("KorAPConnection fails gracefully on timeout", {
- expect_message(new("KorAPConnection", apiUrl="http://httpbin.org/delay/3", accessToken = NULL, timeout = 0.2), "No internet|Timeout|json|progress")
+ expect_message(KorAPConnection(apiUrl="http://httpbin.org/delay/3", accessToken = NULL, timeout = 0.2), "No internet|Timeout|json|progress")
})
test_that("KorAPConnection fails gracefully on Bad Gateway errors", {
- expect_message(new("KorAPConnection", apiUrl="http://httpbin.org/status/502", accessToken = NULL, timeout = 0.5), "No internet|Timeout|progress|json|502")
+ expect_message(KorAPConnection(apiUrl="http://httpbin.org/status/502", accessToken = NULL, timeout = 0.5), "No internet|Timeout|progress|json|502")
})
test_that("KorAPConnection is printable", {
- kco <- new("KorAPConnection", accessToken = NULL, timeout = 1)
+ kco <- KorAPConnection(accessToken = NULL, timeout = 1)
skip_if(is.null(kco@welcome))
expect_error(print(kco), NA)
})
test_that("Opening KorAPConnection prints some message.", {
- expect_message(new("KorAPConnection", accessToken = NULL), "KorAP")
+ expect_message(KorAPConnection(accessToken = NULL), "KorAP")
})
test_that("Opening KorAPConnection with invalid apiToken fails gracefully", {
- expect_message(new("KorAPConnection", accessToken="test token", timeout = 3),
+ expect_message(KorAPConnection(accessToken="test token", timeout = 3),
"401|Timeout|progress")
})
test_that("Persisting null apiToken fails", {
- kco <- new("KorAPConnection", accessToken = NULL, timeout = 3)
+ kco <- KorAPConnection(accessToken = NULL, timeout = 3)
skip_if_not(is.null(kco@accessToken))
skip_if(is.null(kco@welcome))
expect_error(persistAccessToken(kco),
@@ -35,8 +35,8 @@
})
test_that("Opening KorAPConnection with KorAPUrl works", {
- kco <- new("KorAPConnection", accessToken = NULL, KorAPUrl="https://korap.ids-mannheim.de", timeout = 1)
+ kco <- KorAPConnection(accessToken = NULL, KorAPUrl="https://korap.ids-mannheim.de", timeout = 1)
expect_equal(kco@apiUrl, paste0("https://korap.ids-mannheim.de/api/", kco@apiVersion, "/"))
- kco <- new("KorAPConnection", accessToken = NULL, KorAPUrl="https://korap.ids-mannheim.de/", timeout = 1)
+ kco <- KorAPConnection(accessToken = NULL, KorAPUrl="https://korap.ids-mannheim.de/", timeout = 1)
expect_equal(kco@apiUrl, paste0("https://korap.ids-mannheim.de/api/", kco@apiVersion, "/"))
})
diff --git a/tests/testthat/test-collocations.R b/tests/testthat/test-collocations.R
index aa4a771..d0dd761 100644
--- a/tests/testthat/test-collocations.R
+++ b/tests/testthat/test-collocations.R
@@ -1,6 +1,6 @@
test_that("collocationScoreQuery works", {
skip_if_offline()
- kco <- new("KorAPConnection", accessToken = NULL, cache = TRUE, verbose = TRUE)
+ kco <- KorAPConnection(accessToken = NULL, cache = TRUE, verbose = TRUE)
df <- collocationScoreQuery(kco, "Ameisenplage", "heimgesucht", leftContextSize=0, rightContextSize=1)
expect_gt(df$logDice, 1)
expect_equal(df$ll, ll(df$O1, df$O2, df$O, df$N, df$E, df$w))
@@ -13,7 +13,7 @@
test_that("collocationAnalysis works and warns about missing token", {
skip_if_offline()
- kco <- new("KorAPConnection",
+ kco <- KorAPConnection(
accessToken = NULL,
verbose = TRUE)
expect_warning(
@@ -32,7 +32,7 @@
test_that("collocationAnalysis on unaccounted strings does not error out", {
skip_if_offline()
- kco <- new("KorAPConnection", accessToken = NULL, verbose = TRUE)
+ kco <- KorAPConnection(accessToken = NULL, verbose = TRUE)
expect_warning(
df <- collocationAnalysis(kco, "XXXXXXXXAmeisenplage", vc=c("corpusSigle=/WDD17/", "corpusSigle=/WUD17/"), maxRecurse = 2),
"access token"
diff --git a/tests/testthat/test-corpusQuery.R b/tests/testthat/test-corpusQuery.R
index 223f526..e5289e0 100644
--- a/tests/testthat/test-corpusQuery.R
+++ b/tests/testthat/test-corpusQuery.R
@@ -1,13 +1,13 @@
test_that("frequencyQuery can be cached", {
skip_if_offline()
- kco <- new("KorAPConnection", accessToken = NULL, cache = TRUE, verbose = TRUE)
+ kco <- KorAPConnection(accessToken = NULL, cache = TRUE, verbose = TRUE)
frequencyQuery(kco, "Ameisenplage", "pubDate since 2014")
expect_output(frequencyQuery(kco, "Ameisenplage", "pubDate since 2014"), "cached")
})
test_that("collocationScoreQuery works", {
skip_if_offline()
- kco <- new("KorAPConnection", accessToken = NULL, cache = TRUE, verbose = TRUE)
+ kco <- KorAPConnection(accessToken = NULL, cache = TRUE, verbose = TRUE)
df <- collocationScoreQuery(kco,"Ameisenplage", "heimgesucht", leftContextSize=0, rightContextSize=1)
expect_gt(df$logDice, 1)
expect_equal(df$ll, ll(df$O1, df$O2, df$O, df$N, df$E, df$w))
@@ -19,7 +19,7 @@
test_that("Cache depends on indexRevision (handling also NULL values)", {
skip_if_offline()
- kco <- new("KorAPConnection", accessToken = NULL, cache = TRUE, verbose = TRUE)
+ kco <- KorAPConnection(accessToken = NULL, cache = TRUE, verbose = TRUE)
kco@indexRevision <- NULL
frequencyQuery(kco, "Ameisenplage", "pubDate since 2014")
kco@indexRevision <- as.character(Sys.time())
@@ -29,7 +29,7 @@
test_that("corpusQuery returns results", {
skip_if_offline()
- q <- new("KorAPConnection", accessToken = NULL) %>%
+ q <- KorAPConnection(accessToken = NULL) %>%
corpusQuery("Ameisenplage")
expect_gt(q@totalResults, 0)
})
@@ -41,7 +41,7 @@
Encoding(vc)="latin1"
skip_if_offline()
- q <- new("KorAPConnection", accessToken = NULL) %>%
+ q <- KorAPConnection(accessToken = NULL) %>%
corpusQuery(query, vc=vc)
expect_gt(q@totalResults, 0)
})
@@ -53,14 +53,14 @@
Encoding(vc)="UTF-8"
skip_if_offline()
- q <- new("KorAPConnection", accessToken = NULL) %>%
+ q <- KorAPConnection(accessToken = NULL) %>%
corpusQuery(query, vc=vc)
expect_gt(q@totalResults, 0)
})
test_that("fetchAll fetches all results with match positions", {
skip_if_offline()
- q <- new("KorAPConnection", accessToken = NULL, verbose = TRUE) %>%
+ q <- KorAPConnection(accessToken = NULL, verbose = TRUE) %>%
corpusQuery("Ameisenplage", vc = "pubDate since 2014")
expectedResults <- q@totalResults
matches <- fetchAll(q)@collectedMatches
@@ -72,7 +72,7 @@
test_that("fetchAll fetches textClass metadatum", {
skip_if_offline()
- q <- new("KorAPConnection", accessToken = NULL, verbose = TRUE) %>%
+ q <- KorAPConnection(accessToken = NULL, verbose = TRUE) %>%
corpusQuery("Ameisenplage", vc = "pubDate since 2014")
expectedResults <- q@totalResults
matches <- fetchAll(q)@collectedMatches
@@ -83,13 +83,13 @@
test_that("Uncached query for non-matching search string return 0 results", {
skip_if_offline()
- q <- new("KorAPConnection", accessToken = NULL, cache = FALSE) %>% corpusQuery("Xmeisenplagx")
+ q <- KorAPConnection(accessToken = NULL, cache = FALSE) %>% corpusQuery("Xmeisenplagx")
expect_equal( q@totalResults, 0)
})
test_that("Empty query result is printable", {
skip_if_offline()
- q <- new("KorAPConnection", accessToken = NULL, cache = TRUE, verbose = TRUE) %>%
+ q <- KorAPConnection(accessToken = NULL, cache = TRUE, verbose = TRUE) %>%
corpusQuery("Xmeisenplagx", vc = "pubDate in 2012") %>%
fetchNext()
expect_output(print(q), "Xmeisenplagx.*pubDate in 2012")
@@ -97,7 +97,7 @@
test_that("Non-empty query result is printable", {
skip_if_offline()
- q <- new("KorAPConnection", accessToken = NULL, cache = TRUE, verbose = TRUE) %>%
+ q <- KorAPConnection(accessToken = NULL, cache = TRUE, verbose = TRUE) %>%
corpusQuery("Ameisenplage", "pubDate since 2014", fields=c("textSigle")) %>%
fetchRest()
expect_output(print(q), "Ameisenplage.*pubDate since 2014")
@@ -105,7 +105,7 @@
test_that("Query from KorAP URL returns as many results as corresponding direct query", {
skip_if_offline()
- kco <- new("KorAPConnection", accessToken = NULL)
+ kco <- KorAPConnection(accessToken = NULL)
r1 <- corpusQuery(kco, KorAPUrl = "https://korap.ids-mannheim.de/?q=Ameisenplage&cq=pubDate+since+2014&ql=poliqarp")@totalResults
r2 <- corpusQuery(kco, "Ameisenplage", "pubDate since 2014")@totalResults
expect_equal(r1, r2)
@@ -113,13 +113,13 @@
test_that("Typo in query causes error", {
skip_if_offline()
- kco <- new("KorAPConnection", accessToken = NULL, verbose = TRUE)
+ kco <- KorAPConnection(accessToken = NULL, verbose = TRUE)
expect_message(kco %>% corpusQuery("[[xx"), "unbalanced")
})
test_that("corpusQuery token API works", {
skip_if_offline()
- kco <- new("KorAPConnection", accessToken = NULL,
+ kco <- KorAPConnection(accessToken = NULL,
verbose = TRUE)
q <- corpusQuery(kco, "focus([tt/p=ADJA] {Newstickeritis})", vc = "corpusSigle=/W.D17/", metadataOnly = FALSE)
q <- fetchNext(q)
@@ -138,7 +138,7 @@
test_that("matchStart and matchEnd are present and correct", {
skip_if_offline()
- kco <- new("KorAPConnection", accessToken = NULL, verbose = TRUE)
+ kco <- KorAPConnection(accessToken = NULL, verbose = TRUE)
q <- corpusQuery(kco, "focus([tt/p=ADJA] {Newstickeritis})", vc = "corpusSigle=/W.D17/", metadataOnly = FALSE)
q <- fetchNext(q)
matches <-q@collectedMatches
@@ -147,7 +147,7 @@
})
test_that("extended metadata fields work cortrectly on instane KED", {
- kco <- new("KorAPConnection", KorAPUrl = "https://korap.ids-mannheim.de/instance/ked", accessToken = NULL,
+ kco <- KorAPConnection(KorAPUrl = "https://korap.ids-mannheim.de/instance/ked", accessToken = NULL,
verbose = TRUE)
q <- corpusQuery(
kco,
@@ -191,7 +191,7 @@
test_that("corpusQuery token API works when textSigle field is deselected", {
skip_if_offline()
- kco <- new("KorAPConnection", accessToken = NULL, verbose = TRUE)
+ kco <- KorAPConnection(accessToken = NULL, verbose = TRUE)
q <- corpusQuery(kco, "focus([tt/p=ADJA] {Newstickeritis})",
vc = "corpusSigle=/W.D17/",
fields = c("tokens"),
diff --git a/tests/testthat/test-corpusStats.R b/tests/testthat/test-corpusStats.R
index c25670d..f12159d 100644
--- a/tests/testthat/test-corpusStats.R
+++ b/tests/testthat/test-corpusStats.R
@@ -1,6 +1,6 @@
test_that("corpusStats works", {
skip_if_offline()
- stats <- new("KorAPConnection", accessToken = NULL) %>% corpusStats("pubDate since 2020 & pubDate until 2021")
+ stats <- KorAPConnection(accessToken = NULL) %>% corpusStats("pubDate since 2020 & pubDate until 2021")
expect_gt(stats@tokens, 0)
expect_gt(stats@paragraphs, 0)
expect_gt(stats@documents, 0)
@@ -9,7 +9,7 @@
test_that("corpusStats with result as df works", {
skip_if_offline()
- stats <- new("KorAPConnection", accessToken = NULL) %>% corpusStats("pubDate since 2020 & pubDate until 2021", as.df = TRUE)
+ stats <- KorAPConnection(accessToken = NULL) %>% corpusStats("pubDate since 2020 & pubDate until 2021", as.df = TRUE)
expect_gt(stats$tokens, 0)
expect_gt(stats$paragraphs, 0)
expect_gt(stats$documents, 0)
@@ -18,12 +18,12 @@
test_that("Printing corpusStats for the whole corpus works", {
skip_if_offline()
- stats <- new("KorAPConnection", accessToken = NULL) %>% corpusStats()
+ stats <- KorAPConnection(accessToken = NULL) %>% corpusStats()
expect_error(print(stats), NA)
})
test_that("Printing corpusStats for a sub-corpus works", {
skip_if_offline()
- stats <- new("KorAPConnection", accessToken = NULL) %>% corpusStats("pubDate since 2020 & pubDate until 2021")
+ stats <- KorAPConnection(accessToken = NULL) %>% corpusStats("pubDate since 2020 & pubDate until 2021")
expect_error(print(stats), NA)
})
diff --git a/tests/testthat/test-demos.R b/tests/testthat/test-demos.R
index 2e1a0a3..7bd38e4 100644
--- a/tests/testthat/test-demos.R
+++ b/tests/testthat/test-demos.R
@@ -2,7 +2,7 @@
skip_if_offline()
year <- c(2013:2018)
alternatives <- c("macht []{0,3} Sinn", "ergibt []{0,3} Sinn")
- hc <- new("KorAPConnection", accessToken = NULL, verbose = TRUE) %>%
+ hc <- KorAPConnection(accessToken = NULL, verbose = TRUE) %>%
frequencyQuery(
query = alternatives,
vc = paste("textType = /Zeit.*/ & pubDate in", year),
@@ -17,7 +17,7 @@
year <- c(2013:2018)
alternatives <- c("macht []{0,3} Sinn", "ergibt []{0,3} Sinn")
- hc <- new("KorAPConnection", accessToken = NULL, verbose = TRUE) %>%
+ hc <- KorAPConnection(accessToken = NULL, verbose = TRUE) %>%
frequencyQuery(
query = alternatives,
vc = paste("textType = /Zeit.*/ & pubDate in", year),
@@ -32,7 +32,7 @@
year <- c(2013:2018)
alternatives <- c("macht []{0,3} Sinn", "ergibt []{0,3} Sinn")
- hc <- new("KorAPConnection", accessToken = NULL, verbose = TRUE) %>%
+ hc <- KorAPConnection(accessToken = NULL, verbose = TRUE) %>%
frequencyQuery(
query = alternatives,
vc = paste("textType = /Zeit.*/ & pubDate in", year),
@@ -47,7 +47,7 @@
year <- c(2013:2018)
q <- c("macht []{0,3} Sinn")
- hc <- new("KorAPConnection", accessToken = NULL, verbose = TRUE) %>%
+ hc <- KorAPConnection(accessToken = NULL, verbose = TRUE) %>%
frequencyQuery(
query = q,
vc = paste("textType = /Zeit.*/ & pubDate in", year),
@@ -59,7 +59,7 @@
test_that("Auto conditions over time highcharter example works", {
skip_if_offline()
- kco <- new("KorAPConnection", accessToken = NULL, verbose=TRUE)
+ kco <- KorAPConnection(accessToken = NULL, verbose=TRUE)
hc <- expand_grid(
myconditions = c("textDomain = /Wirtschaft.*/",
"textDomain != /Wirtschaft.*/"),
@@ -76,7 +76,7 @@
test_that("Single condition over time highcharter example works", {
skip_if_offline()
- kco <- new("KorAPConnection", accessToken = NULL, verbose=TRUE)
+ kco <- KorAPConnection(accessToken = NULL, verbose=TRUE)
hc <- expand_grid(
condition = c("textDomain = /Wirtschaft.*/"),
year = (2011:2013)
@@ -92,7 +92,7 @@
test_that("Multiple conditions over time highcharter example works", {
skip_if_offline()
- kco <- new("KorAPConnection", accessToken = NULL, verbose=TRUE)
+ kco <- KorAPConnection(accessToken = NULL, verbose=TRUE)
hc <- expand_grid(
condition = c("textDomain = /Wirtschaft.*/",
"textDomain != /Wirtschaft.*/"),
@@ -109,7 +109,7 @@
test_that("Multiple conditions and queries over time highcharter example works", {
skip_if_offline()
- kco <- new("KorAPConnection", accessToken = NULL, verbose=TRUE)
+ kco <- KorAPConnection(accessToken = NULL, verbose=TRUE)
hc <- expand_grid(
qx = c("[tt/l=Heuschrecke]", "Ameise"),
condition = c("textDomain = /Wirtschaft.*/",
@@ -127,7 +127,7 @@
test_that("collocationScoreQuery works with hchart and hc_add_onclick_korap_search", {
skip_if_offline()
- kco <- new("KorAPConnection", accessToken = NULL, cache = TRUE, verbose = TRUE)
+ kco <- KorAPConnection(accessToken = NULL, cache = TRUE, verbose = TRUE)
df <- collocationScoreQuery(kco,"Ameisenplage", "heimgesucht", leftContextSize=0, rightContextSize=1)
hc <- hchart(df, type="spline", hcaes(label, logDice))
hc <- hc_add_onclick_korap_search(hc)
diff --git a/tests/testthat/test-textMetadata.R b/tests/testthat/test-textMetadata.R
index 2355322..ab9ba01 100644
--- a/tests/testthat/test-textMetadata.R
+++ b/tests/testthat/test-textMetadata.R
@@ -1,18 +1,18 @@
test_that("textMetadata works", {
skip_if_offline()
- m <- new("KorAPConnection", accessToken = NULL) %>% textMetadata(c("WUD17/B96/57558", "WUD17/A97/08541"))
+ m <- KorAPConnection(accessToken = NULL) %>% textMetadata(c("WUD17/B96/57558", "WUD17/A97/08541"))
expect("textType" %in% names(m), "textMetadata value should contain a textType column")
})
test_that("textMetadata works for unknown text sigles", {
skip_if_offline()
- m <- new("KorAPConnection", accessToken = NULL) %>% textMetadata(c("WUD17/B96/57558", "unknownsigle"))
+ m <- KorAPConnection(accessToken = NULL) %>% textMetadata(c("WUD17/B96/57558", "unknownsigle"))
expect("errors" %in% names(m), "textMetadata should return an errors column if a text does not exist")
})
test_that("textMetadata works with list valued fields", {
skip_if_offline()
- m <- new("KorAPConnection", accessToken = NULL) %>% textMetadata("WUD17/B96/57558")
+ m <- KorAPConnection(accessToken = NULL) %>% textMetadata("WUD17/B96/57558")
expect("staat-gesellschaft\\tbiographien-interviews" == m$textClass[1], "multiple text classes / domnains should be tab separated")
})