blob: 7c05658612a848186271d3663759a3bfafbe762f [file] [log] [blame]
Marc Kupietzdbd431a2021-08-29 12:17:45 +02001test_that("collocationScoreQuery works", {
Marc Kupietz83d0af32022-02-24 12:49:28 +01002 skip_if_offline()
Marc Kupietzdbd431a2021-08-29 12:17:45 +02003 kco <- new("KorAPConnection", cache = TRUE, verbose = TRUE)
4 df <- collocationScoreQuery(kco, "Ameisenplage", "heimgesucht", leftContextSize=0, rightContextSize=1)
5 expect_gt(df$logDice, 1)
6 expect_equal(df$ll, ll(df$O1, df$O2, df$O, df$N, df$E, df$w))
7 expect_equal(df$pmi, pmi(df$O1, df$O2, df$O, df$N, df$E, df$w))
8 expect_equal(df$mi2, mi2(df$O1, df$O2, df$O, df$N, df$E, df$w))
9 expect_equal(df$mi3, mi3(df$O1, df$O2, df$O, df$N, df$E, df$w))
10 expect_equal(df$logDice, logDice(df$O1, df$O2, df$O, df$N, df$E, df$w))
11})
12
Marc Kupietz581a29b2021-09-04 20:51:04 +020013
14test_that("collocationAnalysis works and warns about missing token", {
Marc Kupietz83d0af32022-02-24 12:49:28 +010015 skip_if_offline()
16 kco <- new("KorAPConnection",
Marc Kupietz581a29b2021-09-04 20:51:04 +020017 accessToken = NULL,
18 verbose = TRUE)
19 expect_warning(
20 df <-
21 collocationAnalysis(
22 kco,
23 "focus([tt/p=ADJA] {Newstickeritis})",
24 vc = "corpusSigle=/W.D17/",
25 leftContextSize = 1,
26 rightContextSize = 0,
27 searchHitsSampleLimit = 100,
28 topCollocatesLimit = 1,
Marc Kupietzbdb95272021-12-22 17:42:21 +010029 exactFrequencies = FALSE,
30 maxRecurse = 2
Marc Kupietz581a29b2021-09-04 20:51:04 +020031 ),
32 "access token"
Marc Kupietza3fedbe2021-09-04 20:24:03 +020033 )
Marc Kupietzdbd431a2021-08-29 12:17:45 +020034 expect_gt(df$O, df$E)
35 expect_gt(df$logDice, 1)
36})
37
38test_that("collocationAnalysis on unaccounted strings does not error out", {
Marc Kupietz83d0af32022-02-24 12:49:28 +010039 skip_if_offline()
Marc Kupietz581a29b2021-09-04 20:51:04 +020040 kco <- new("KorAPConnection", accessToken = NULL, verbose = TRUE)
41 expect_warning(
Marc Kupietzbdb95272021-12-22 17:42:21 +010042 df <- collocationAnalysis(kco, "XXXXXXXXAmeisenplage", vc=c("corpusSigle=/WDD17/", "corpusSigle=/WUD17/"), maxRecurse = 2),
Marc Kupietz581a29b2021-09-04 20:51:04 +020043 "access token"
44 )
Marc Kupietzdbd431a2021-08-29 12:17:45 +020045 testthat::expect_equal(nrow(df), 0)
46})
Marc Kupietzd6314b62021-12-22 12:49:09 +010047
48test_that("temoveWithinSpanWorks", {
49 expect_equal(
50 removeWithinSpan("contains(<base/s=s>, (machen []{0,1} aufmerksam | aufmerksam []{0,1} machen))", "base/s=s"),
51 "(machen []{0,1} aufmerksam | aufmerksam []{0,1} machen)")
52})