Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add step_label_emoji #135

Open
EmilHvitfeldt opened this issue Jul 30, 2021 · 0 comments
Open

add step_label_emoji #135

EmilHvitfeldt opened this issue Jul 30, 2021 · 0 comments
Labels
feature a feature request or enhancement new steps

Comments

@EmilHvitfeldt
Copy link
Member

This step will take a string/tokenlist and replace any emoji with a natural language label, that can then be used in downstream steps easier.

Should have a pre and post argument used to paste characters around the labels.

library(emoji)
library(tokenizers)
library(textrecipes)

token_x <- tokenize_words(emoji_samples$text, strip_punct = FALSE)

emoji_swap <- function(x, emoji, label, pre = "_", post = "_") {
  emoji_ind <- emoji_detect(x)

  x[emoji_ind] <- paste0(pre, label[match(x[emoji_ind], emoji)], post)
 x
}

emoji_swap(token_x[[1]], emoji_name, names(emoji_name))
#> [1] "my"            "_alarm_clock_" "didn’t"        "work"         
#> [5] "."
emoji_swap(token_x[[1]], emojis$emoji, emojis$group)
#> [1] "my"                "_Travel & Places_" "didn’t"           
#> [4] "work"              "."
emoji_swap(token_x[[1]], emojis$emoji, emojis$subgroup)
#> [1] "my"     "_time_" "didn’t" "work"   "."

Created on 2021-07-29 by the reprex package (v2.0.0)

@EmilHvitfeldt EmilHvitfeldt added the feature a feature request or enhancement label Jul 30, 2021
@EmilHvitfeldt EmilHvitfeldt added upkeep maintenance, infrastructure, and similar new steps and removed upkeep maintenance, infrastructure, and similar labels Jan 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement new steps
Projects
None yet
Development

No branches or pull requests

1 participant