<string name="SA">Sanskrit</string>
<string name="SR">Serbisch</string>
<string name="SK">Slowakisch</string>
+ <string name="SL">Slowenisch</string>
<string name="SO">Somali</string>
<string name="ES">Spanisch</string>
<string name="SW">Swahili</string>
<string name="unzippingDictionary">Wörterbuch entpacken…</string>
<string name="failedToUnzipDictionary">Fehler beim Entpackung der Wörterbuch…</string>
<string name="invalidDictionary">Invalid dictionary: file=%1$s, error=%2$s</string>
- <string name="noSearchResults">Keine Treffe.</string>
+ <string name="noSearchResults">Kein Treffer.</string>
<string name="aboutDictionary">Über Wörterbuch…</string>
<string name="randomWord">Random Wort</string>
<string name="fontFailure">Font failure: %s</string>
<string name="GA">Irish</string>
<string name="IT">Italian</string>
<string name="LA">Latin</string>
+ <string name="LO">Lao</string>
<string name="LV">Latvian</string>
<string name="LT">Lithuanian</string>
<string name="JA">Japanese</string>
<string name="KO">Korean</string>
<string name="KU">Kurdish</string>
<string name="MS">Malay</string>
+ <string name="ML">Malayalam</string>
<string name="MI">Maori</string>
<string name="MN">Mongolian</string>
<string name="NE">Nepali</string>
<string name="SA">Sanskrit</string>
<string name="SR">Serbian</string>
<string name="SK">Slovak</string>
+ <string name="SL">Slovenian</string>
<string name="SO">Somali</string>
<string name="ES">Spanish</string>
<string name="SW">Swahili</string>
import java.io.PrintStream;
import java.io.RandomAccessFile;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import com.hughes.android.dictionary.DictionaryInfo;
static final int CACHE_SIZE = 5000;
- static final int CURRENT_DICT_VERSION = 4;
+ static final int CURRENT_DICT_VERSION = 5;
static final String END_OF_DICTIONARY = "END OF DICTIONARY";
// persisted
public final String dictInfo;
public final List<PairEntry> pairEntries;
public final List<TextEntry> textEntries;
+ public final List<HtmlEntry> htmlEntries;
public final List<EntrySource> sources;
public final List<Index> indices;
this.dictInfo = dictInfo;
pairEntries = new ArrayList<PairEntry>();
textEntries = new ArrayList<TextEntry>();
+ htmlEntries = new ArrayList<HtmlEntry>();
sources = new ArrayList<EntrySource>();
indices = new ArrayList<Index>();
}
pairEntries = CachingList.create(RAFList.create(raf, new PairEntry.Serializer(this), raf.getFilePointer()), CACHE_SIZE);
textEntries = CachingList.create(RAFList.create(raf, new TextEntry.Serializer(this), raf.getFilePointer()), CACHE_SIZE);
+ if (dictFileVersion >= 5) {
+ htmlEntries = CachingList.create(RAFList.create(raf, new HtmlEntry.Serializer(this), raf.getFilePointer()), CACHE_SIZE);
+ } else {
+ htmlEntries = Collections.emptyList();
+ }
indices = CachingList.createFullyCached(RAFList.create(raf, indexSerializer, raf.getFilePointer()));
} catch (RuntimeException e) {
final IOException ioe = new IOException("RuntimeException loading dictionary");
RAFList.write(raf, sources, new EntrySource.Serializer(this));
RAFList.write(raf, pairEntries, new PairEntry.Serializer(this));
RAFList.write(raf, textEntries, new TextEntry.Serializer(this));
+ RAFList.write(raf, htmlEntries, new HtmlEntry.Serializer(this));
RAFList.write(raf, indices, indexSerializer);
raf.writeUTF(END_OF_DICTIONARY);
}
--- /dev/null
+package com.hughes.android.dictionary.engine;
+
+import java.io.IOException;
+import java.io.PrintStream;
+import java.io.RandomAccessFile;
+import java.util.List;
+import java.util.regex.Pattern;
+
+import com.hughes.android.dictionary.engine.PairEntry.Pair;
+import com.hughes.util.raf.RAFSerializable;
+import com.hughes.util.raf.RAFSerializer;
+import com.ibm.icu.text.Transliterator;
+
+public class HtmlEntry extends AbstractEntry implements RAFSerializable<HtmlEntry>, Comparable<HtmlEntry> {
+
+ final String title;
+ final String html;
+
+ public HtmlEntry(Dictionary dictionary, RandomAccessFile raf) throws IOException {
+ super(dictionary, raf);
+ title = raf.readUTF();
+ html = raf.readUTF();
+ }
+ @Override
+ public void write(RandomAccessFile raf) throws IOException {
+ super.write(raf);
+ raf.writeUTF(title);
+ raf.writeUTF(html);
+ }
+
+ @Override
+ public int addToDictionary(Dictionary dictionary) {
+ dictionary.htmlEntries.add(this);
+ return dictionary.htmlEntries.size() - 1;
+ }
+
+ static final class Serializer implements RAFSerializer<HtmlEntry> {
+
+ final Dictionary dictionary;
+
+ Serializer(Dictionary dictionary) {
+ this.dictionary = dictionary;
+ }
+
+ @Override
+ public HtmlEntry read(RandomAccessFile raf) throws IOException {
+ return new HtmlEntry(dictionary, raf);
+ }
+
+ @Override
+ public void write(RandomAccessFile raf, HtmlEntry t) throws IOException {
+ t.write(raf);
+ }
+ };
+
+ public String getRawText(final boolean compact) {
+ return title + ": " + html;
+ }
+
+
+ @Override
+ public int compareTo(HtmlEntry another) {
+ if (title.compareTo(another.title) != 0) {
+ return title.compareTo(another.title);
+ }
+ return html.compareTo(another.html);
+ }
+
+ @Override
+ public String toString() {
+ return getRawText(false);
+ }
+
+ // --------------------------------------------------------------------
+
+
+ public static class Row extends RowBase {
+
+ Row(final RandomAccessFile raf, final int thisRowIndex,
+ final Index index) throws IOException {
+ super(raf, thisRowIndex, index);
+ }
+
+ Row(final int referenceIndex, final int thisRowIndex,
+ final Index index) {
+ super(referenceIndex, thisRowIndex, index);
+ }
+
+ @Override
+ public String toString() {
+ return getRawText(false);
+ }
+
+ public HtmlEntry getEntry() {
+ return index.dict.htmlEntries.get(referenceIndex);
+ }
+
+ @Override
+ public void print(PrintStream out) {
+ final HtmlEntry entry = getEntry();
+ out.println(entry);
+ }
+
+ @Override
+ public String getRawText(boolean compact) {
+ final HtmlEntry entry = getEntry();
+ return entry.getRawText(compact);
+ }
+
+ @Override
+ public RowMatchType matches(final List<String> searchTokens, final Pattern orderedMatchPattern, final Transliterator normalizer, final boolean swapPairEntries) {
+ final String text = normalizer.transform(getRawText(false));
+ if (orderedMatchPattern.matcher(text).find()) {
+ return RowMatchType.ORDERED_MATCH;
+ }
+ for (int i = searchTokens.size() - 1; i >= 0; --i) {
+ final String searchToken = searchTokens.get(i);
+ if (!text.contains(searchToken)) {
+ return RowMatchType.NO_MATCH;
+ }
+ }
+ return RowMatchType.BAG_OF_WORDS_MATCH;
+ }
+
+ }
+
+}
}
RAFList.write(raf, sortedIndexEntries, IndexEntry.SERIALIZER);
new SerializableSerializer<Set<String>>().write(raf, stoplist);
- UniformRAFList.write(raf, (Collection<RowBase>) rows, new RowBase.Serializer(this), 5);
+ UniformRAFList.write(raf, (Collection<RowBase>) rows, new RowBase.Serializer(this), 5 /* bytes per entry */);
}
public void print(final PrintStream out) {
return new TokenRow(raf, listIndex, index, rowType == 1);
} else if (rowType == 2) {
return new TextEntry.Row(raf, listIndex, index);
+ } else if (rowType == 4) {
+ return new HtmlEntry.Row(raf, listIndex, index);
}
throw new RuntimeException("Invalid rowType:" + rowType);
}
raf.writeByte(tokenRow.hasMainEntry ? 1 : 3);
} else if (t instanceof TextEntry.Row) {
raf.writeByte(2);
+ } else if (t instanceof HtmlEntry.Row) {
+ raf.writeByte(4);
}
raf.writeInt(t.referenceIndex);
}