private static Map<String, CharNgramLanguageModel> getModelsFromDir(File dir, boolean compressed) throws IOException {
        Map<String, CharNgramLanguageModel> map = Maps.newHashMap();
        if (!dir.exists())
            throw new IllegalArgumentException("Training data directory does not exist:" + dir);
        if (!dir.isDirectory())
            throw new IllegalArgumentException(dir + "is not a directory");
        File[] allFiles = dir.listFiles();
        if (allFiles == null || allFiles.length == 0)
            throw new IllegalArgumentException("There is no file in:" + dir);
        for (File file : allFiles) {
            final String langStr = file.getName().substring(0, file.getName().indexOf("."));
            if (compressed) {
                map.put(langStr, CompressedCharNgramModel.load(file));
            } else {
                map.put(langStr, MapBasedCharNgramLanguageModel.loadCustom(file));
            }
        }
        if (map.size() == 0) {
            throw new IllegalArgumentException("There is no model file in dir:" + dir);
        }
        return map;
    }