Java Code Examples for org.ansj.domain.Term#getName()
The following examples show how to use
org.ansj.domain.Term#getName() .
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: UserDefineRecognition.java From deeplearning4j with Apache License 2.0 | 5 votes |
/** * 传入一个term 返回这个term的状态 * * @param branch * @param term * @return */ private SmartForest<String[]> termStatus(SmartForest<String[]> branch, Term term) { String name = term.getName(); SmartForest<String[]> sf = branch; for (int j = 0; j < name.length(); j++) { sf = sf.get(name.charAt(j)); if (sf == null) { return null; } } return sf; }
Example 2
Source File: ForeignPersonRecognition.java From deeplearning4j with Apache License 2.0 | 5 votes |
@Override public void recognition(Term[] terms) { this.terms = terms; String name = null; Term term = null; reset(); for (int i = 0; i < terms.length; i++) { if (terms[i] == null) { continue; } term = terms[i]; // 如果名字的开始是人名的前缀,或者后缀.那么忽略 if (tempList.isEmpty()) { if (term.termNatures().personAttr.end > 10) { continue; } if ((terms[i].getName().length() == 1 && ISNOTFIRST.contains(terms[i].getName().charAt(0)))) { continue; } } name = term.getName(); if (term.termNatures() == TermNatures.NR || term.termNatures() == TermNatures.NW || name.length() == 1) { boolean flag = validate(name); if (flag) { tempList.add(term); } } else if (tempList.size() == 1) { reset(); } else if (tempList.size() > 1) { TermUtil.insertTerm(terms, tempList, TermNatures.NR); reset(); } } }
Example 3
Source File: ForeignPersonRecognition.java From deeplearning4j with Apache License 2.0 | 5 votes |
public List<Term> getNewTerms() { LinkedList<Term> result = new LinkedList<>(); String name = null; Term term = null; reset(); for (int i = 0; i < terms.length; i++) { if (terms[i] == null) { continue; } term = terms[i]; // 如果名字的开始是人名的前缀,或者后缀.那么忽略 if (tempList.isEmpty()) { if (term.termNatures().personAttr.end > 10) { continue; } if ((terms[i].getName().length() == 1 && ISNOTFIRST.contains(terms[i].getName().charAt(0)))) { continue; } } name = term.getName(); if (term.termNatures() == TermNatures.NR || term.termNatures() == TermNatures.NW || name.length() == 1) { boolean flag = validate(name); if (flag) { tempList.add(term); } } else if (tempList.size() == 1) { reset(); } else if (tempList.size() > 1) { result.add(makeNewTerm()); reset(); } } return result; }
Example 4
Source File: KeyWordComputer.java From deeplearning4j with Apache License 2.0 | 5 votes |
/** * @param content 正文 * @return */ private List<Keyword> computeArticleTfidf(String content, int titleLength) { Map<String, Keyword> tm = new HashMap<>(); List<Term> parse = analysisType.parseStr(content).getTerms(); //FIXME: 这个依赖于用户自定义词典的词性,所以得需要另一个方法.. // parse = FilterModifWord.updateNature(parse) ; for (Term term : parse) { double weight = getWeight(term, content.length(), titleLength); if (weight == 0) continue; Keyword keyword = tm.get(term.getName()); if (keyword == null) { keyword = new Keyword(term.getName(), term.natrue().allFrequency, weight); tm.put(term.getName(), keyword); } else { keyword.updateWeight(1); } } TreeSet<Keyword> treeSet = new TreeSet<>(tm.values()); ArrayList<Keyword> arrayList = new ArrayList<>(treeSet); if (treeSet.size() <= nKeyword) { return arrayList; } else { return arrayList.subList(0, nKeyword); } }
Example 5
Source File: TermUtil.java From deeplearning4j with Apache License 2.0 | 5 votes |
/** * 将两个term合并为一个全新的term * * @param termNatures * @return */ public static Term makeNewTermNum(Term from, Term to, TermNatures termNatures) { Term term = new Term(from.getName() + to.getName(), from.getOffe(), termNatures); term.termNatures().numAttr = from.termNatures().numAttr; TermUtil.termLink(term, to.to()); TermUtil.termLink(term.from(), term); return term; }
Example 6
Source File: TermUtil.java From deeplearning4j with Apache License 2.0 | 5 votes |
/** * 得到细颗粒度的分词,并且确定词性 * * @return 返回是null说明已经是最细颗粒度 */ public static void parseNature(Term term) { if (!Nature.NW.equals(term.natrue())) { return; } String name = term.getName(); if (name.length() <= 3) { return; } // 是否是外国人名 if (ForeignPersonRecognition.isFName(name)) { term.setNature(NatureLibrary.getNature("nrf")); return; } List<Term> subTerm = term.getSubTerm(); // 判断是否是机构名 term.setSubTerm(subTerm); Term first = subTerm.get(0); Term last = subTerm.get(subTerm.size() - 1); int[] is = companyMap.get(first.getName()); int all = 0; is = companyMap.get(last.getName()); if (is != null) { all += is[1]; } if (all > 1000) { term.setNature(NatureLibrary.getNature("nt")); return; } }
Example 7
Source File: ForeignPersonRecognition.java From deeplearning4j with Apache License 2.0 | 4 votes |
public List<NewWord> getNewWords(Term[] terms) { this.terms = terms; List<NewWord> all = new ArrayList<>(); String name = null; Term term = null; reset(); for (int i = 0; i < terms.length; i++) { if (terms[i] == null) { continue; } term = terms[i]; // 如果名字的开始是人名的前缀,或者后缀.那么忽略 if (tempList.isEmpty()) { if (term.termNatures().personAttr.end > 10) { continue; } if ((terms[i].getName().length() == 1 && ISNOTFIRST.contains(terms[i].getName().charAt(0)))) { continue; } } name = term.getName(); if (term.termNatures() == TermNatures.NR || term.termNatures() == TermNatures.NW || name.length() == 1) { boolean flag = validate(name); if (flag) { tempList.add(term); } } else if (tempList.size() == 1) { reset(); } else if (tempList.size() > 1) { StringBuilder sb = new StringBuilder(); for (Term temp : tempList) { sb.append(temp.getName()); } all.add(new NewWord(sb.toString(), Nature.NRF)); reset(); } } return all; }
Example 8
Source File: TimeRecognition.java From deeplearning4j with Apache License 2.0 | 4 votes |
@Override public void recognition(Result result) { String name = ""; String timeWord = ""; List<Term> terms = result.getTerms(); LinkedList<Term> mergeList = new LinkedList<>(); List<Term> list = new LinkedList<>(); Pattern pattern = Pattern.compile("((\\d|[0123456789]){1,4}年(\\d|[0123456789]){1,2}月(\\d|[0123456789]){1,2}[日|号](上午|下午|中午|晚)?(\\s)*((\\d|[0123456789]){1,2}([点|时|點|時])?((:)?(\\d|[0123456789]){1,2}(分)?((:)?(\\d|[0123456789]){1,2}(秒)?)?)?)?(\\s)*(PM|AM)?|(\\d|[0123456789]){1,2}(月|月份)(\\d|[0123456789]){1,2}([日|号])?(上午|下午|中午|晚)?(\\s)*((\\d|[0123456789]){1,2}([点|时|點|時])?((:)?(\\d|[0123456789]){1,2}(分)?((:)?(\\d|[0123456789]){1,2}(秒)?)?)?)?(\\s)*(PM|AM)?|(\\d|[0123456789]){1,2}日(上午|下午|中午|晚)?(\\s)*((\\d|[0123456789]){1,2}([点|时|點|時])?((:)?(\\d|[0123456789]){1,2}(分)?((:)?(\\d|[0123456789]){1,2}(秒)?)?)?)?(\\s)*(PM|AM)?|(昨天|昨日|昨日上午|昨日下午|昨日晚上|昨天早上|昨天上午|昨天中午|昨天下午|昨晚|昨夜|昨天晚上|今天早上|今天上午|今天下午|今晚|今天晚上|今日上午|今日下午|今日|今天|前天|今年|去年|当日|当日上午|上午|下午|中午|清晨|前晚|早上|凌晨|今晨|近日|日前|不久前)((\\d|[0123456789]){1,2}[点|时|點|時])?((:)?(\\d|[0123456789]){1,2}(分)?((:)?(\\d|[0123456789]){1,2}(秒)?)?)?(\\s)*(PM|AM)?|[\\“|\"](1|2|3|4|5|6|7|8|9|10|11|12)[·|.| |-](\\d|[0123456789]){1,2}[\\”|\"]|星期[一|二|三|四|五|六|天|日]|(\\d|[0123456789]){1,2}[点|时|點|時]((:)?(\\d|[0123456789]){1,2}(分)?((:)?(\\d|[0123456789]){1,2}(秒)?)?)?(\\s)*(PM|AM)?|(\\d|[0123456789]){4}年((\\d|[0123456789]){1,2}月)?|(\\d|[0123456789]){1,2}月|(正|一|二|三|四|五|六|七|八|九|十|十一|十二|腊)月((初|十|二十|三十)[ 一二三四五六七八九十])?(上午|下午|中午|晚)?|((\\d|[0123456789]){4}-(\\d|[0123456789]){2}-(\\d|[0123456789]){2})?(\\s)*(\\d|[0123456789]){2}:(\\d|[0123456789]){2}:(\\d|[0123456789]){2}|(\\d|[0123456789]){4}-(\\d|[0123456789]){2}-(\\d|[0123456789]){2}(\\s)*((\\d|[0123456789]){2}:(\\d|[0123456789]){2}:(\\d|[0123456789]){2})?)", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE); for (int i = 0; i < terms.size(); i++) { boolean isTime = false; Term termBase = terms.get(i); int timeTermsLength = 1; int matchLength = 0; //匹配长度 for (int j = i; j < terms.size() && matchLength < 11; j++) { //向后最大找14个词匹配是否是时间词 Term term = terms.get(j); name = term.getName(); timeWord += name; Matcher matcher = pattern.matcher(timeWord); mergeList.add(term); if (matcher.matches()) { isTime = true; timeTermsLength += (j - i); i = j; } matchLength++; } if (isTime) { Term ft = mergeList.pollFirst(); for (int k = 0; k < timeTermsLength - 1; k++) { ft.merageWithBlank(mergeList.get(k)); } ft.setNature(nature); list.add(ft); } else { list.add(termBase); } mergeList.clear(); timeWord = ""; } result.setTerms(list); }