org.ansj.util.MyStaticValue Java Examples

The following examples show how to use org.ansj.util.MyStaticValue. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AmbiguityLibrary.java    From deeplearning4j with Apache License 2.0 6 votes vote down vote up
/**
 * 根据key获取
 * 
 */
public static Forest get(String key) {

    KV<String, Forest> kv = AMBIGUITY.get(key);

    if (kv == null) {
        if (MyStaticValue.ENV.containsKey(key)) {
            putIfAbsent(key, MyStaticValue.ENV.get(key));
            return get(key);
        }

        LOG.warn("crf " + key + " not found in config ");
        return null;
    }

    Forest sw = kv.getV();
    if (sw == null) {
        try {
            sw = init(key, kv, false);
        } catch (Exception e) {
        }
    }
    return sw;
}
 
Example #2
Source File: PersonAttrLibrary.java    From deeplearning4j with Apache License 2.0 6 votes vote down vote up
private void init2() {
    Map<String, int[][]> personFreqMap = MyStaticValue.getPersonFreqMap();
    Set<Entry<String, int[][]>> entrySet = personFreqMap.entrySet();
    PersonNatureAttr pna = null;
    for (Entry<String, int[][]> entry : entrySet) {
        pna = pnMap.get(entry.getKey());
        if (pna == null) {
            pna = new PersonNatureAttr();
            pna.setlocFreq(entry.getValue());
            pnMap.put(entry.getKey(), pna);
        } else {
            pna.setlocFreq(entry.getValue());
        }

    }
}
 
Example #3
Source File: CompanyAttrLibrary.java    From deeplearning4j with Apache License 2.0 6 votes vote down vote up
private static void init() {
    try (BufferedReader br = MyStaticValue.getCompanReader()) {
        cnMap = new HashMap<>();
        String temp = null;
        String[] strs = null;
        int[] cna = null;
        while ((temp = br.readLine()) != null) {
            strs = temp.split("\t");
            cna = new int[2];
            cna[0] = Integer.parseInt(strs[1]);
            cna[1] = Integer.parseInt(strs[2]);
            cnMap.put(strs[0], cna);
        }
    } catch (IOException e) {
        logger.warn("IO异常", e);
    }
}
 
Example #4
Source File: DicLibrary.java    From deeplearning4j with Apache License 2.0 6 votes vote down vote up
/**
 * 根据模型名称获取crf模型
 * 
 * @param modelName
 * @return
 */
public static Forest get(String key) {

    KV<String, Forest> kv = DIC.get(key);

    if (kv == null) {
        if (MyStaticValue.ENV.containsKey(key)) {
            putIfAbsent(key, MyStaticValue.ENV.get(key));
            return get(key);
        }
        LOG.warn("dic " + key + " not found in config ");
        return null;
    }
    Forest forest = kv.getV();
    if (forest == null) {
        forest = init(key, kv, false);
    }
    return forest;

}
 
Example #5
Source File: CrfLibrary.java    From deeplearning4j with Apache License 2.0 6 votes vote down vote up
/**
 * 根据key获取crf分词器
 * 
 * @param key
 * @return crf分词器
 */
public static SplitWord get(String key) {

    KV<String, SplitWord> kv = CRF.get(key);

    if (kv == null) {
        if (MyStaticValue.ENV.containsKey(key)) {
            putIfAbsent(key, MyStaticValue.ENV.get(key));
            return get(key);
        }
        LOG.warn("crf " + key + " not found in config ");
        return null;
    }

    SplitWord sw = kv.getV();
    if (sw == null) {
        sw = initCRFModel(kv);
    }
    return sw;
}
 
Example #6
Source File: SynonymsLibrary.java    From deeplearning4j with Apache License 2.0 6 votes vote down vote up
/**
 */
public static SmartForest<List<String>> get(String key) {
    KV<String, SmartForest<List<String>>> kv = SYNONYMS.get(key);

    if (kv == null) {
        if (MyStaticValue.ENV.containsKey(key)) {
            putIfAbsent(key, MyStaticValue.ENV.get(key));
            return get(key);
        }
        LOG.warn("crf " + key + " not found in config ");
        return null;
    }

    SmartForest<List<String>> sw = kv.getV();
    if (sw == null) {
        sw = init(key, kv, false);
    }
    return sw;
}
 
