]> gitweb.fperrin.net Git - DictionaryPC.git/blobdiff - src/com/hughes/android/dictionary/engine/WiktionarySplitter.java
Fix splitting of Greek/Ancient Greek.
[DictionaryPC.git] / src / com / hughes / android / dictionary / engine / WiktionarySplitter.java
index a0c04c5ea22851964a8377da8884562a0a6513b9..a5dfebc88203a51321928272635f4cfd9a0571c5 100644 (file)
@@ -39,6 +39,8 @@ public class WiktionarySplitter extends org.xml.sax.helpers.DefaultHandler {
 
   // 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>>();
@@ -56,7 +58,7 @@ public class WiktionarySplitter extends org.xml.sax.helpers.DefaultHandler {
   private WiktionarySplitter() {
     List<Selector> selectors;
     for (final String code : WiktionaryLangs.wikiCodeToIsoCodeToWikiName.keySet()) {
-      //if (code.equals("en") || code.equals("de") || code.equals("fr")) {continue;}
+      //if (!code.equals("fr")) {continue;}
       selectors = new ArrayList<WiktionarySplitter.Selector>();
       pathToSelectors.put(String.format("data/inputs/%swiktionary-pages-articles.xml", code), selectors);
       for (final Map.Entry<String, String> entry : WiktionaryLangs.wikiCodeToIsoCodeToWikiName.get(code).entrySet()) {
@@ -120,6 +122,7 @@ public class WiktionarySplitter extends org.xml.sax.helpers.DefaultHandler {
             title.startsWith("Thread:") || 
             title.startsWith("Template:") ||
             title.startsWith("Summary:") ||
+            title.startsWith("Module:") ||
             // DE
             title.startsWith("Datei:") ||
             title.startsWith("Verzeichnis:") ||
@@ -127,6 +130,7 @@ public class WiktionarySplitter extends org.xml.sax.helpers.DefaultHandler {
             title.startsWith("Thesaurus:") ||
             title.startsWith("Kategorie:") ||
             title.startsWith("Hilfe:") ||
+            title.startsWith("Reim:") ||
             // FR:
             title.startsWith("Annexe:") ||
             title.startsWith("Catégori:") ||
@@ -146,6 +150,13 @@ public class WiktionarySplitter extends org.xml.sax.helpers.DefaultHandler {
             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
@@ -184,7 +195,16 @@ public class WiktionarySplitter extends org.xml.sax.helpers.DefaultHandler {
             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);
+          }
           final Section section = new Section(title, heading, sectionText);
           
           try {
@@ -198,6 +218,7 @@ public class WiktionarySplitter extends org.xml.sax.helpers.DefaultHandler {
           }
           
           text = text.substring(end);
+          break;
         }
       }
     }
@@ -268,13 +289,10 @@ public class WiktionarySplitter extends org.xml.sax.helpers.DefaultHandler {
       }
     }
     
-
     public void parse(final File file) throws ParserConfigurationException,
         SAXException, IOException {
       final SAXParser parser = SAXParserFactoryImpl.newInstance().newSAXParser();
       parser.parse(file, this);
     }
-
-    
     
 }