@Override public void inform(ResourceLoader loader) throws IOException { String dicts[] = dictionaryFiles.split(","); InputStream affix = null; List<InputStream> dictionaries = new ArrayList<>(); try { dictionaries = new ArrayList<>(); for (String file : dicts) { dictionaries.add(loader.openResource(file)); } affix = loader.openResource(affixFile); Path tempPath = Files.createTempDirectory(Dictionary.getDefaultTempDir(), "Hunspell"); try (Directory tempDir = FSDirectory.open(tempPath)) { this.dictionary = new Dictionary(tempDir, "hunspell", affix, dictionaries, ignoreCase); } finally { IOUtils.rm(tempPath); } } catch (ParseException e) { throw new IOException("Unable to load hunspell data! [dictionary=" + dictionaries + ",affix=" + affixFile + "]", e); } finally { IOUtils.closeWhileHandlingException(affix); IOUtils.closeWhileHandlingException(dictionaries); } }
return new Dictionary(tmp, "hunspell", affixStream, dicStreams, ignoreCase);
private static Dictionary initDict(Language language) { populateInstalledDicts(); File affixFile; File dictionaryFile; synchronized (HunspellTokenizer.class) { affixFile = affixFiles.get(language); dictionaryFile = dictionaryFiles.get(language); } if (affixFile == null || dictionaryFile == null || !affixFile.exists() || !dictionaryFile.exists()) { Log.logErrorRB("HUNSPELL_TOKENIZER_DICT_NOT_INSTALLED", language.getLocale()); return null; } try { return new Dictionary(new FileInputStream(affixFile), new FileInputStream(dictionaryFile)); } catch (Throwable t) { Log.log(t); return null; } }
@Override public void inform(ResourceLoader loader) throws IOException { String dicts[] = dictionaryFiles.split(","); InputStream affix = null; List<InputStream> dictionaries = new ArrayList<>(); try { dictionaries = new ArrayList<>(); for (String file : dicts) { dictionaries.add(loader.openResource(file)); } affix = loader.openResource(affixFile); this.dictionary = new Dictionary(affix, dictionaries, ignoreCase); } catch (ParseException e) { throw new IOException("Unable to load hunspell data! [dictionary=" + dictionaries + ",affix=" + affixFile + "]", e); } finally { IOUtils.closeWhileHandlingException(affix); IOUtils.closeWhileHandlingException(dictionaries); } }
/** * Loads a german hunspell dictionary. * * @return a german hunspell dictionary */ public static Dictionary getGermanHunspellDict() { List<InputStream> dictionaries = new ArrayList<>(); InputStream affix = null; try { dictionaries = new ArrayList<>(); dictionaries.add(RessourceLoading.class.getResourceAsStream(HUNSPELL_PATH + ".dic")); affix = RessourceLoading.class.getResourceAsStream(HUNSPELL_PATH + ".aff"); Path tempPath = Files.createTempDirectory(Paths.get(System.getProperty("java.io.tmpdir")), "Hunspell"); try (Directory tempDir = FSDirectory.open(tempPath)) { return new Dictionary(tempDir, "hunspell", affix, dictionaries, true); } finally { IOUtils.rm(tempPath); } } catch (ParseException | IOException e) { throw new ElasticsearchException(e); } finally { IOUtils.closeWhileHandlingException(affix); IOUtils.closeWhileHandlingException(dictionaries); } }
return new Dictionary(tmp, "hunspell", affixStream, dicStreams, ignoreCase);
return new Dictionary(tmp, "hunspell", affixStream, dicStreams, ignoreCase);
return new Dictionary(tmp, "hunspell", affixStream, dicStreams, ignoreCase);