org.elasticsearch.index.analysis.Analysis.loadWordList()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(7.0k)|赞(0)|评价(0)|浏览(116)

本文整理了Java中org.elasticsearch.index.analysis.Analysis.loadWordList()方法的一些代码示例,展示了Analysis.loadWordList()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Analysis.loadWordList()方法的具体详情如下:
包路径:org.elasticsearch.index.analysis.Analysis
类名称:Analysis
方法名:loadWordList

Analysis.loadWordList介绍

暂无

代码示例

代码示例来源:origin: org.elasticsearch/elasticsearch

/**
 * Fetches a list of words from the specified settings file. The list should either be available at the key
 * specified by <code>settingList</code> or in a file specified by <code>settingPath</code>.
 *
 * @throws IllegalArgumentException
 *          If the word list cannot be found at either key.
 */
public static List<String> getWordList(Environment env, Settings settings, String settingPath, String settingList) {
  String wordListPath = settings.get(settingPath, null);
  if (wordListPath == null) {
    List<String> explicitWordList = settings.getAsList(settingList, null);
    if (explicitWordList == null) {
      return null;
    } else {
      return explicitWordList;
    }
  }
  final Path path = env.configFile().resolve(wordListPath);
  try (BufferedReader reader = Files.newBufferedReader(path, StandardCharsets.UTF_8)) {
    return loadWordList(reader, "#");
  } catch (CharacterCodingException ex) {
    String message = String.format(Locale.ROOT,
      "Unsupported character encoding detected while reading %s: %s - files must be UTF-8 encoded",
      settingPath, path.toString());
    throw new IllegalArgumentException(message, ex);
  } catch (IOException ioe) {
    String message = String.format(Locale.ROOT, "IOException while reading %s: %s", settingPath, path.toString());
    throw new IllegalArgumentException(message, ioe);
  }
}

代码示例来源:origin: skroutz/elasticsearch-analysis-turkishstemmer

private CharArraySet parseExceptions(Environment env, Settings settings,
   String settingPrefix) throws IOException {

  List<String> exceptionsList = new ArrayList<String>();
  Reader exceptionsReader = null;

  try {
   exceptionsReader = Analysis.getReaderFromFile(env, settings, settingPrefix);
  } catch (InvalidPathException e) {
   logger.info("failed to find the " + settingPrefix + ", using the default set");
  }

  if (exceptionsReader != null) {
   try {
    exceptionsList = Analysis.loadWordList(exceptionsReader, "#");
    if (exceptionsList.isEmpty()) {
     return CharArraySet.EMPTY_SET;
    } else {
     return new CharArraySet(exceptionsList, false);
    }
   } finally {
    if (exceptionsReader != null)
     exceptionsReader.close();
   }
  } else {
   return null;
  }
 }
}

代码示例来源:origin: apache/servicemix-bundles

/**
 * Fetches a list of words from the specified settings file. The list should either be available at the key
 * specified by settingsPrefix or in a file specified by settingsPrefix + _path.
 *
 * @throws IllegalArgumentException
 *          If the word list cannot be found at either key.
 */
