es封装
parent
be59d6b2ad
commit
0bfc0fd1c0
@ -1,13 +0,0 @@
|
|||||||
package com.ruoyi;
|
|
||||||
|
|
||||||
import com.ruoyi.biemo.nlp.NamedEntity;
|
|
||||||
|
|
||||||
public class Test {
|
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
|
||||||
String text = "巴拉克·奥巴马是美国总统。他在2008年当选?今年的美国总统是特朗普?普京的粉丝";
|
|
||||||
//System.out.println(new Segmentation(text).getSegtext());
|
|
||||||
//System.out.println(new SPTree(text).getPrasetext());
|
|
||||||
System.out.println(new NamedEntity(text).getNertext());
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,36 +1,36 @@
|
|||||||
//package com.ruoyi.biemo.mongodb.config;
|
package com.ruoyi.biemo.mongodb.config;
|
||||||
//
|
|
||||||
//import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
//import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
//import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
//import org.springframework.data.mongodb.MongoDatabaseFactory;
|
import org.springframework.data.mongodb.MongoDatabaseFactory;
|
||||||
//import org.springframework.data.mongodb.core.convert.DbRefResolver;
|
import org.springframework.data.mongodb.core.convert.DbRefResolver;
|
||||||
//import org.springframework.data.mongodb.core.convert.DefaultDbRefResolver;
|
import org.springframework.data.mongodb.core.convert.DefaultDbRefResolver;
|
||||||
//import org.springframework.data.mongodb.core.convert.DefaultMongoTypeMapper;
|
import org.springframework.data.mongodb.core.convert.DefaultMongoTypeMapper;
|
||||||
//import org.springframework.data.mongodb.core.convert.MappingMongoConverter;
|
import org.springframework.data.mongodb.core.convert.MappingMongoConverter;
|
||||||
//import org.springframework.data.mongodb.core.mapping.MongoMappingContext;
|
import org.springframework.data.mongodb.core.mapping.MongoMappingContext;
|
||||||
//
|
|
||||||
///**
|
/**
|
||||||
// * 配置去掉_class字段
|
* 配置去掉_class字段
|
||||||
// *
|
*
|
||||||
// * @author 陈钇蒙
|
* @author 陈钇蒙
|
||||||
// *
|
*
|
||||||
// */
|
*/
|
||||||
//@Configuration
|
@Configuration
|
||||||
//public class MongoConverterConfig {
|
public class MongoConverterConfig {
|
||||||
// @Autowired
|
@Autowired
|
||||||
// private MongoDatabaseFactory mongoDatabaseFactory;
|
private MongoDatabaseFactory mongoDatabaseFactory;
|
||||||
//
|
|
||||||
// @Autowired
|
@Autowired
|
||||||
// private MongoMappingContext mongoMappingContext;
|
private MongoMappingContext mongoMappingContext;
|
||||||
//
|
|
||||||
// @Bean
|
@Bean
|
||||||
// public MappingMongoConverter mappingMongoConverter() {
|
public MappingMongoConverter mappingMongoConverter() {
|
||||||
// DbRefResolver dbRefResolver = new DefaultDbRefResolver(mongoDatabaseFactory);
|
DbRefResolver dbRefResolver = new DefaultDbRefResolver(mongoDatabaseFactory);
|
||||||
// MappingMongoConverter converter = new MappingMongoConverter(dbRefResolver, mongoMappingContext);
|
MappingMongoConverter converter = new MappingMongoConverter(dbRefResolver, mongoMappingContext);
|
||||||
// // 此处是去除插入数据库的 _class 字段
|
// 此处是去除插入数据库的 _class 字段
|
||||||
// converter.setTypeMapper(new DefaultMongoTypeMapper(null));
|
converter.setTypeMapper(new DefaultMongoTypeMapper(null));
|
||||||
//
|
|
||||||
// return converter;
|
return converter;
|
||||||
// }
|
}
|
||||||
//}
|
}
|
||||||
|
@ -1,120 +1,120 @@
|
|||||||
//package com.ruoyi.biemo.mongodb.config;
|
package com.ruoyi.biemo.mongodb.config;
|
||||||
//
|
|
||||||
//import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
//import java.util.Set;
|
import java.util.Set;
|
||||||
//
|
|
||||||
//import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
//
|
|
||||||
//import com.ruoyi.biemo.mongodb.bean.IgnoreDocument;
|
import com.ruoyi.biemo.mongodb.bean.IgnoreDocument;
|
||||||
//import com.ruoyi.biemo.mongodb.bean.InitValue;
|
import com.ruoyi.biemo.mongodb.bean.InitValue;
|
||||||
//import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
//import org.springframework.data.mongodb.core.MongoTemplate;
|
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||||
//import org.springframework.data.mongodb.core.index.IndexOperations;
|
import org.springframework.data.mongodb.core.index.IndexOperations;
|
||||||
//import org.springframework.data.mongodb.core.index.IndexResolver;
|
import org.springframework.data.mongodb.core.index.IndexResolver;
|
||||||
//import org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexResolver;
|
import org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexResolver;
|
||||||
//import org.springframework.data.mongodb.core.mapping.Document;
|
import org.springframework.data.mongodb.core.mapping.Document;
|
||||||
//import org.springframework.data.mongodb.core.mapping.MongoMappingContext;
|
import org.springframework.data.mongodb.core.mapping.MongoMappingContext;
|
||||||
//import org.springframework.data.mongodb.core.query.Criteria;
|
import org.springframework.data.mongodb.core.query.Criteria;
|
||||||
//import org.springframework.data.mongodb.core.query.Query;
|
import org.springframework.data.mongodb.core.query.Query;
|
||||||
//import org.springframework.data.mongodb.core.query.Update;
|
import org.springframework.data.mongodb.core.query.Update;
|
||||||
//import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
//
|
|
||||||
//import com.mongodb.client.result.UpdateResult;
|
import com.mongodb.client.result.UpdateResult;
|
||||||
//
|
|
||||||
//import com.ruoyi.biemo.mongodb.utils.PackageUtil;
|
import com.ruoyi.biemo.mongodb.utils.PackageUtil;
|
||||||
//import cn.hutool.core.util.ClassUtil;
|
import cn.hutool.core.util.ClassUtil;
|
||||||
//import cn.hutool.core.util.ReflectUtil;
|
import cn.hutool.core.util.ReflectUtil;
|
||||||
//
|
|
||||||
///**
|
/**
|
||||||
// * 启动时将表初始化
|
* 启动时将表初始化
|
||||||
// *
|
*
|
||||||
// */
|
*/
|
||||||
//@Service
|
@Service
|
||||||
//public class ScanNewField {
|
public class ScanNewField {
|
||||||
// @Autowired
|
@Autowired
|
||||||
// PackageUtil packageUtil;
|
PackageUtil packageUtil;
|
||||||
// // 写链接(写到主库,可使用事务)
|
// 写链接(写到主库,可使用事务)
|
||||||
// @Autowired
|
@Autowired
|
||||||
// private MongoTemplate mongoTemplate;
|
private MongoTemplate mongoTemplate;
|
||||||
//
|
|
||||||
// @Autowired
|
@Autowired
|
||||||
// MongoMappingContext mongoMappingContext;
|
MongoMappingContext mongoMappingContext;
|
||||||
//
|
|
||||||
// @PostConstruct
|
@PostConstruct
|
||||||
// public void scan() {
|
public void scan() {
|
||||||
// // 找到主程序包
|
// 找到主程序包
|
||||||
// Set<Class<?>> set = ClassUtil.scanPackage(packageUtil.getMainPackage());
|
Set<Class<?>> set = ClassUtil.scanPackage(packageUtil.getMainPackage());
|
||||||
// for (Class<?> clazz : set) {
|
for (Class<?> clazz : set) {
|
||||||
// IgnoreDocument ignoreDocument = clazz.getAnnotation(IgnoreDocument.class);
|
IgnoreDocument ignoreDocument = clazz.getAnnotation(IgnoreDocument.class);
|
||||||
// if (ignoreDocument != null) {
|
if (ignoreDocument != null) {
|
||||||
// continue;
|
continue;
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// Document document = clazz.getAnnotation(Document.class);
|
Document document = clazz.getAnnotation(Document.class);
|
||||||
// if (document == null) {
|
if (document == null) {
|
||||||
// continue;
|
continue;
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// // 创建表
|
// 创建表
|
||||||
// if (!mongoTemplate.collectionExists(clazz)) {
|
if (!mongoTemplate.collectionExists(clazz)) {
|
||||||
// mongoTemplate.createCollection(clazz);
|
mongoTemplate.createCollection(clazz);
|
||||||
// System.out.println("创建了" + clazz.getSimpleName() + "表");
|
System.out.println("创建了" + clazz.getSimpleName() + "表");
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// // 创建索引
|
// 创建索引
|
||||||
// IndexOperations indexOps = mongoTemplate.indexOps(clazz);
|
IndexOperations indexOps = mongoTemplate.indexOps(clazz);
|
||||||
// IndexResolver resolver = new MongoPersistentEntityIndexResolver(mongoMappingContext);
|
IndexResolver resolver = new MongoPersistentEntityIndexResolver(mongoMappingContext);
|
||||||
// resolver.resolveIndexFor(clazz).forEach(indexOps::ensureIndex);
|
resolver.resolveIndexFor(clazz).forEach(indexOps::ensureIndex);
|
||||||
//
|
|
||||||
// Field[] fields = ReflectUtil.getFields(clazz);
|
Field[] fields = ReflectUtil.getFields(clazz);
|
||||||
// for (Field field : fields) {
|
for (Field field : fields) {
|
||||||
// // 获取注解
|
// 获取注解
|
||||||
// if (field.isAnnotationPresent(InitValue.class)) {
|
if (field.isAnnotationPresent(InitValue.class)) {
|
||||||
// InitValue initValue = field.getAnnotation(InitValue.class);
|
InitValue initValue = field.getAnnotation(InitValue.class);
|
||||||
// if (initValue.value() != null) {
|
if (initValue.value() != null) {
|
||||||
//
|
|
||||||
// // 更新表默认值
|
// 更新表默认值
|
||||||
// Query query = new Query();
|
Query query = new Query();
|
||||||
// query.addCriteria(Criteria.where(field.getName()).is(null));
|
query.addCriteria(Criteria.where(field.getName()).is(null));
|
||||||
//
|
|
||||||
// Long count = mongoTemplate.count(query, clazz);
|
Long count = mongoTemplate.count(query, clazz);
|
||||||
// if (count > 0) {
|
if (count > 0) {
|
||||||
// Object value = null;
|
Object value = null;
|
||||||
// Class<?> type = field.getType();
|
Class<?> type = field.getType();
|
||||||
//
|
|
||||||
// if (type.equals(String.class)) {
|
if (type.equals(String.class)) {
|
||||||
// value = initValue.value();
|
value = initValue.value();
|
||||||
// }
|
}
|
||||||
// if (type.equals(Short.class)) {
|
if (type.equals(Short.class)) {
|
||||||
// value = Short.parseShort(initValue.value());
|
value = Short.parseShort(initValue.value());
|
||||||
// }
|
}
|
||||||
// if (type.equals(Integer.class)) {
|
if (type.equals(Integer.class)) {
|
||||||
// value = Integer.parseInt(initValue.value());
|
value = Integer.parseInt(initValue.value());
|
||||||
// }
|
}
|
||||||
// if (type.equals(Long.class)) {
|
if (type.equals(Long.class)) {
|
||||||
// value = Long.parseLong(initValue.value());
|
value = Long.parseLong(initValue.value());
|
||||||
// }
|
}
|
||||||
// if (type.equals(Float.class)) {
|
if (type.equals(Float.class)) {
|
||||||
// value = Float.parseFloat(initValue.value());
|
value = Float.parseFloat(initValue.value());
|
||||||
// }
|
}
|
||||||
// if (type.equals(Double.class)) {
|
if (type.equals(Double.class)) {
|
||||||
// value = Double.parseDouble(initValue.value());
|
value = Double.parseDouble(initValue.value());
|
||||||
// }
|
}
|
||||||
// if (type.equals(Boolean.class)) {
|
if (type.equals(Boolean.class)) {
|
||||||
// value = Boolean.parseBoolean(initValue.value());
|
value = Boolean.parseBoolean(initValue.value());
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// Update update = new Update().set(field.getName(), value);
|
Update update = new Update().set(field.getName(), value);
|
||||||
// UpdateResult updateResult = mongoTemplate.updateMulti(query, update, clazz);
|
UpdateResult updateResult = mongoTemplate.updateMulti(query, update, clazz);
|
||||||
//
|
|
||||||
// System.out.println(clazz.getSimpleName() + "表更新了" + updateResult.getModifiedCount() + "条默认值");
|
System.out.println(clazz.getSimpleName() + "表更新了" + updateResult.getModifiedCount() + "条默认值");
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
//}
|
}
|
||||||
|
@ -1,137 +1,137 @@
|
|||||||
//package com.ruoyi.biemo.mongodb.utils;
|
package com.ruoyi.biemo.mongodb.utils;
|
||||||
//
|
|
||||||
//import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
//import java.io.File;
|
import java.io.File;
|
||||||
//import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
//import java.util.List;
|
import java.util.List;
|
||||||
//import java.util.Map;
|
import java.util.Map;
|
||||||
//import java.util.Set;
|
import java.util.Set;
|
||||||
//
|
|
||||||
//import com.ruoyi.biemo.mongodb.bean.Page;
|
import com.ruoyi.biemo.mongodb.bean.Page;
|
||||||
//import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
//import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
//import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
//import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
//import org.springframework.data.mongodb.core.MongoTemplate;
|
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||||
//import org.springframework.data.mongodb.core.mapping.Document;
|
import org.springframework.data.mongodb.core.mapping.Document;
|
||||||
//import org.springframework.data.mongodb.core.mapping.MongoMappingContext;
|
import org.springframework.data.mongodb.core.mapping.MongoMappingContext;
|
||||||
//import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
//
|
|
||||||
//import cn.hutool.core.io.FileUtil;
|
import cn.hutool.core.io.FileUtil;
|
||||||
//import cn.hutool.core.io.IoUtil;
|
import cn.hutool.core.io.IoUtil;
|
||||||
//import cn.hutool.core.util.ClassUtil;
|
import cn.hutool.core.util.ClassUtil;
|
||||||
//import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
//import cn.hutool.core.util.ZipUtil;
|
import cn.hutool.core.util.ZipUtil;
|
||||||
//import cn.hutool.json.JSONArray;
|
import cn.hutool.json.JSONArray;
|
||||||
//import cn.hutool.json.JSONObject;
|
import cn.hutool.json.JSONObject;
|
||||||
//import cn.hutool.json.JSONUtil;
|
import cn.hutool.json.JSONUtil;
|
||||||
//
|
|
||||||
///**
|
/**
|
||||||
// * 数据库导入导出工具
|
* 数据库导入导出工具
|
||||||
// *
|
*
|
||||||
// */
|
*/
|
||||||
//@Service
|
@Service
|
||||||
//public class ImportExportUtil {
|
public class ImportExportUtil {
|
||||||
// // 写链接(写到主库,可使用事务)
|
// 写链接(写到主库,可使用事务)
|
||||||
// @Autowired
|
@Autowired
|
||||||
// private MongoTemplate mongoTemplate;
|
private MongoTemplate mongoTemplate;
|
||||||
//
|
|
||||||
// @Autowired
|
@Autowired
|
||||||
// private MongoHelper mongoHelper;
|
private MongoHelper mongoHelper;
|
||||||
//
|
|
||||||
// @Autowired
|
@Autowired
|
||||||
// PackageUtil packageUtil;
|
PackageUtil packageUtil;
|
||||||
// public void exportDb(String path) {
|
public void exportDb(String path) {
|
||||||
// path = path.replace(".zip", "");
|
path = path.replace(".zip", "");
|
||||||
// FileUtil.del(path);
|
FileUtil.del(path);
|
||||||
// FileUtil.del(path + ".zip");
|
FileUtil.del(path + ".zip");
|
||||||
// try {
|
try {
|
||||||
//
|
|
||||||
// // 找到主程序包
|
// 找到主程序包
|
||||||
// Set<Class<?>> set = ClassUtil.scanPackage(packageUtil.getMainPackage());
|
Set<Class<?>> set = ClassUtil.scanPackage(packageUtil.getMainPackage());
|
||||||
// Page page = new Page();
|
Page page = new Page();
|
||||||
// page.setLimit(1000);
|
page.setLimit(1000);
|
||||||
//
|
|
||||||
// for (Class<?> clazz : set) {
|
for (Class<?> clazz : set) {
|
||||||
// Document document = clazz.getAnnotation(Document.class);
|
Document document = clazz.getAnnotation(Document.class);
|
||||||
// if (document == null) {
|
if (document == null) {
|
||||||
// continue;
|
continue;
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// page.setCurr(1);
|
page.setCurr(1);
|
||||||
// while (true) {
|
while (true) {
|
||||||
// page = mongoHelper.findPage(page, clazz);
|
page = mongoHelper.findPage(page, clazz);
|
||||||
// if (page.getList().size() == 0) {
|
if (page.getList().size() == 0) {
|
||||||
// break;
|
break;
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// List<String> lines = new ArrayList<String>();
|
List<String> lines = new ArrayList<String>();
|
||||||
// for (Object object : page.getList()) {
|
for (Object object : page.getList()) {
|
||||||
// lines.add(JSONUtil.toJsonStr(object));
|
lines.add(JSONUtil.toJsonStr(object));
|
||||||
// }
|
}
|
||||||
// FileUtil.appendLines(lines, path + File.separator + clazz.getSimpleName() + ".json", "UTF-8");
|
FileUtil.appendLines(lines, path + File.separator + clazz.getSimpleName() + ".json", "UTF-8");
|
||||||
// System.out.println(clazz.getSimpleName() + "表导出了" + page.getList().size() + "条数据");
|
System.out.println(clazz.getSimpleName() + "表导出了" + page.getList().size() + "条数据");
|
||||||
// page.setCurr(page.getCurr() + 1);
|
page.setCurr(page.getCurr() + 1);
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// ZipUtil.zip(path);
|
ZipUtil.zip(path);
|
||||||
//
|
|
||||||
// } catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// e.printStackTrace();
|
e.printStackTrace();
|
||||||
// FileUtil.del(path + ".zip");
|
FileUtil.del(path + ".zip");
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// FileUtil.del(path);
|
FileUtil.del(path);
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// public void importDb(String path) {
|
public void importDb(String path) {
|
||||||
// if (!FileUtil.exist(path)) {
|
if (!FileUtil.exist(path)) {
|
||||||
// System.out.println(path + "文件不存在");
|
System.out.println(path + "文件不存在");
|
||||||
// return;
|
return;
|
||||||
// }
|
}
|
||||||
// BufferedReader reader = null;
|
BufferedReader reader = null;
|
||||||
//
|
|
||||||
// path = path.replace(".zip", "");
|
path = path.replace(".zip", "");
|
||||||
// FileUtil.del(path);
|
FileUtil.del(path);
|
||||||
// ZipUtil.unzip(path + ".zip");
|
ZipUtil.unzip(path + ".zip");
|
||||||
// try {
|
try {
|
||||||
//
|
|
||||||
// // 找到主程序包
|
// 找到主程序包
|
||||||
// Set<Class<?>> set = ClassUtil.scanPackage(packageUtil.getMainPackage());
|
Set<Class<?>> set = ClassUtil.scanPackage(packageUtil.getMainPackage());
|
||||||
// for (Class<?> clazz : set) {
|
for (Class<?> clazz : set) {
|
||||||
// Document document = clazz.getAnnotation(Document.class);
|
Document document = clazz.getAnnotation(Document.class);
|
||||||
// if (document == null) {
|
if (document == null) {
|
||||||
// continue;
|
continue;
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// File file = new File(path + File.separator + clazz.getSimpleName() + ".json");
|
File file = new File(path + File.separator + clazz.getSimpleName() + ".json");
|
||||||
// if (file.exists()) {
|
if (file.exists()) {
|
||||||
// mongoTemplate.dropCollection(clazz);
|
mongoTemplate.dropCollection(clazz);
|
||||||
//
|
|
||||||
// reader = FileUtil.getReader(file, "UTF-8");
|
reader = FileUtil.getReader(file, "UTF-8");
|
||||||
// List<Object> list = new ArrayList<Object>();
|
List<Object> list = new ArrayList<Object>();
|
||||||
// while (true) {
|
while (true) {
|
||||||
// String json = reader.readLine();
|
String json = reader.readLine();
|
||||||
// if (StrUtil.isEmpty(json)) {
|
if (StrUtil.isEmpty(json)) {
|
||||||
// mongoTemplate.insertAll(list);
|
mongoTemplate.insertAll(list);
|
||||||
// System.out.println(clazz.getSimpleName() + "表导入了" + list.size() + "条数据");
|
System.out.println(clazz.getSimpleName() + "表导入了" + list.size() + "条数据");
|
||||||
// list.clear();
|
list.clear();
|
||||||
// break;
|
break;
|
||||||
// }
|
}
|
||||||
// list.add(JSONUtil.toBean(json, clazz));
|
list.add(JSONUtil.toBean(json, clazz));
|
||||||
// if (list.size() == 1000) {
|
if (list.size() == 1000) {
|
||||||
// mongoTemplate.insertAll(list);
|
mongoTemplate.insertAll(list);
|
||||||
// System.out.println(clazz.getSimpleName() + "表导入了" + list.size() + "条数据");
|
System.out.println(clazz.getSimpleName() + "表导入了" + list.size() + "条数据");
|
||||||
// list.clear();
|
list.clear();
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// } catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// e.printStackTrace();
|
e.printStackTrace();
|
||||||
// } finally {
|
} finally {
|
||||||
// IoUtil.close(reader);
|
IoUtil.close(reader);
|
||||||
// }
|
}
|
||||||
// FileUtil.del(path);
|
FileUtil.del(path);
|
||||||
// }
|
}
|
||||||
//}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1,22 +0,0 @@
|
|||||||
package com.ruoyi.biemo.nlp;
|
|
||||||
|
|
||||||
import edu.stanford.nlp.pipeline.StanfordCoreNLP;
|
|
||||||
|
|
||||||
public class CoreNLPHel {
|
|
||||||
private static CoreNLPHel instance = new CoreNLPHel();
|
|
||||||
private StanfordCoreNLP pipeline;
|
|
||||||
|
|
||||||
private CoreNLPHel() {
|
|
||||||
String props = "CoreNLP-chinese.properties";
|
|
||||||
pipeline = new StanfordCoreNLP(props);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static CoreNLPHel getInstance() {
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
public StanfordCoreNLP getPipeline() {
|
|
||||||
return pipeline;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,38 +0,0 @@
|
|||||||
package com.ruoyi.biemo.nlp;
|
|
||||||
|
|
||||||
import edu.stanford.nlp.ling.CoreAnnotations;
|
|
||||||
import edu.stanford.nlp.ling.CoreLabel;
|
|
||||||
import edu.stanford.nlp.pipeline.Annotation;
|
|
||||||
import edu.stanford.nlp.pipeline.StanfordCoreNLP;
|
|
||||||
import edu.stanford.nlp.util.CoreMap;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class PosTag {
|
|
||||||
|
|
||||||
private String postext = "";
|
|
||||||
|
|
||||||
public String getPostext() {
|
|
||||||
return postext;
|
|
||||||
}
|
|
||||||
public PosTag(String text){
|
|
||||||
|
|
||||||
CoreNLPHel coreNLPHel = CoreNLPHel.getInstance();
|
|
||||||
StanfordCoreNLP pipeline = coreNLPHel.getPipeline();
|
|
||||||
Annotation annotation = new Annotation(text);
|
|
||||||
pipeline.annotate(annotation);
|
|
||||||
List<CoreMap> sentences = annotation.get(CoreAnnotations.SentencesAnnotation.class);
|
|
||||||
StringBuffer sb = new StringBuffer();
|
|
||||||
for (CoreMap sentence:sentences){
|
|
||||||
for (CoreLabel token : sentence.get(CoreAnnotations.TokensAnnotation.class)){
|
|
||||||
String word = token.get(CoreAnnotations.TextAnnotation.class);
|
|
||||||
String pos = token.get(CoreAnnotations.PartOfSpeechAnnotation.class);
|
|
||||||
sb.append(word);
|
|
||||||
sb.append("/");
|
|
||||||
sb.append(pos);
|
|
||||||
sb.append(" ");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
postext = sb.toString().trim();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,51 +0,0 @@
|
|||||||
package com.ruoyi.biemo.nlp;
|
|
||||||
|
|
||||||
import edu.stanford.nlp.ling.CoreAnnotations;
|
|
||||||
import edu.stanford.nlp.pipeline.Annotation;
|
|
||||||
import edu.stanford.nlp.pipeline.StanfordCoreNLP;
|
|
||||||
import edu.stanford.nlp.semgraph.SemanticGraph;
|
|
||||||
import edu.stanford.nlp.semgraph.SemanticGraphCoreAnnotations;
|
|
||||||
import edu.stanford.nlp.trees.Tree;
|
|
||||||
import edu.stanford.nlp.trees.TreeCoreAnnotations;
|
|
||||||
import edu.stanford.nlp.util.CoreMap;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class SPTree {
|
|
||||||
List<CoreMap>sentences;
|
|
||||||
|
|
||||||
public SPTree(String text){
|
|
||||||
CoreNLPHel coreNLPHel = CoreNLPHel.getInstance();
|
|
||||||
StanfordCoreNLP pipeline = coreNLPHel.getPipeline();
|
|
||||||
Annotation annotation = new Annotation(text);
|
|
||||||
pipeline.annotate(annotation);
|
|
||||||
sentences = annotation.get(CoreAnnotations.SentencesAnnotation.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
//句子的依赖图(依存分析)
|
|
||||||
public String getDepprasetext() {
|
|
||||||
StringBuffer sb2 = new StringBuffer();
|
|
||||||
for (CoreMap sentence:sentences){
|
|
||||||
String sentext = sentence.get(CoreAnnotations.TextAnnotation.class);
|
|
||||||
SemanticGraph graph = sentence.get(SemanticGraphCoreAnnotations.BasicDependenciesAnnotation.class);
|
|
||||||
//System.out.println("句子的依赖图");
|
|
||||||
sb2.append(sentext);
|
|
||||||
sb2.append("\n");
|
|
||||||
sb2.append(graph.toString(SemanticGraph.OutputFormat.LIST));
|
|
||||||
sb2.append("\n");
|
|
||||||
}
|
|
||||||
return sb2.toString().trim();
|
|
||||||
}
|
|
||||||
// 句子的解析树
|
|
||||||
public String getPrasetext() {
|
|
||||||
StringBuffer sb1 = new StringBuffer();
|
|
||||||
for (CoreMap sentence:sentences){
|
|
||||||
Tree tree = sentence.get(TreeCoreAnnotations.TreeAnnotation.class);
|
|
||||||
String sentext = sentence.get(CoreAnnotations.TextAnnotation.class);
|
|
||||||
sb1.append(sentext);
|
|
||||||
sb1.append("/");
|
|
||||||
sb1.append(tree.toString());
|
|
||||||
sb1.append("\n");
|
|
||||||
}
|
|
||||||
return sb1.toString().trim();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,47 +0,0 @@
|
|||||||
package com.ruoyi.biemo.nlp;
|
|
||||||
import edu.stanford.nlp.ling.CoreAnnotations;
|
|
||||||
import edu.stanford.nlp.ling.CoreLabel;
|
|
||||||
import edu.stanford.nlp.pipeline.Annotation;
|
|
||||||
import edu.stanford.nlp.pipeline.StanfordCoreNLP;
|
|
||||||
import edu.stanford.nlp.util.CoreMap;
|
|
||||||
import edu.stanford.nlp.util.PropertiesUtils;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class Segmentation {
|
|
||||||
private String segtext="";
|
|
||||||
|
|
||||||
public String getSegtext() {
|
|
||||||
return segtext;
|
|
||||||
}
|
|
||||||
public Segmentation(String text){
|
|
||||||
// StanfordCoreNLP pipeline = new StanfordCoreNLP(PropertiesUtils.asProperties(
|
|
||||||
// "annotators", "tokenize,ssplit",
|
|
||||||
// "ssplit.isOneSentence", "true",
|
|
||||||
// "tokenize.language", "zh",
|
|
||||||
// "segment.model", "edu/stanford/nlp/models/segmenter/chinese/ctb.gz",
|
|
||||||
// "segment.sighanCorporaDict", "edu/stanford/nlp/models/segmenter/chinese",
|
|
||||||
// "segment.serDictionary", "edu/stanford/nlp/models/segmenter/chinese/dict-chris6.ser.gz",
|
|
||||||
// "segment.sighanPostProcessing", "true"
|
|
||||||
// ));
|
|
||||||
StanfordCoreNLP pipeline = CoreNLPHel.getInstance().getPipeline();
|
|
||||||
Annotation annotation = new Annotation(text);
|
|
||||||
pipeline.annotate(annotation);
|
|
||||||
List<CoreMap> sentences = annotation.get(CoreAnnotations.SentencesAnnotation.class);
|
|
||||||
//ArrayList<String> array = new ArrayList<String>();
|
|
||||||
StringBuffer sb = new StringBuffer();
|
|
||||||
for (CoreMap sentence:sentences){
|
|
||||||
for (CoreLabel token : sentence.get(CoreAnnotations.TokensAnnotation.class)){
|
|
||||||
String word = token.get(CoreAnnotations.TextAnnotation.class);
|
|
||||||
sb.append(word);
|
|
||||||
sb.append(" ");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
segtext = sb.toString().trim();
|
|
||||||
//segtext = array.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,28 +0,0 @@
|
|||||||
package com.ruoyi.biemo.nlp;
|
|
||||||
|
|
||||||
import edu.stanford.nlp.ling.CoreAnnotations;
|
|
||||||
import edu.stanford.nlp.pipeline.Annotation;
|
|
||||||
import edu.stanford.nlp.pipeline.StanfordCoreNLP;
|
|
||||||
import edu.stanford.nlp.util.CoreMap;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class SenSplit {
|
|
||||||
|
|
||||||
private ArrayList<String>sensRes = new ArrayList<String>();
|
|
||||||
|
|
||||||
public ArrayList<String> getSensRes() {
|
|
||||||
return sensRes; //返回存储句子的数组(ArrayList类型)
|
|
||||||
}
|
|
||||||
public SenSplit(String text){
|
|
||||||
CoreNLPHel coreNLPHel = CoreNLPHel.getInstance();
|
|
||||||
StanfordCoreNLP pipeline = coreNLPHel.getPipeline();
|
|
||||||
Annotation annotation = new Annotation(text);
|
|
||||||
pipeline.annotate(annotation);
|
|
||||||
List<CoreMap>sentences = annotation.get(CoreAnnotations.SentencesAnnotation.class);
|
|
||||||
for (CoreMap setence:sentences){
|
|
||||||
sensRes.add(setence.get(CoreAnnotations.TextAnnotation.class));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,42 @@
|
|||||||
|
package com.ruoyi.common.exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自定义异常
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class CustomException extends RuntimeException
|
||||||
|
{
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
private Integer code;
|
||||||
|
|
||||||
|
private String message;
|
||||||
|
|
||||||
|
public CustomException(String message)
|
||||||
|
{
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CustomException(String message, Integer code)
|
||||||
|
{
|
||||||
|
this.message = message;
|
||||||
|
this.code = code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CustomException(String message, Throwable e)
|
||||||
|
{
|
||||||
|
super(message, e);
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getMessage()
|
||||||
|
{
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getCode()
|
||||||
|
{
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue