org.ansj.splitWord.analysis.NlpAnalysis Java Examples

The following examples show how to use org.ansj.splitWord.analysis.NlpAnalysis. 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: DicSegment.java    From youkefu with Apache License 2.0 5 votes vote down vote up
public synchronized static String[] segment(String content) throws IOException{
	List<Term> terms = null ;
	if (librarykeyList != null && librarykeyList.size()>0) {
		terms = NlpAnalysis.parse(content,DicLibrary.gets(librarykeyList)).getTerms();
	}else {
		terms = NlpAnalysis.parse(content).getTerms();
	}
	List<String> words = new ArrayList<String>() ;
	for(Term term : terms) {
		words.add(term.getName()) ;
	}
	
	return words.toArray(new String[words.size()]);
}
 
Example #2
Source File: DicSegment.java    From youkefu with Apache License 2.0 5 votes vote down vote up
public static String[] byNature(String content , Set<String> expectedNature){
	List<String> wordList = new ArrayList<String>();
	if (!StringUtils.isBlank(content) && expectedNature != null && expectedNature.size() > 0) {
		Result result = NlpAnalysis.parse(content,DicLibrary.gets(librarykeyList));//分词结果的一个封装,主要是一个List<Term>的terms
           List<Term> terms = result.getTerms(); //拿到terms
           for(int i=0; i<terms.size(); i++) {
               String word = terms.get(i).getName(); //拿到词
               String natureStr = terms.get(i).getNatureStr(); //拿到词性
               if(expectedNature.contains(natureStr)) {
                   wordList.add(word+"/"+natureStr);
               }
           }
	}
	return wordList.toArray(new String[wordList.size()]);
}
 
Example #3
Source File: SummaryComputer.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
/**
 * 根据用户查询串计算摘要
 * 
 * @return
 */
public Summary toSummary(String query) {

    List<Term> parse = NlpAnalysis.parse(query).getTerms();

    List<Keyword> keywords = new ArrayList<>();
    for (Term term : parse) {
        if (FILTER_SET.contains(term.natrue().natureStr)) {
            continue;
        }
        keywords.add(new Keyword(term.getName(), term.termNatures().allFreq, 1));
    }

    return toSummary(keywords);
}
 
Example #4
Source File: KeyWordComputer.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
/**
 * 返回关键词个数
 *
 * @param nKeyword
 */
public KeyWordComputer(int nKeyword) {
    this.nKeyword = nKeyword;
    this.analysisType = (T) new NlpAnalysis();//默认使用NLP的分词方式

}
 
Example #5
Source File: ChineseTokenizer.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
public ChineseTokenizer(String toTokenize) {
    Result result = NlpAnalysis.parse(toTokenize);
    this.tokenList = result.getTerms();
    this.tokenIter = tokenList.iterator();
}