@Test void testSingleSentence() throws RedPenException { HyphenationValidator validator = (HyphenationValidator) ValidatorFactory.getInstance("Hyphenation"); List<Document> documents = new ArrayList<>(); documents.add( Document.builder(new WhiteSpaceTokenizer()) .addSection(1) .addParagraph() .addSentence(new Sentence("Hyphenation is very useful to stop a sentence such as bad tempered " + "man from meaning a bad man that is tempered.", 1)) .addSentence(new Sentence("Part-time job is a valid hyphenation, since it binds " + "part to time rather than the job, which is not ill advised.", 2)) .build()); Sentence st = documents.get(0).getLastSection().getParagraph(0).getSentence(0); List<ValidationError> errors = new ArrayList<>(); validator.setErrorList(errors); validator.validate(st); assertEquals(1, errors.size(), st.toString()); st = documents.get(0).getLastSection().getParagraph(0).getSentence(1); errors = new ArrayList<>(); validator.setErrorList(errors); validator.validate(st); assertEquals(1, errors.size(), st.toString()); }
@Override public void validate(Sentence sentence) { TokenElement tokens[] = new TokenElement[]{null, null, null, null}; for (int i = 0; i < sentence.getTokens().size(); i++) { for (int j = 0; j < tokens.length - 1; j++) { tokens[j] = i + j < sentence.getTokens().size() ? sentence.getTokens().get(i + j) : null; } if (tokens[0] != null) { String hyphenatedForm = tokens[0].getSurface(); for (int j = 1; (j < tokens.length) && (tokens[j] != null); j++) { hyphenatedForm += "-" + tokens[j].getSurface(); if (inDictionary(hyphenatedForm.toLowerCase())) { addLocalizedErrorWithPosition( "HyphenatedInDictionary", sentence, tokens[0].getOffset(), tokens[j].getOffset() + tokens[j].getSurface().length(), hyphenatedForm); break; } } } } }
HyphenationValidator extends SpellingDictionaryValidator { @Override public void validate(Sentence sentence) { TokenElement tokens[] = new TokenElement[]{null, null, null, null}; for (int i = 0; i < sentence.getTokens().size(); i++) { for (int j = 0; j < tokens.length - 1; j++) { tokens[j] = i + j < sentence.getTokens().size() ? sentence.getTokens().get(i + j) : null; } if (tokens[0] != null) { String hyphenatedForm = tokens[0].getSurface(); for (int j = 1; (j < tokens.length) && (tokens[j] != null); j++) { hyphenatedForm += "-" + tokens[j].getSurface(); if (inDictionary(hyphenatedForm.toLowerCase())) { addLocalizedErrorWithPosition( "HyphenatedInDictionary", sentence, tokens[0].getOffset(), tokens[j].getOffset() + tokens[j].getSurface().length(), hyphenatedForm); break; } } } } } }
HyphenationValidator extends SpellingDictionaryValidator { @Override public void validate(Sentence sentence) { TokenElement tokens[] = new TokenElement[]{null, null, null, null}; for (int i = 0; i < sentence.getTokens().size(); i++) { for (int j = 0; j < tokens.length - 1; j++) { tokens[j] = i + j < sentence.getTokens().size() ? sentence.getTokens().get(i + j) : null; } if (tokens[0] != null) { String hyphenatedForm = tokens[0].getSurface(); for (int j = 1; (j < tokens.length) && (tokens[j] != null); j++) { hyphenatedForm += "-" + tokens[j].getSurface(); if (inDictionary(hyphenatedForm.toLowerCase())) { addLocalizedErrorWithPosition( "HyphenatedInDictionary", sentence, tokens[0].getOffset(), tokens[j].getOffset() + tokens[j].getSurface().length(), hyphenatedForm); break; } } } } }  }
HyphenationValidator extends SpellingDictionaryValidator { @Override public void validate(Sentence sentence) { TokenElement tokens[] = new TokenElement[]{null, null, null, null}; for (int i = 0; i < sentence.getTokens().size(); i++) { for (int j = 0; j < tokens.length - 1; j++) { tokens[j] = i + j < sentence.getTokens().size() ? sentence.getTokens().get(i + j) : null; } if (tokens[0] != null) { String hyphenatedForm = tokens[0].getSurface(); for (int j = 1; (j < tokens.length) && (tokens[j] != null); j++) { hyphenatedForm += "-" + tokens[j].getSurface(); if (inDictionary(hyphenatedForm.toLowerCase())) { addLocalizedErrorWithPosition( "HyphenatedInDictionary", sentence, tokens[0].getOffset(), tokens[j].getOffset() + tokens[j].getSurface().length(), hyphenatedForm); break; } } } } }  @Override void validate(Sentence sentence); }
HyphenationValidator extends SpellingDictionaryValidator { @Override public void validate(Sentence sentence) { TokenElement tokens[] = new TokenElement[]{null, null, null, null}; for (int i = 0; i < sentence.getTokens().size(); i++) { for (int j = 0; j < tokens.length - 1; j++) { tokens[j] = i + j < sentence.getTokens().size() ? sentence.getTokens().get(i + j) : null; } if (tokens[0] != null) { String hyphenatedForm = tokens[0].getSurface(); for (int j = 1; (j < tokens.length) && (tokens[j] != null); j++) { hyphenatedForm += "-" + tokens[j].getSurface(); if (inDictionary(hyphenatedForm.toLowerCase())) { addLocalizedErrorWithPosition( "HyphenatedInDictionary", sentence, tokens[0].getOffset(), tokens[j].getOffset() + tokens[j].getSurface().length(), hyphenatedForm); break; } } } } }  @Override void validate(Sentence sentence);  }