I have a for loop currently that will go through a list of paragraphs separated by word, psw_list
, randomly select a word paragraph, and then change that word to another of the same part of speech. You'll notice the bottom else statement is blank because I want it to go back to the beginning of the if statement if the part of speech is any of the ones listed, but I'm not sure how, any ideas? Sorry if the code snippet is long.
for (i in iterations){ # for a specific change in the total amount of changes
n <- sample(names(psw_list), 1)
j <- sample(length(psw_list[[n]]), 1)
parsed <- spacy_parse(psw_list[[n]][j])
pos <- parsed[1,6]
# tabbing because the if starts here
if (pos == "NOUN"){
sample(nouns, 1) -> replacement
as.character(replacement) -> replacement
psw_list[[n]][j] <- replacement
} else if (pos == "ADJ"){
sample(adjs, 1) -> replacement
as.character(replacement) -> replacement
psw_list[[n]][j] <- replacement
} else if (pos == "ADV"){
sample(adverbs, 1) -> replacement
as.character(replacement) -> replacement
psw_list[[n]][j] <- replacement
} else if (pos == "PROPN"){
sample(proper_nouns, 1) -> replacement
as.character(replacement) -> replacement
psw_list[[n]][j] <- replacement
} else if (pos == "ADP"){
sample(prepositions, 1) -> replacement
as.character(replacement) -> replacement
psw_list[[n]][j] <- replacement
} else if (pos == "VERB"){
# Need to add nested if to determine if it's past or present tense
sample(verbs_past, 1) -> replacement
as.character(replacement) -> replacement
psw_list[[n]][j] <- replacement
} else if( word.pos == "AUX" || "CONJ" || "DET" || "INTJ" || "NUM" || "PART" || "PROPN" || "PUNCT"
|| "SCONJ" || "SYM" || "X") {
}
}
Aucun commentaire:
Enregistrer un commentaire