用户自定义词典加载

@param key
@param path
@return
187176
private synchronized static Forest init(String key, KV<String, Forest> kv, boolean reload) {
        Forest forest = kv.getV();
        if (forest != null) {
            if (reload) {
                forest.clear();
            } else {
                return forest;
            }
        } else {
            forest = new Forest();
        }
        try {

            LOG.debug("begin init dic !");
            long start = System.currentTimeMillis();
            String temp = null;
            String[] strs = null;
            Value value = null;
            try (BufferedReader br = IOUtil.getReader(PathToStream.stream(kv.getK()), "UTF-8")) {
                while ((temp = br.readLine()) != null) {
                    if (StringUtil.isNotBlank(temp)) {
                        temp = StringUtil.trim(temp);
                        strs = temp.split("\t");
                        strs[0] = strs[0].toLowerCase();
                        // 如何核心辞典存在那么就放弃
                        if (MyStaticValue.isSkipUserDefine && DATDictionary.getId(strs[0]) > 0) {
                            continue;
                        }
                        if (strs.length != 3) {
                            value = new Value(strs[0], DEFAULT_NATURE, DEFAULT_FREQ_STR);
                        } else {
                            value = new Value(strs[0], strs[1], strs[2]);
                        }
                        Library.insertWord(forest, value);
                    }
                }
            }
            LOG.info("load dic use time:" + (System.currentTimeMillis() - start) + " path is : " + kv.getK());
            kv.setV(forest);
            return forest;
        } catch (Exception e) {
            LOG.error("Init dic library error :" + e.getMessage() + ", path: " + kv.getK());
            DIC.remove(key);
            return null;
        }
    }
427654
public VarSetBuilder varSetAtPath( String[] path)
    {
    VarSet varSet = null;
    if( path != null && path.length > 0)
      {
      varSet = new VarSet( path[0]);
      varSet_.addMember( varSet);

      for( int i = 1; i < path.length; i++)
        {
        VarSet child = new VarSet( path[i]);
        varSet.addMember( child);
        varSet = child;
        }
      }

    return
      varSet == null
      ? null
      : new VarSetBuilder( varSet);
    }
159091
public static function add($key, $path)
    {
        self::$_registeredNamespaces[$key] = true;
        self::$_options['loader']->addPsr4($key, $path);
    }
542193
public boolean load(String path)
    {
        trie = new DoubleArrayTrie<V>();
        long start = System.currentTimeMillis();
        if (loadDat(ByteArray.createByteArray(path + BIN_EXT)))
        {
            return true;
        }
        TreeMap<String, V> map = new TreeMap<String, V>();
        try
        {
            BufferedReader br = new BufferedReader(new InputStreamReader(IOUtil.newInputStream(path), "UTF-8"));
            String line;
            while ((line = br.readLine()) != null)
            {
                String[] paramArray = line.split("\\s");
                map.put(paramArray[0], createValue(paramArray));
            }
            br.close();
        }
        catch (Exception e)
        {
            logger.warning("读取" + path + "失败" + e);
            return false;
        }
        onLoaded(map);
        Set<Map.Entry<String, V>> entrySet = map.entrySet();
        List<String> keyList = new ArrayList<String>(entrySet.size());
        List<V> valueList = new ArrayList<V>(entrySet.size());
        for (Map.Entry<String, V> entry : entrySet)
        {
            keyList.add(entry.getKey());
            valueList.add(entry.getValue());
        }
        int resultCode = trie.build(keyList, valueList);
        if (resultCode != 0)
        {
            logger.warning("trie建立失败");
            return false;
        }
        logger.info(path + "加载成功，耗时" + (System.currentTimeMillis() - start) + "ms");
        saveDat(path + BIN_EXT, valueList);
        return true;
    }
1171310
public void addForeigerKey(String key) {
    String[] foreigers = new String[foreigerKeys.length + 1];
    int i = 0;
    for (; i < foreigerKeys.length; i++) {
      foreigers[i] = foreigerKeys[i];
    }
    foreigers[i] = key;
    foreigerKeys = foreigers;
  }
