Update dictionary format.
app/src/main/java/eu/lepiller/nani/DictionaryDownloadActivity.java
| 64 | 64 | download_bar = findViewById(R.id.download_progress); | |
| 65 | 65 | download_button = findViewById(R.id.download_button); | |
| 66 | 66 | ||
| 67 | + | Log.d("DOWNLOAD_ACTIVITY", "dictionary " + name + " is " + (d.isDownloaded()? "downloaded": "not downloaded")); | |
| 68 | + | ||
| 67 | 69 | setResult(DictionaryActivity.DICO_REQUEST); | |
| 68 | 70 | ||
| 69 | 71 | updateLayout(false); |
app/src/main/java/eu/lepiller/nani/dictionary/DictionaryFactory.java
| 93 | 93 | chooseLanguage(synopsis), | |
| 94 | 94 | chooseLanguage(description), | |
| 95 | 95 | cacheDir, url, size, entries, sha256); | |
| 96 | + | Log.d("FACTORY", "radk: " + (d.isDownloaded()? "downloaded": "not downloaded")); | |
| 96 | 97 | } else if (type.compareTo("jmdict") == 0) { | |
| 97 | 98 | d = new JMDict(name, | |
| 98 | 99 | chooseLanguage(synopsis), |
app/src/main/java/eu/lepiller/nani/dictionary/FileDictionary.java
| 47 | 47 | ||
| 48 | 48 | @Override | |
| 49 | 49 | public boolean isDownloaded() { | |
| 50 | + | Log.d("FILEDICT", getFile().getAbsolutePath()); | |
| 50 | 51 | return getFile().exists(); | |
| 51 | 52 | } | |
| 52 | 53 | ||
… | |||
| 205 | 206 | while(c == null || !c.isEmpty()) { | |
| 206 | 207 | if(h instanceof ResultDictionary.HuffmanValue) { | |
| 207 | 208 | c = ((ResultDictionary.HuffmanValue) h).character; | |
| 208 | - | Log.v(TAG, "Huffman read: " + c); | |
| 209 | + | //Log.v(TAG, "Huffman read: " + c); | |
| 209 | 210 | b.append(c); | |
| 210 | 211 | h = huffman; | |
| 211 | 212 | } else if(h instanceof ResultDictionary.HuffmanTree) { | |
| 212 | 213 | if(bits.isEmpty()) { | |
| 213 | 214 | byte by = file.readByte(); | |
| 214 | - | Log.v(TAG, "Read byte for huffman: " + by); | |
| 215 | + | //Log.v(TAG, "Read byte for huffman: " + by); | |
| 215 | 216 | for(int i = 7; i>-1; i--) { | |
| 216 | 217 | bits.add((by&(1<<i))!=0); | |
| 217 | 218 | } | |
| 218 | - | Log.v(TAG, "Read byte for huffman: " + bits); | |
| 219 | + | //Log.v(TAG, "Read byte for huffman: " + bits); | |
| 219 | 220 | } | |
| 220 | 221 | ||
| 221 | 222 | Boolean bo = bits.get(0); | |
app/src/main/java/eu/lepiller/nani/dictionary/Jibiki.java
| 4 | 4 | ||
| 5 | 5 | import eu.lepiller.nani.R; | |
| 6 | 6 | ||
| 7 | - | public class Jibiki extends ResultDictionary { | |
| 7 | + | public class Jibiki extends ResultDictionary { | |
| 8 | 8 | Jibiki(String name, String description, String fullDescription, File cacheDir, String url, int fileSize, int entries, String hash) { | |
| 9 | 9 | super(name, description, fullDescription, cacheDir, url, fileSize, entries, hash); | |
| 10 | 10 | } |
app/src/main/java/eu/lepiller/nani/dictionary/ResultDictionary.java
| 53 | 53 | for(int i=0; i<meaning_number; i++) { | |
| 54 | 54 | ArrayList<String> sense_references = getStringList(file); | |
| 55 | 55 | ArrayList<String> sense_limits = getStringList(file); | |
| 56 | - | ArrayList<String> sense_infos = getStringList(file); | |
| 57 | 56 | ArrayList<Result.Source> sense_sources = new ArrayList<>(); | |
| 58 | 57 | int source_number = file.readShort(); | |
| 59 | 58 | for(int j=0; j<source_number; j++) { | |
| 60 | 59 | ArrayList<String> source_content = getStringList(file); | |
| 61 | 60 | boolean source_wasei = file.read() != 0; | |
| 62 | - | String source_type = getString(file); | |
| 63 | 61 | String source_language = getString(file); | |
| 64 | - | sense_sources.add(new Result.Source(source_content, source_wasei, source_type, source_language)); | |
| 62 | + | sense_sources.add(new Result.Source(source_content, source_wasei, source_language)); | |
| 65 | 63 | } | |
| 66 | - | ArrayList<Integer> sense_tags = getIntList(file); | |
| 64 | + | ArrayList<String> sense_infos = getStringList(file); | |
| 67 | 65 | ArrayList<String> sense_glosses = getHuffmanStringList(file, meaningHuffman); | |
| 68 | 66 | String sense_language = getString(file); | |
| 69 | 67 | senses.add(new Result.Sense(sense_references, sense_limits, sense_infos, sense_sources, | |
| 70 | - | sense_tags, sense_glosses, sense_language)); | |
| 68 | + | sense_glosses, sense_language)); | |
| 71 | 69 | } | |
| 72 | - | return new Result(kanjis, readings, senses); | |
| 70 | + | ||
| 71 | + | int score = file.readChar(); | |
| 72 | + | return new Result(kanjis, readings, senses, score); | |
| 73 | 73 | } | |
| 74 | 74 | ||
| 75 | 75 | private ArrayList<Integer> getValues(RandomAccessFile file, long triePos) throws IOException { | |
… | |||
| 126 | 126 | return null; | |
| 127 | 127 | ||
| 128 | 128 | // Check file format version | |
| 129 | - | if(!Arrays.equals(header, "NANI_JMDICT002".getBytes())) { | |
| 130 | - | Log.d(TAG, "search: incompatible header: " + header); | |
| 129 | + | if(!Arrays.equals(header, "NANI_JMDICT003".getBytes())) { | |
| 130 | + | StringBuilder error = new StringBuilder("search: incompatible header: ["); | |
| 131 | + | boolean first = true; | |
| 132 | + | for(byte b: header) { | |
| 133 | + | if(first) | |
| 134 | + | first = false; | |
| 135 | + | else | |
| 136 | + | error.append(", "); | |
| 137 | + | error.append(b); | |
| 138 | + | } | |
| 139 | + | error.append("]."); | |
| 140 | + | Log.d(TAG, error.toString()); | |
| 131 | 141 | throw new IncompatibleFormatException(getName()); | |
| 132 | 142 | } | |
| 133 | 143 | ||
| 134 | 144 | byte[] search = text.toLowerCase().getBytes(); | |
| 135 | 145 | ||
| 136 | - | long tagsListPos = file.readInt(); | |
| 146 | + | file.skipBytes(4); // unused | |
| 137 | 147 | long kanjiTriePos = file.readInt(); | |
| 138 | 148 | long readingTriePos = file.readInt(); | |
| 139 | 149 | long meaningTriePos = file.readInt(); | |
… | |||
| 166 | 176 | if(results == null || results.isEmpty()) | |
| 167 | 177 | return null; | |
| 168 | 178 | ||
| 179 | + | Log.d(TAG, results.size() + " result(s)"); | |
| 180 | + | ||
| 169 | 181 | ArrayList<Result> r = new ArrayList<>(); | |
| 170 | 182 | ArrayList<Integer> uniqResults = new ArrayList<>(); | |
| 171 | 183 | for(Integer i: results) { | |
app/src/main/java/eu/lepiller/nani/dictionary/WadokuPitchDictionary.java
| 27 | 27 | return R.drawable.wadoku; | |
| 28 | 28 | } | |
| 29 | 29 | ||
| 30 | - | private String findPitch(String kanji, RandomAccessFile file) throws IOException { | |
| 31 | - | return searchTrie(file, triePos, kanji.getBytes(), new TrieValsDecoder<String>() { | |
| 30 | + | private String findPitch(String kanji, String reading, RandomAccessFile file) throws IOException { | |
| 31 | + | String concat = kanji + reading; | |
| 32 | + | return searchTrie(file, triePos, concat.getBytes(), new TrieValsDecoder<String>() { | |
| 32 | 33 | @Override | |
| 33 | 34 | public String decodeVals(RandomAccessFile file, long pos) throws IOException { | |
| 34 | 35 | file.seek(pos); | |
… | |||
| 68 | 69 | } | |
| 69 | 70 | ||
| 70 | 71 | List<String> kanjis = r.getAlternatives(); | |
| 72 | + | List<Result.Reading> readings = r.getReadings(); | |
| 71 | 73 | ||
| 72 | 74 | for(String k: kanjis) { | |
| 73 | 75 | Log.d(TAG, "Searching pitch for " + Arrays.toString(k.getBytes())); | |
| 74 | - | String pitch = findPitch(k, file); | |
| 75 | - | if(pitch != null) { | |
| 76 | - | Log.d(TAG, "Found " + pitch); | |
| 77 | - | r.addPitch(k, pitch); | |
| 76 | + | for(Result.Reading read: readings) { | |
| 77 | + | List<String> readingKanjis = read.getKanjis(); | |
| 78 | + | if(readingKanjis != null && !readingKanjis.contains(k)) { | |
| 79 | + | // this is not a reading for the current kanji, so continue to the next | |
| 80 | + | // reading | |
| 81 | + | continue; | |
| 82 | + | } | |
| 83 | + | List<String> innerReadings = read.getReadings(); | |
| 84 | + | for(String reading: innerReadings) { | |
| 85 | + | String pitch = findPitch(k, reading, file); | |
| 86 | + | if(pitch != null) { | |
| 87 | + | Log.d(TAG, "Found " + pitch); | |
| 88 | + | read.addPitch(pitch); | |
| 89 | + | } | |
| 90 | + | } | |
| 78 | 91 | } | |
| 79 | 92 | } | |
| 80 | 93 | } catch (FileNotFoundException e) { | |
app/src/main/java/eu/lepiller/nani/result/Result.java
| 3 | 3 | import android.util.Log; | |
| 4 | 4 | ||
| 5 | 5 | import java.util.ArrayList; | |
| 6 | + | import java.util.List; | |
| 6 | 7 | import java.util.regex.Matcher; | |
| 7 | 8 | import java.util.regex.Pattern; | |
| 8 | 9 | ||
… | |||
| 12 | 13 | public static class Source { | |
| 13 | 14 | private ArrayList<String> content; | |
| 14 | 15 | private boolean wasei; | |
| 15 | - | private String type, language; | |
| 16 | + | private String language; | |
| 16 | 17 | ||
| 17 | - | public Source(ArrayList<String> content, boolean wasei, String type, String language) { | |
| 18 | + | public Source(ArrayList<String> content, boolean wasei, String language) { | |
| 18 | 19 | this.content = content; | |
| 19 | 20 | this.wasei = wasei; | |
| 20 | - | this.type = type; | |
| 21 | 21 | this.language = language; | |
| 22 | 22 | } | |
| 23 | 23 | } | |
| 24 | 24 | ||
| 25 | 25 | public static class Sense { | |
| 26 | 26 | private ArrayList<String> references, limits, infos, glosses; | |
| 27 | - | private ArrayList<Integer> tags; | |
| 28 | 27 | private String language; | |
| 29 | 28 | private ArrayList<Source> sources; | |
| 30 | 29 | ||
| 31 | 30 | public Sense(ArrayList<String> references, ArrayList<String> limits, ArrayList<String> infos, | |
| 32 | - | ArrayList<Source> sources, ArrayList<Integer> tags, ArrayList<String> glosses, | |
| 31 | + | ArrayList<Source> sources, ArrayList<String> glosses, | |
| 33 | 32 | String language) { | |
| 34 | 33 | this.references = references; | |
| 35 | 34 | this.limits = limits; | |
| 36 | 35 | this.infos = infos; | |
| 37 | 36 | this.sources = sources; | |
| 38 | - | this.tags = tags; | |
| 39 | 37 | this.glosses = glosses; | |
| 40 | 38 | this.language = language; | |
| 41 | 39 | } | |
… | |||
| 55 | 53 | this.pitches = new ArrayList<>(); | |
| 56 | 54 | } | |
| 57 | 55 | ||
| 58 | - | void addPitch(String pitch) { | |
| 56 | + | public List<String> getKanjis() { | |
| 57 | + | return kanjis; | |
| 58 | + | } | |
| 59 | + | ||
| 60 | + | public List<String> getReadings() { | |
| 61 | + | return readings; | |
| 62 | + | } | |
| 63 | + | ||
| 64 | + | public void addPitch(String pitch) { | |
| 59 | 65 | pitches.add(pitch); | |
| 60 | 66 | } | |
| 61 | 67 | } | |
… | |||
| 63 | 69 | private ArrayList<String> kanjis; | |
| 64 | 70 | private ArrayList<Reading> readings; | |
| 65 | 71 | private ArrayList<Sense> senses; | |
| 72 | + | private int score; | |
| 66 | 73 | ||
| 67 | - | public Result(ArrayList<String> kanjis, ArrayList<Reading> readings, ArrayList<Sense> senses) { | |
| 74 | + | public Result(ArrayList<String> kanjis, ArrayList<Reading> readings, ArrayList<Sense> senses, int score) { | |
| 68 | 75 | this.kanjis = kanjis; | |
| 69 | 76 | this.readings = readings; | |
| 70 | 77 | this.senses = senses; | |
| 78 | + | this.score = score; | |
| 71 | 79 | } | |
| 72 | 80 | ||
| 73 | 81 | public String getKanji() { | |