Skip to content

Commit

Permalink
fix a bug of ti when input_corpus is NULL, ref #49
Browse files Browse the repository at this point in the history
  • Loading branch information
chainsawriot committed May 17, 2021
1 parent 44015e0 commit 6c0b9ce
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 7 deletions.
3 changes: 3 additions & 0 deletions R/oolong_tm.R
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,9 @@

.generate_test_content <- function(input_model, input_corpus = NULL, n_top_terms = 5, bottom_terms_percentile = 0.6, exact_n = NULL, frac = 0.01, n_top_topics = 3, n_topiclabel_words = 8, difficulty = 1, use_frex_words = FALSE, input_dfm = NULL, btm_dataframe = NULL, type = "witi", n_correct_ws = 3, wsi_n_top_terms = 20) {
ingredients <- .extract_ingredients(.convert_input_model_s3(input_model), n_top_terms = n_top_terms, difficulty = difficulty, need_topic = !is.null(input_corpus), n_topiclabel_words = n_topiclabel_words, input_dfm = input_dfm, use_frex_words = use_frex_words, input_corpus = input_corpus, btm_dataframe = btm_dataframe)
if (type %in% c("ti") & is.null(ingredients$theta)) {
.cstop(TRUE, "input_corpus can't be NULL for generating oolong test object with only topic intrusion test.")
}
test_content <- list()
if (type %in% c("wi", "witi")) {
test_content$word <- .generate_word_intrusion_test(ingredients, bottom_terms_percentile = bottom_terms_percentile, n_top_terms = n_top_terms)
Expand Down
2 changes: 1 addition & 1 deletion README.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion overview_gh.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ All the API endpoints are the same, except the one for the creation of topic int

```{r warplda2}
### Just word intrusion test.
oolong_test <- ti(abstracts_warplda, userid = "Lionel")
oolong_test <- wi(abstracts_warplda, userid = "Lionel")
oolong_test
```

Expand Down
6 changes: 4 additions & 2 deletions overview_gh.md
Original file line number Diff line number Diff line change
Expand Up @@ -373,15 +373,17 @@ topic intrusion test cases. You must supply also the `input_dfm`.

``` r
### Just word intrusion test.
oolong_test <- ti(abstracts_warplda, userid = "Lionel")
oolong_test <- wi(abstracts_warplda, userid = "Lionel")
oolong_test
#>
#> ── oolong (topic model) ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
#> WI ✖ TI ✖ WSI
#> WI ✖ TI ✖ WSI
#> ☺ Lionel
#> ℹ WI: k = 20, 0 coded.
#>
#> ── Methods ──
#>
#> • <$do_word_intrusion_test()>: do word intrusion test
#> • <$lock()>: finalize and see the results
```

Expand Down
5 changes: 4 additions & 1 deletion tests/testthat/test-ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ test_that("wi basic", {

test_that("witi basic", {
skip_on_cran()
expect_error(witi(abstracts_stm, abstracts$text), NA)
expect_error(witi(abstracts_stm, abstracts$text), NA)
## We need to talk about how to handle these two.
expect_error(witi(abstracts_stm), NA)
expect_error(witi(abstracts_warplda), NA)
expect_error(witi(abstracts_warplda, abstracts$text))
expect_error(witi(abstracts_warplda, abstracts$text, input_dfm = abstracts_dfm), NA)
expect_error(witi(abstracts_btm, abstracts$text))
Expand Down
2 changes: 1 addition & 1 deletion vig_body.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ All the API endpoints are the same, except the one for the creation of topic int

```{r warplda2}
### Just word intrusion test.
oolong_test <- ti(abstracts_warplda, userid = "Lionel")
oolong_test <- wi(abstracts_warplda, userid = "Lionel")
oolong_test
```

Expand Down
2 changes: 1 addition & 1 deletion vignettes/overview.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ All the API endpoints are the same, except the one for the creation of topic int

```{r warplda2}
### Just word intrusion test.
oolong_test <- ti(abstracts_warplda, userid = "Lionel")
oolong_test <- wi(abstracts_warplda, userid = "Lionel")
oolong_test
```

Expand Down

0 comments on commit 6c0b9ce

Please sign in to comment.