// The matches the whole line, otherwise regexes don't work well on French:
// {{=uk=}}
+ // Spanish has no initial headings, tried to also detect {{ES as such
+ // with "^(\\{\\{ES|(=+)[^=]).*$" but that broke English.
static final Pattern headingStart = Pattern.compile("^(=+)[^=].*$", Pattern.MULTILINE);
final Map<String,List<Selector>> pathToSelectors = new LinkedHashMap<String, List<Selector>>();
title.startsWith("Thread:") ||
title.startsWith("Template:") ||
title.startsWith("Summary:") ||
+ title.startsWith("Module:") ||
// DE
title.startsWith("Datei:") ||
title.startsWith("Verzeichnis:") ||
title.startsWith("Thesaurus:") ||
title.startsWith("Kategorie:") ||
title.startsWith("Hilfe:") ||
+ title.startsWith("Reim:") ||
// FR:
title.startsWith("Annexe:") ||
title.startsWith("Catégori:") ||
title.startsWith("Categoria:") ||
title.startsWith("Aiuto:") ||
title.startsWith("Portail:") ||
+ // ES
+ title.startsWith("Apéndice:") ||
+ title.startsWith("Archivo:") ||
+ title.startsWith("Ayuda:") ||
+ title.startsWith("Categoría:") ||
+ title.startsWith("Plantilla:") ||
+ title.startsWith("Wikcionario:") ||
// sentinel
false
}
String text = textBuilder.toString();
+ String translingual = "";
while (text.length() > 0) {
// Find start.
final String heading = startMatcher.group();
for (final Selector selector : currentSelectors) {
+ if (heading.indexOf("Translingual") != -1) {
+ // Find end.
+ final int depth = startMatcher.group(1).length();
+ final Pattern endPattern = Pattern.compile(String.format("^={1,%d}[^=].*$", depth), Pattern.MULTILINE);
+
+ final Matcher endMatcher = endPattern.matcher(text);
+ if (endMatcher.find()) {
+ int end = endMatcher.start();
+ translingual = text.substring(0, endMatcher.start());
+ text = text.substring(end);
+ break;
+ }
+ }
if (selector.pattern.matcher(heading).find()) {
// Find end.
end = text.length();
}
- final String sectionText = text.substring(0, end);
+ String sectionText = text.substring(0, end);
+ // Hack to remove empty dummy section from French
+ if (sectionText.startsWith("\n=== {{S|étymologie}} ===\n: {{ébauche-étym"))
+ {
+ int dummy_end = sectionText.indexOf("}}", 41) + 2;
+ while (dummy_end + 1 < sectionText.length() &&
+ sectionText.charAt(dummy_end) == '\n' &&
+ sectionText.charAt(dummy_end + 1) == '\n') ++dummy_end;
+ sectionText = sectionText.substring(dummy_end);
+ }
+ if (heading.indexOf("Japanese") == -1) sectionText += translingual;
final Section section = new Section(title, heading, sectionText);
try {
}
text = text.substring(end);
+ break;
}
}
}