public static String toCapitalizeCamelCase(String s) { return WordUtils.toCapitalizeCamelCase(s); }
public void correctText(LanguageTextPane textPane, int position, int length) { StyledDocument doc = textPane.getStyledDocument(); int startWordPosition = 0; int endWordPosition = 0; String wordorig, word, wordlc, wordnew, wordnewlc; int percentageDone = 0; int nrWords = 0; int nrCorrected = 0; if (markCorrection) { nrWords = 0; nrCorrected = 0; MsgTextPane.write(String.format("%d%% corrected", percentageDone)); } position = WordUtils.startOfWord(doc, position); length = WordUtils.endOfWord(doc, position + length) - position; int endPosition = position + length; while (position < endPosition) { try { if (markCorrection) { nrWords++; } startWordPosition = WordUtils.nextAlphabetic(doc, position); endWordPosition = WordUtils.nextNonAlphabetic(doc, startWordPosition); wordorig = doc.getText(startWordPosition, endWordPosition - startWordPosition); word = language.removeDiacritics(wordorig); wordlc = language.toLowerCase(word); wordnewlc = correctWord(wordlc); // dictionary lookup for words and stems // make characters uppercase if they were originally wordnew = ""; for (int i = 0; i < word.length(); i++) { char nextChar = wordnewlc.charAt(i); if (Character.isUpperCase(word.charAt(i))) { wordnew = wordnew + language.toUpperCase(nextChar); // DocUtils does I correctly } else { wordnew = wordnew + nextChar; } } if (!wordnew.equals(wordorig)) { doc.remove(startWordPosition, endWordPosition - startWordPosition); doc.insertString(startWordPosition, wordnew, null); if (markCorrection) { doc.setCharacterAttributes(startWordPosition, wordnew.length(), Sas.red, false); nrCorrected++; } } } catch (BadLocationException ex) { MsgTextPane.write("Bad Location in runDictionary "); ex.printStackTrace(); System.exit(1); } ; position = endWordPosition; if (markCorrection) { int p = Math.round(((float) position / (float) length) * 100); if (((p / 10) * 10) > (percentageDone)) { percentageDone = ((p / 10) * 10); MsgTextPane.write(String.format("%d%% corrected", percentageDone)); } } } if (markCorrection) { MsgTextPane.write(nrWords + " words in selected text"); if (nrWords > 0) { float percentage = (float) nrCorrected / (float) nrWords; percentage = 100 * (1 - percentage); MsgTextPane.write(nrCorrected + " words corrected"); MsgTextPane.write(percentage + "% unchanged"); } markCorrection = false; } }
// ---- String ------------------------------------------------------- public static String toUnderlineName(String s) { return WordUtils.toUnderlineName(s); }