|
|
|
@ -1,6 +1,15 @@
|
|
|
|
|
package com.dsideal.base.Tools.FillData.Area;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
|
|
import com.alibaba.dashscope.aigc.generation.Generation;
|
|
|
|
|
import com.alibaba.dashscope.aigc.generation.GenerationResult;
|
|
|
|
|
import com.alibaba.dashscope.aigc.generation.models.QwenParam;
|
|
|
|
|
import com.alibaba.dashscope.common.Message;
|
|
|
|
|
import com.alibaba.dashscope.common.Role;
|
|
|
|
|
import com.alibaba.dashscope.exception.ApiException;
|
|
|
|
|
import com.alibaba.dashscope.exception.InputRequiredException;
|
|
|
|
|
import com.alibaba.dashscope.exception.NoApiKeyException;
|
|
|
|
|
import com.alibaba.dashscope.utils.Constants;
|
|
|
|
|
import com.dsideal.base.DataEase.Model.DataEaseModel;
|
|
|
|
|
import com.dsideal.base.Tools.FillData.DataEaseKit.DsKit;
|
|
|
|
|
import com.dsideal.base.Tools.Util.LocalMysqlConnectUtil;
|
|
|
|
@ -10,6 +19,8 @@ import org.apache.poi.ss.usermodel.Row;
|
|
|
|
|
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
|
|
|
|
|
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
|
|
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
|
|
import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
|
|
|
|
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
|
|
|
|
|
import org.dom4j.Document;
|
|
|
|
|
import org.dom4j.DocumentException;
|
|
|
|
|
import org.dom4j.Element;
|
|
|
|
@ -105,6 +116,28 @@ public class A13 {
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 调用通义千问
|
|
|
|
|
*
|
|
|
|
|
* @param question
|
|
|
|
|
* @return
|
|
|
|
|
* @throws NoApiKeyException
|
|
|
|
|
* @throws ApiException
|
|
|
|
|
* @throws InputRequiredException
|
|
|
|
|
*/
|
|
|
|
|
public static String callTongYiQianWen(String question)
|
|
|
|
|
throws NoApiKeyException, ApiException, InputRequiredException {
|
|
|
|
|
//使用驿来特的api key
|
|
|
|
|
Constants.apiKey = "sk-f6da0c787eff4b0389e4ad03a35a911f";
|
|
|
|
|
Generation gen = new Generation();
|
|
|
|
|
Message userMsg = Message.builder().role(Role.USER.getValue()).content(question).build();
|
|
|
|
|
QwenParam param =
|
|
|
|
|
QwenParam.builder().model("qwen-long").messages(Arrays.asList(userMsg))
|
|
|
|
|
.resultFormat(QwenParam.ResultFormat.MESSAGE).topP(0.8).build();
|
|
|
|
|
GenerationResult result = gen.call(param);
|
|
|
|
|
return result.getOutput().getChoices().getFirst().getMessage().getContent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static String rs(String s) {
|
|
|
|
|
//如果s中以 形如 (一) (二)或者 (三) (四)这样的内容替换为空,其它的内容保留下来
|
|
|
|
|
String regex = "(\\([一二三四五六七八九十]+\\))|(\\([一二三四五六七八九十]+\\))";
|
|
|
|
@ -112,7 +145,25 @@ public class A13 {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) throws IOException, DocumentException {
|
|
|
|
|
public static String get2012Summary(String filePath) {
|
|
|
|
|
try (FileInputStream fis = new FileInputStream(filePath);
|
|
|
|
|
XWPFDocument document = new XWPFDocument(fis)) {
|
|
|
|
|
|
|
|
|
|
List<XWPFParagraph> paragraphs = document.getParagraphs();
|
|
|
|
|
for (XWPFParagraph paragraph : paragraphs) {
|
|
|
|
|
String text = paragraph.getText();
|
|
|
|
|
if (text != null && text.trim().startsWith("2012")) {
|
|
|
|
|
return text.trim();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) throws IOException, DocumentException, NoApiKeyException, InputRequiredException {
|
|
|
|
|
//初始化数据库连接
|
|
|
|
|
LocalMysqlConnectUtil.Init();
|
|
|
|
|
//结果Excel
|
|
|
|
@ -170,7 +221,11 @@ public class A13 {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Row outRow = outSheet.createRow(++rowIndex);
|
|
|
|
|
DsKit.putData(outRow, Arrays.asList(areaName, "教育特征", "全县人口呈平稳增长趋势",
|
|
|
|
|
String content = get2012Summary(file.getAbsolutePath());
|
|
|
|
|
String question = "我将给你一段文字,帮我缩短到30字以内,我给出一个范例:红河人口负增长加剧,城镇人口先增后减,乡村人口剧减 ,后面就是原始文字:";
|
|
|
|
|
question += content;
|
|
|
|
|
String tz = callTongYiQianWen(question);
|
|
|
|
|
DsKit.putData(outRow, Arrays.asList(areaName, "教育特征", tz,
|
|
|
|
|
rs(list4.getFirst()),
|
|
|
|
|
rs(list4.get(1)),
|
|
|
|
|
rs(list4.get(2)),
|
|
|
|
|