Beispiel #1
0
  public static void reload() {
    AutoDetector.loadAndWatch(
        new ResourceLoader() {

          @Override
          public void clear() {
            quantifiers.clear();
          }

          @Override
          public void load(List<String> lines) {
            LOGGER.info("初始化数量词");
            for (String line : lines) {
              if (line.length() == 1) {
                char _char = line.charAt(0);
                if (quantifiers.contains(_char)) {
                  LOGGER.info("配置文件有重复项:" + line);
                } else {
                  quantifiers.add(_char);
                }
              } else {
                LOGGER.info("忽略不合法数量词:" + line);
              }
            }
            LOGGER.info("数量词初始化完毕,数量词个数:" + quantifiers.size());
          }

          @Override
          public void add(String line) {
            if (line.length() == 1) {
              char _char = line.charAt(0);
              quantifiers.add(_char);
            } else {
              LOGGER.info("忽略不合法数量词:" + line);
            }
          }

          @Override
          public void remove(String line) {
            if (line.length() == 1) {
              char _char = line.charAt(0);
              quantifiers.remove(_char);
            } else {
              LOGGER.info("忽略不合法数量词:" + line);
            }
          }
        },
        WordConfTools.get("quantifier.path", "classpath:quantifier.txt"));
  }
Beispiel #2
0
  public static void reload() {
    AutoDetector.loadAndWatch(
        new ResourceLoader() {

          @Override
          public void clear() {
            DOUBLE_ARRAY_GENERIC_TRIE.clear();
          }

          @Override
          public void load(List<String> lines) {
            LOGGER.info("初始化trigram");
            Map<String, Integer> map = new HashMap<>();
            for (String line : lines) {
              try {
                addLine(line, map);
              } catch (Exception e) {
                LOGGER.error("错误的trigram数据:" + line);
              }
            }
            int size = map.size();
            DOUBLE_ARRAY_GENERIC_TRIE.putAll(map);
            LOGGER.info("trigram初始化完毕,trigram数据条数:" + size);
          }

          @Override
          public void add(String line) {
            throw new RuntimeException("not yet support menthod!");
          }

          private void addLine(String line, Map<String, Integer> map) {
            String[] attr = line.split("\\s+");
            int frequency = Integer.parseInt(attr[1]);
            if (frequency > maxFrequency) {
              maxFrequency = frequency;
            }
            map.put(attr[0], frequency);
          }

          @Override
          public void remove(String line) {
            throw new RuntimeException("not yet support menthod!");
          }
        },
        WordConfTools.get("trigram.path", "classpath:trigram.txt"));
  }