I have a corpus of texts from various countries. I am trying to see how often a specific term appears in the texts for each country. To do so, I am following the example here: https://quanteda.io/articles/pkgdown/examples/plotting.html#frequency-plots
freq_grouped <- textstat_frequency(dfm(full_corpus),
groups = "Country")
freq_const <- subset(freq_grouped, freq_grouped$feature %in% "constitution")
This works fine, except that this only captures the exact term ("constitution"). I'd like to be able to capture variations of the term (e.g. "charter of rights and freedoms") use globs (e.g. "*constitution*"), and count the results under the same category. I tried using a dictionary for this, but I get zero results.
dict <- dictionary(list(constitution = c('*constitution*', 'charter of rights and freedoms',
'canadian charter', 'constituição*', '*constitucion*')))
freq_const <- subset(freq_grouped, freq_grouped$feature %in% dict)
freq_const
[1] feature frequency rank docfreq group
<0 rows> (or 0-length row.names)
How can I go about achieving this?
freq_groupedobject usinggrepl()for your pattern match, or the stringi alternative togrepl(). You can convert a glob into a regex usingglob2rx(). - Ken Benoit