boolean isPunctuation(char in) { char[] punc = { '!', '\'', '\"', '(', ')', '-', '/', ':', ';', '.', ',' }; for (int i = 0; i < punc.length; i++) { if (punc[i] == in) { return true; } } return false; } boolean isVowel(char in) { char[] vowels = { 'a', 'e', 'i', 'o', 'u' }; for (int i = 0; i < vowels.length; i++) { if (vowels[i] == in) { return true; } } return false; } class Text { ArrayList tokens; Text(String in) { tokens = new ArrayList(); String[] tok = in.split("\\s*\\b\\s*"); for (int i = 0; i < tok.length; i++) { if (tok[i].length() == 0) { continue; } else if (tok[i].length() == 1 && isPunctuation(tok[i].charAt(0))) { tokens.add(new Punctuation(tok[i].charAt(0))); } else { tokens.add(new Word(tok[i])); } } } } class Token { } class Punctuation extends Token { char punc; Punctuation(char punc_) { punc = punc_; } String toString() { char[] tmp = { punc }; return new String(tmp); } } class Word extends Token { String word; Word(String word_) { word = word_; } Word charsObliterated(float prob) { String newString = ""; for (int i = 0; i < word.length(); i++) { if (prob > noise(word.hashCode(), (int)word.charAt(i))) { newString += " "; } else { newString += word.charAt(i); } } return new Word(newString); } Word charsMixedUp(float prob) { String newString = ""; char[] charray = word.toCharArray(); for (int i = 0; i < charray.length; i++) { if (prob > noise(word.hashCode() + (int)charray[i], 100)) { int randidx = floor(noise(word.hashCode(), (int)charray[i])*charray.length); char tmp = charray[i]; charray[i] = charray[randidx]; charray[randidx] = tmp; } } return new Word(new String(charray)); } Word mixUpSparesOutside(float prob) { String newString = ""; char[] charray = word.toCharArray(); for (int i = 1; i < charray.length - 1; i++) { if (prob > noise(word.hashCode()*i, i*10)) { int randidx = floor(noise(word.hashCode()*i, i*10)*(charray.length-2)); char tmp = charray[i]; charray[i] = charray[randidx+1]; charray[randidx+1] = tmp; } } return new Word(new String(charray)); } Word replaceVowelsWithE(float prob) { String newString = ""; for (int i = 0; i < word.length(); i++) { if (isVowel(word.charAt(i)) && prob > noise(word.hashCode()*i, (int)word.charAt(0))) { newString += "e"; } else { newString += word.charAt(i); } } return new Word(newString); } String toString() { return word; } }