Apply several rules of select_collocations() to the same
scores and compare what they keep: how many n-grams of each size, how
many occurrences they cover (the word positions that will be merged), how
frequent they are, how many are kept by every rule, and examples kept by
one rule only.
Arguments
- scores
Output of
score_collocations().- rules
A named list of rules, each a list of arguments of
select_collocations().- n_examples
Integer scalar, number of examples kept by one rule only (the most frequent).
- ...
Not used: an argument renamed in the development version of mintR gives an error naming its replacement, any other one an error.
Value
A data.table with one row per rule and n-gram size: rule,
ngram, n_selected, occurrences (sum of counts), median_count,
n_shared (selected by every rule) and only_here (examples selected by
this rule only).
Examples
df <- data.frame(id = 1:4, text = c(
"monetary policy and fiscal policy", "the monetary policy rule",
"monetary policy matters", "a policy of growth"
))
scores <- score_collocations(df, min_count = 1)
compare_collocation_rules(scores, list(
npmi = list(rule = "npmi", min_npmi = 0.3, min_count = 1),
top_2 = list(rule = "top_n", n = 2, min_count = 1)
))
#> rule ngram n_selected occurrences median_count n_shared
#> <char> <int> <int> <int> <num> <int>
#> 1: npmi 2 4 6 1 1
#> 2: npmi 3 2 2 1 1
#> 3: top_2 2 1 3 3 1
#> 4: top_2 3 1 1 1 1
#> only_here
#> <char>
#> 1: fiscal_policy, policy_rule, policy_matters
#> 2: monetary_policy_matters
#> 3:
#> 4:
