R/textToAttribute.R

Defines functions textToAttribute

Documented in textToAttribute

#' textToAttribute
#'
#' Calculate the attribute values for the given text (i.e. email)
#' @param inputText Text to be converted into attributes for prediction
#' @return data frame of attributes for the given text
#' @examples
#' textToAttribute("HELLO, this is my email?!!")
#' @export
#'

textToAttribute <- function(inputText) {

  attributeVals <- vector(,57)
  wordAttributes <- sapply(headers[1:48,], function (header) {
    splitted <- strsplit(as.character(header), "_")
    return(splitted[[1]][3])
  })
  charAttributes <- c(";", "(", "[", "!", "$", "#")

  ## Fill the attribute values
  attributeVals[1:48] <- getWordFrequency(inputText, wordAttributes)
  attributeVals[49:54] <- getCharFrequency(inputText, charAttributes)
  attributeVals[55:57] <- getCapitalAttributes(inputText)

  # Create data frame for the attributes
  attr <- as.data.frame(t(attributeVals))
  colnames(attr) <- headers[1:57,]

  return(attr)
}
megahf/spamfilter documentation built on May 29, 2019, 4:42 a.m.