Created
September 3, 2012 17:06
-
-
Save joyita/3610897 to your computer and use it in GitHub Desktop.
Parsing spam
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
private static String trimShortSentanceSequences(Set<String> paragraphs) { | |
List<String> sens = new ArrayList<String>(); | |
List<Integer> counts = new ArrayList<Integer>(); | |
int cachecount = 0; | |
for(String sentances:paragraphs) { | |
counts.add(sentances.split(" ").length); | |
sens.add(sentances); | |
} | |
List<String> killindex = new ArrayList<String>(); | |
for(int i = 0; i<counts.size(); i++) { | |
Integer in = counts.get(i); | |
// arbitary decision, 15 words = short parapgraph. | |
if(in<15) { | |
cachecount++; | |
} | |
// 3 short sentances in a row. | |
if(cachecount>2) { | |
killindex.add(sens.get(i)); | |
killindex.add(sens.get(i-1)); | |
killindex.add(sens.get(i-2)); | |
cachecount = 0; | |
} | |
} | |
for(String index:killindex) { | |
sens.remove(index); | |
} | |
// rebuild document | |
StringBuilder builder = new StringBuilder(); | |
for(String sen:sens) { | |
// "\n" was used as the paragraph splitter | |
builder.append(sen + "\n"); | |
} | |
return builder.toString(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment