Compare commits

...

9 Commits

  1. 10
      kcui/src/api/kcInfo.js
  2. BIN
      kcui/src/assets/img/leftBox1.png
  3. BIN
      kcui/src/assets/img/tt.png
  4. BIN
      kcui/src/assets/img/twbg.jpg
  5. 6
      kcui/src/router/router.js
  6. 68
      kcui/src/view/Graph.vue
  7. 438
      kcui/src/view/TWInfo.vue
  8. 183
      src/main/java/com/main/woka/Common/util/RelationUtil.java
  9. 188
      src/main/java/com/main/woka/Common/util/RelationUtil1.java
  10. 2
      src/main/java/com/main/woka/Filter/TestFilter.java
  11. 89
      src/main/java/com/main/woka/Web/Controller/KcInfoController.java
  12. 9
      src/main/java/com/main/woka/Web/Dao/KcInfo.java
  13. 23
      src/main/java/com/main/woka/Web/Service/impl/KcTlFileServiceImpl.java
  14. 3
      src/main/resources/application.properties

10
kcui/src/api/kcInfo.js

@ -12,3 +12,13 @@ export function getDocList(data) {
}
})
}
export function getTwInfo(params) {
return request({
url: '/kcDoc/getTwInfo',
method: 'get',
params,
headers: {
'Authorization': 'Bearer '+ getToken() // 将 token 放在请求头中
}
})
}

BIN
kcui/src/assets/img/leftBox1.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

BIN
kcui/src/assets/img/tt.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

BIN
kcui/src/assets/img/twbg.jpg

Binary file not shown.

After

Width:  |  Height:  |  Size: 971 KiB

6
kcui/src/router/router.js

@ -5,6 +5,7 @@ import Home from '@/view/Graph.vue'
import Book from '@/view/Book.vue'
import Calculator from "@/view/Calculator.vue";
import TwInfo from '@/view/TWInfo.vue'
import TwInfoXq from '@/view/TWInfoXq.vue'
import Login from '@/view/Login.vue'
import Mulu from '@/view/Mulu.vue'
//2.调用vue.use() 函数,把 VueRouter 安装为 Vue 的插件
@ -44,5 +45,10 @@ export default new VueRouter({
name: 'TwInfo', //路由名称,
component: TwInfo //对应的组件模板
},
{ //每一个链接都是一个对象
path: '/TwInfoXq', //链接路径
name: 'TwInfoXq', //路由名称,
component: TwInfoXq //对应的组件模板
},
]
})

68
kcui/src/view/Graph.vue

