Exemplo n.º 1
0
 public static void main(String[] args) {
   Term from = new Term("阿", 0, new TermNatures(TermNature.NULL));
   from.getTermNatures().id = InitDictionary.getWordId(from.getName());
   Term to = new Term("全国", 0, new TermNatures(TermNature.NULL));
   to.getTermNatures().id = InitDictionary.getWordId(to.getName());
   System.out.println(getTwoWordFreq(from, to));
 }
Exemplo n.º 2
0
  static {
    try {

      long start = System.currentTimeMillis();
      FOREST = new Forest();

      // 先加载系统内置补充词典
      BufferedReader br = MyStaticValue.getUserDefineReader();
      String temp = null;
      while ((temp = br.readLine()) != null) {
        if (StringUtil.isBlank(temp) || InitDictionary.isInSystemDic(temp.split("\t")[0])) {
          continue;
        } else {
          Library.insertWord(FOREST, temp);
        }
      }
      // 如果系统设置了用户词典.那么..呵呵
      temp = MyStaticValue.userDefinePath;
      // 加载用户自定义词典
      Value value = null;
      String[] strs = null;
      if ((temp != null || (temp = MyStaticValue.rb.getString("userLibrary")) != null)
          && new File(temp).isFile()) {
        br = IOUtil.getReader(temp, "UTF-8");
        while ((temp = br.readLine()) != null) {
          if (StringUtil.isBlank(temp)) {
            continue;
          } else {
            strs = temp.split("\t");
            if (strs.length != 3) {
              value = new Value(strs[0], PARAMER);
            } else {
              value = new Value(strs[0], strs[1], strs[2]);
            }

            if (!InitDictionary.isInSystemDic(value.getKeyword())) {
              Library.insertWord(FOREST, value);
            }
          }
        }
      } else {
        System.err.println("用户自定义词典:" + temp + ", 没有这个文件!");
      }
      System.out.println("加载用户自定义词典完成用时:" + (System.currentTimeMillis() - start));
    } catch (Exception e) {
      // TODO Auto-generated catch block
      System.out.println("加载用户自定义词典加载失败:");
    }
  }