【问题标题】:How to decode an Android binary dictionary to a human readable format like .xml如何将 Android 二进制字典解码为人类可读的格式,如 .xml
【发布时间】:2015-04-04 01:18:19
【问题描述】:

我有一个 .dict 目录,其中包含用于我的个性化键盘建议的二元组文件。通过查看Android source,我收集到文件以二进制字典格式编码,描述为here。该 wiki 页面描述了如何将 .xml 文件转换为 .dict 二进制字典,但没有描述如何将二进制字典转换为人类可读的格式。是从这些文件中提取人类可读数据以使用 Android 源代码中的函数的唯一方法吗?

这里是有问题的文件:

谢谢

【问题讨论】:

    标签: android dictionary binary decode


    【解决方案1】:

    我不知道这是否会有所帮助,但参考您的陈述“如果有一些 java 代码显示如何从二进制字典中读取单词会很棒”,也许this 会是一个好的开始。 This is the GIT

    它说它返回一个单词列表,但我不确定它返回的格式是什么,也不知道它的外观。此代码 sn-p 来自此页面的第 240 行。

    > * Returns the list of cached files for a specific locale, one for each category.
    >      *
    >      * This will return exactly one file for each word list category that matches
    >      * the passed locale. If several files match the locale for any given category,
    >      * this returns the file with the closest match to the locale. For example, if
    >      * the passed word list is en_US, and for a category we have an en and an en_US
    >      * word list available, we'll return only the en_US one.
    >      * Thus, the list will contain as many files as there are categories.
    >      *
    >      * @param locale the locale to find the dictionary files for, as a string.
    >      * @param context the context on which to open the files upon.
    >      * @return an array of binary dictionary files, which may be empty but may not be null.
    >      */
    >     private static File[] getCachedWordLists(final String locale,
    >             final Context context) {
    >         final File[] directoryList = getCachedDirectoryList(context);
    >         if (null == directoryList) return EMPTY_FILE_ARRAY;
    >         final HashMap<String, FileAndMatchLevel> cacheFiles =
    >                 new HashMap<String, FileAndMatchLevel>();
    >         for (File directory : directoryList) {
    >             if (!directory.isDirectory()) continue;
    >             final String dirLocale = getWordListIdFromFileName(directory.getName());
    >             final int matchLevel = LocaleUtils.getMatchLevel(dirLocale, locale);
    >             if (LocaleUtils.isMatch(matchLevel)) {
    >                 final File[] wordLists = directory.listFiles();
    >                 if (null != wordLists) {
    >                     for (File wordList : wordLists) {
    >                         final String category = getCategoryFromFileName(wordList.getName());
    >                         final FileAndMatchLevel currentBestMatch = cacheFiles.get(category);
    >                         if (null == currentBestMatch || currentBestMatch.mMatchLevel < matchLevel) {
    >                             cacheFiles.put(category, new FileAndMatchLevel(wordList, matchLevel));
    >                         }
    >                     }
    >                 }
    >             }
    >         }
    >         if (cacheFiles.isEmpty()) return EMPTY_FILE_ARRAY;
    >         final File[] result = new File[cacheFiles.size()];
    >         int index = 0;
    >         for (final FileAndMatchLevel entry : cacheFiles.values()) {
    >             result[index++] = entry.mFile;
    >         }
    >         return result;
    >     }
    

    至于如何将 .dict 二进制文件转换为人类可读的形式,我知道这不是您要专门寻找的,但也许它会给您一个良好的开端。看起来你可能需要自己写一些东西来进行转换,就像他们在Here 所做的那样。他们编写了这个脚本来处理这个过程。

    "Lingoes Converter 是一个用 PHP 编写的脚本,可以转换 将 Lingoes 的 .LD2/.LDX 字典转换为人类可读的文本文件。这 脚本是基于朱小云分析(lingoes-extractor)上的 LD2/LDX 字典格式。”

    我希望其中的一些内容至少能给你一个开始。这是一个利基需求,肯定需要提供一个好的解决方案。希望你能解决!

    【讨论】:

    • 这给了我一个好的开始。我打算写一些类似于 Lingoes Converter 的东西并在 GitHub 上发布。非常感谢您的帮助,谢谢!
    • @Miles,你有任何结果吗?我遇到了同样的问题,但找不到解决方案。
    • @AndreyRudenko 嗨,安德烈。是的,我能够使用 packages/inputmethods/LatinIME/tools/dicttool 中的命令行实用程序 dicttool 对其进行解码。有更多关于如何做到这一点的信息here。我相信我必须使用 Docker 编译 dicttool。
    • 万里,可以分享一下编译好的dicttool吗?
    猜你喜欢
    • 1970-01-01
    • 2018-04-16
    • 1970-01-01
    • 2018-10-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-21
    相关资源
    最近更新 更多