Collection<PageElementTemplate> templates = analysis.getTemplates(elements[1]);
for (PageElementTemplate template : templates) {
String chapterId = PageAnalysisUtils.getCurrentChapterId(analysis, template.getBeginIndex());
if ((suggestionIgnore == null) || (!suggestionIgnore.contains(chapterId))) {
String patternText = template.getParameterValue(elements[2]);
Suggestion suggestion = tmpMap.get(patternText);
if (suggestion == null) {
String chapter = PageAnalysisUtils.getCurrentChapterId(analysis, template.getBeginIndex());
suggestion = Suggestion.createSuggestion(patternText, false, chapter);
if (suggestion != null) {
tmpMap.put(patternText, suggestion);
}
}
if (suggestion != null) {
boolean automatic = false;
if (elements.length > 4) {
suggestion.setComment(template.getParameterValue(elements[4]));
if (elements.length > 6) {
if (elements[6].equalsIgnoreCase(template.getParameterValue(elements[5]))) {
automatic = true;
}
}
}
for (String elementReplacement : elementsReplacement) {
String replacementText = template.getParameterValue(elementReplacement);
if ((replacementText != null) &&
(replacementText.length() > 0)) {
suggestion.addReplacement(replacementText, automatic);
}
}
}
}
}
}
}
}
}
// Construct suggestions from AWB format
if (suggestionTypoPages != null) {
List<String> suggestionIgnore = getStringList(WPCConfigurationStringList.SUGGESTION_IGNORE);
for (String suggestionPage : suggestionTypoPages) {
Page page = pages.get(suggestionPage);
if ((page != null) && (page.getContents() != null)) {
String contents = page.getContents();
PageAnalysis analysis = page.getAnalysis(contents, true);
Collection<PageElementTag> tags = analysis.getTags(PageElementTag.TAG_OTHER_TYPO);
for (PageElementTag tag : tags) {
String chapterId = PageAnalysisUtils.getCurrentChapterId(analysis, tag.getBeginIndex());
if ((suggestionIgnore == null) || (!suggestionIgnore.contains(chapterId))) {
Parameter word = tag.getParameter("word");
Parameter find = tag.getParameter("find");
Parameter replace = tag.getParameter("replace");
Parameter disabled = tag.getParameter("disabled");
if ((word != null) && (find != null) && (replace != null) && (disabled == null)) {
String wordValue = word.getValue();
String findValue = find.getValue();
String replaceValue = replace.getValue();
if ((wordValue != null) && (findValue != null) && (replaceValue != null)) {
String cleanFindValue = Suggestion.cleanPattern(findValue);
if (cleanFindValue == null) {
System.err.println("Rejecting " + wordValue + " : " + findValue);
} else {
Suggestion suggestion = tmpMap.get(cleanFindValue);
if (suggestion == null) {
String chapter = PageAnalysisUtils.getCurrentChapterId(analysis, tag.getBeginIndex());
suggestion = Suggestion.createSuggestion(cleanFindValue, true, chapter);
if (suggestion != null) {
tmpMap.put(cleanFindValue, suggestion);
}
}
if (suggestion != null) {
suggestion.setComment("Typo AWB " + wordValue);
suggestion.addReplacement(replaceValue, false);
}
}
}
}
}