]> gitweb.fperrin.net Git - DictionaryPC.git/blobdiff - src/com/hughes/android/dictionary/engine/CheckDictionariesMain.java
Minor automated code simplifications.
[DictionaryPC.git] / src / com / hughes / android / dictionary / engine / CheckDictionariesMain.java
index 97cfeefb52b58f720f11f33ed6f1aa2b6241e88f..e43f1d098ff7c99903abfd3fecf2638b31e1bd53 100644 (file)
@@ -10,64 +10,81 @@ import java.util.Collections;
 import java.util.List;
 
 import com.hughes.android.dictionary.DictionaryInfo;
-import com.hughes.android.dictionary.engine.Index.IndexEntry;
-
+import com.hughes.android.dictionary.DictionaryInfo.IndexInfo;
+import com.hughes.util.CollectionUtil;
 
 public class CheckDictionariesMain {
 
-  public static void main(String[] args) throws IOException {
-    final File dictDir = new File(DictionaryBuilderMain.OUTPUTS);
-    
-    final PrintWriter dictionaryInfoOut = new PrintWriter(new File("../Dictionary/res/raw/dictionary_info.txt"));
-    dictionaryInfoOut.println("# LANG_1\t%LANG_2\tFILENAME\tFILESIZE\tNUM_MAIN_WORDS_1\tNUM_MAIN_WORDS_2\tNUM_ALL_WORDS_1\tNUM_ALL_WORDS_2");
-
-    final File[] files = dictDir.listFiles();
-    Arrays.sort(files);
-    for (final File dictFile : files) {
-      if (!dictFile.getName().endsWith("quickdic")) {
-        continue;
-      }
-      System.out.println(dictFile.getPath());
-      
-      final DictionaryInfo dictionaryInfo = new DictionaryInfo();
-      
-      final RandomAccessFile raf = new RandomAccessFile(dictFile, "r");
-      final Dictionary dict = new Dictionary(raf);
-      
-      dictionaryInfo.uncompressedFilename = dictFile.getName();
-      dictionaryInfo.uncompressedSize = dictFile.length();
-
-      // Print it.
-      final PrintWriter textOut = new PrintWriter(new File(dictFile + ".text"));
-      final List<PairEntry> sorted = new ArrayList<PairEntry>(dict.pairEntries);
-      Collections.sort(sorted);
-      for (final PairEntry pairEntry : sorted) {
-        textOut.println(pairEntry.getRawText(false));
-      }
-      textOut.close();
-      
-      // Find the stats.
-      System.out.println("Stats...");
-      for (int i = 0; i < 2; ++i) {
-        dictionaryInfo.langIsos[i] = dict.indices.get(i).sortLanguage.getIsoCode();
-        final Index index = dict.indices.get(i);
-        for (final IndexEntry indexEntry : index.sortedIndexEntries) {
-          final TokenRow tokenRow = (TokenRow) index.rows.get(indexEntry.startRow);
-          dictionaryInfo.allTokenCounts[i]++; 
-          if (tokenRow.hasMainEntry) {
-            dictionaryInfo.mainTokenCounts[i]++; 
-          }
+    static final String BASE_URL = "https://github.com/rdoeffinger/Dictionary/releases/download/v0.3-dictionaries/";
+    static final String VERSION_CODE_OLD = "v006";
+    static final String VERSION_CODE = "v007";
+
+    public static void main(String[] args) throws IOException {
+        final File dictDir = new File(DictionaryBuilderMain.OUTPUTS);
+
+        final PrintWriter dictionaryInfoOut = new PrintWriter(new File("../Dictionary/res/raw/dictionary_info.txt"));
+//    dictionaryInfoOut.println("# LANG_1\t%LANG_2\tFILENAME\tVERSION_CODE\tFILESIZE\tNUM_MAIN_WORDS_1\tNUM_MAIN_WORDS_2\tNUM_ALL_WORDS_1\tNUM_ALL_WORDS_2");
+
+        final File[] files = dictDir.listFiles();
+        final List<String> dictNames = new ArrayList<>();
+        Arrays.sort(files);
+        for (final File dictFile : files) {
+            if (!dictFile.getName().endsWith("quickdic")) {
+                continue;
+            }
+            System.out.println(dictFile.getPath());
+
+
+            final RandomAccessFile raf = new RandomAccessFile(dictFile, "r");
+            final Dictionary dict = new Dictionary(raf.getChannel());
+
+            final DictionaryInfo dictionaryInfo = dict.getDictionaryInfo();
+
+            String version_code = VERSION_CODE;
+            File zipFile = new File(dictFile.getPath() + "." + version_code + ".zip");
+            if (!zipFile.canRead()) {
+                version_code = VERSION_CODE_OLD;
+                zipFile = new File(dictFile.getPath() + "." + version_code + ".zip");
+            }
+            dictionaryInfo.uncompressedFilename = dictFile.getName();
+            dictionaryInfo.downloadUrl = BASE_URL + dictFile.getName() + "." + version_code + ".zip";
+            // TODO: zip it right here....
+            dictionaryInfo.uncompressedBytes = dictFile.length();
+            dictionaryInfo.zipBytes = zipFile.canRead() ? zipFile.length() : -1;
+
+            // Print it.
+//      final PrintWriter textOut = new PrintWriter(new BufferedWriter(new FileWriter(dictFile + ".text")));
+//      final List<PairEntry> sorted = new ArrayList<PairEntry>(dict.pairEntries);
+//      Collections.sort(sorted);
+//      for (final PairEntry pairEntry : sorted) {
+//        textOut.println(pairEntry.getRawText(false));
+//      }
+//      textOut.close();
+
+            // Find the stats.
+            System.out.println("Stats...");
+            final List<String> indexNames = new ArrayList<>();
+            for (final IndexInfo indexInfo : dictionaryInfo.indexInfos) {
+                indexNames.add(indexInfo.shortName);
+            }
+            dictNames.add(CollectionUtil.join(indexNames, "-") + "\n");
+            final String row = dictionaryInfo.append(new StringBuilder()).toString();
+            if (!zipFile.canRead()) {
+                System.err.println("Couldn't read zipfile: " + zipFile);
+            }
+            System.out.println(row + "\n");
+
+
+            dictionaryInfoOut.println(row);
+            dictionaryInfoOut.flush();
+
+            raf.close();
         }
-      }
-      
-      raf.close();
-      
-      dictionaryInfoOut.println(dictionaryInfo.toTabSeparatedString());
-      dictionaryInfoOut.flush();
-      System.out.println(dictionaryInfo.toTabSeparatedString() + "\n");
+
+        Collections.sort(dictNames);
+        System.out.println(dictNames.toString().replace(",", "  *"));
+
+        dictionaryInfoOut.close();
     }
-    
-    dictionaryInfoOut.close();
-  }
 
 }