org.nlpcn.commons.lang.tire.SmartGetWord Java Examples

The following examples show how to use org.nlpcn.commons.lang.tire.SmartGetWord. 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: TagContent.java    From deeplearning4j with Apache License 2.0 6 votes vote down vote up
public String tagContent(List<Keyword> keyWords, String content) {
    SmartForest<Double> sf = new SmartForest<>();
    for (Keyword keyWord : keyWords) {
        sf.add(keyWord.getName().toLowerCase(), keyWord.getScore());
    }

    SmartGetWord<Double> sgw = new SmartGetWord<>(sf, content.toLowerCase());

    int beginOffe = 0;
    String temp = null;
    StringBuilder sb = new StringBuilder();
    while ((temp = sgw.getFrontWords()) != null) {
        sb.append(content.substring(beginOffe, sgw.offe));
        sb.append(beginTag);
        sb.append(content.substring(sgw.offe, sgw.offe + temp.length()));
        sb.append(endTag);
        beginOffe = sgw.offe + temp.length();
    }

    if (beginOffe <= content.length() - 1) {
        sb.append(content.substring(beginOffe, content.length()));
    }

    return sb.toString();
}
 
Example #2
Source File: AnsjDictionary.java    From jstarcraft-nlp with Apache License 2.0 5 votes vote down vote up
@Override
public boolean contain(String text) {
    SmartGetWord<?> word = forest.getWord(text);
    String string = word.getFrontWords();
    if (string == null) {
        return false;
    } else {
        return text.equals(string);
    }
}
 
Example #3
Source File: AllWordTest.java    From nlp-lang with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
	/**
	 * 词典的构造.一行一个词后面是参数.可以从文件读取.可以是read流.
	 */
	long start = System.currentTimeMillis();
	SmartForest<Integer> forest = new SmartForest<Integer>();

	forest.add("中国", 3);

	forest.add("android", 3);

	forest.add("java", 3);
	
	forest.add("jav", 3);

	forest.add("中国人", 3);
	forest.add("国人", 3);
	
	forest.add("0",3);
	forest.add("3",3);

	String content = " Android-java-中国人00000000000000 1230 013 33333";
	
	
	content = StringUtil.rmHtmlTag(content);

	for (int i = 0; i < 1; i++) {
		SmartGetWord<Integer> udg = forest.getWord(content.toLowerCase().toCharArray());

		String temp;
		while ((temp = udg.getAllWords()) != null) {
			System.out.println(temp + "\t" + udg.getParam());
		}
	}
	System.out.println(System.currentTimeMillis() - start);
}
 
Example #4
Source File: SmartGetWordTest.java    From nlp-lang with Apache License 2.0 5 votes vote down vote up
@Test
public void test() {
	/**
	 * 词典的构造.一行一个词后面是参数.可以从文件读取.可以是read流.
	 */
	long start = System.currentTimeMillis();
	SmartForest<Integer> forest = new SmartForest<Integer>();

	forest.add("中国", 3);

	forest.add("android", 3);

	forest.add("java", 3);

	forest.add("中国人", 3);

	String content = " Android-java-中国人";
	
	
	forest.remove("中国人") ;
	
	content = StringUtil.rmHtmlTag(content);

	for (int i = 0; i < 1; i++) {
		SmartGetWord<Integer> udg = forest.getWord(content.toLowerCase().toCharArray());

		String temp;
		while ((temp = udg.getFrontWords()) != null) {
			System.out.println(temp + "\t" + udg.getParam());
		}
	}
	System.out.println(System.currentTimeMillis() - start);
}
 
Example #5
Source File: SummaryComputer.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
/**
 * 计算一个句子的分数
 * 
 * @param sentence
 * @param sf
 */
private void computeScore(Sentence sentence, SmartForest<Double> forest) {
    SmartGetWord<Double> sgw = new SmartGetWord<>(forest, sentence.value);
    String name = null;
    while ((name = sgw.getFrontWords()) != null) {
        sentence.updateScore(name, sgw.getParam());
    }
    if (sentence.score == 0) {
        sentence.score = sentence.value.length() * -0.005;
    } else {
        sentence.score /= Math.log(sentence.value.length() + 3);
    }
}
 
Example #6
Source File: SmartForest.java    From nlp-lang with Apache License 2.0 4 votes vote down vote up
public SmartGetWord<T> getWord(String str) {
	return getWord(str.toCharArray());
}
 
Example #7
Source File: SmartForest.java    From nlp-lang with Apache License 2.0 2 votes vote down vote up
/**
 * 得到抽詞器
 * 
 * @param chars
 * @return
 */
public SmartGetWord<T> getWord(char[] chars) {
	return new SmartGetWord<T>(this, chars);
}