Example #7
Source File: StopLibrary.java    From deeplearning4j with Apache License 2.0 6 votes vote down vote up
/**
 * 根据模型名称获取crf模型
 * 
 * @param modelName
 * @return
 */
public static StopRecognition get(String key) {
    KV<String, StopRecognition> kv = STOP.get(key);

    if (kv == null) {
        if (MyStaticValue.ENV.containsKey(key)) {
            putIfAbsent(key, MyStaticValue.ENV.get(key));
            return get(key);
        }
        LOG.warn("STOP " + key + " not found in config ");
        return null;
    }
    StopRecognition stopRecognition = kv.getV();
    if (stopRecognition == null) {
        stopRecognition = init(key, kv, false);
    }
    return stopRecognition;

}
 
Example #8
Source File: StopLibrary.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
public static KV<String, StopRecognition> remove(String key) {
    KV<String, StopRecognition> kv = STOP.get(key);
    if (kv != null && kv.getV() != null) {
        kv.getV().clear();
    }
    MyStaticValue.ENV.remove(key);
    return STOP.remove(key);
}
 
Example #9
Source File: Analysis.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
/**
 * 将为标准化的词语设置到分词中
 * 
 * @param gp
 * @param result
 */
protected void setRealName(Graph graph, List<Term> result) {

    if (!MyStaticValue.isRealName) {
        return;
    }

    String str = graph.realStr;

    for (Term term : result) {
        term.setRealName(str.substring(term.getOffe(), term.getOffe() + term.getName().length()));
    }
}
 
Example #10
Source File: DicLibrary.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
public static void reload(String key) {
    if (!MyStaticValue.ENV.containsKey(key)) { //如果变量中不存在直接删掉这个key不解释了
        remove(key);
    }

    putIfAbsent(key, MyStaticValue.ENV.get(key));

    KV<String, Forest> kv = DIC.get(key);

    init(key, kv, true);
}
 
Example #11
Source File: SynonymsLibrary.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
/**
 * 删除一个key
 * 
 * @param key
 * @return
 */
public static KV<String, SmartForest<List<String>>> remove(String key) {
    KV<String, SmartForest<List<String>>> kv = SYNONYMS.get(key);
    if (kv != null && kv.getV() != null) { //先清空后删除
        kv.getV().clear();
    }
    MyStaticValue.ENV.remove(key);
    return SYNONYMS.remove(key);
}
 
Example #12
Source File: DicLibrary.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
public static KV<String, Forest> remove(String key) {
    KV<String, Forest> kv = DIC.get(key);
    if (kv != null && kv.getV() != null) {
        kv.getV().clear();
    }
    MyStaticValue.ENV.remove(key);
    return DIC.remove(key);
}
 
Example #13
Source File: Analysis.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
protected Analysis() {
    this.forests = new Forest[] {DicLibrary.get()};
    this.isNameRecognition = MyStaticValue.isNameRecognition;
    this.isNumRecognition = MyStaticValue.isNumRecognition;
    this.isQuantifierRecognition = MyStaticValue.isQuantifierRecognition;
    this.isRealName = MyStaticValue.isRealName;
}
 
Example #14
Source File: AmbiguityLibrary.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
/**
 * 删除一个key
 * 
 * @param key
 * @return
 */
public static KV<String, Forest> remove(String key) {
    KV<String, Forest> kv = AMBIGUITY.get(key);
    if (kv != null && kv.getV() != null) {
        kv.getV().clear();
    }
    MyStaticValue.ENV.remove(key);
    return AMBIGUITY.remove(key);
}
 
Example #15
Source File: DicSegment.java    From youkefu with Apache License 2.0 5 votes vote down vote up
public static void addWord(List<String> words , String librarykey){
	if (DicLibrary.get(DicLibrary.DEFAULT+librarykey) == null) {
		MyStaticValue.ENV.put(DicLibrary.DEFAULT+librarykey,new File(loadpath,"ukefu-"+librarykey+".dic").getAbsolutePath());
		librarykeyList.add(DicLibrary.DEFAULT+librarykey);
	}
	if(words!=null && words.size() > 0  ) {
		for(String word : words) {
			DicLibrary.insert(DicLibrary.DEFAULT +librarykey, word);
		}
	}
}
 
