R/score.R

Defines functions tm_term_score.DocumentTermMatrix tm_term_score.TermDocumentMatrix tm_term_score.PlainTextDocument tm_term_score.term_frequency tm_term_score

Documented in tm_term_score tm_term_score.DocumentTermMatrix tm_term_score.PlainTextDocument tm_term_score.TermDocumentMatrix tm_term_score.term_frequency

tm_term_score <-
function(x, terms, FUN)
    UseMethod("tm_term_score", x)

tm_term_score.term_frequency <-
function(x, terms, FUN = function(x) sum(x, na.rm = TRUE))
    FUN(x[match(terms, names(x), nomatch = 0L)])

tm_term_score.PlainTextDocument <-
function(x, terms, FUN = function(x) sum(x, na.rm = TRUE))
    tm_term_score(termFreq(x, control = list(tolower = FALSE,
                                             removePunctuation = TRUE,
                                             wordLengths = c(1, Inf))),
                  terms, FUN)

tm_term_score.TermDocumentMatrix <-
function(x, terms, FUN = col_sums)
    FUN(x[match(terms, Terms(x), nomatch = 0L), ])

tm_term_score.DocumentTermMatrix <-
function(x, terms, FUN = row_sums)
    FUN(x[, match(terms, Terms(x), nomatch = 0L)])

Try the tm package in your browser

Any scripts or data that you put into this service are public.

tm documentation built on Feb. 16, 2023, 9:40 p.m.