/** * for ES to initialize the user dictionary. * * @param configFile */ public void init(Path configFile) { String abspath = configFile.toAbsolutePath().toString(); System.out.println("initialize user dictionary:" + abspath); synchronized (WordDictionary.class) { if (loadedPath.contains(abspath)) return; DirectoryStream<Path> stream; try { stream = Files.newDirectoryStream( configFile, String.format(Locale.getDefault(), "*%s", USER_DICT_SUFFIX)); for (Path path : stream) { System.err.println( String.format(Locale.getDefault(), "loading dict %s", path.toString())); singleton.loadUserDict(path); } loadedPath.add(abspath); } catch (IOException e) { // TODO Auto-generated catch block // e.printStackTrace(); System.err.println( String.format( Locale.getDefault(), "%s: load user dict failure!", configFile.toString())); } } }
public void loadUserDict(Path userDict) { loadUserDict(userDict, StandardCharsets.UTF_8); }