All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.code972.hebmorph.hspell.HSpellDictionaryLoader Maven / Gradle / Ivy

There is a newer version: 6.6.1
Show newest version
package com.code972.hebmorph.hspell;

import com.code972.hebmorph.DictionaryLoader;
import com.code972.hebmorph.datastructures.DictHebMorph;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

/**
 * DictionaryLoader implementation for loading hspell data files
 */
public class HSpellDictionaryLoader implements DictionaryLoader {
    @Override
    public String dictionaryLoaderName() {
        return "hspell";
    }

    @Override
    public String[] dictionaryPossiblePaths() {
        return new String[] {"plugins/analysis-hebrew/hspell-data-files/", "/var/lib/hspell-data-files/"};
    }

    @Override
    public DictHebMorph loadDictionaryFromPath(String path) throws IOException {
        if (!path.endsWith("/")) {
            path += "/";
        }

        final File file = new File(path);
        if (file.isDirectory()) {
            HSpellLoader loader = new HSpellLoader(new File(path), true);
            return loader.loadDictionaryFromHSpellData(new FileInputStream(new File(path, HSpellLoader.PREFIX_H)));
        } else {
            throw new IOException("Expected a folder. Cannot load dictionary from HSpell files.");
        }
    }

    @Override
    public DictHebMorph loadDictionaryFromDefaultPath() throws IOException {
        HSpellLoader loader = new HSpellLoader(new File(HSpellLoader.getHspellPath()), true);
        return loader.loadDictionaryFromHSpellData(new FileInputStream(new File(HSpellLoader.getHspellPath(), HSpellLoader.PREFIX_NOH)));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy