Skip to content

Commit

Permalink
Improve error message
Browse files Browse the repository at this point in the history
  • Loading branch information
takahi-i committed Oct 24, 2017
1 parent 42aff4a commit 3dd663d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,28 +56,23 @@ public void validate(Document document) {
}

private void generateErrors(Document document, Sentence sentence, TokenElement targetToken, String reading) {
// extract words which have same reading as targetToken
Map<String, List<CandidateTokenInfo>> variationMap = generateVariationMap(document, targetToken, reading);

for (String surface : variationMap.keySet()) {
generateError(document, sentence, targetToken, variationMap, surface);
List<CandidateTokenInfo> variationList = variationMap.get(surface);
String variation = generateErrorMessage(variationList, surface);
String positionList = addVariationPositions(variationList);
addLocalizedErrorFromToken(sentence, targetToken, variation, positionList);
}
}

private void generateError(Document document, Sentence sentence, TokenElement targetToken, Map<String, List<CandidateTokenInfo>> variationMap, String surface) {
StringBuilder candidates = new StringBuilder();
candidates.append(surface);
List<CandidateTokenInfo> candidateTokenList = variationMap.get(surface);
candidates.append("(");
candidates.append(candidateTokenList.get(0).element.getTags().get(0));
candidates.append(")");
if (document.getFileName().orElse("").length() > 0) {
candidates.append(" in ");
candidates.append(document.getFileName().orElse(""));
}
candidates.append(" at ");
candidates.append(addTokenInfo(candidateTokenList));
addLocalizedErrorFromToken(sentence, targetToken, candidates.toString());
private String generateErrorMessage(List<CandidateTokenInfo> variationList, String surface) {
StringBuilder variation = new StringBuilder();
variation.append(surface);
variation.append("(");
variation.append(variationList.get(0).element.getTags().get(0));
variation.append(")");
return variation.toString();
}

private Map<String, List<CandidateTokenInfo>> generateVariationMap(Document document, TokenElement targetToken, String reading) {
Expand All @@ -94,7 +89,7 @@ private Map<String, List<CandidateTokenInfo>> generateVariationMap(Document docu
return variationMap;
}

private String addTokenInfo(List<CandidateTokenInfo> candidateTokenList) {
private String addVariationPositions(List<CandidateTokenInfo> candidateTokenList) {
StringBuilder builder = new StringBuilder();
for (CandidateTokenInfo candidateToken : candidateTokenList) {
if (builder.length() > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ UnexpandedAcronymValidator.UnexpandedAcronym=The expanded form of the acronym {0
FrequentSentenceStartValidator.SentenceStartTooFrequent={0}% of sentences start with "{1}".
WordFrequencyValidator.WordUsedTooFrequently=The word "{0}" comprises {1}% of all words. Expected around {2}%.
GappedSectionValidator=The section "{0}" (level {1}) is misplaced. It should have level of {2}.
JapaneseExpressionVariationValidator=Found possible Japanese word variations: "{0}" and "{1}"
JapaneseExpressionVariationValidator=Found possible Japanese word variations for "{0}", "{1}" at {2}
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ UnexpandedAcronymValidator.UnexpandedAcronym=\u7701\u7565 "{0}"\u3001\u306E\u6B6
FrequentSentenceStartValidator.SentenceStartTooFrequent={0}% \u306E\u6587\u304C "{1}" \u304B\u3089\u306F\u3058\u307E\u3063\u3066\u3044\u307E\u3059\u3002
WordFrequencyValidator.WordUsedTooFrequently=\u5358\u8A9E "{0}" \u306E\u5229\u7528\u7387\u304C {1}% \u3067\u3059\u3002\u3053\u306E\u5358\u8A9E\u306E\u4F7F\u7528\u7387\u306F "{2}" \u7A0B\u5EA6\u304C\u671B\u307E\u3057\u3044\u3067\u3059\u3002
GappedSectionValidator=\u7BC0 "{0}" \uFF08\u30EC\u30D9\u30EB {1}\uFF09\u306E\u914D\u7F6E\u304C\u6B63\u3057\u304F\u3042\u308A\u307E\u305B\u3093\u3002\u30EC\u30D9\u30EB {2} \u3067\u3042\u308B\u5FC5\u8981\u304C\u3042\u308A\u307E\u3059\u3002
JapaneseExpressionVariationValidator=\u5358\u8A9E\u306E\u63FA\u3089\u304E\u306E\u53EF\u80FD\u6027\u304C\u3042\u308B\u8868\u73FE\u3001 \u201D{0}\u201D \u3001\u201D{1}\u201D\u304C\u898B\u3064\u304B\u308A\u307E\u3057\u305F\u3002
JapaneseExpressionVariationValidator=\u5358\u8A9E \u201D{0}\u201D \u306E\u63FA\u3089\u304E\u3068\u8003\u3048\u3089\u308C\u308B\u8868\u73FE \u201D{1}\u201D \u304C {2}\u3000\u3067\u898B\u3064\u304B\u308A\u307E\u3057\u305F\u3002

0 comments on commit 3dd663d

Please sign in to comment.