@ -1,10 +1,12 @@
<template>
<div style="width: 100%;height: 100%;">
<div style="width: 100%;height: 4vw;background-color: #42b983;">
<div style="background-color: silver;width: 3vw;height: 2vw;line-height: 2vw;text-align: center;" @click="goBook">跳转1</div>
<div style="background-color: silver;width: 3vw;height: 2vw;line-height: 2vw;text-align: center;" @click="goBook">
跳转1
</div>
<div class="stText">关键字:</div>
<input class="stInput" placeholder="请输入关键字" v-model="keywords"/>
<div @click="getInfo"
<div @click="getInfo1"
style="width: 4vw;height: 2vw;margin-left:0.2vw;background-color: #0AB7FD;float: right;font-size: 1vw;line-height: 2vw;text-align: center;border-radius:2vw;margin-top: 0.1vw;">
查询
</div>
@ -30,9 +32,10 @@
</el-form-item>
<el-form-item label="类型">
<el-select v-model="typeValue" placeholder="请选择类型">
<el-option label="图文" value="图文"></el-option>
<el-option label="视频" value="视频"></el-option>
<el-option label="动画" value="动画"></el-option>
<el-option label="图文" value="tw"></el-option>
<el-option label="视频" value="sp"></el-option>
<el-option label="动画" value="dh"></el-option>
<el-option label="计算模块" value="jsmk"></el-option>
</el-select>
</el-form-item>
<el-form-item label="节点名称">
@ -70,7 +73,7 @@ import {addNode, getFileIdByDocId} from "@/api/file";
export default {
// eslint-disable-next-line vue/multi-word-component-names
name: 'Graph',
name: 'Home',
data() {
return {
infos: [],
@ -101,16 +104,10 @@ export default {
onCreated(editor) {
this.editor = Object.seal(editor) // Object.seal()
},
// getInfo(){
// var data = {}
// getgraphInfo(data).then((res)=>{
// this.zhengl(res.data);
//
// })
// },
getInfo() {
this.graphData = undefined;
this.demoData = {}
this.data = undefined;
if (this.keywords != '' && this.keywords != undefined) {
this.visGraph.clearAll();
let params = {
@ -122,7 +119,28 @@ export default {
} else {
let params = {};
getgraphInfo(params).then((res) => {
this.zhengl(res.data);
})
}
},
getInfo1() {
this.graphData = undefined;
this.demoData = {}
if (this.keywords != '' && this.keywords != undefined) {
this.visGraph.clearAll();
let params = {
nodename: this.keywords,
};
getgraphInfo(params).then((res) => {
this.zhengl(res.data);
})
} else {
this.visGraph.clearAll();
let params = {};
getgraphInfo(params).then((res) => {
this.zhengl(res.data);
})
@ -130,24 +148,20 @@ export default {
},
async drawGraphData() {
this.graphData = this.demoData;
if (this.visGraph === null) {
this.createGraph();
// this.genrateGraphData();
this.visGraph.drawData(this.graphData);
// this.refreshGraphData();
this.visGraph.incremaNodesCodinate(this.graphData.nodes);
this.reLayout();
// this.goCenter();
} else {
this.createGraph();
this.visGraph.drawData(this.graphData);
// this.refreshGraphData();
this.visGraph.incremaNodesCodinate(this.graphData.nodes);
this.reLayout();
// this.goCenter();
}
this.loading = false;
@ -166,8 +180,6 @@ export default {
this.visGraph = new VisGraph(document.getElementById('graph-panel'), configWithEvents);
},
async showPopup(node) {
console.log("o----------")
console.log(node)
this.selectedNode = node;
this.newBranchParentId = node.properties.docId;
this.newBranchLevel = parseInt(node.properties.level) + 1;
@ -338,28 +350,22 @@ export default {
{size: 250, width: 250, height: 250, color: '30,255,0', font: 'normal 40px Arial', fontColor: '0,0,0'},
{size: 200, width: 200, height: 200, color: '248,143,248', font: 'normal 32px Arial', fontColor: '255,255,255'},
{size: 150, width: 150, height: 150, color: '65,154,255', font: 'normal 30px Arial', fontColor: '255,255,255'},
{ size: 100, width: 100, height: 100, color: '0,228,255', font: 'normal 28px Arial', fontColor: '0,0,0' }
{size: 120, width: 120, height: 120, color: '0,228,255', font: 'normal 28px Arial', fontColor: '0,0,0'}
];
return styles[group] || {};
},
// doLogin(){
// userLogin().then((res)=>{
// console.log(res);
// this.testInfo();
// this.getInfo();
// })
// },
testInfo() {
test().then((res) => {
console.log(res);
})
}
},
mounted() {
this.doLogin();
this.testInfo();
this.getInfo();
}
}
</script>

438
kcui/src/view/TWInfo.vue

@ -1,5 +1,6 @@
<template>
<div style="width: 100%;height: 100%;background-color: #00173a">
<div style="width: 100%;height: 100%;">
<img style="width: 100%;height: 100%;position: absolute;z-index:-1;" src="../assets/img/twbg.jpg">
<headInfo></headInfo>
<!-- 这是内容界面 -->
<div class="content">
@ -12,7 +13,7 @@
</div>
<div class="leftBox2">
<div class="muluBox">
<img src="../assets/img/leftBox.png" style="width: 100%;object-fit: contain;z-index: 1;position: absolute;">
<img src="../assets/img/leftBox1.png" style="width: 100%;object-fit: contain;z-index: 1;position: absolute;">
<div class="muluList">
<div v-for="item in mulu" :key="item">
<div class="oneMulu" v-if="page!=item" @click="goInfo(item.info)">
@ -44,9 +45,19 @@
</div>
<div
style="width: 94%;height:3vw;position: absolute;z-index: 1;top: 4.9vw;left: 3%;background-color: #0c3068;box-shadow: 0px -9px 10px 0px rgb(75,230,255);"></div>
<!-- <img src="../assets/img/rightHead.png"-->
<!-- style="width: 96%;height:5vw;position: absolute;z-index: 1;top: 3.1vw;left: 2%;">-->
<div style="width: 94.4%;height: 2.9vw;position: absolute;z-index: 2;margin-left: 2.6%;top: 5vw;">
<div style="width: 94.4%;height: 2.9vw;position: absolute;z-index: 2;margin-left: 2.6%;top: 5vw;"
v-if="this.userType==1">
<div
style="width: 100%;height: 100%;display: flex;flex-direction: row;line-height: 2.9vw;text-align: center;color: #ffffff;">
<div style="width: 10%;">序号</div>
<div style="width: 20%;">标题</div>
<div style="width: 60%;">图片</div>
<div style="width: 10%;">详情</div>
<div style="width: 10%;">操作</div>
</div>
</div>
<div style="width: 94.4%;height: 2.9vw;position: absolute;z-index: 2;margin-left: 2.6%;top: 5vw;"
v-if="this.userType==0">
<div
style="width: 100%;height: 100%;display: flex;flex-direction: row;line-height: 2.9vw;text-align: center;color: #ffffff;">
<div style="width: 10%;">序号</div>
@ -58,12 +69,84 @@
</div>
<div class="rightList">
<img src="../assets/img/rightList.png" style="width: 100%;height: 95%;position: absolute;z-index: 1;"/>
<div class="rightListContent">
<div class="tupu">
<div style="color: white; margin:0 15px 5px 15px;">关键字:
<input style="background-color: transparent; border: none; border-bottom: 1px solid white; color: white; outline: none;" placeholder="请输入关键字" v-model="keywords"/>
<div @click="getInfo1"
style="width: 3vw;height: 1.5vw;background-color: #001c3a;float: right;text-align: center;border-radius:1vw;">
查询
</div>
</div>
<div style="width: 100%;height: 80%;">
<div class="gContainer">
<div id="graph-panel" style="width: 100%;height: 100%;"></div>
</div>
</div>
</div>
<!-- 弹窗 -->
<el-dialog
:visible.sync="isModalVisible"
title="添加分支内容"
width="30%"
top="15vh"
append-to-body
custom-class="custom-dialog"
>
<el-form label-width="80px">
<el-form-item label="fileId">
<el-input v-model="newBranchFileId"></el-input>
</el-form-item>
<el-form-item label="类型">
<el-select v-model="typeValue" placeholder="请选择类型">
<el-option label="图文" value="tw"></el-option>
<el-option label="视频" value="sp"></el-option>
<el-option label="动画" value="dh"></el-option>
<el-option label="计算模块" value="jsmk"></el-option>
</el-select>
</el-form-item>
<el-form-item label="节点名称">
<el-input v-model="newBranchContent"></el-input>
</el-form-item>
<el-form-item label="节点内容">
<el-input type="textarea" v-model="newBranchValue"></el-input>
</el-form-item>
<el-form-item label="父级节点ID">
<el-input v-model="newBranchParentId" disabled></el-input>
</el-form-item>
<el-form-item label="关系">
<el-input v-model="newBranchRelation"
@input="newBranchRelation = $event.target.value.replace(/[^a-zA-Z\u4e00-\u9fa5]/g, '')"></el-input>
</el-form-item>
<el-form-item label="层级">
<el-input-number v-model="newBranchLevel" controls-position="right" :min="1"></el-input-number>
</el-form-item>
</el-form>
<span slot="footer" class="dialog-footer">
<el-button @click="closeModal"> </el-button>
<el-button type="primary" @click="addNewBranch"> </el-button>
</span>
</el-dialog>
<div class="rightListContent" v-if="this.userType==0">
<div class="oneRight" v-for="item in contentList" :key="item">
<div style="width: 8%;">{{ item.id }}</div>
<div style="width: 22%;">{{ item.name }}</div>
<div style="width: 60%;">图片</div>
<div style="width: 10%;text-decoration: underline;font-style: italic;">点击查看详情</div>
<div style="width: 10%;text-decoration: underline;font-style: italic;" @click="goXq(item.id)">点击查看详情</div>
</div>
</div>
<div class="rightListContent" v-if="this.userType==1">
<div class="oneRight" v-for="item in contentList" :key="item">
<div style="width: 8%;">{{ item.id }}</div>
<div style="width: 22%;">{{ item.name }}</div>
<div style="width: 60%;">图片</div>
<div style="width: 10%;text-decoration: underline;font-style: italic;" @click="goXq(item.id)">点击查看详情</div>
<div
style="width: 9%;text-decoration: underline;font-style: italic;display: flex;justify-content: space-around;margin-left: 1%;">
<div @click="editTw(item.id)">修改</div>
<div @click="deleteTw(item.id)">删除</div>
</div>
</div>
</div>
<div class="pageList">
@ -88,7 +171,12 @@
<script>
import headInfo from '@/components/Head.vue';
import Foot from "@/components/Foot.vue";
import {getDocList} from "@/api/kcInfo";
import {getDocList, getTwInfo} from "@/api/kcInfo";
import {getgraphInfo, test} from "@/api/login";
import VisGraph from '@/assets/js/graphvis.min.20241008.js'
import LayoutFactory from '@/assets/js/graphvis.layout.min.js'
import {config} from '@/assets/defaultConfig.js'
import {addNode, getFileIdByDocId} from "@/api/file";
export default {
// eslint-disable-next-line vue/multi-word-component-names
@ -117,6 +205,26 @@ export default {
totalPage: 0,
pagesList: [],
onePagesList: [],
infos: [],
demoData: {},
graphData: {
nodes: [],
links: []
},
config,
visGraph: null, // VisGraph
isModalVisible: false,
newBranchContent: '',
selectedNode: null,
newBranchValue: '',
newBranchFileId: '',
newBranchLevel: null,
newBranchParentId: '',
newBranchRelation: '',
typeValue: '',
keywords: '',
}
},
@ -167,12 +275,301 @@ export default {
console.log(this.onePagesList)
})
},
goXq(id) {
var data = {
id: id
}
getTwInfo(data).then((res) => {
this.$router.push({path: '/TwInfoXq', query: {id: id, level: res.data.level, type: "tw"}})
})
},
//
deleteTw() {
console.log("这是删除操作")
},
editTw(id) {
//
var data = {
id: id
}
getTwInfo(data).then((res) => {
console.log(res.data)
})
},
goBook() {
this.$router.push({name: 'Book', query: {id: '1'}})
},
onCreated(editor) {
this.editor = Object.seal(editor) // Object.seal()
},
getInfo() {
this.graphData = undefined;
this.demoData = {}
if (this.keywords != '' && this.keywords != undefined) {
this.visGraph.clearAll();
let params = {
nodename: this.keywords,
};
getgraphInfo(params).then((res) => {
this.zhengl(res.data);
})
} else {
let params = {};
getgraphInfo(params).then((res) => {
this.zhengl(res.data);
})
}
},
getInfo1() {
this.graphData = undefined;
this.demoData = {}
if (this.keywords != '' && this.keywords != undefined) {
this.visGraph.clearAll();
let params = {
nodename: this.keywords,
};
getgraphInfo(params).then((res) => {
this.zhengl(res.data);
})
} else {
this.visGraph.clearAll();
let params = {};
getgraphInfo(params).then((res) => {
this.zhengl(res.data);
})
}
},
async drawGraphData() {
this.graphData = this.demoData;
if (this.visGraph === null) {
this.createGraph();
// this.genrateGraphData();
this.visGraph.drawData(this.graphData);
this.visGraph.incremaNodesCodinate(this.graphData.nodes);
this.reLayout();
} else {
this.createGraph();
this.visGraph.drawData(this.graphData);
this.visGraph.incremaNodesCodinate(this.graphData.nodes);
this.reLayout();
}
this.loading = false;
},
//
createGraph() {
const configWithEvents = {
...this.config,
node: {
...this.config.node,
ondblClick: (event, node) => {
this.showPopup(node);
}
}
};
this.visGraph = new VisGraph(document.getElementById('graph-panel'), configWithEvents);
},
async showPopup(node) {
this.selectedNode = node;
this.newBranchParentId = node.properties.docId;
this.newBranchLevel = parseInt(node.properties.level) + 1;
try {
const response = await this.getFileIdByDocId({docId: node.properties.docId});
this.newBranchFileId = response.fileId;
} catch (error) {
console.error('Failed to fetch file ID:', error);
alert('无法获取文件ID,请稍后再试。');
return;
}
this.isModalVisible = true; //
},
getFileIdByDocId(data) {
return getFileIdByDocId(data);
},
closeModal() {
this.isModalVisible = false;
this.newBranchContent = '';
this.selectedNode = null;
},
async addNewBranch() {
const content = this.newBranchContent.trim();
const value = this.newBranchValue.trim();
const fileId = this.newBranchFileId.trim();
const relation = this.newBranchRelation.trim();
if (this.selectedNode && content && value) {
//
const data = {
fileId: fileId,
txtName: content,
TxtValue: value,
relation: relation,
parentId: this.newBranchParentId,
level: this.newBranchLevel
};
try {
await addNode(data);
//
const newNodeId = Date.now().toString(); // 使ID
const newNode = {
id: newNodeId,
label: content,
properties: {name: content, docId: newNodeId, level: this.newBranchLevel},
...this.getNodeStyle(this.newBranchLevel) //
};
const newLink = {
source: this.selectedNode.id,
target: newNodeId,
type: '',
};
this.graphData.nodes.push(newNode);
this.graphData.links.push(newLink);
//
this.visGraph.drawData(this.graphData);
this.reLayout();
this.closeModal(); //
} catch (error) {
console.error('Failed to add new branch:', error);
alert('Failed to add new branch. Please try again.');
}
}
},
//
reLayout(alpha) {
var that = this;
if (alpha == null) {
that.visLayout = null;
that.visLayout = new LayoutFactory(this.visGraph.getGraphData()).createLayout('fastFR');
that.visLayout.resetConfig({
label: {
show: true
},
friction: 0.8,
linkDistance: 400,
linkStrength: 0.2,
charge: -1000,
gravity: 0.01,
noverlap: true,
size: [that.visGraph.stage.width, that.visGraph.stage.height]
});
} else {
that.visLayout.alpha += (alpha > 1 ? 0.2 : alpha); //
}
runLayout();//
//
function runLayout() {
cancelAnimationFrame(that.layoutLoopName);//
that.visLayout.runLayout(); //
that.visGraph.refresh();
if (that.visLayout.alpha > 0.05) {
that.layoutLoopName = requestAnimationFrame(runLayout);
} else {
if (that.visGraph.currentNode && that.visGraph.currentNode.isDragging) {
that.visLayout.alpha = 0.1; //
that.layoutLoopName = requestAnimationFrame(runLayout);
} else {
that.visLayout.alpha = 0; //
cancelAnimationFrame(that.layoutLoopName);
}
}
}
// this.autoLayout();
},
zhengl(data) {
const nodes = []
const links = [] //
var nodeList = data.nodes;
var lineList = data.links;
var allOne = ""
console.log(nodeList)
if (nodeList != undefined) {
allOne = nodeList[0].docId
for (let a = 0; a < nodeList.length; a++) {
const group = parseInt(nodeList[a].group, 10);
const style = this.getNodeStyle(group);
nodes.push({
id: nodeList[a].id,
label: nodeList[a].name,
properties: {name: nodeList[a].name, docId: nodeList[a].docId, parent: allOne, leve: nodeList[a].group},
...style // style
});
}
}
// var allOne = nodeList[0].docId
if (lineList != undefined) {
for (let b = 0; b < lineList.length; b++) {
var bbb = {name: lineList[b].relate}
links.push({
source: lineList[b].source,
target: lineList[b].target,
type: lineList[b].relate,
properties: bbb,
color: '202,202,202',
lineWidth: 3,
})
}
}
this.demoData = {
"nodes": nodes,
"links": links
}
this.drawGraphData();
},
getNodeStyle(group) {
const styles = [
{size: 450, color: '227,203,0', font: 'normal 70px Arial', fontColor: '255,255,255'},
{size: 350, width: 350, height: 300, color: '47,47,230', font: 'normal 68px Arial', fontColor: '255,255,255'},
{size: 300, width: 300, height: 250, color: '255,138,0', font: 'normal 50px Arial', fontColor: '255,255,255'},
{size: 250, width: 250, height: 250, color: '30,255,0', font: 'normal 40px Arial', fontColor: '0,0,0'},
{size: 200, width: 200, height: 200, color: '248,143,248', font: 'normal 32px Arial', fontColor: '255,255,255'},
{size: 150, width: 150, height: 150, color: '65,154,255', font: 'normal 30px Arial', fontColor: '255,255,255'},
{size: 120, width: 120, height: 120, color: '0,228,255', font: 'normal 28px Arial', fontColor: '0,0,0'}
];
return styles[group] || {};
},
testInfo() {
test().then((res) => {
console.log(res);
})
}
},
mounted() {
this.userType = localStorage.getItem("type");
this.userName = localStorage.getItem("name");
this.getContentList();
this.getInfo();
}
}
</script>
@ -191,7 +588,7 @@ export default {
.leftBox1 {
width: 100%;
height: 10%;
margin-top: 12%;
margin-top: 10%;
color: #7cdeff;
}
@ -202,7 +599,7 @@ export default {
}
.muluBox {
margin: 3% 14%;
margin: 0% 14%;
height: 92%;
width: 72%;
position: relative;
@ -278,6 +675,27 @@ export default {
}
.tupu {
width: 100%;
height: 100%;
position: absolute;
z-index: 3;
top: 1%;
}
.gContainer {
position: relative;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
overflow: hidden;
width: 100%;
height: 32vw;
border-radius:2vw;
}
.oneRight {
width: 98%;
height: 5vw;

183
src/main/java/com/main/woka/Common/util/RelationUtil.java

@ -1,9 +1,14 @@
package com.main.woka.Common.util;
import edu.stanford.nlp.pipeline.*;
import edu.stanford.nlp.ling.CoreAnnotations;
import edu.stanford.nlp.util.CoreMap;
import java.util.Properties;
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.StringUtils;
import org.springframework.stereotype.Component;
@ -11,9 +16,8 @@ import java.util.*;
@Component
public class RelationUtil {
//标题分词
public String analyzeRelationship(String title1, String title2) {
//载入properties 文件
String[] args = new String[]{"-props", "CoreNLP-chinese.properties"};
Properties properties = StringUtils.argsToProperties(args);
properties.setProperty("annotators", "tokenize, ssplit, pos");
@ -21,167 +25,38 @@ public class RelationUtil {
StanfordCoreNLP pipline = new StanfordCoreNLP(properties);
// 分析第一个短语 "低温"
String phrase1 = title1;
List<Map> ll = analyzePhrase(pipline, phrase1);
//循环第一个短语的分词
String useTitle = "";
for(int i=0;i<ll.size();i++){
if (ll.get(i).get("pos").equals("NN") || ll.get(i).get("pos").equals("JJ")){
useTitle = useTitle+ll.get(i).get("text");
}else {
break;
}
}
// 分析第二个短语 "低温的影响"
String phrase2 = title2;
String result = analyzePhrase1(pipline, phrase2, useTitle);
return result;
}
public List<Map> analyzePhrase(StanfordCoreNLP pipeline, String phrase) {
List<Map> list = new ArrayList<>();
Annotation document = new Annotation(phrase);
pipeline.annotate(document);
List<CoreLabel> tokens = document.get(CoreAnnotations.TokensAnnotation.class);
for (CoreLabel token : tokens) {
String word = token.get(CoreAnnotations.TextAnnotation.class);
String pos = token.get(CoreAnnotations.PartOfSpeechAnnotation.class);
System.out.println(word + ": " + pos);
Map mm = new HashMap();
mm.put("text",word);
mm.put("pos",pos);
list.add(mm);
}
return list;
// 对两个标题进行NLP处理
CoreDocument doc1 = new CoreDocument(title1);
CoreDocument doc2 = new CoreDocument(title2);
pipline.annotate(doc1);
pipline.annotate(doc2);
// 提取名词短语作为核心概念
String concept1 = extractKeyConcept(doc1);
String concept2 = extractKeyConcept(doc2);
System.out.println(concept1);
System.out.println(concept2);
// 简单检查是否第二个标题是第一个标题的定义
if (title2.contains(concept1) && title2.contains("定义")) {
return "定义";
} else if (title1.contains(concept2) && title1.contains("现象")) {
return "实例";
}
public String analyzePhrase1(StanfordCoreNLP pipeline, String phrase,String useTitle) {
Annotation document = new Annotation(phrase);
pipeline.annotate(document);
String title= "";
String result ="";
Integer index = 0;
System.out.println(useTitle);
List<CoreLabel> tokens = document.get(CoreAnnotations.TokensAnnotation.class);
for(int i=0;i<tokens.size();i++){
CoreLabel token = tokens.get(i);
String word = token.get(CoreAnnotations.TextAnnotation.class);
String pos = token.get(CoreAnnotations.PartOfSpeechAnnotation.class);
title= title + word;
if(useTitle.equals(title)){
//有相同词汇有关系
index = i+1;
break;
}
}
System.out.println(index);
if (index==0){
return "属于";
}else {
for(int j=index;j<tokens.size();j++){
CoreLabel token1 = tokens.get(j);
String word1 = token1.get(CoreAnnotations.TextAnnotation.class);
String pos1 = token1.get(CoreAnnotations.PartOfSpeechAnnotation.class);
if(j==index){
System.out.println(pos1);
if(word1.equals("的")){
System.out.println("aaaaaaaaaaaaaaaa");
}else {
if(pos1.equals("PU")){
result = "属于";
break;
}
if (!pos1.equals("CC") && !pos1.equals("DEG")){
result= result + word1;
}
}
}else {
result= result + word1;
private static String extractKeyConcept(CoreDocument document) {
StringBuilder keyConcept = new StringBuilder();
for (CoreSentence sentence : document.sentences()) {
for (int i = 0; i < sentence.tokens().size(); i++) {
String pos = sentence.tokens().get(i).get(CoreAnnotations.PartOfSpeechAnnotation.class);
if (pos.startsWith("NN")) { // 包括名词和专有名词
keyConcept.append(sentence.tokens().get(i).originalText()).append(" ");
}
}
if(result.equals("")){
result = "属于";
}
return result;
return keyConcept.toString().trim();
}
}
//将一句话分成多个词语
public List<String> analyzeRelationshipLong(String title1) {
List<String> list = new ArrayList<>();
String[] args = new String[]{"-props", "CoreNLP-chinese.properties"};
Properties properties = StringUtils.argsToProperties(args);
properties.setProperty("annotators", "tokenize, ssplit, pos");
properties.setProperty("tokenize.language", "zh"); // 设置为中文
StanfordCoreNLP pipline = new StanfordCoreNLP(properties);
// 分析第一个短语 "低温"
String phrase1 = title1;
List<Map> ll = analyzePhrase(pipline, phrase1);
for(int i=0;i<ll.size();i++){
if (ll.get(i).get("pos").equals("NN")){
list.add(String.valueOf(ll.get(i).get("text")));
}
}
return list;
}
public List<String> analyzeRelationshipLong1(String title1) {
List<String> list = new ArrayList<>();
String[] args = new String[]{"-props", "CoreNLP-chinese.properties"};
Properties properties = StringUtils.argsToProperties(args);
properties.setProperty("annotators", "tokenize, ssplit, pos");
properties.setProperty("tokenize.language", "zh"); // 设置为中文
StanfordCoreNLP pipline = new StanfordCoreNLP(properties);
// 分析第一个短语 "低温"
String phrase1 = title1;
List<Map> ll = analyzePhrase(pipline, phrase1);
for(int i=0;i<ll.size();i++){
if (ll.get(i).get("pos").equals("NN")){
if(String.valueOf(ll.get(i).get("text")).charAt(0)!='<' && String.valueOf(ll.get(i).get("text")).charAt(0)!='&' && String.valueOf(ll.get(i).get("text")).charAt(String.valueOf(ll.get(i).get("text")).length()-1)!='t'){
int hh = 0;
for(int b=0;b<list.size();b++){
if(list.get(b).equals(String.valueOf(ll.get(i).get("text")))){
hh = 1;
break;
}
}
if (hh == 0){
list.add(String.valueOf(ll.get(i).get("text")));
}
}
}
}
return list;
}
}

188
src/main/java/com/main/woka/Common/util/RelationUtil1.java

@ -0,0 +1,188 @@
package com.main.woka.Common.util;
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.StringUtils;
import org.springframework.stereotype.Component;
import java.util.*;
@Component
public class RelationUtil1 {
//标题分词
public String analyzeRelationship(String title1, String title2) {
//载入properties 文件
String[] args = new String[]{"-props", "CoreNLP-chinese.properties"};
Properties properties = StringUtils.argsToProperties(args);
properties.setProperty("annotators", "tokenize, ssplit, pos");
properties.setProperty("tokenize.language", "zh"); // 设置为中文
StanfordCoreNLP pipline = new StanfordCoreNLP(properties);
// 分析第一个短语 "低温"
String phrase1 = title1;
List<Map> ll = analyzePhrase(pipline, phrase1);
//循环第一个短语的分词
String useTitle = "";
for(int i=0;i<ll.size();i++){
if (ll.get(i).get("pos").equals("NN") || ll.get(i).get("pos").equals("JJ")){
useTitle = useTitle+ll.get(i).get("text");
}else {
break;
}
}
// 分析第二个短语 "低温的影响"
String phrase2 = title2;
String result = analyzePhrase1(pipline, phrase2, useTitle);
return result;
}
public List<Map> analyzePhrase(StanfordCoreNLP pipeline, String phrase) {
List<Map> list = new ArrayList<>();
Annotation document = new Annotation(phrase);
pipeline.annotate(document);
List<CoreLabel> tokens = document.get(CoreAnnotations.TokensAnnotation.class);
for (CoreLabel token : tokens) {
String word = token.get(CoreAnnotations.TextAnnotation.class);
String pos = token.get(CoreAnnotations.PartOfSpeechAnnotation.class);
System.out.println(word + ": " + pos);
Map mm = new HashMap();
mm.put("text",word);
mm.put("pos",pos);
list.add(mm);
}
return list;
}
public String analyzePhrase1(StanfordCoreNLP pipeline, String phrase,String useTitle) {
Annotation document = new Annotation(phrase);
pipeline.annotate(document);
String title= "";
String result ="";
Integer index = 0;
System.out.println(useTitle);
List<CoreLabel> tokens = document.get(CoreAnnotations.TokensAnnotation.class);
for(int i=0;i<tokens.size();i++){
CoreLabel token = tokens.get(i);
String word = token.get(CoreAnnotations.TextAnnotation.class);
String pos = token.get(CoreAnnotations.PartOfSpeechAnnotation.class);
title= title + word;
if(useTitle.equals(title)){
//有相同词汇有关系
index = i+1;
break;
}
}
System.out.println(index);
if (index==0){
return "属于";
}else {
for(int j=index;j<tokens.size();j++){
CoreLabel token1 = tokens.get(j);
String word1 = token1.get(CoreAnnotations.TextAnnotation.class);
String pos1 = token1.get(CoreAnnotations.PartOfSpeechAnnotation.class);
if(j==index){
System.out.println(pos1);
if(word1.equals("的")){
System.out.println("aaaaaaaaaaaaaaaa");
}else {
if(pos1.equals("PU")){
result = "属于";
break;
}
if (!pos1.equals("CC") && !pos1.equals("DEG")){
result= result + word1;
}
}
}else {
result= result + word1;
}
}
if(result.equals("")){
result = "属于";
}
return result;
}
}
//将一句话分成多个词语
public List<String> analyzeRelationshipLong(String title1) {
List<String> list = new ArrayList<>();
String[] args = new String[]{"-props", "CoreNLP-chinese.properties"};
Properties properties = StringUtils.argsToProperties(args);
properties.setProperty("annotators", "tokenize, ssplit, pos");
properties.setProperty("tokenize.language", "zh"); // 设置为中文
StanfordCoreNLP pipline = new StanfordCoreNLP(properties);
// 分析第一个短语 "低温"
String phrase1 = title1;
List<Map> ll = analyzePhrase(pipline, phrase1);
for(int i=0;i<ll.size();i++){
if (ll.get(i).get("pos").equals("NN")){
list.add(String.valueOf(ll.get(i).get("text")));
}
}
return list;
}
public List<String> analyzeRelationshipLong1(String title1) {
List<String> list = new ArrayList<>();
String[] args = new String[]{"-props", "CoreNLP-chinese.properties"};
Properties properties = StringUtils.argsToProperties(args);
properties.setProperty("annotators", "tokenize, ssplit, pos");
properties.setProperty("tokenize.language", "zh"); // 设置为中文
StanfordCoreNLP pipline = new StanfordCoreNLP(properties);
// 分析第一个短语 "低温"
String phrase1 = title1;
List<Map> ll = analyzePhrase(pipline, phrase1);
for(int i=0;i<ll.size();i++){
if (ll.get(i).get("pos").equals("NN")){
if(String.valueOf(ll.get(i).get("text")).charAt(0)!='<' && String.valueOf(ll.get(i).get("text")).charAt(0)!='&' && String.valueOf(ll.get(i).get("text")).charAt(String.valueOf(ll.get(i).get("text")).length()-1)!='t'){
int hh = 0;
for(int b=0;b<list.size();b++){
if(list.get(b).equals(String.valueOf(ll.get(i).get("text")))){
hh = 1;
break;
}
}
if (hh == 0){
list.add(String.valueOf(ll.get(i).get("text")));
}
}
}
}
return list;
}
}

2
src/main/java/com/main/woka/Filter/TestFilter.java

@ -49,7 +49,7 @@ public class TestFilter implements Filter {
response.setHeader("Access-Control-Allow-Headers", "Content-Type, Authorization, Accept, Origin, X-Requested-With"); // 确保包含 Content-Type
response.setHeader("Access-Control-Allow-Credentials", "true");
//校验重复提交
System.out.println("laile");
if(true){

89
src/main/java/com/main/woka/Web/Controller/KcInfoController.java

@ -4,10 +4,13 @@ import com.main.woka.Common.core.AjaxResult;
import com.main.woka.Web.Dao.KcInfo;
import com.main.woka.Web.Mapper.KcFileMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.List;
@RestController
@RequestMapping("/kcDoc")
@ -21,25 +24,63 @@ public class KcInfoController extends BaseController {
public AjaxResult getDocList(@RequestBody KcInfo kcInfo) {
// int pageNum = kcInfo.getPageNum() == null ? 1 : kcInfo.getPageNum();
// int pageSize = kcInfo.getPageSize() == null ? 10 : kcInfo.getPageSize();
// int offset = (pageNum - 1) * pageSize;
//
// kcInfo.setOffset(offset);
// Long total = kcFileMapper.getKcCount(kcInfo);
// List<KcInfo> list = kcFileMapper.getkcList(kcInfo);
//
// int totalPages = (int) Math.ceil((double) total / pageSize);
//
// AjaxResult ajax = new AjaxResult();
// ajax.put("list",list);
// ajax.put("total",total);
// ajax.put("totalPages",totalPages);
// ajax.put("pageSize",pageSize);
//
//
//
// return AjaxResult.success(ajax);
return null;
int pageNum = kcInfo.getPageNum() == null ? 1 : kcInfo.getPageNum();
int pageSize = kcInfo.getPageSize() == null ? 10 : kcInfo.getPageSize();
int offset = (pageNum - 1) * pageSize;
kcInfo.setOffset(offset);
Long total = kcFileMapper.getKcCount(kcInfo);
List<KcInfo> list = kcFileMapper.getkcList(kcInfo);
int totalPages = (int) Math.ceil((double) total / pageSize);
AjaxResult ajax = new AjaxResult();
ajax.put("list",list);
ajax.put("total",total);
ajax.put("totalPages",totalPages);
ajax.put("pageSize",pageSize);
return AjaxResult.success(ajax);
// return null;
}
//管理员修改文件
@GetMapping("/getTwInfo")
public AjaxResult editTwInfo(@RequestParam("id") Long id){
System.out.println(id);
AjaxResult ajax = new AjaxResult();
KcInfo aa = kcFileMapper.selectById(id);
String path = aa.getTwUrl();
File file = new File(path);
String string = txt2String(file);
aa.setContentInfo(string);
ajax.put("data",aa);
return AjaxResult.success(ajax);
}
//读取txt文件方法
public static String txt2String(File file) {
StringBuilder result = new StringBuilder();
try {
// 构造一个BufferedReader类来读取文件
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
// BufferedReader br = new BufferedReader(new FileReader(file));
String s = null;
// 使用readLine方法,一次读一行
while ((s = br.readLine()) != null) {
result.append(System.lineSeparator() + s);
}
br.close();
} catch (Exception e) {
e.printStackTrace();
}
return result.toString();
}
}

9
src/main/java/com/main/woka/Web/Dao/KcInfo.java

@ -37,6 +37,15 @@ public class KcInfo {
private Integer offset;
private String contentInfo;//文章内容
public String getContentInfo() {
return contentInfo;
}
public void setContentInfo(String contentInfo) {
this.contentInfo = contentInfo;
}
public Long getId() {
return id;

23
src/main/java/com/main/woka/Web/Service/impl/KcTlFileServiceImpl.java

@ -30,6 +30,9 @@ public class KcTlFileServiceImpl {
RelationUtil relationUtil;
@Autowired
RelationUtil1 relationUtil1;
@Autowired
Neo4jUtil neo4jUtil;
@Autowired
@ -86,8 +89,8 @@ public class KcTlFileServiceImpl {
for(int i=0;i<list1.size();i++){
String target = list1.get(i).getName();
// String aa = relationUtil.analyzeRelationship(source,target);
String aa = "属于";
String aa = relationUtil1.analyzeRelationship(source,target);
// String aa = "属于";
// System.out.println(aa);
//获取两个的Id
Long TwoId = list1.get(i).getId();
@ -110,8 +113,8 @@ public class KcTlFileServiceImpl {
for(int i=0;i<list1.size();i++){
String source = list2.get(a1).getName();
String target = list1.get(i).getName();
// String aa = relationUtil.analyzeRelationship(source,target);
String aa = "属于";
String aa = relationUtil1.analyzeRelationship(source,target);
// String aa = "属于";
System.out.println(aa);
//获取两个的Id
Long TwoId = list1.get(i).getId();
@ -135,8 +138,8 @@ public class KcTlFileServiceImpl {
for(int i=0;i<list1.size();i++){
String source = list3.get(a2).getName();
String target = list1.get(i).getName();
String aa = "属于";
// String aa = relationUtil.analyzeRelationship(source,target);
// String aa = "属于";
String aa = relationUtil1.analyzeRelationship(source,target);
System.out.println(aa);
//获取两个的Id
Long TwoId = list1.get(i).getId();
@ -161,8 +164,8 @@ public class KcTlFileServiceImpl {
for(int i=0;i<list1.size();i++){
String source = list4.get(a2).getName();
String target = list1.get(i).getName();
String aa = "属于";
// String aa = relationUtil.analyzeRelationship(source,target);
// String aa = "属于";
String aa = relationUtil1.analyzeRelationship(source,target);
System.out.println(aa);
//获取两个的Id
Long TwoId = list1.get(i).getId();
@ -186,8 +189,8 @@ public class KcTlFileServiceImpl {
for(int i=0;i<list1.size();i++){
String source = list5.get(a2).getName();
String target = list1.get(i).getName();
String aa = "属于";
// String aa = relationUtil.analyzeRelationship(source,target);
// String aa = "属于";
String aa = relationUtil1.analyzeRelationship(source,target);
System.out.println(aa);
//获取两个的Id
Long TwoId = list1.get(i).getId();

3
src/main/resources/application.properties

@ -6,7 +6,8 @@
#spring.task.execution.shutdown.await-termination:是否等待剩余任务完成后才关闭应用
#spring.task.execution.shutdown.await-termination-period:等待剩余任务完成的最大时间
#spring.task.execution.thread-name-prefix:线程名的前缀,设置好了之后可以方便我们在日志中查看处理任务所在的线程池
spring.servlet.multipart.max-file-size=50MB
spring.servlet.multipart.max-request-size=50MB
spring.task.execution.pool.core-size=8
spring.task.execution.pool.max-size=20
spring.task.execution.pool.queue-capacity=20

Loading…
Cancel
Save