Example #16
Source File: AmbiguityLibrary.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
/**
 * 刷新一个,将值设置为null
 * 
 * @param key
 * @return
 */
public static void reload(String key) {
    if (!MyStaticValue.ENV.containsKey(key)) { //如果变量中不存在直接删掉这个key不解释了
        remove(key);
    }

    putIfAbsent(key, MyStaticValue.ENV.get(key));

    KV<String, Forest> kv = AMBIGUITY.get(key);

    init(key, kv, true);
}
 
Example #17
Source File: AmbiguityLibrary.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
public static void put(String key, String path, Forest value) {
    AMBIGUITY.put(key, KV.with(path, value));
    MyStaticValue.ENV.put(key, path);
}
 
Example #18
Source File: DicSegment.java    From youkefu with Apache License 2.0 4 votes vote down vote up
public static void removeLibrary(String librarykey){
	if (!StringUtils.isBlank(librarykey)) {
		MyStaticValue.removeLibrary(DicLibrary.DEFAULT +librarykey);
	}
}
 
Example #19
Source File: CrfLibrary.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
public static void put(String key, String path, SplitWord sw) {
    CRF.put(key, KV.with(path, sw));
    MyStaticValue.ENV.put(key, path);
}
 
Example #20
Source File: SynonymsLibrary.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
public static void put(String key, String path, SmartForest<List<String>> value) {
    SYNONYMS.put(key, KV.with(path, value));
    MyStaticValue.ENV.put(key, path);
}
 
Example #21
Source File: NumRecognition.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
/**
 * 数字+数字合并,zheng
 * 
 * @param terms
 */
@Override
public void recognition(Term[] terms) {
    int length = terms.length - 1;
    Term from = null;
    Term to = null;
    Term temp = null;
    for (int i = 0; i < length; i++) {
        if (terms[i] == null) {
            continue;
        } else if (".".equals(terms[i].getName()) || ".".equals(terms[i].getName())) {
            // 如果是.前后都为数字进行特殊处理
            to = terms[i].to();
            from = terms[i].from();
            if (from.termNatures().numAttr.flag && to.termNatures().numAttr.flag) {
                from.setName(from.getName() + "." + to.getName());
                TermUtil.termLink(from, to.to());
                terms[to.getOffe()] = null;
                terms[i] = null;
                i = from.getOffe() - 1;
            }
            continue;
        } else if (!terms[i].termNatures().numAttr.flag) {
            continue;
        }

        temp = terms[i];
        // 将所有的数字合并
        while ((temp = temp.to()).termNatures().numAttr.flag) {
            terms[i].setName(terms[i].getName() + temp.getName());
        }
        // 如果是数字结尾
        if (MyStaticValue.isQuantifierRecognition && temp.termNatures().numAttr.numEndFreq > 0) {
            terms[i].setName(terms[i].getName() + temp.getName());
            temp = temp.to();
        }

        // 如果不等,说明terms[i]发生了改变
        if (terms[i].to() != temp) {
            TermUtil.termLink(terms[i], temp);
            // 将中间无用元素设置为null
            for (int j = i + 1; j < temp.getOffe(); j++) {
                terms[j] = null;
            }
            i = temp.getOffe() - 1;
        }
    }

}
 
