Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cooccurrences()-method cannot process zero left and/or right context #117

Closed
PolMine opened this issue Dec 25, 2019 · 1 comment
Closed

Comments

@PolMine
Copy link
Collaborator

PolMine commented Dec 25, 2019

Not a problem if you just want to prepare term-cooccurrence matrices, but for phrase detection (bigram detection), this would be necessary.

@PolMine
Copy link
Collaborator Author

PolMine commented Feb 29, 2020

The problem of processzing zero values for left and/or right context had been adressed a while ago. This unit test checks whether everywhing works as expected.

test_that(
  "identity of phrase detection of decode-workflow and Cooccurrences workflow",
  {
    a <- corpus("GERMAPARLMINI") %>%
      decode(p_attribute = "word", s_attribute = character(), to = "data.table", verbose = FALSE) %>%
      ngrams(n = 2L, p_attribute = "word") %>%
      pmi(observed = count("GERMAPARLMINI", p_attribute = "word"))
    
    b <- Cooccurrences("GERMAPARLMINI", p_attribute = "word", left = 0L, right = 1L, verbose = FALSE) %>%
      decode() %>%
      pmi()
    
    a_min <- subset(a, ngram_count == 5L) %>% slot("stat") %>% data.table::setorderv(cols = c("word_1", "word_2"))
    b_min <- subset(b, ab_count == 5L) %>% slot("stat") %>% data.table::setorderv(cols = c("a_word", "b_word"))
    
    expect_identical(nrow(a_min), nrow(b_min))
    expect_identical(a_min[["word_1"]], b_min[["a_word"]])
    expect_identical(a_min[["word_2"]], b_min[["b_word"]])
  }
)

@PolMine PolMine closed this as completed Feb 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants