Find nonsense words in a text












2















I have a dataset with answers of user if they know a brand or not. Some of the users just answered nonsense, as you can see in my example.



meinstring <- c("----asdada", "no idea", "C&A", "aaaaaaaaaa", "---", "adaosdjasodajsdoad")


spamidenfifier <- function(x) {
verhaeltnis <- str_count(tolower(x), "[aeoiu]") / str_count(x)
sequenz <- sum(sequence(rle(as.character(data.frame(strsplit(as.character(x), ""))[,1]))$lengths) >= 3, na.rm = TRUE)
if(str_count(x) > 4) { weight <- 0.9 } else { weight <- 1 } ## Gewicht, weil unwahrscheinlicher bei längerem String
variation_buchstaben <- (length(unique(data.frame(strsplit(as.character(x), ""))[,1])) / str_count(x) * weight)
if(verhaeltnis < 0.2 | verhaeltnis > 0.8 | sequenz > 0 | variation_buchstaben < 0.5) {
return(TRUE)
} else {
return(FALSE)
}
}


sapply(meinstring, spamidenfifier)


Output:



----asdada            no idea                C&A         aaaaaaaaaa                --- adaosdjasodajsdoad 
TRUE FALSE FALSE TRUE TRUE FALSE


My function does not work too bad, however there might be better solutions. Is there a package or better method to identify if a word was just misspelled or a person answered nonsense.
If not, suggestions to improve that function are highly appreciated!



edit: Updated some improvements :-)










share|improve this question




















  • 1





    I think a good first order solution is see if the words can be recognized as real words. You could use a spellchecker such as hunspell and see if that package can recognize the words. If they cannot, the word is probably a bogus word.

    – Paul Hiemstra
    Nov 19 '18 at 16:51
















2















I have a dataset with answers of user if they know a brand or not. Some of the users just answered nonsense, as you can see in my example.



meinstring <- c("----asdada", "no idea", "C&A", "aaaaaaaaaa", "---", "adaosdjasodajsdoad")


spamidenfifier <- function(x) {
verhaeltnis <- str_count(tolower(x), "[aeoiu]") / str_count(x)
sequenz <- sum(sequence(rle(as.character(data.frame(strsplit(as.character(x), ""))[,1]))$lengths) >= 3, na.rm = TRUE)
if(str_count(x) > 4) { weight <- 0.9 } else { weight <- 1 } ## Gewicht, weil unwahrscheinlicher bei längerem String
variation_buchstaben <- (length(unique(data.frame(strsplit(as.character(x), ""))[,1])) / str_count(x) * weight)
if(verhaeltnis < 0.2 | verhaeltnis > 0.8 | sequenz > 0 | variation_buchstaben < 0.5) {
return(TRUE)
} else {
return(FALSE)
}
}


sapply(meinstring, spamidenfifier)


Output:



----asdada            no idea                C&A         aaaaaaaaaa                --- adaosdjasodajsdoad 
TRUE FALSE FALSE TRUE TRUE FALSE


My function does not work too bad, however there might be better solutions. Is there a package or better method to identify if a word was just misspelled or a person answered nonsense.
If not, suggestions to improve that function are highly appreciated!



edit: Updated some improvements :-)










share|improve this question




















  • 1





    I think a good first order solution is see if the words can be recognized as real words. You could use a spellchecker such as hunspell and see if that package can recognize the words. If they cannot, the word is probably a bogus word.

    – Paul Hiemstra
    Nov 19 '18 at 16:51














2












2








2


1






I have a dataset with answers of user if they know a brand or not. Some of the users just answered nonsense, as you can see in my example.



meinstring <- c("----asdada", "no idea", "C&A", "aaaaaaaaaa", "---", "adaosdjasodajsdoad")


spamidenfifier <- function(x) {
verhaeltnis <- str_count(tolower(x), "[aeoiu]") / str_count(x)
sequenz <- sum(sequence(rle(as.character(data.frame(strsplit(as.character(x), ""))[,1]))$lengths) >= 3, na.rm = TRUE)
if(str_count(x) > 4) { weight <- 0.9 } else { weight <- 1 } ## Gewicht, weil unwahrscheinlicher bei längerem String
variation_buchstaben <- (length(unique(data.frame(strsplit(as.character(x), ""))[,1])) / str_count(x) * weight)
if(verhaeltnis < 0.2 | verhaeltnis > 0.8 | sequenz > 0 | variation_buchstaben < 0.5) {
return(TRUE)
} else {
return(FALSE)
}
}


sapply(meinstring, spamidenfifier)


Output:



----asdada            no idea                C&A         aaaaaaaaaa                --- adaosdjasodajsdoad 
TRUE FALSE FALSE TRUE TRUE FALSE


My function does not work too bad, however there might be better solutions. Is there a package or better method to identify if a word was just misspelled or a person answered nonsense.
If not, suggestions to improve that function are highly appreciated!



edit: Updated some improvements :-)










share|improve this question
















I have a dataset with answers of user if they know a brand or not. Some of the users just answered nonsense, as you can see in my example.



meinstring <- c("----asdada", "no idea", "C&A", "aaaaaaaaaa", "---", "adaosdjasodajsdoad")


spamidenfifier <- function(x) {
verhaeltnis <- str_count(tolower(x), "[aeoiu]") / str_count(x)
sequenz <- sum(sequence(rle(as.character(data.frame(strsplit(as.character(x), ""))[,1]))$lengths) >= 3, na.rm = TRUE)
if(str_count(x) > 4) { weight <- 0.9 } else { weight <- 1 } ## Gewicht, weil unwahrscheinlicher bei längerem String
variation_buchstaben <- (length(unique(data.frame(strsplit(as.character(x), ""))[,1])) / str_count(x) * weight)
if(verhaeltnis < 0.2 | verhaeltnis > 0.8 | sequenz > 0 | variation_buchstaben < 0.5) {
return(TRUE)
} else {
return(FALSE)
}
}


sapply(meinstring, spamidenfifier)


Output:



----asdada            no idea                C&A         aaaaaaaaaa                --- adaosdjasodajsdoad 
TRUE FALSE FALSE TRUE TRUE FALSE


My function does not work too bad, however there might be better solutions. Is there a package or better method to identify if a word was just misspelled or a person answered nonsense.
If not, suggestions to improve that function are highly appreciated!



edit: Updated some improvements :-)







r text-mining stringr stringi






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 '18 at 18:59







Markus LnGa

















asked Nov 19 '18 at 15:54









Markus LnGaMarkus LnGa

1129




1129








  • 1





    I think a good first order solution is see if the words can be recognized as real words. You could use a spellchecker such as hunspell and see if that package can recognize the words. If they cannot, the word is probably a bogus word.

    – Paul Hiemstra
    Nov 19 '18 at 16:51














  • 1





    I think a good first order solution is see if the words can be recognized as real words. You could use a spellchecker such as hunspell and see if that package can recognize the words. If they cannot, the word is probably a bogus word.

    – Paul Hiemstra
    Nov 19 '18 at 16:51








1




1





I think a good first order solution is see if the words can be recognized as real words. You could use a spellchecker such as hunspell and see if that package can recognize the words. If they cannot, the word is probably a bogus word.

– Paul Hiemstra
Nov 19 '18 at 16:51





I think a good first order solution is see if the words can be recognized as real words. You could use a spellchecker such as hunspell and see if that package can recognize the words. If they cannot, the word is probably a bogus word.

– Paul Hiemstra
Nov 19 '18 at 16:51












1 Answer
1






active

oldest

votes


















1














Just my spontaneous idea:



meinstring <- c("----asdada", "no idea", "C&A", "aaaaaaaaaa", "---", "adaosdjasodajsdoad", "+-*-", "*-+-", "adfpdflrraaeea")

grepl('^\W+$|(?:[-!@#$%^&*\[\]()";:_<>.,=+/ ]){2,}|[-!@#$%^&*\[\]()";:_<>.,=+/ ]{3,}|[aeoiu]{3,}',
meinstring , perl = T) & !grepl("iou|zweieiig", meinstring) # add the exceptions in the second grepl.

[1] TRUE FALSE FALSE TRUE TRUE FALSE TRUE TRUE TRUE




There is no neat perfect solution.






share|improve this answer





















  • 1





    Interesting try, but your solution will find words like delicious (iou) as nonsense.

    – iod
    Nov 19 '18 at 16:28











  • hehe :D, sure also in in german there is zweieiig, Donauauen, Donau-Auen, Treueeid some micro is well needed.

    – Andre Elrico
    Nov 19 '18 at 16:30













  • Yeah, I think a real solution will have to use something like the lexicon package and search through it. Which could be overkill, depending on how big the actual data is.

    – iod
    Nov 19 '18 at 16:35











  • wow i understand nothing ;-). But it does not work too bad. Guess it might be better than my solution

    – Markus LnGa
    Nov 19 '18 at 18:13











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53378325%2ffind-nonsense-words-in-a-text%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














Just my spontaneous idea:



meinstring <- c("----asdada", "no idea", "C&A", "aaaaaaaaaa", "---", "adaosdjasodajsdoad", "+-*-", "*-+-", "adfpdflrraaeea")

grepl('^\W+$|(?:[-!@#$%^&*\[\]()";:_<>.,=+/ ]){2,}|[-!@#$%^&*\[\]()";:_<>.,=+/ ]{3,}|[aeoiu]{3,}',
meinstring , perl = T) & !grepl("iou|zweieiig", meinstring) # add the exceptions in the second grepl.

[1] TRUE FALSE FALSE TRUE TRUE FALSE TRUE TRUE TRUE




There is no neat perfect solution.






share|improve this answer





















  • 1





    Interesting try, but your solution will find words like delicious (iou) as nonsense.

    – iod
    Nov 19 '18 at 16:28











  • hehe :D, sure also in in german there is zweieiig, Donauauen, Donau-Auen, Treueeid some micro is well needed.

    – Andre Elrico
    Nov 19 '18 at 16:30













  • Yeah, I think a real solution will have to use something like the lexicon package and search through it. Which could be overkill, depending on how big the actual data is.

    – iod
    Nov 19 '18 at 16:35











  • wow i understand nothing ;-). But it does not work too bad. Guess it might be better than my solution

    – Markus LnGa
    Nov 19 '18 at 18:13
















1














Just my spontaneous idea:



meinstring <- c("----asdada", "no idea", "C&A", "aaaaaaaaaa", "---", "adaosdjasodajsdoad", "+-*-", "*-+-", "adfpdflrraaeea")

grepl('^\W+$|(?:[-!@#$%^&*\[\]()";:_<>.,=+/ ]){2,}|[-!@#$%^&*\[\]()";:_<>.,=+/ ]{3,}|[aeoiu]{3,}',
meinstring , perl = T) & !grepl("iou|zweieiig", meinstring) # add the exceptions in the second grepl.

[1] TRUE FALSE FALSE TRUE TRUE FALSE TRUE TRUE TRUE




There is no neat perfect solution.






share|improve this answer





















  • 1





    Interesting try, but your solution will find words like delicious (iou) as nonsense.

    – iod
    Nov 19 '18 at 16:28











  • hehe :D, sure also in in german there is zweieiig, Donauauen, Donau-Auen, Treueeid some micro is well needed.

    – Andre Elrico
    Nov 19 '18 at 16:30













  • Yeah, I think a real solution will have to use something like the lexicon package and search through it. Which could be overkill, depending on how big the actual data is.

    – iod
    Nov 19 '18 at 16:35











  • wow i understand nothing ;-). But it does not work too bad. Guess it might be better than my solution

    – Markus LnGa
    Nov 19 '18 at 18:13














1












1








1







Just my spontaneous idea:



meinstring <- c("----asdada", "no idea", "C&A", "aaaaaaaaaa", "---", "adaosdjasodajsdoad", "+-*-", "*-+-", "adfpdflrraaeea")

grepl('^\W+$|(?:[-!@#$%^&*\[\]()";:_<>.,=+/ ]){2,}|[-!@#$%^&*\[\]()";:_<>.,=+/ ]{3,}|[aeoiu]{3,}',
meinstring , perl = T) & !grepl("iou|zweieiig", meinstring) # add the exceptions in the second grepl.

[1] TRUE FALSE FALSE TRUE TRUE FALSE TRUE TRUE TRUE




There is no neat perfect solution.






share|improve this answer















Just my spontaneous idea:



meinstring <- c("----asdada", "no idea", "C&A", "aaaaaaaaaa", "---", "adaosdjasodajsdoad", "+-*-", "*-+-", "adfpdflrraaeea")

grepl('^\W+$|(?:[-!@#$%^&*\[\]()";:_<>.,=+/ ]){2,}|[-!@#$%^&*\[\]()";:_<>.,=+/ ]{3,}|[aeoiu]{3,}',
meinstring , perl = T) & !grepl("iou|zweieiig", meinstring) # add the exceptions in the second grepl.

[1] TRUE FALSE FALSE TRUE TRUE FALSE TRUE TRUE TRUE




There is no neat perfect solution.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 19 '18 at 16:32

























answered Nov 19 '18 at 16:21









Andre ElricoAndre Elrico

5,72011029




5,72011029








  • 1





    Interesting try, but your solution will find words like delicious (iou) as nonsense.

    – iod
    Nov 19 '18 at 16:28











  • hehe :D, sure also in in german there is zweieiig, Donauauen, Donau-Auen, Treueeid some micro is well needed.

    – Andre Elrico
    Nov 19 '18 at 16:30













  • Yeah, I think a real solution will have to use something like the lexicon package and search through it. Which could be overkill, depending on how big the actual data is.

    – iod
    Nov 19 '18 at 16:35











  • wow i understand nothing ;-). But it does not work too bad. Guess it might be better than my solution

    – Markus LnGa
    Nov 19 '18 at 18:13














  • 1





    Interesting try, but your solution will find words like delicious (iou) as nonsense.

    – iod
    Nov 19 '18 at 16:28











  • hehe :D, sure also in in german there is zweieiig, Donauauen, Donau-Auen, Treueeid some micro is well needed.

    – Andre Elrico
    Nov 19 '18 at 16:30













  • Yeah, I think a real solution will have to use something like the lexicon package and search through it. Which could be overkill, depending on how big the actual data is.

    – iod
    Nov 19 '18 at 16:35











  • wow i understand nothing ;-). But it does not work too bad. Guess it might be better than my solution

    – Markus LnGa
    Nov 19 '18 at 18:13








1




1





Interesting try, but your solution will find words like delicious (iou) as nonsense.

– iod
Nov 19 '18 at 16:28





Interesting try, but your solution will find words like delicious (iou) as nonsense.

– iod
Nov 19 '18 at 16:28













hehe :D, sure also in in german there is zweieiig, Donauauen, Donau-Auen, Treueeid some micro is well needed.

– Andre Elrico
Nov 19 '18 at 16:30







hehe :D, sure also in in german there is zweieiig, Donauauen, Donau-Auen, Treueeid some micro is well needed.

– Andre Elrico
Nov 19 '18 at 16:30















Yeah, I think a real solution will have to use something like the lexicon package and search through it. Which could be overkill, depending on how big the actual data is.

– iod
Nov 19 '18 at 16:35





Yeah, I think a real solution will have to use something like the lexicon package and search through it. Which could be overkill, depending on how big the actual data is.

– iod
Nov 19 '18 at 16:35













wow i understand nothing ;-). But it does not work too bad. Guess it might be better than my solution

– Markus LnGa
Nov 19 '18 at 18:13





wow i understand nothing ;-). But it does not work too bad. Guess it might be better than my solution

– Markus LnGa
Nov 19 '18 at 18:13




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53378325%2ffind-nonsense-words-in-a-text%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Guess what letter conforming each word

Port of Spain

Run scheduled task as local user group (not BUILTIN)