示例#1
0
  static {
    /** 配置文件变量 */
    ResourceBundle rb = null;
    try {
      rb = ResourceBundle.getBundle("library");
    } catch (Exception e) {
      try {
        File find = FileFinder.find("library.properties");
        if (find != null) {
          rb =
              new PropertyResourceBundle(
                  IOUtil.getReader(find.getAbsolutePath(), System.getProperty("file.encoding")));
          LIBRARYLOG.info(
              "load library not find in classPath ! i find it in "
                  + find.getAbsolutePath()
                  + " make sure it is your config!");
        }
      } catch (Exception e1) {
        LIBRARYLOG.warning(
            "not find library.properties. and err " + e.getMessage() + " i think it is a bug!");
      }
    }

    if (rb == null) {
      LIBRARYLOG.warning("not find library.properties in classpath use it by default !");
    }

    if (rb.containsKey("userLibrary")) userLibrary = rb.getString("userLibrary");
    if (rb.containsKey("ambiguityLibrary")) ambiguityLibrary = rb.getString("ambiguityLibrary");
    if (rb.containsKey("isSkipUserDefine"))
      isSkipUserDefine = Boolean.valueOf(rb.getString("isSkipUserDefine"));
    if (rb.containsKey("isRealName")) isRealName = Boolean.valueOf(rb.getString("isRealName"));
    if (rb.containsKey("crfModel")) crfModel = rb.getString("crfModel");
  }
示例#2
0
  /**
   * 词与词之间的关联表数据
   *
   * @return
   */
  public static void initBigramTables() {
    BufferedReader reader = null;
    try {
      reader = IOUtil.getReader(DicReader.getInputStream("bigramdict.dic"), "UTF-8");
      String temp = null;
      String[] strs = null;
      int freq = 0;
      while ((temp = reader.readLine()) != null) {
        if (StringUtil.isBlank(temp)) {
          continue;
        }
        strs = temp.split("\t");
        freq = Integer.parseInt(strs[1]);
        strs = strs[0].split("@");
        AnsjItem fromItem = DATDictionary.getItem(strs[0]);

        AnsjItem toItem = DATDictionary.getItem(strs[1]);

        if (fromItem == AnsjItem.NULL && strs[0].contains("#")) {
          fromItem = AnsjItem.BEGIN;
        }

        if (toItem == AnsjItem.NULL && strs[1].contains("#")) {
          toItem = AnsjItem.END;
        }

        if (fromItem == AnsjItem.NULL || toItem == AnsjItem.NULL) {
          continue;
        }

        if (fromItem.bigramEntryMap == null) {
          fromItem.bigramEntryMap = new HashMap<Integer, Integer>();
        }

        fromItem.bigramEntryMap.put(toItem.getIndex(), freq);
      }
    } catch (NumberFormatException e) {
      e.printStackTrace();
    } catch (UnsupportedEncodingException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    } finally {
      IOUtil.close(reader);
    }
  }