|
@@ -5,6 +5,7 @@ import java.nio.charset.StandardCharsets;
|
|
|
import java.nio.file.Files;
|
|
|
import java.nio.file.Path;
|
|
|
import java.nio.file.Paths;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
@@ -23,14 +24,14 @@ import org.springframework.web.bind.annotation.PathVariable;
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
-import com.kgraph.common.annotation.Log;;
|
|
|
-import com.kgraph.common.core.controller.BaseController;;
|
|
|
-import com.kgraph.common.core.domain.AjaxResult;;
|
|
|
-import com.kgraph.common.enums.BusinessType;;
|
|
|
+import com.kgraph.common.annotation.Log;
|
|
|
+import com.kgraph.common.core.controller.BaseController;
|
|
|
+import com.kgraph.common.core.domain.AjaxResult;
|
|
|
+import com.kgraph.common.enums.BusinessType;
|
|
|
import com.kgraph.graph.suport.domain.ExtractResult;
|
|
|
import com.kgraph.graph.suport.service.IExtractResultService;
|
|
|
-import com.kgraph.common.utils.poi.ExcelUtil;;
|
|
|
-import com.kgraph.common.core.page.TableDataInfo;;
|
|
|
+import com.kgraph.common.utils.poi.ExcelUtil;
|
|
|
+import com.kgraph.common.core.page.TableDataInfo;
|
|
|
|
|
|
/**
|
|
|
* 抽取结果信息Controller
|
|
@@ -131,13 +132,7 @@ public class ExtractResultController extends BaseController
|
|
|
if (!FileUtils.checkAllowDownload(filePath)) {
|
|
|
throw new RuntimeException(StringUtils.format("文件名称({})非法,不允许下载。 ", filePath));
|
|
|
}
|
|
|
- String realFileName = FileUtils.getFileNameByPath(filePath);
|
|
|
-
|
|
|
-// String parentPath = dictDataService.getValueByTypeAndValue("kg_algorithm", "resultPath");
|
|
|
String filePathFinal = filePath;
|
|
|
-// if (StringUtils.isNotEmpty(parentPath)) {
|
|
|
-// filePathFinal = parentPath + filePathFinal;
|
|
|
-// }
|
|
|
Path path = Paths.get(filePathFinal);
|
|
|
String data = new String(Files.readAllBytes(path), StandardCharsets.UTF_8);
|
|
|
return AjaxResult.success("success", data);
|
|
@@ -170,8 +165,45 @@ public class ExtractResultController extends BaseController
|
|
|
if(StringUtils.isNotEmpty(resultPath)){
|
|
|
String data = (String) getResult(resultPath).get(AjaxResult.DATA_TAG);
|
|
|
JSONObject jsonObject = JSONObject.parseObject(data);
|
|
|
- return success(jsonObject);
|
|
|
+ return success(refactorData(jsonObject));
|
|
|
}
|
|
|
return error("没有生成抽取结果");
|
|
|
}
|
|
|
+ private JSONObject refactorData(JSONObject jsonObject) {
|
|
|
+ JSONArray dataList = new JSONArray();
|
|
|
+ JSONArray sentenceList = jsonObject.getJSONArray("sentenceList");
|
|
|
+ JSONArray knowledgeList = jsonObject.getJSONArray("knowledgeList");
|
|
|
+ int step = 5;
|
|
|
+ int sentSize = sentenceList.size();
|
|
|
+ int pageSize = (sentSize - 1) / step;
|
|
|
+ for (int i = 0; i <= pageSize; i++) {
|
|
|
+ JSONObject newData = new JSONObject();
|
|
|
+ JSONArray subSentenceList = new JSONArray();
|
|
|
+ JSONArray subKnowledgeList = new JSONArray();
|
|
|
+ List sentenceIdList = new ArrayList<>(8);;
|
|
|
+ for (int index = 0; index < step; index++) {
|
|
|
+ if(i * step + index >= sentSize){
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ JSONObject sentence = sentenceList.getJSONObject(i * step + index);
|
|
|
+ subSentenceList.add(sentence);
|
|
|
+ sentenceIdList.add(sentence.get("id"));
|
|
|
+ }
|
|
|
+ int size = knowledgeList.size();
|
|
|
+ for(int index = 0; index < size; index++){
|
|
|
+ JSONObject knowledge = knowledgeList.getJSONObject(index);
|
|
|
+ if(sentenceIdList.contains(knowledge.get("sentenceId"))){
|
|
|
+ subKnowledgeList.add(knowledge);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ newData.put("sentenceList",subSentenceList);
|
|
|
+ newData.put("knowledgeList",subKnowledgeList);
|
|
|
+ dataList.add(newData);
|
|
|
+ }
|
|
|
+ JSONObject returnValue = new JSONObject();
|
|
|
+ returnValue.put("dataList",dataList);
|
|
|
+ returnValue.put("total",pageSize+1);
|
|
|
+ returnValue.put("step",step);
|
|
|
+ return returnValue;
|
|
|
+ }
|
|
|
}
|