Example #22
Source File: DicSegment.java    From youkefu with Apache License 2.0 4 votes vote down vote up
public static void loadDic(String path , List<Words> wordsList) throws IOException{
	loadpath = path ;
	
	File dicPath = new File(path) ;
	if(!dicPath.exists()){
		dicPath.mkdirs() ;
	}
	File ukefudicFile = new File(path ,"ukefu.dic") ;//ukefu词典
	if(!ukefudicFile.getParentFile().exists()){
		ukefudicFile.getParentFile().mkdirs();
	}
	if(!ukefudicFile.exists()){
		ukefudicFile.createNewFile();
	}
	File ambiguitydicFile = new File(path ,"ambiguity.dic") ;//歧义词典
	if(!ambiguitydicFile.getParentFile().exists()){
		ambiguitydicFile.getParentFile().mkdirs();
	}
	if(!ambiguitydicFile.exists()){
		ambiguitydicFile.createNewFile();
	}
	File stopdicFile = new File(path ,"stop.dic") ;//停词词典
	if(!stopdicFile.getParentFile().exists()){
		stopdicFile.getParentFile().mkdirs();
	}
	if(!stopdicFile.exists()){
		stopdicFile.createNewFile();
	}
	try {
		librarykeyList = new ArrayList<String>() ;
		File[] tempList = dicPath.listFiles();
		for(File file : tempList){
			String name = file.getName();
			if (file.isFile() && name.contains("ukefu")) {
				String dicname = DicLibrary.DEFAULT+name.replaceAll(".dic","").replaceAll("ukefu-", "");//格式:[dic]+[类型id]
				if (MyStaticValue.ENV.get(dicname)!=null && !StringUtils.isBlank(MyStaticValue.ENV.get(dicname))) {
					MyStaticValue.reloadLibrary(dicname);
				}else {
					MyStaticValue.ENV.put(dicname, new File(path,name).getAbsolutePath());
				}
				librarykeyList.add(dicname);
			}
		}
		MyStaticValue.ENV.put(DicLibrary.DEFAULT,ukefudicFile.getAbsolutePath());
		MyStaticValue.ENV.put(AmbiguityLibrary.DEFAULT,ambiguitydicFile.getAbsolutePath());//歧义词典
		MyStaticValue.ENV.put(StopLibrary.DEFAULT,stopdicFile.getAbsolutePath());//停词词典
	} catch (Exception e) {
		e.printStackTrace();
	}//加载字典文件
	if (wordsList != null && wordsList.size()>0) {//加载数据库词典表
		for(Words words : wordsList){
			if(!StringUtils.isBlank(words.getContent())){
	    		for(String word : words.getContent().split("[, ,:;;\\n\t ]")){
	    			if(!StringUtils.isBlank(word)){
	    				DicLibrary.insert(DicLibrary.DEFAULT+"ukefu", word);
	    			}
	    		}
	    	}
		}
	}
}
 
Example #23
Source File: SynonymsLibrary.java    From deeplearning4j with Apache License 2.0 3 votes vote down vote up
/**
 * 刷新一个,将值设置为null
 * 
 * @param key
 * @return
 */
public static void reload(String key) {

    if (!MyStaticValue.ENV.containsKey(key)) { //如果变量中不存在直接删掉这个key不解释了
        remove(key);
    }

    putIfAbsent(key, MyStaticValue.ENV.get(key));

    KV<String, SmartForest<List<String>>> kv = SYNONYMS.get(key);

    init(key, kv, true);
}
 
Example #24
Source File: StopLibrary.java    From deeplearning4j with Apache License 2.0 3 votes vote down vote up
public static void reload(String key) {

        if (!MyStaticValue.ENV.containsKey(key)) { //如果变量中不存在直接删掉这个key不解释了
            remove(key);
        }

        putIfAbsent(key, MyStaticValue.ENV.get(key));

        KV<String, StopRecognition> kv = STOP.get(key);

        init(key, kv, true);
    }
 
Example #25
Source File: CrfLibrary.java    From deeplearning4j with Apache License 2.0 2 votes vote down vote up
/**
 * 删除一个key
 * 
 * @param key
 * @return
 */
public static KV<String, SplitWord> remove(String key) {
    MyStaticValue.ENV.remove(key);
    return CRF.remove(key);
}
 
Example #26
Source File: DicLibrary.java    From deeplearning4j with Apache License 2.0 2 votes vote down vote up
/**
 * 动态添加词典
 * 
 * @param dicDefault
 * @param dicDefault2
 * @param dic2
 */
public static void put(String key, String path, Forest forest) {
    DIC.put(key, KV.with(path, forest));
    MyStaticValue.ENV.put(key, path);
}
 
Example #27
Source File: StopLibrary.java    From deeplearning4j with Apache License 2.0 2 votes vote down vote up
/**
 * 动态添加词典
 * 
 * @param FILTERDefault
 * @param FILTERDefault2
 * @param FILTER2
 */
public static void put(String key, String path, StopRecognition stopRecognition) {
    STOP.put(key, KV.with(path, stopRecognition));
    MyStaticValue.ENV.put(key, path);
}