I am in the process of writing a spell checker program. basically i split a string into individual words and then compare each string to see if it’s in the dictionary. I managed to remove the string before and after the word with the following code…
private final static String PUNC_PREFIX = "^\\p{Punct}+";
private final static String PUNC_SUFFIX = "[\\p{Punct}&&[^']+$]";
private final String fixPrefix(String sendIn) {
sendIn = sendIn.replaceFirst(PUNC_PREFIX, "");
return sendIn;
}
private final String fixSuffix(String sendIn) {
sendIn = sendIn.replaceFirst(PUNC_SUFFIX, "");
return sendIn;
}
my problem right now is for words like…”hello–there”, “all–first”, words that are split with punctuation…they’re marked as incorrectly spelt. but technically hello, there, all, first, are all words that are spelt correctly…just that there’s punctuations between them making them “wrong”. At the same time, I don’t want to just strip away all the punctuations in a word because for words like “don’t”, “won’t”, “can’t” it requires the apostrophes to be marked as correctly spelt. Any idea how I should approach solving this?
Thanks in advance
You could probably make a seperate search if you don’t find something with punctuations. The you would check the two thread words alone (not together anymore). If the second check is true; all is fine.