2015-04-04 13 views
2

我有一個.dict目錄,其中包含用於個性化鍵盤建議的bigrams文件。從環視Android source我收集了文件以二進制字典格式編碼,如here所述。該wiki頁面描述瞭如何將.xml文件轉換爲.dict二進制字典,而不是如何將二進制字典轉換爲可讀格式。從這些文件中提取人類可讀數據以使用Android源代碼中的函數的唯一方法是?如何將Android二進制字典解碼爲諸如.xml之類的人類可讀格式

這裏有問題的文件:

enter image description here

感謝

回答

1

我不知道這是否會在所有幫助,但在提到你的聲明「將是優秀的有一些Java代碼顯示如何從二進制字典中讀取單詞「,也許this將是一個好的開始。 This is the GIT

它說,它返回一個單詞列表,但我不知道它返回它的格式是什麼,也不知道它看起來如何。此代碼片段來自此頁面上的第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。他們編寫了這個腳本來處理這個過程。

「靈格斯轉換器是用PHP編寫的,可以轉換靈格斯的 .LD2/.LDX詞典爲人類可讀的文本文件的腳本。該腳本 基於對小云朱分析(靈格斯詞霸,提取) LD2/LDX字典格式。「

我希望也許這其中的一些至少會給你一個開始。這是一個利基需求,肯定需要一個好的解決方案。我希望你弄明白!

+1

這給了我一個很好的開始。我打算寫一些類似於Lingoes Converter的東西,然後在GitHub上發佈它。我非常感謝幫助,謝謝! – Miles 2015-04-11 02:47:00

+0

@Miles,你有什麼結果嗎?我有同樣的問題,但找不到解決方案。 – 2016-02-25 00:02:32

+1

@AndreyRudenko嗨安德烈。是的,我可以使用packages/inputmethods/LatinIME/tools/dicttool中的命令行實用程序dicttool將其解碼。有關於如何做[這裏]的更多信息(http://stackoverflow.com/questions/29949865/latinime-dicttool-for-use-with-a-v401-binary-dictionary)。我相信我必須使用[Docker](https://www.docker.com/what-docker)編譯dicttool。 – Miles 2016-02-26 04:01:18

相關問題