Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
*
replace_grade
and replace_rating
have been moved from the *sent…
…imentr* package to *textclean*, a more fitting home.
- Loading branch information
Showing
19 changed files
with
319 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#' Replace Emoticons With Words | ||
#' | ||
#' Replaces emoticons with word equivalents. | ||
#' | ||
#' @param text.var The text variable. | ||
#' @param emoticon_dt A \pkg{data.table} of emoticons (graphical representations) | ||
#' and corresponding word meanings. | ||
#' @param \ldots Other arguments passed to \code{.mgsub} (see | ||
#' \code{sentimentr:::.mgsub} for details). | ||
#' @return Returns a vector of strings with emoticons replaced with word | ||
#' equivalents. | ||
#' @keywords emoticon | ||
#' @export | ||
#' @examples | ||
#' x <- c( | ||
#' "text from: http://www.webopedia.com/quick_ref/textmessageabbreviations_02.asp", | ||
#' "... understanding what different characters used in smiley faces mean:", | ||
#' "The close bracket represents a sideways smile )", | ||
#' "Add in the colon and you have sideways eyes :", | ||
#' "Put them together to make a smiley face :)", | ||
#' "Use the dash - to add a nose :-)", | ||
#' "Change the colon to a semi-colon ; and you have a winking face ;) with a nose ;-)", | ||
#' "Put a zero 0 (halo) on top and now you have a winking, smiling angel 0;) with a nose 0;-)", | ||
#' "Use the letter 8 in place of the colon for sunglasses 8-)", | ||
#' "Use the open bracket ( to turn the smile into a frown :-(" | ||
#' ) | ||
#' | ||
#' replace_emoticon(x) | ||
replace_emoticon <- function(text.var, emoticon_dt = lexicon::hash_emoticons, ...){ | ||
gsub("\\s+", " ", .mgsub(emoticon_dt[["x"]], paste0(" ", emoticon_dt[["y"]], " "), text.var, ...)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#' Replace Grades With Words | ||
#' | ||
#' Replaces grades with word equivalents. | ||
#' | ||
#' @param x The text variable. | ||
#' @param grade_dt A \pkg{data.table} of grades and corresponding word meanings. | ||
#' @param \ldots ignored. | ||
#' @return Returns a vector of strings with grades replaced with word | ||
#' equivalents. | ||
#' @keywords grade | ||
#' @export | ||
#' @examples | ||
#' (text <- replace_grade(c( | ||
#' "I give an A+", | ||
#' "He deserves an F", | ||
#' "It's C+ work", | ||
#' "A poor example deserves a C!" | ||
#' ))) | ||
#' replace_grade(text) | ||
replace_grade <- function (x, grade_dt = lexicon::key_grades, ...) { | ||
mgsub(x, grade_dt[["x"]], grade_dt[["y"]], fixed = FALSE) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#' Replace Ratings With Words | ||
#' | ||
#' Replaces ratings with word equivalents. | ||
#' | ||
#' @param x The text variable. | ||
#' @param rating_dt A \pkg{data.table} of ratings and corresponding word meanings. | ||
#' @param \ldots ignored. | ||
#' @return Returns a vector of strings with ratings replaced with word | ||
#' equivalents. | ||
#' @keywords rating | ||
#' @export | ||
#' @examples | ||
#' x <- c("This place receives 5 stars for their APPETIZERS!!!", | ||
#' "Four stars for the food & the guy in the blue shirt for his great vibe!", | ||
#' "10 out of 10 for both the movie and trilogy.", | ||
#' "* Both the Hot & Sour & the Egg Flower Soups were absolutely 5 Stars!", | ||
#' "For service, I give them no stars.", "This place deserves no stars.", | ||
#' "10 out of 10 stars.", | ||
#' "My rating: just 3 out of 10.", | ||
#' "If there were zero stars I would give it zero stars.", | ||
#' "Rating: 1 out of 10.", | ||
#' "I gave it 5 stars because of the sound quality.", | ||
#' "If it were possible to give them 0/10, they'd have it." | ||
#' ) | ||
#' | ||
#' replace_rating(x) | ||
replace_rating <- function (x, rating_dt = lexicon::key_ratings, ...) { | ||
gsub("\\s+", " ", .mgsub(rating_dt[["x"]], paste0(" ", | ||
rating_dt[["y"]], " "), x, ...)) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.