Marc Kupietz | dbd431a | 2021-08-29 12:17:45 +0200 | [diff] [blame] | 1 | test_that("collocationScoreQuery works", { |
| 2 | kco <- new("KorAPConnection", cache = TRUE, verbose = TRUE) |
| 3 | df <- collocationScoreQuery(kco, "Ameisenplage", "heimgesucht", leftContextSize=0, rightContextSize=1) |
| 4 | expect_gt(df$logDice, 1) |
| 5 | expect_equal(df$ll, ll(df$O1, df$O2, df$O, df$N, df$E, df$w)) |
| 6 | expect_equal(df$pmi, pmi(df$O1, df$O2, df$O, df$N, df$E, df$w)) |
| 7 | expect_equal(df$mi2, mi2(df$O1, df$O2, df$O, df$N, df$E, df$w)) |
| 8 | expect_equal(df$mi3, mi3(df$O1, df$O2, df$O, df$N, df$E, df$w)) |
| 9 | expect_equal(df$logDice, logDice(df$O1, df$O2, df$O, df$N, df$E, df$w)) |
| 10 | }) |
| 11 | |
Marc Kupietz | 581a29b | 2021-09-04 20:51:04 +0200 | [diff] [blame] | 12 | |
| 13 | test_that("collocationAnalysis works and warns about missing token", { |
| 14 | kco <- new("KorAPConnection", |
| 15 | accessToken = NULL, |
| 16 | verbose = TRUE) |
| 17 | expect_warning( |
| 18 | df <- |
| 19 | collocationAnalysis( |
| 20 | kco, |
| 21 | "focus([tt/p=ADJA] {Newstickeritis})", |
| 22 | vc = "corpusSigle=/W.D17/", |
| 23 | leftContextSize = 1, |
| 24 | rightContextSize = 0, |
| 25 | searchHitsSampleLimit = 100, |
| 26 | topCollocatesLimit = 1, |
Marc Kupietz | bdb9527 | 2021-12-22 17:42:21 +0100 | [diff] [blame^] | 27 | exactFrequencies = FALSE, |
| 28 | maxRecurse = 2 |
Marc Kupietz | 581a29b | 2021-09-04 20:51:04 +0200 | [diff] [blame] | 29 | ), |
| 30 | "access token" |
Marc Kupietz | a3fedbe | 2021-09-04 20:24:03 +0200 | [diff] [blame] | 31 | ) |
Marc Kupietz | dbd431a | 2021-08-29 12:17:45 +0200 | [diff] [blame] | 32 | expect_gt(df$O, df$E) |
| 33 | expect_gt(df$logDice, 1) |
| 34 | }) |
| 35 | |
| 36 | test_that("collocationAnalysis on unaccounted strings does not error out", { |
Marc Kupietz | 581a29b | 2021-09-04 20:51:04 +0200 | [diff] [blame] | 37 | kco <- new("KorAPConnection", accessToken = NULL, verbose = TRUE) |
| 38 | expect_warning( |
Marc Kupietz | bdb9527 | 2021-12-22 17:42:21 +0100 | [diff] [blame^] | 39 | df <- collocationAnalysis(kco, "XXXXXXXXAmeisenplage", vc=c("corpusSigle=/WDD17/", "corpusSigle=/WUD17/"), maxRecurse = 2), |
Marc Kupietz | 581a29b | 2021-09-04 20:51:04 +0200 | [diff] [blame] | 40 | "access token" |
| 41 | ) |
Marc Kupietz | dbd431a | 2021-08-29 12:17:45 +0200 | [diff] [blame] | 42 | testthat::expect_equal(nrow(df), 0) |
| 43 | }) |
Marc Kupietz | d6314b6 | 2021-12-22 12:49:09 +0100 | [diff] [blame] | 44 | |
| 45 | test_that("temoveWithinSpanWorks", { |
| 46 | expect_equal( |
| 47 | removeWithinSpan("contains(<base/s=s>, (machen []{0,1} aufmerksam | aufmerksam []{0,1} machen))", "base/s=s"), |
| 48 | "(machen []{0,1} aufmerksam | aufmerksam []{0,1} machen)") |
| 49 | }) |