Java Code Examples for org.ansj.domain.Term#next()
The following examples show how to use
org.ansj.domain.Term#next() .
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: Graph.java From deeplearning4j with Apache License 2.0 | 6 votes |
/** * 干涉性增加相对权重 * * @param relationMap */ public void walkPath(Map<String, Double> relationMap) { Term term = null; // BEGIN先行打分 merger(root, 0, relationMap); // 从第一个词开始往后打分 for (int i = 0; i < terms.length; i++) { term = terms[i]; while (term != null && term.from() != null && term != end) { int to = term.toValue(); merger(term, to, relationMap); term = term.next(); } } optimalRoot(); }
Example 2
Source File: Graph.java From deeplearning4j with Apache License 2.0 | 6 votes |
/** * 具体的遍历打分方法 * * @param i 起始位置 * @param j 起始属性 * @param to */ private void merger(Term fromTerm, int to, Map<String, Double> relationMap) { Term term = null; if (terms[to] != null) { term = terms[to]; while (term != null) { // 关系式to.set(from) term.setPathScore(fromTerm, relationMap); term = term.next(); } } else { char c = chars[to]; TermNatures tn = DATDictionary.getItem(c).termNatures; if (tn == null || tn == TermNatures.NULL) { tn = TermNatures.NULL; } terms[to] = new Term(String.valueOf(c), to, tn); terms[to].setPathScore(fromTerm, relationMap); } }
Example 3
Source File: Graph.java From deeplearning4j with Apache License 2.0 | 5 votes |
/** * 得道最到本行最大term,也就是最右面的term * * @param i * @return */ private Term getMaxTerm(int i) { Term maxTerm = terms[i]; if (maxTerm == null) { return null; } Term term = maxTerm; while ((term = term.next()) != null) { maxTerm = term; } return maxTerm; }
Example 4
Source File: Graph.java From deeplearning4j with Apache License 2.0 | 5 votes |
public void walkPathByScore() { Term term = null; // BEGIN先行打分 mergerByScore(root, 0); // 从第一个词开始往后打分 for (int i = 0; i < terms.length; i++) { term = terms[i]; while (term != null && term.from() != null && term != end) { int to = term.toValue(); mergerByScore(term, to); term = term.next(); } } optimalRoot(); }
Example 5
Source File: Graph.java From deeplearning4j with Apache License 2.0 | 5 votes |
/** * 根据分数 * * @param i 起始位置 * @param j 起始属性 * @param to */ private void mergerByScore(Term fromTerm, int to) { Term term = null; if (terms[to] != null) { term = terms[to]; while (term != null) { // 关系式to.set(from) term.setPathSelfScore(fromTerm); term = term.next(); } } }
Example 6
Source File: Graph.java From deeplearning4j with Apache License 2.0 | 5 votes |
/** * 对graph进行调试用的 */ public void printGraph() { for (Term term : terms) { if (term == null) { continue; } System.out.print(term.getName() + "\t" + term.score() + " ,"); while ((term = term.next()) != null) { System.out.print(term + "\t" + term.score() + " ,"); } System.out.println(); } }
Example 7
Source File: Graph.java From deeplearning4j with Apache License 2.0 | 4 votes |
/** * 删除小节点。保证被删除的小节点的单个分数小于等于大节点的分数 */ public void rmLittlePathByScore() { int maxTo = -1; Term temp = null; for (int i = 0; i < terms.length; i++) { if (terms[i] == null) { continue; } Term maxTerm = null; double maxScore = 0; Term term = terms[i]; // 找到自身分数对大最长的 do { if (maxTerm == null || maxScore > term.score()) { maxTerm = term; } else if (maxScore == term.score() && maxTerm.getName().length() < term.getName().length()) { maxTerm = term; } } while ((term = term.next()) != null); term = maxTerm; do { maxTo = term.toValue(); maxScore = term.score(); if (maxTo - i == 1 || i + 1 == terms.length) continue; boolean flag = true;// 可以删除 out: for (int j = i; j < maxTo; j++) { temp = terms[j]; if (temp == null) { continue; } do { if (temp.toValue() > maxTo || temp.score() < maxScore) { flag = false; break out; } } while ((temp = temp.next()) != null); } // 验证通过可以删除了 if (flag) { for (int j = i + 1; j < maxTo; j++) { terms[j] = null; } } } while ((term = term.next()) != null); } }