blob: 9734173f2827eb97a0d9fd870f92c90fbf03fa52 [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})",
Marc Kupietz581a29b2021-09-04 20:51:04 +020024 leftContextSize = 1,
25 rightContextSize = 0,
Marc Kupietz581a29b2021-09-04 20:51:04 +020026 ),
27 "access token"
Marc Kupietza3fedbe2021-09-04 20:24:03 +020028 )
Marc Kupietzdbd431a2021-08-29 12:17:45 +020029 expect_gt(df$O, df$E)
Marc Kupietzf9129592025-01-26 19:17:54 +010030 expect_gt(df$logDice, -1)
Marc Kupietzdbd431a2021-08-29 12:17:45 +020031})
32
33test_that("collocationAnalysis on unaccounted strings does not error out", {
Marc Kupietz83d0af32022-02-24 12:49:28 +010034 skip_if_offline()
Marc Kupietz581a29b2021-09-04 20:51:04 +020035 kco <- new("KorAPConnection", accessToken = NULL, verbose = TRUE)
36 expect_warning(
Marc Kupietzbdb95272021-12-22 17:42:21 +010037 df <- collocationAnalysis(kco, "XXXXXXXXAmeisenplage", vc=c("corpusSigle=/WDD17/", "corpusSigle=/WUD17/"), maxRecurse = 2),
Marc Kupietz581a29b2021-09-04 20:51:04 +020038 "access token"
39 )
Marc Kupietzdbd431a2021-08-29 12:17:45 +020040 testthat::expect_equal(nrow(df), 0)
41})
Marc Kupietzd6314b62021-12-22 12:49:09 +010042
Marc Kupietz9707c752025-01-08 20:51:35 +010043test_that("removeWithinSpanWorks", {
Marc Kupietzd6314b62021-12-22 12:49:09 +010044 expect_equal(
45 removeWithinSpan("contains(<base/s=s>, (machen []{0,1} aufmerksam | aufmerksam []{0,1} machen))", "base/s=s"),
46 "(machen []{0,1} aufmerksam | aufmerksam []{0,1} machen)")
47})