Marc Kupietz | dbd431a | 2021-08-29 12:17:45 +0200 | [diff] [blame] | 1 | test_that("collocationScoreQuery works", { |
Marc Kupietz | 83d0af3 | 2022-02-24 12:49:28 +0100 | [diff] [blame^] | 2 | skip_if_offline() |
Marc Kupietz | dbd431a | 2021-08-29 12:17:45 +0200 | [diff] [blame] | 3 | 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 Kupietz | 581a29b | 2021-09-04 20:51:04 +0200 | [diff] [blame] | 13 | |
| 14 | test_that("collocationAnalysis works and warns about missing token", { |
Marc Kupietz | 83d0af3 | 2022-02-24 12:49:28 +0100 | [diff] [blame^] | 15 | skip_if_offline() |
| 16 | kco <- new("KorAPConnection", |
Marc Kupietz | 581a29b | 2021-09-04 20:51:04 +0200 | [diff] [blame] | 17 | 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 Kupietz | bdb9527 | 2021-12-22 17:42:21 +0100 | [diff] [blame] | 29 | exactFrequencies = FALSE, |
| 30 | maxRecurse = 2 |
Marc Kupietz | 581a29b | 2021-09-04 20:51:04 +0200 | [diff] [blame] | 31 | ), |
| 32 | "access token" |
Marc Kupietz | a3fedbe | 2021-09-04 20:24:03 +0200 | [diff] [blame] | 33 | ) |
Marc Kupietz | dbd431a | 2021-08-29 12:17:45 +0200 | [diff] [blame] | 34 | expect_gt(df$O, df$E) |
| 35 | expect_gt(df$logDice, 1) |
| 36 | }) |
| 37 | |
| 38 | test_that("collocationAnalysis on unaccounted strings does not error out", { |
Marc Kupietz | 83d0af3 | 2022-02-24 12:49:28 +0100 | [diff] [blame^] | 39 | skip_if_offline() |
Marc Kupietz | 581a29b | 2021-09-04 20:51:04 +0200 | [diff] [blame] | 40 | kco <- new("KorAPConnection", accessToken = NULL, verbose = TRUE) |
| 41 | expect_warning( |
Marc Kupietz | bdb9527 | 2021-12-22 17:42:21 +0100 | [diff] [blame] | 42 | df <- collocationAnalysis(kco, "XXXXXXXXAmeisenplage", vc=c("corpusSigle=/WDD17/", "corpusSigle=/WUD17/"), maxRecurse = 2), |
Marc Kupietz | 581a29b | 2021-09-04 20:51:04 +0200 | [diff] [blame] | 43 | "access token" |
| 44 | ) |
Marc Kupietz | dbd431a | 2021-08-29 12:17:45 +0200 | [diff] [blame] | 45 | testthat::expect_equal(nrow(df), 0) |
| 46 | }) |
Marc Kupietz | d6314b6 | 2021-12-22 12:49:09 +0100 | [diff] [blame] | 47 | |
| 48 | test_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 | }) |