main
黄海 8 months ago
parent f9bb2c7492
commit dca57c8cb8

@ -221,10 +221,11 @@ public class A13 {
} }
} }
Row outRow = outSheet.createRow(++rowIndex); Row outRow = outSheet.createRow(++rowIndex);
String content = get2012Summary(file.getAbsolutePath()); //String content = get2012Summary(file.getAbsolutePath());
String question = "我将给你一段文字帮我缩短到30字以内,我给出一个范例:红河人口负增长加剧,城镇人口先增后减,乡村人口剧减 ,后面就是原始文字:"; //String question = "帮我对下面内容进行归纳总结润色不超过30字:";
question += content; //question += content;
String tz = callTongYiQianWen(question); // String tz = callTongYiQianWen(question);
String tz = "";
DsKit.putData(outRow, Arrays.asList(areaName, "教育特征", tz, DsKit.putData(outRow, Arrays.asList(areaName, "教育特征", tz,
rs(list4.getFirst()), rs(list4.getFirst()),
rs(list4.get(1)), rs(list4.get(1)),
@ -236,7 +237,7 @@ public class A13 {
cityName), dataStyle); cityName), dataStyle);
List<String> list5 = get(5); List<String> list5 = get(5);
System.out.println(list5);
//如果list5的元素个数不足8个需要补全到8个空的用空字符串 //如果list5的元素个数不足8个需要补全到8个空的用空字符串
if (list5.size() < 8) { if (list5.size() < 8) {
for (int i = list5.size(); i < 8; i++) { for (int i = list5.size(); i < 8; i++) {

@ -12,6 +12,7 @@ import com.alibaba.dashscope.utils.Constants;
import org.dom4j.DocumentException; import org.dom4j.DocumentException;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import org.apache.poi.xwpf.usermodel.XWPFDocument; import org.apache.poi.xwpf.usermodel.XWPFDocument;
@ -19,7 +20,6 @@ import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFRun; import org.apache.poi.xwpf.usermodel.XWPFRun;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.List; import java.util.List;
@ -47,6 +47,10 @@ public class A15 {
return result.getOutput().getChoices().getFirst().getMessage().getContent(); return result.getOutput().getChoices().getFirst().getMessage().getContent();
} }
public static String removeEmptyLines(String text) {
// 使用正则表达式分割字符串,然后过滤掉空行
return text.replace("\n\n", "\n");
}
public static void main(String[] args) throws IOException, DocumentException, NoApiKeyException, InputRequiredException { public static void main(String[] args) throws IOException, DocumentException, NoApiKeyException, InputRequiredException {
String filePath = "D:\\dsWork\\YunNanDsBase\\Doc\\县区研究报告\\保山市\\昌宁县人口变化及其对教育的影响.docx"; String filePath = "D:\\dsWork\\YunNanDsBase\\Doc\\县区研究报告\\保山市\\昌宁县人口变化及其对教育的影响.docx";
@ -56,20 +60,34 @@ public class A15 {
XWPFDocument document = new XWPFDocument(inputStream); XWPFDocument document = new XWPFDocument(inputStream);
List<XWPFParagraph> paragraphs = document.getParagraphs(); List<XWPFParagraph> paragraphs = document.getParagraphs();
String[] a = {"学前教育发展规模现状", "小学教育发展规模现状", "初中教育发展规模现状", "高中教育发展规模现状", "基础教育资源配置现状"};
//接下我将遍历 word文档 中的每一段文字,如果遍历到的文字中包含上面数组的某一个字符串,开始截取此学段的文字
for (XWPFParagraph paragraph : paragraphs) { for (XWPFParagraph paragraph : paragraphs) {
List<XWPFRun> runs = paragraph.getRuns(); List<XWPFRun> runs = paragraph.getRuns();
for (XWPFRun run : runs) { for (XWPFRun run : runs) {
String text = run.getText(0); String text = run.getText(0);
if (text != null) { if (text != null) {
content = content + text; content += text;
} }
} }
} }
String question = "我将给你提供一大段文字,帮我总结下学前教育幼儿入园情况,划分两个阶段:(1)学前教育过去几年入园情况 (2)学前教育幼儿入园未来发展预测。语言尽量精简。"; List<Integer> posList = new ArrayList<>();
question += "示例: 1. 与2022年相比寻甸县未来几年学前教育幼儿入园人数增长不大至2035年预计在6800左右仅增加几百人"; for (String s : a) {
question += "2. 未来镇区幼儿入园人数将逐年增加,而乡村幼儿入园人数将明显减少。"; int pos = content.indexOf(s);
question += "下面是文字内容:"; posList.add(pos);
question += content; }
System.out.println(callTongYiQianWen(question)); List<String> res = new ArrayList<>();
for (int i = 0; i < posList.size() - 1; i++) {
int start = posList.get(i) + a[i].length(), end = posList.get(i + 1);
res.add(content.substring(start, end));
}
for (String re : res) {
String question = "我将给你提供一大段文字,帮我总结下入园或招生情况,划分两个阶段:(1)过去几年入园、招生情况 (2)入园、招生未来发展预测。尽量保留文中原话一个阶段不要超过30字。不要使用markdown语法。";
question += "示例: 1. 与2022年相比寻甸县未来几年学前教育幼儿入园人数增长不大至2035年预计在6800左右仅增加几百人";
question += "2. 未来镇区幼儿入园人数将逐年增加,而乡村幼儿入园人数将明显减少。";
question += "下面是文字内容:";
question += re;
System.out.println(removeEmptyLines(callTongYiQianWen(question)));
}
} }
} }
Loading…
Cancel
Save