fdesc = new GZIPInputStream(new FileInputStream(new File(hspellFolder, Constants.descFile)));
fstem = new GZIPInputStream(new FileInputStream(new File(hspellFolder, Constants.stemsFile)));
final Loader loader = new Loader(hspellFolder);
for (int i = 0; lookup[i] != null; i++) {
MorphData data = new MorphData();
data.setPrefixes((short) fprefixes.read()); // Read prefix hint byte
data.setDescFlags(loader.readDescFile(fdesc));
final List<Integer> stemReferences = loader.readStemFile(fstem);
final String[] lemmas = new String[stemReferences.size()];
int stemPosition = 0;
for (int r : stemReferences) {
// This is a bypass for the psuedo-stem "שונות", as defined by hspell
// TODO: Try looking into changing this in hspell itself
if (lookup[r].equals("שונות") && !lookup[r].equals(lookup[i])) {
lemmas[stemPosition++] = null;
} else {
lemmas[stemPosition++] = lookup[r];
}
}
data.setLemmas(lemmas);
ret.addNode(lookup[i], data);
}
} finally {
if (fprefixes != null) try { fprefixes.close(); } catch (IOException ignored) {}
if (fdesc != null) try { fdesc.close(); } catch (IOException ignored) {}
if (fstem != null) try { fstem.close(); } catch (IOException ignored) {}
}
return ret;
} else { // Use optimized version for loading HSpell's dictionary files
DictRadix<MorphData> ret = new DictRadix<MorphData>();
InputStream fprefixes = null, fdict = null;
try {
fdict = new GZIPInputStream(new FileInputStream(new File(hspellFolder, Constants.dictionaryFile)));
fprefixes = new GZIPInputStream(new FileInputStream(new File(hspellFolder, Constants.prefixesFile)));
final char[] sbuf = new char[Constants.MaxWordLength];
int c = 0, n, slen = 0;
while ((c = fdict.read()) > -1) {
if ((c >= '0') && (c <= '9')) { // No conversion required for chars < 0xBE
// new word - finalize old word first (set value)
sbuf[slen] = '\0';
// TODO: Avoid creating new MorphData object, and enhance DictRadix to store
// the prefixes mask in the node itself
MorphData data = new MorphData();
data.setPrefixes((short) fprefixes.read()); // Read prefix hint byte
ret.addNode(sbuf, data);
// and read how much to go back
n = 0;
do {