Example #1
0
  public boolean exportDict(String dictPath) throws Exception {
    if (dictPath == null) {
      System.out.println("warning: null " + dictPath + "\n");
      dictPath = hashDictPath.replace(".json", "Out.json");
    }

    long size = dictMap.size();
    JSONObject object = new JSONObject(dictMap);
    JSONLib jsonLib = new JSONLib();
    boolean ret = jsonLib.formatObject(object, dictPath);
    if (!ret) {
      System.out.println("export dictionary fail\n");
      return ret;
    }
    System.out.println("exported dictionary size: " + size + "\n");
    return true;
  }
Example #2
0
  public boolean importFilterWords(String filterWordsPath) throws Exception {

    if (filterWordsPath == null) {
      System.out.println("warning: null " + filterWordsPath + "\n");
      filterWordsPath = this.filterWordsPath;
    }
    JSONLib jsonLib = new JSONLib();
    JSONArray filterArray = jsonLib.parseArrayFile(filterWordsPath);
    if (filterArray == null) {
      System.out.println("warning: parse " + filterWordsPath + " fail\n");
      filterSet = new HashSet<>(hashSetCapacity);
    } else {
      filterSet = new HashSet<>(filterArray);
    }
    int size = filterSet.size();
    System.out.println("imported filter words size: " + size + "\n");

    return true;
  }
Example #3
0
  public boolean importDict(String dictPath) throws Exception {

    if (dictPath == null) {
      System.out.println("warning: null " + dictPath + "\n");
      dictPath = hashDictPath;
    }

    JSONLib jsonLib = new JSONLib();
    JSONObject dictObj = jsonLib.parseObjectFile(dictPath);
    if (dictObj == null) {
      System.out.println("error: fail to parse " + dictPath + "\n");
      dictMap = new HashMap<>(hashMapCapacity);
    } else {
      dictMap = new HashMap<>(dictObj);
    }

    int size = dictMap.size();

    System.out.println("imported dictionary size: " + size + "\n");

    return true;
  }