1296436
public static <KT> PathMetadata forMapAccess(Path<?> parent, KT key) {
        return new PathMetadata(parent, key, PathType.MAPVALUE_CONSTANT);
    }
284988
public void pushNestedPath(final String subPath, final String key) {
        final String canonicalPath = normalizePath(subPath);
        ArgUtils.notEmpty(subPath, "subPath");
        ArgUtils.notEmpty(key, "key");
        
        pushNestedPath(String.format("%s[%s]", canonicalPath, key));
    }
585073
public static String loadAndGet (String loaderPath, String key)
    {
        try {
            Properties props = ConfigUtil.loadProperties(loaderPath);
            return props.getProperty(key);
        } catch (IOException ioe) {
            return null;
        }
    }
1348372
public Jar addEntry(String path, String file) throws IOException {
        try (FileInputStream fos = new FileInputStream(file)) {
            return addEntry(path, fos);
        }
    }
187782
public static synchronized StopRecognition putIfAbsent(String key, String path, StopRecognition stopRecognition) {
        KV<String, StopRecognition> kv = STOP.get(key);
        if (kv != null && kv.getV() != null) {
            return kv.getV();
        }
        put(key, path, stopRecognition);
        return stopRecognition;
    }
1234071
static boolean load(String path)
    {
        if (loadDat(path)) return true;
        // 从文本中载入并且尝试生成dat
        StringDictionary dictionary = new StringDictionary("=");
        if (!dictionary.load(path)) return false;
        TreeMap<String, Pinyin[]> map = new TreeMap<String, Pinyin[]>();
        for (Map.Entry<String, String> entry : dictionary.entrySet())
        {
            String[] args = entry.getValue().split(",");
            Pinyin[] pinyinValue = new Pinyin[args.length];
            for (int i = 0; i < pinyinValue.length; ++i)
            {
                try
                {
                    Pinyin pinyin = Pinyin.valueOf(args[i]);
                    pinyinValue[i] = pinyin;
                }
                catch (IllegalArgumentException e)
                {
                    logger.severe("读取拼音词典" + path + "失败，问题出在【" + entry + "】，异常是" + e);
                    return false;
                }
            }
            map.put(entry.getKey(), pinyinValue);
        }
        trie.build(map);
        logger.info("正在缓存双数组" + path);
        saveDat(path, trie, map.entrySet());
        return true;
    }
825642
public boolean containsPathConfigs(
      java.lang.String key) {
    if (key == null) { throw new java.lang.NullPointerException(); }
    return internalGetPathConfigs().getMap().containsKey(key);
  }
863210
public static CRFModel loadBin(String path)
    {
        ByteArray byteArray = ByteArray.createByteArray(path);
        if (byteArray == null) return null;
        CRFModel model = new CRFModel();
        if (model.load(byteArray)) return model;
        return null;
    }
344202
public static function add( $key, $path, $url = null )
	{
		static::$paths[$key] = $path;
		
		if ( !is_null( $url ) )
		{
			static::$urls[$key] = $url;
		}
	}
1187853
public void add(final String path) {
        final Set<String> paths = new LinkedHashSet<String>();
        paths.addAll(get());
        paths.add(path);
        set(paths);
    }
921265
private static void getResPathKeys(String path, int num, String[] keys, int start) {
        if (num == 0) {
            return;
        }
        if (num == 1) {
            keys[start] = path;
            return;
        }
        int i = 0;
        for (;;) {
            int j = path.indexOf(RES_PATH_SEP_CHAR, i);
            assert j >= i;
            keys[start++] = path.substring(i, j);
            if (num == 2) {
                assert path.indexOf(RES_PATH_SEP_CHAR, j + 1) < 0;
                keys[start] = path.substring(j + 1);
                break;
            } else {
                i = j + 1;
                --num;
            }
        }
    }
108139
String withPath(String[] path) {
        StringBuilder sb = new StringBuilder();
        if (path.length > 0) {
            sb.append(" (with path ");
            for (int i = 0; i < path.length - 1; i++) {
                sb.append(path[i]);
                sb.append(".");
            }
            sb.append(path[path.length - 1]);
            sb.append(") ");
        }
        return sb.toString();

    }