提交 20f4084e 编写于 作者: Z zhourui

增加pickPersonWithName设置

上级 5effb049
...@@ -3,6 +3,7 @@ package com.x.base.core.project.config; ...@@ -3,6 +3,7 @@ package com.x.base.core.project.config;
import java.io.File; import java.io.File;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.BooleanUtils;
import com.x.base.core.project.annotation.FieldDescribe; import com.x.base.core.project.annotation.FieldDescribe;
import com.x.base.core.project.gson.XGsonBuilder; import com.x.base.core.project.gson.XGsonBuilder;
...@@ -14,7 +15,8 @@ public class Organization extends ConfigObject { ...@@ -14,7 +15,8 @@ public class Organization extends ConfigObject {
private static final long serialVersionUID = -2193428649985413384L; private static final long serialVersionUID = -2193428649985413384L;
public final static Integer DEFAULT_UNITLEVELORDERNUMBERDIGITS = 10; public static final Integer DEFAULT_UNITLEVELORDERNUMBERDIGITS = 10;
public static final Boolean DEFAULT_PICKPERSONWITHNAME = false;
public static Organization defaultInstance() { public static Organization defaultInstance() {
return new Organization(); return new Organization();
...@@ -23,11 +25,18 @@ public class Organization extends ConfigObject { ...@@ -23,11 +25,18 @@ public class Organization extends ConfigObject {
@FieldDescribe("unit中unitLevelOrderNumber扩充位数,<=0不扩充.") @FieldDescribe("unit中unitLevelOrderNumber扩充位数,<=0不扩充.")
private Integer unitLevelOrderNumberDigits = DEFAULT_UNITLEVELORDERNUMBERDIGITS; private Integer unitLevelOrderNumberDigits = DEFAULT_UNITLEVELORDERNUMBERDIGITS;
@FieldDescribe("人员识别过程中过程为先查找 distinguishedName 再查找中间的 unique 如果还是没有查找到是否要通过那么进行查找.")
private Boolean pickPersonWithName = DEFAULT_PICKPERSONWITHNAME;
public Integer getUnitLevelOrderNumberDigits() { public Integer getUnitLevelOrderNumberDigits() {
return NumberTools.nullOrLessThan(this.unitLevelOrderNumberDigits, 1) ? DEFAULT_UNITLEVELORDERNUMBERDIGITS return NumberTools.nullOrLessThan(this.unitLevelOrderNumberDigits, 1) ? DEFAULT_UNITLEVELORDERNUMBERDIGITS
: this.unitLevelOrderNumberDigits; : this.unitLevelOrderNumberDigits;
} }
public Boolean getPickPersonWithName() {
return BooleanUtils.isTrue(this.pickPersonWithName);
}
public void save() throws Exception { public void save() throws Exception {
File file = new File(Config.base(), Config.PATH_CONFIG_ORGANIZATION); File file = new File(Config.base(), Config.PATH_CONFIG_ORGANIZATION);
FileUtils.write(file, XGsonBuilder.toJson(this), DefaultCharset.charset); FileUtils.write(file, XGsonBuilder.toJson(this), DefaultCharset.charset);
......
package com.x.base.core.project.nlp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import com.hankcs.hanlp.HanLP;
import com.hankcs.hanlp.seg.common.Term;
import com.x.base.core.project.gson.GsonPropertyObject;
public class NaturalLanguageProcessing {
public static String[] SKIP_START_WITH = new String[] { "~", "!", "#", "$", "%", "^", "&", "*", "(", ")", "<", ">",
"[", "]", "{", "}", "\\", "?" };
public static String[] SKIP_END_WITH = new String[] { "~", "!", "#", "$", "%", "^", "&", "*", "(", ")", "<", ">",
"[", "]", "{", "}", "\\", "?" };
public List<Item> word(String content) {
List<Item> items = new ArrayList<>();
if (StringUtils.isNotBlank(content)) {
for (Term t : HanLP.segment(content)) {
Item item = new Item();
item.setLabel(t.nature.toString());
/* 去掉中文空格和空格 */
item.setValue(StringUtils.trimToEmpty(StringUtils.replace(t.word, " ", " ")));
if (!skip(item)) {
items.add(item);
}
}
}
/*
* b 区别词 c 连词 d 副词 e 叹词 f 方位词 h 前缀 k 后缀 o 拟声词 p 介词 q 量词 r 代词 u 组词 w 标点
*/
items = items.stream()
// .filter(o -> (StringUtils.length(o.getValue()) > 1)
// && (!StringUtils.startsWithAny(o.getValue(), SKIP_START_WITH))
// && (!StringUtils.endsWithAny(o.getValue(), SKIP_END_WITH))
// && (!StringUtils.startsWithIgnoreCase(o.getLabel(), "b"))
// && (!StringUtils.startsWithIgnoreCase(o.getLabel(), "c"))
// && (!StringUtils.startsWithIgnoreCase(o.getLabel(), "d"))
// && (!StringUtils.startsWithIgnoreCase(o.getLabel(), "e"))
// && (!StringUtils.startsWithIgnoreCase(o.getLabel(), "f"))
// && (!StringUtils.startsWithIgnoreCase(o.getLabel(), "h"))
// && (!StringUtils.startsWithIgnoreCase(o.getLabel(), "k"))
// && (!StringUtils.startsWithIgnoreCase(o.getLabel(), "o"))
// && (!StringUtils.startsWithIgnoreCase(o.getLabel(), "p"))
// && (!StringUtils.startsWithIgnoreCase(o.getLabel(), "q"))
// && (!StringUtils.startsWithIgnoreCase(o.getLabel(), "r"))
// && (!StringUtils.startsWithIgnoreCase(o.getLabel(), "u"))
// && (!StringUtils.startsWithIgnoreCase(o.getLabel(), "w")) && (!label_skip_m(o)))
.collect(Collectors.toList());
Map<Item, Long> map = items.stream().collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
List<Item> list = new ArrayList<>();
map.entrySet().stream().sorted(Map.Entry.<Item, Long>comparingByValue().reversed()).forEach(o -> {
Item t = o.getKey();
t.setCount(o.getValue());
list.add(t);
});
return list;
}
private boolean skip(Item o) {
if ((StringUtils.length(o.getValue()) > 1) && (!StringUtils.startsWithAny(o.getValue(), SKIP_START_WITH))
&& (!StringUtils.endsWithAny(o.getValue(), SKIP_END_WITH))
&& (!StringUtils.startsWithIgnoreCase(o.getLabel(), "b"))
&& (!StringUtils.startsWithIgnoreCase(o.getLabel(), "c"))
&& (!StringUtils.startsWithIgnoreCase(o.getLabel(), "d"))
&& (!StringUtils.startsWithIgnoreCase(o.getLabel(), "e"))
&& (!StringUtils.startsWithIgnoreCase(o.getLabel(), "f"))
&& (!StringUtils.startsWithIgnoreCase(o.getLabel(), "h"))
&& (!StringUtils.startsWithIgnoreCase(o.getLabel(), "k"))
&& (!StringUtils.startsWithIgnoreCase(o.getLabel(), "o"))
&& (!StringUtils.startsWithIgnoreCase(o.getLabel(), "p"))
&& (!StringUtils.startsWithIgnoreCase(o.getLabel(), "q"))
&& (!StringUtils.startsWithIgnoreCase(o.getLabel(), "r"))
&& (!StringUtils.startsWithIgnoreCase(o.getLabel(), "u"))
&& (!StringUtils.startsWithIgnoreCase(o.getLabel(), "w")) && (!label_skip_m(o))) {
return false;
}
return true;
}
private boolean label_skip_m(Item item) {
if (!StringUtils.startsWithIgnoreCase(item.getLabel(), "m")) {
return false;
} else {
return NumberUtils.isParsable(item.getValue());
}
}
public static class Item extends GsonPropertyObject {
private String value;
private String label;
private Long count;
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
public Long getCount() {
return count;
}
public void setCount(Long count) {
this.count = count;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((value == null) ? 0 : value.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Item other = (Item) obj;
if (value == null) {
if (other.value != null)
return false;
} else if (!value.equals(other.value))
return false;
return true;
}
}
}
\ No newline at end of file
...@@ -13,12 +13,14 @@ import javax.persistence.criteria.CriteriaQuery; ...@@ -13,12 +13,14 @@ import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root; import javax.persistence.criteria.Root;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import com.x.base.core.entity.JpaObject; import com.x.base.core.entity.JpaObject;
import com.x.base.core.project.cache.Cache.CacheCategory; import com.x.base.core.project.cache.Cache.CacheCategory;
import com.x.base.core.project.cache.Cache.CacheKey; import com.x.base.core.project.cache.Cache.CacheKey;
import com.x.base.core.project.cache.CacheManager; import com.x.base.core.project.cache.CacheManager;
import com.x.base.core.project.config.Config;
import com.x.base.core.project.tools.ListTools; import com.x.base.core.project.tools.ListTools;
import com.x.organization.assemble.express.AbstractFactory; import com.x.organization.assemble.express.AbstractFactory;
import com.x.organization.assemble.express.Business; import com.x.organization.assemble.express.Business;
...@@ -69,7 +71,7 @@ public class PersonFactory extends AbstractFactory { ...@@ -69,7 +71,7 @@ public class PersonFactory extends AbstractFactory {
this.entityManagerContainer().get(Person.class).detach(o); this.entityManagerContainer().get(Person.class).detach(o);
} }
} }
if (null == o) { if ((null == o) && BooleanUtils.isTrue(Config.organization().getPickPersonWithName())) {
EntityManager em = this.entityManagerContainer().get(Person.class); EntityManager em = this.entityManagerContainer().get(Person.class);
CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Person> cq = cb.createQuery(Person.class); CriteriaQuery<Person> cq = cb.createQuery(Person.class);
...@@ -169,8 +171,8 @@ public class PersonFactory extends AbstractFactory { ...@@ -169,8 +171,8 @@ public class PersonFactory extends AbstractFactory {
CriteriaQuery<String> cq = cb.createQuery(String.class); CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<Person> root = cq.from(Person.class); Root<Person> root = cq.from(Person.class);
Predicate p = cb.equal(root.get(Person_.superior), person.getId()); Predicate p = cb.equal(root.get(Person_.superior), person.getId());
list = em.createQuery(cq.select(root.get(Person_.id)).where(p)) list = em.createQuery(cq.select(root.get(Person_.id)).where(p)).getResultList().stream().distinct()
.getResultList().stream().distinct().collect(Collectors.toList()); .collect(Collectors.toList());
return list; return list;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册