Created
June 12, 2020 16:25
-
-
Save brunaw/bc9c5786e5634b35d393d3daaf74aa18 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
eliminate_words <- function(first_sentence, second_sentence){ | |
if(is.na(second_sentence)) return(first_sentence) | |
first_word <- word(second_sentence, 1) | |
characters_first_word <- strsplit(first_word, split = "")[[1]] | |
# Get all possible words that could have remained in the previous | |
# sentence | |
words_list <- vector() | |
for(i in 1:length(characters_first_word)) { | |
words_list[i] <- paste(characters_first_word[1:i], collapse = "") | |
} | |
# Eliminate them | |
first_sentence <- str_split(first_sentence, " ")[[1]] | |
if(first_sentence[length(first_sentence)] %in% words_list){ | |
first_sentence <- first_sentence[-length(first_sentence)] | |
} | |
first_sentence <- paste0(first_sentence, collapse = " ") | |
return(first_sentence) | |
} | |
chords.net %>% | |
mutate( | |
second_sentence = lead(lyric, n = 1)) %>% | |
rowwise() %>% | |
mutate( | |
new_lyric = | |
eliminate_words(first_sentence = lyric, | |
second_sentence = second_sentence)) %>% | |
select(-second_sentence) %>% | |
View() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment