Skip to content

Commit

Permalink
Add candidate token sufaces in the error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
takahi-i committed Oct 16, 2017
1 parent f890b68 commit f9b485f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,35 @@ public void validate(Document document) {
if (!this.words.containsKey(reading)) {
continue;
}

List<TokenElement> tokens = this.words.get(reading);
StringBuilder stringBuilder = new StringBuilder();
for (TokenElement candidate : tokens) {
if (candidate != token && !token.getSurface().equals(candidate.getSurface())) {
addLocalizedErrorFromToken(sentence, token, candidate.getSurface());
String candidateStr = getTokenString(candidate);
if (stringBuilder.length() > 0) {
stringBuilder.append(", ");
}
stringBuilder.append(candidateStr);
}
}

String candidates = stringBuilder.toString();
if (candidates.length() > 0) {
addLocalizedErrorFromToken(sentence, token, candidates);
}
this.words.remove(reading);
}
}
}

private String getTokenString(TokenElement token) {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(token.getSurface());
return stringBuilder.toString();
}


@Override
public void preValidate(Document document) {
sentenceMap.put(document, extractSentences(document));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void detecSameReadingsInJapaneseCharacters() throws RedPenException {

RedPen redPen = new RedPen(config);
Map<Document, List<ValidationError>> errors = redPen.validate(singletonList(document));
assertEquals(2, errors.get(document).size());
assertEquals(1, errors.get(document).size());
}

@Test
Expand All @@ -60,6 +60,19 @@ void detectSameAlphabecicalReadings() throws RedPenException {

RedPen redPen = new RedPen(config);
Map<Document, List<ValidationError>> errors = redPen.validate(singletonList(document));
assertEquals(2, errors.get(document).size());
assertEquals(1, errors.get(document).size());
}

@Test
void detectMultipleSameReadings() throws RedPenException {
config = Configuration.builder("ja")
.addValidatorConfig(new ValidatorConfiguration(validatorName))
.build();

Document document = prepareSimpleDocument("このExcelはあのエクセルともこのエクセルとも違います。");

RedPen redPen = new RedPen(config);
Map<Document, List<ValidationError>> errors = redPen.validate(singletonList(document));
assertEquals(1, errors.get(document).size());
}
}

0 comments on commit f9b485f

Please sign in to comment.