public static List<String> getWordList(Environment env, Settings settings, String settingPrefix) {
  String wordListPath = settings.get(settingPrefix + "_path", null);
  if (wordListPath == null) {
    List<String> explicitWordList = settings.getAsList(settingPrefix, null);
    if (explicitWordList == null) {
      return null;
    } else {
      return explicitWordList;
    }
  }
  final Path path = env.configFile().resolve(wordListPath);
  try (BufferedReader reader = Files.newBufferedReader(path, StandardCharsets.UTF_8)) {
    return loadWordList(reader, "#");
  } catch (CharacterCodingException ex) {
    String message = String.format(Locale.ROOT,
      "Unsupported character encoding detected while reading %s_path: %s - files must be UTF-8 encoded",
      settingPrefix, path.toString());
    throw new IllegalArgumentException(message, ex);
  } catch (IOException ioe) {
    String message = String.format(Locale.ROOT, "IOException while reading %s_path: %s", settingPrefix, path.toString());
    throw new IllegalArgumentException(message, ioe);
  }
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.elasticsearch

/**
 * Fetches a list of words from the specified settings file. The list should either be available at the key
 * specified by settingsPrefix or in a file specified by settingsPrefix + _path.
 *
 * @throws IllegalArgumentException
 *          If the word list cannot be found at either key.
 */
public static List<String> getWordList(Environment env, Settings settings, String settingPrefix) {
  String wordListPath = settings.get(settingPrefix + "_path", null);
  if (wordListPath == null) {
    List<String> explicitWordList = settings.getAsList(settingPrefix, null);
    if (explicitWordList == null) {
      return null;
    } else {
      return explicitWordList;
    }
  }
  final Path path = env.configFile().resolve(wordListPath);
  try (BufferedReader reader = Files.newBufferedReader(path, StandardCharsets.UTF_8)) {
    return loadWordList(reader, "#");
  } catch (CharacterCodingException ex) {
    String message = String.format(Locale.ROOT,
      "Unsupported character encoding detected while reading %s_path: %s - files must be UTF-8 encoded",
      settingPrefix, path.toString());
    throw new IllegalArgumentException(message, ex);
  } catch (IOException ioe) {
    String message = String.format(Locale.ROOT, "IOException while reading %s_path: %s", settingPrefix, path.toString());
    throw new IllegalArgumentException(message, ioe);
  }
}

代码示例来源:origin: harbby/presto-connectors

/**
 * Fetches a list of words from the specified settings file. The list should either be available at the key
 * specified by settingsPrefix or in a file specified by settingsPrefix + _path.
 *
 * @throws IllegalArgumentException
 *          If the word list cannot be found at either key.
 */
public static List<String> getWordList(Environment env, Settings settings, String settingPrefix) {
  String wordListPath = settings.get(settingPrefix + "_path", null);
  if (wordListPath == null) {
    String[] explicitWordList = settings.getAsArray(settingPrefix, null);
    if (explicitWordList == null) {
      return null;
    } else {
      return Arrays.asList(explicitWordList);
    }
  }
  final Path wordListFile = env.configFile().resolve(wordListPath);
  try (BufferedReader reader = FileSystemUtils.newBufferedReader(wordListFile.toUri().toURL(), Charsets.UTF_8)) {
    return loadWordList(reader, "#");
  } catch (IOException ioe) {
    String message = String.format(Locale.ROOT, "IOException while reading %s_path: %s", settingPrefix, ioe.getMessage());
    throw new IllegalArgumentException(message);
  }
}

代码示例来源:origin: com.strapdata.elasticsearch/elasticsearch

/**
 * Fetches a list of words from the specified settings file. The list should either be available at the key
 * specified by settingsPrefix or in a file specified by settingsPrefix + _path.
 *
 * @throws IllegalArgumentException
 *          If the word list cannot be found at either key.
 */
public static List<String> getWordList(Environment env, Settings settings, String settingPrefix) {
  String wordListPath = settings.get(settingPrefix + "_path", null);
  if (wordListPath == null) {
    String[] explicitWordList = settings.getAsArray(settingPrefix, null);
    if (explicitWordList == null) {
      return null;
    } else {
      return Arrays.asList(explicitWordList);
    }
  }
  final Path path = env.configFile().resolve(wordListPath);
  try (BufferedReader reader = FileSystemUtils.newBufferedReader(path.toUri().toURL(), StandardCharsets.UTF_8)) {
    return loadWordList(reader, "#");
  } catch (CharacterCodingException ex) {
    String message = String.format(Locale.ROOT,
      "Unsupported character encoding detected while reading %s_path: %s - files must be UTF-8 encoded",
      settingPrefix, path.toString());
    throw new IllegalArgumentException(message, ex);
  } catch (IOException ioe) {
    String message = String.format(Locale.ROOT, "IOException while reading %s_path: %s", settingPrefix, path.toString());
    throw new IllegalArgumentException(message, ioe);
  }
}

相关文章