فهرست منبع

合并知识图谱

201250038 2 سال پیش
والد
کامیت
da02faeeda

+ 5 - 2
package.json

@@ -26,7 +26,8 @@
     "vue-router": "^4.0.0-0",
     "vuex": "^4.0.0-0",
     "webpack-bundle-analyzer": "^4.5.0",
-    "webpackbar": "^5.0.2"
+    "webpackbar": "^5.0.2",
+    "d3": "^6.7.0"
   },
   "devDependencies": {
     "@vue/cli-plugin-babel": "~4.5.0",
@@ -37,7 +38,9 @@
     "@vue/compiler-sfc": "^3.0.0",
     "@vue/test-utils": "^2.0.0-0",
     "chai": "^4.1.2",
-    "sass-loader": "^10.0.1"
+    "sass-loader": "^10.0.1",
+    "less": "^3.0.4",
+    "less-loader": "^5.0.0"
   },
   "browserslist": [
     "> 1%",

+ 15 - 0
src/api/kg/entity.js

@@ -0,0 +1,15 @@
+/* eslint-disable no-unused-vars */
+import {axios} from "@/api/axios.config";
+
+const prefix = "/entity";
+
+function updateEntity(entityVO){
+  return axios.post(`${prefix}/update`, entityVO);
+}
+
+
+const entityAPIs = {
+  updateEntity,
+};
+
+export default entityAPIs;

+ 19 - 0
src/api/kg/index.js

@@ -0,0 +1,19 @@
+import kgAPIs from "@/api/kg/kg";
+import testAPIs from "@/api/kg/test";
+import userAPIs from "@/api/kg/user";
+import LacAPIs from "@/api/kg/lac";
+import entityAPIs from "@/api/kg/entity";
+import relationAPIs from "@/api/kg/relation";
+import modelAPIs from "@/api/kg/model";
+
+const APIs = {
+  ...kgAPIs,
+  ...testAPIs,
+  ...userAPIs,
+  ...LacAPIs,
+  ...entityAPIs,
+  ...relationAPIs,
+  ...modelAPIs,
+};
+
+export default APIs;

+ 30 - 0
src/api/kg/kg.js

@@ -0,0 +1,30 @@
+import {axios} from "@/api/axios.config";
+
+const prefix = "/kg";
+
+function createKg(kgInfo) {
+  return axios.post(`${prefix}/create`, kgInfo);
+}
+
+function initKg(kg) {
+  return axios.post(`${prefix}/init`, kg);
+}
+
+function getKgById(id) {
+  return axios.get(`${prefix}/getById`, {
+    params: {id},
+  });
+}
+
+function getKgInfoList() {
+  return axios.get(`${prefix}/getList`);
+}
+
+const kgAPIs = {
+  createKg,
+  initKg,
+  getKgById,
+  getKgInfoList,
+};
+
+export default kgAPIs;

+ 18 - 0
src/api/kg/lac.js

@@ -0,0 +1,18 @@
+import {axios} from "@/api/axios.config";
+
+const prefix = "/lac";
+
+function parseTxt(txt) {
+  return axios.post(`${prefix}/parse/txt`, txt);
+}
+
+function generateModel(relations_data) {
+  return axios.post(`${prefix}/generate/model`, relations_data);
+}
+
+const LacAPIs = {
+  parseTxt,
+  generateModel,
+};
+
+export default LacAPIs;

+ 14 - 0
src/api/kg/model.js

@@ -0,0 +1,14 @@
+import {axios} from "@/api/axios.config";
+
+const prefix = "/model";
+
+function generateModelRe(modelVO){
+  return axios.post(`${prefix}/generate/re`, modelVO);
+}
+
+
+const modelAPIs = {
+  generateModelRe,
+};
+
+export default modelAPIs;

+ 14 - 0
src/api/kg/relation.js

@@ -0,0 +1,14 @@
+import {axios} from "@/api/axios.config";
+
+const prefix = "/relation";
+
+function updateRelation(relationVO){
+  return axios.post(`${prefix}/update`, relationVO);
+}
+
+
+const relationAPIs = {
+  updateRelation,
+};
+
+export default relationAPIs;

+ 13 - 0
src/api/kg/test.js

@@ -0,0 +1,13 @@
+import {axios} from "@/api/axios.config";
+
+const prefix = "/test";
+
+function getExampleKg(){
+  return axios.get(`${prefix}/exampleKg`);
+}
+
+const testAPIs = {
+  getExampleKg
+};
+
+export default testAPIs;

+ 13 - 0
src/api/kg/user.js

@@ -0,0 +1,13 @@
+import {axios} from "@/api/axios.config";
+
+const prefix = "/user";
+
+function login(id_token) {
+  return axios.post(`${prefix}/login`, id_token);
+}
+
+const userAPIs = {
+  login,
+};
+
+export default userAPIs;

+ 64 - 0
src/components/ExampleKg.vue

@@ -0,0 +1,64 @@
+<script>
+import Kg from "@/components/Kg.vue";
+import APIs from "@/api";
+
+export default {
+  name: "ExampleKg",
+  components: {Kg},
+  data() {
+    return {
+      entities: [],
+      relations: [],
+    };
+  },
+  computed: {
+    kgDataValid() {
+      return this.entities.length !== 0 && this.relations.length !== 0;
+    },
+  },
+  mounted() {
+    this.init();
+  },
+  methods: {
+    async init() {
+      const res = await APIs.getExampleKg();
+      this.entities = res.data.entities;
+      this.relations = res.data.relations;
+    },
+
+    closeExampleKg() {
+      this.$emit("close");
+    },
+  },
+}
+</script>
+
+<template>
+  <div class="example-kg">
+    <kg v-if="kgDataValid"
+        :entities="entities"
+        :relations="relations"
+        uniqueKey="example"/>
+
+    <el-button class="example-kg-close-btn"
+      icon="el-icon-back"
+               circle
+               @click="closeExampleKg"/>
+  </div>
+</template>
+
+<style scoped lang="less">
+.example-kg {
+  position: relative;
+  width: 100%;
+  height: 100%;
+  background: whitesmoke;
+
+  &-close-btn{
+    position: absolute;
+    top: 50%;
+    left: 0;
+    transform: translate(0, -50%);
+  }
+}
+</style>

+ 60 - 0
src/components/HelloWorld.vue

@@ -0,0 +1,60 @@
+<template>
+  <div class="hello">
+    <h1>{{ msg }}</h1>
+    <p>
+      For a guide and recipes on how to configure / customize this project,<br>
+      check out the
+      <a href="https://cli.vuejs.org" target="_blank" rel="noopener">vue-cli documentation</a>.
+    </p>
+    <h3>Installed CLI Plugins</h3>
+    <ul>
+      <li><a href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-babel" target="_blank" rel="noopener">babel</a></li>
+      <li><a href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-router" target="_blank" rel="noopener">router</a></li>
+      <li><a href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-vuex" target="_blank" rel="noopener">vuex</a></li>
+      <li><a href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-eslint" target="_blank" rel="noopener">eslint</a></li>
+    </ul>
+    <h3>Essential Links</h3>
+    <ul>
+      <li><a href="https://vuejs.org" target="_blank" rel="noopener">Core Docs</a></li>
+      <li><a href="https://forum.vuejs.org" target="_blank" rel="noopener">Forum</a></li>
+      <li><a href="https://chat.vuejs.org" target="_blank" rel="noopener">Community Chat</a></li>
+      <li><a href="https://twitter.com/vuejs" target="_blank" rel="noopener">Twitter</a></li>
+      <li><a href="https://news.vuejs.org" target="_blank" rel="noopener">News</a></li>
+    </ul>
+    <h3>Ecosystem</h3>
+    <ul>
+      <li><a href="https://router.vuejs.org" target="_blank" rel="noopener">vue-router</a></li>
+      <li><a href="https://vuex.vuejs.org" target="_blank" rel="noopener">vuex</a></li>
+      <li><a href="https://github.com/vuejs/vue-devtools#vue-devtools" target="_blank" rel="noopener">vue-devtools</a></li>
+      <li><a href="https://vue-loader.vuejs.org" target="_blank" rel="noopener">vue-loader</a></li>
+      <li><a href="https://github.com/vuejs/awesome-vue" target="_blank" rel="noopener">awesome-vue</a></li>
+    </ul>
+  </div>
+</template>
+
+<script>
+export default {
+  name: 'HelloWorld',
+  props: {
+    msg: String
+  }
+}
+</script>
+
+<!-- Add "scoped" attribute to limit CSS to this component only -->
+<style scoped lang="less">
+h3 {
+  margin: 40px 0 0;
+}
+ul {
+  list-style-type: none;
+  padding: 0;
+}
+li {
+  display: inline-block;
+  margin: 0 10px;
+}
+a {
+  color: #42b983;
+}
+</style>

+ 283 - 0
src/components/Kg.vue

@@ -0,0 +1,283 @@
+<script>
+/* eslint-disable no-unused-vars */
+import * as d3 from "d3";
+
+export default {
+  name: "Kg",
+  props: {
+    entities: {
+      required: true,
+      default: [],
+    },
+    relations: {
+      required: true,
+      default: [],
+    },
+    uniqueKey: {
+      required: true,
+      default: "",
+    }
+  },
+  data() {
+    return {
+      i: 1,
+
+      kg: undefined,
+      svg: undefined,
+      g: undefined,
+      nodes: undefined,
+      links: undefined,
+    };
+  },
+  mounted() {
+    this.init();
+    this.paint();
+  },
+  methods: {
+    init() {
+      this.kg = document.getElementById(`kg-${this.uniqueKey}`);
+      const w = this.kg.clientWidth;
+      const h = this.kg.clientHeight;
+      this.svg = d3.select(`#kg-${this.uniqueKey}`)
+        .append("svg")
+        .attr("id", `kg-${this.uniqueKey}-svg`)
+        .attr("viewBox", [0, 0, w, h]);
+      this.nodes = this.entities.map(d => {
+        return Object.create(d);
+      });
+      this.links = this.relations.map(d => {
+        return Object.create(d);
+      });
+    },
+
+    paint() {
+      const _this = this;
+      const w = _this.kg.clientWidth;
+      const h = _this.kg.clientHeight;
+      _this.g = _this.svg.append("g");
+      let g = _this.g;
+      let nodes = _this.nodes;
+      let links = _this.links;
+
+      let marker1 = g.append('g')
+        .append("marker")
+        .attr("id", 'arrowhead1')
+        .attr('viewBox', '-0 -5 10 10')
+        .attr('refX', 18)
+        .attr('refY', 0)
+        .attr('orient', 'auto')
+        .attr('markerWidth', 8)
+        .attr('markerHeight', 8)
+        .attr('xoverflow', 'visible')
+        .append('svg:path')
+        .attr('d', 'M 0,-5 L 10 ,0 L 0,5')
+        .attr("stroke-opacity", 0.8)
+        .attr('fill', 'darkgrey');
+
+      let marker2 = g.append('g')
+        .append("marker")
+        .attr("id", 'arrowhead2')
+        .attr('viewBox', '-0 -5 10 10')
+        .attr('refX', -8)
+        .attr('refY', 0)
+        .attr('orient', 'auto')
+        .attr('markerWidth', 8)
+        .attr('markerHeight', 8)
+        .attr('xoverflow', 'visible')
+        .append('svg:path')
+        .attr('d', 'M 10,-5 L 0 ,0 L 10,5')
+        .attr("stroke-opacity", 0.8)
+        .attr('fill', 'darkgrey');
+
+      let simulation = d3.forceSimulation(nodes)
+        .force("link", d3.forceLink(links).id(d => d.id))
+        .force("charge", d3.forceManyBody().strength(-50))
+        .force("center", d3.forceCenter(w / 2, h / 2));
+
+      let link = g.append("g")
+        .selectAll(".link")
+        .data(links)
+        .join("path")
+        .attr("stroke-width", 1.5)
+        .attr("stroke", "darkgrey")
+        .attr("stroke-opacity", 0.8)
+        .attr("id", function (d) {
+          return ("link-" + d.id)
+        })
+        .attr("class", "link")
+        .on("click", (e, d) => _this.$emit("LinkClick", d));
+
+      let node = g.append("g")
+        .selectAll("circle")
+        .data(nodes)
+        .join("circle")
+        .attr("r", 12)
+        .attr("fill", "#409EFF")
+        .attr("stroke", "#fff")
+        .attr("stroke-width", 1)
+        .attr("id", d => "node-" + d.id)
+        .attr("class", "node")
+        .on("click", (e, d) => _this.$emit("NodeClick", d))
+        .call(drag(simulation))
+
+      let defs = g.append("defs");
+      let circleTextFilter1 = defs
+        .append("filter")
+        .attr("id", "nodeTextBg1")
+        .attr("x", -0.05)
+        .attr("y", -0.05)
+        .attr("width", 1.1)
+        .attr("height", 1.1);
+
+      circleTextFilter1.append("feFlood")
+        .attr("flood-color", "#fff")
+        .attr("flood-opacity", "1");
+
+      circleTextFilter1.append("feComposite")
+        .attr("in", "SourceGraphic")
+        .attr("operator", "over");
+
+      // 节点名称显示
+      let nodeText = g.append("g")
+        .selectAll(".nodeText")
+        .data(nodes)
+        .join("text")
+        .text(d => d.name)
+        .attr("dx", function () {
+          return 0 - this.getBoundingClientRect().width / 2;
+        })
+        .attr("dy", 25)
+        .attr("font-size", 12)
+        .attr("id", d => "nodeText" + d.id)
+        .attr("filter", "url(#nodeTextBg1)")
+        .attr("class", "nodeText");
+
+      // 力导:节点、关系、节点文字、关系标签
+      simulation.on("tick", () => {
+        link
+          // .attr("marker-end", function (d) {
+          //   if (d.source.x < d.target.x) {
+          //     return "url(#arrowhead1)"
+          //   } else {
+          //     return null
+          //   }
+          // })
+          // .attr("marker-start", function (d) {
+          //   if (d.source.x < d.target.x) {
+          //     return null
+          //   } else {
+          //     return "url(#arrowhead2)"
+          //   }
+          // })
+          .attr('d', function (d) {
+            if (d.source.x < d.target.x) {
+              return 'M ' + d.source.x + ' ' + d.source.y + ' L ' + d.target.x + ' ' + d.target.y;
+            } else {
+              return 'M ' + d.target.x + ' ' + d.target.y + ' L ' + d.source.x + ' ' + d.source.y;
+            }
+          });
+
+        node
+          .attr("cx", d => d.x)
+          .attr("cy", d => d.y);
+
+        nodeText
+          .attr("x", d => d.x)
+          .attr("y", d => d.y);
+
+      });
+
+      // 设置图谱的缩放
+      let zoom = d3.zoom()
+        .extent([[0, 0], [w, h]])
+        .scaleExtent([0.1, 8])
+        .on("zoom", zoomed);
+
+      this.svg.call(zoom)
+        .on("dblclick.zoom", null);
+
+      function drag(simulation) {
+        function dragstarted(event) {
+          if (!event.active) simulation.alphaTarget(0.3).restart();
+          event.subject.fx = event.subject.x;
+          event.subject.fy = event.subject.y;
+        }
+
+        function dragged(event) {
+          event.subject.fx = event.x;
+          event.subject.fy = event.y;
+        }
+
+        function dragended(event) {
+          if (!event.active) simulation.alphaTarget(0);
+          event.subject.fx = null;
+          event.subject.fy = null;
+        }
+
+        return d3.drag()
+          .on("start", dragstarted)
+          .on("drag", dragged)
+          .on("end", dragended);
+      }
+
+      function zoomed(event) {
+        g.attr("transform", event.transform);
+        if (event.transform.k >= 1) {
+          g.selectAll("circle")
+            .attr("r", 12 / event.transform.k)
+            .attr("stroke-width", 1 / event.transform.k);
+          g.selectAll("path")
+            .attr("stroke-width", 2 / event.transform.k);
+          g.selectAll(".nodeText")
+            .attr("font-size", 12 / event.transform.k)
+            .attr("dx", function () {
+              return (0 - this.getBoundingClientRect().width / 2) / event.transform.k
+            })
+            .attr("dy", 25 / event.transform.k);
+          g.selectAll(".linkText")
+            .attr("font-size", 10 / event.transform.k)
+            .attr("dy", -5 / event.transform.k);
+        }
+      }
+    },
+
+    updateNode(entity) {
+      for (let i = 0; i < this.nodes.length; i++) {
+        if (this.nodes[i].id === entity.id) {
+          this.nodes[i] = entity;
+        }
+      }
+      this.update();
+    },
+
+    updateLink(relation) {
+      for (let i = 0; i < this.links.length; i++) {
+        if (this.links[i].id === relation.id) {
+          this.links[i] = relation;
+        }
+      }
+      this.update();
+    },
+
+    update() {
+      this.g.remove();
+      this.paint();
+    },
+  },
+}
+</script>
+
+<template>
+  <div v-if="entities && relations && uniqueKey"
+       :id="`kg-${uniqueKey}`"
+       class="kg">
+  </div>
+</template>
+
+<style lang="less" scoped>
+.kg {
+  position: relative;
+  width: 100%;
+  height: 100%;
+}
+</style>

+ 54 - 0
src/components/KgCard.vue

@@ -0,0 +1,54 @@
+<script>
+export default {
+  name: "KgCard",
+  props: {
+    kg: {
+      default: undefined,
+      required: true,
+    },
+  },
+  methods: {
+    handleCardClick() {
+      this.$router.push({
+        name: "KgView",
+        params: {
+          id: this.kg.id,
+        }
+      })
+    },
+  },
+}
+</script>
+
+<template>
+  <div class="kg-card" @click="handleCardClick">
+    <el-card shadow="hover">
+      <img :src="kg?.image" alt="#" class="card-img">
+      <el-link>{{ kg?.name }}</el-link>
+    </el-card>
+  </div>
+</template>
+
+<style lang="less" scoped>
+.kg-card {
+  padding: var(--gap);
+  cursor: pointer;
+  flex-basis: 25%;
+  box-sizing: border-box;
+
+  :deep(.el-card__body) {
+    padding: var(--gap-2);
+  }
+
+  .card-img {
+    width: 100%;
+    aspect-ratio: 16 / 9;
+    object-fit: cover;
+    object-position: top;
+  }
+
+  &:hover {
+    transform: translate(0, -1%);
+  }
+}
+</style>

+ 36 - 0
src/components/KgCreation/index.vue

@@ -0,0 +1,36 @@
+<script>
+import KgCreatorTxt from "@/views/create/simple/index.vue";
+
+export default {
+  name: "kgCreation",
+  components: {KgCreatorTxt},
+  data() {
+    return {
+      currentTab: "txt",
+    };
+  },
+}
+</script>
+
+<template>
+  <div class="kg-creation">
+    <el-tabs v-model="currentTab">
+      <el-tab-pane label="文本解析" name="txt">
+        <kg-creator-txt/>
+      </el-tab-pane>
+      <el-tab-pane label="文件上传" name="file">
+
+      </el-tab-pane>
+      <el-tab-pane label="手动创建" name="diy">
+
+      </el-tab-pane>
+    </el-tabs>
+  </div>
+</template>
+
+<style scoped lang="less">
+.kg-creation {
+  width: 100%;
+  position: relative;
+}
+</style>

+ 38 - 0
src/components/KgList/index.vue

@@ -0,0 +1,38 @@
+<script>
+import APIs from "@/api";
+
+export default {
+  name: "KgList",
+  data() {
+    return {
+      kgList: [],
+    }
+  },
+  mounted() {
+    this.init();
+  },
+  methods: {
+    async init() {
+      const res = await APIs.getKgInfoList();
+      if (!res || !res.data) {
+        return;
+      }
+      this.kgList = res.data;
+    },
+  },
+}
+</script>
+
+<template>
+  <div class="kg-list">
+    <el-button v-for="kg in kgList"
+               :key="`kgs-${kg.id}`"
+               @click="$router.push(`/kg/${kg.id}`)">
+      {{ kg.name }}
+    </el-button>
+  </div>
+</template>
+
+<style scoped lang="less">
+
+</style>

+ 78 - 0
src/components/KgTree.vue

@@ -0,0 +1,78 @@
+<script>
+import KgCard from "@/components/KgCard.vue";
+
+export default {
+  name: "KgTree",
+  components: {KgCard},
+  props: {
+    kgList: {
+      default: [],
+      required: true,
+    }
+  },
+  data() {
+    return {
+      kg: undefined,
+    };
+  },
+  computed: {
+    tree() {
+      return this.getPathTree();
+    }
+  },
+  methods: {
+    getPathTree() {
+      function f(data, info) {
+        let add = {
+          label: info.paths[0],
+          children: [],
+        };
+        let newAdd = true;
+        for (let item of data) {
+          if (item.label === info.paths[0]) {
+            add = item;
+            newAdd = false;
+            break;
+          }
+        }
+        info.paths.shift();
+        if (info.paths.length === 0) {
+          add.kg = info.kg;
+        } else {
+          f(add.children, info);
+        }
+        if (newAdd) data.push(add);
+      }
+
+      const result = [];
+      for (let kg of this.kgList) {
+        const paths = kg.path.split("/");
+        paths.shift();
+        f(result, {paths, kg});
+      }
+      return result;
+    },
+
+    handleNodeClick(data) {
+      if (data.children.length === 0) {
+        this.kg = data.kg;
+      }
+    },
+  },
+}
+</script>
+
+<template>
+  <div class="kg-tree">
+    <el-tree :data="tree" @node-click="handleNodeClick"/>
+    <div style="position: relative;width: 66%;margin: auto">
+      <kg-card v-if="kg!==undefined" :kg="kg"/>
+    </div>
+  </div>
+</template>
+
+<style lang="less" scoped>
+.kg-tree {
+  position: relative;
+}
+</style>

+ 60 - 51
src/mock/index.js

@@ -1,74 +1,83 @@
-import Mock from 'mockjs';
+import Mock from "mockjs";
+import kgAPIs from "@/mock/kg";
 
 // mockjs拦截下来的请求方法写在@/api/mock.js中
 
 let questionVO = {
-    analysis: "测试",
-    answer: "A",
+  analysis: "测试",
+  answer: "A",
+  blanks: null,
+  checkedUserId: 364,
+  createdTime: "2021-10-31T11:47:29.412Z",
+  id: "596adc65-f595-4515-a433-e49ef7752e80",
+  inputOutputMapping: null,
+  keyPoints: "",
+  knowledgeId: ["2", "1"],
+  lastModifiedTime: null,
+  memoryLimit: null,
+  millisecondLimit: null,
+  options: { A: "1", B: "2", C: "3 ", D: "4" },
+  savedUserId: 1481,
+  state: "APPROVED",
+  stem: "测试2",
+  tags: ["Java"],
+  title: null,
+  type: "choice",
+  weight: 1,
+};
+
+Mock.mock("/mock/test", "get", () => {
+  return "hello, mock!";
+});
+
+Mock.mock("/mock/searchQuestion/update", "get", () => {
+  let oldQuestionVO = questionVO;
+
+  let newQuestionVO = {
+    analysis: "测试111",
+    answer: "B",
     blanks: null,
     checkedUserId: 364,
     createdTime: "2021-10-31T11:47:29.412Z",
     id: "596adc65-f595-4515-a433-e49ef7752e80",
     inputOutputMapping: null,
-    keyPoints: "",
-    knowledgeId: ['2','1'],
+    keyPoints: "1",
+    knowledgeId: ["1"],
     lastModifiedTime: null,
     memoryLimit: null,
     millisecondLimit: null,
-    options: {A: '1', B: '2', C: '3 ', D: '4'},
+    options: { A: "11", B: "2", C: "33", D: "44" },
     savedUserId: 1481,
     state: "APPROVED",
     stem: "测试2",
-    tags: ['Java'],
+    tags: ["Python", "C"],
     title: null,
     type: "choice",
-    weight: 1,
-}
-
-Mock.mock('/mock/test', 'get', () => {
-    return "hello, mock!"
-})
+    weight: 2,
+  };
 
-Mock.mock('/mock/searchQuestion/update', 'get', () => {
-    let oldQuestionVO = questionVO
+  return [
+    {
+      oldQuestionVO,
+      newQuestionVO,
+    },
+  ];
+});
 
-    let newQuestionVO = {
-        analysis: "测试111",
-        answer: "B",
-        blanks: null,
-        checkedUserId: 364,
-        createdTime: "2021-10-31T11:47:29.412Z",
-        id: "596adc65-f595-4515-a433-e49ef7752e80",
-        inputOutputMapping: null,
-        keyPoints: "1",
-        knowledgeId: ['1'],
-        lastModifiedTime: null,
-        memoryLimit: null,
-        millisecondLimit: null,
-        options: {A: '11', B: '2', C: '33', D: '44'},
-        savedUserId: 1481,
-        state: "APPROVED",
-        stem: "测试2",
-        tags: ['Python','C'],
-        title: null,
-        type: "choice",
-        weight: 2
-    }
+Mock.mock("/mock/searchQuestion/create", "get", () => {
+  return [questionVO];
+});
 
-    return [{
-        oldQuestionVO,
-        newQuestionVO,
-    }]
-})
+Mock.mock("/mock/searchQuestion/execute", "get", () => {
+  return [questionVO];
+});
 
-Mock.mock('/mock/searchQuestion/create', 'get', () => {
-    return [questionVO]
-})
+Mock.mock("/mock/searchQuestion/delete", "get", () => {
+  return [questionVO];
+});
 
-Mock.mock("/mock/searchQuestion/execute", "get", ()=>{
-    return [questionVO]
-})
+const mockAPIs = {
+  ...kgAPIs,
+};
 
-Mock.mock("/mock/searchQuestion/delete", "get", ()=>{
-    return [questionVO]
-})
+export default mockAPIs;

+ 84 - 0
src/mock/kg/index.js

@@ -0,0 +1,84 @@
+import {getSwebokKg} from "@/mock/kg/swebok";
+
+const kgList = () => [
+  {
+    id: 1,
+    name: "kg-1",
+    image: "https://lain.bgm.tv/r/400/pic/cover/l/08/df/372010_KBWk9.jpg",
+    path: "/b/kg-1",
+  },
+  {
+    id: 2,
+    name: "kg-2",
+    image: "https://lain.bgm.tv/r/400/pic/cover/l/19/1a/405785_7Yq6o.jpg",
+    path: "/kg-2"
+  },
+  {
+    id: 3,
+    name: "kg-3",
+    image: "https://lain.bgm.tv/r/400/pic/cover/l/ef/8f/283643_2bcm7.jpg",
+    path: "/kg-3",
+  },
+  {
+    id: 4,
+    name: "kg-4",
+    image: "https://lain.bgm.tv/r/400/pic/cover/l/f0/f4/407573_993Vy.jpg",
+    path: "/a/b/kg-4",
+  },
+  {
+    id: 5,
+    name: "kg-5",
+    image: "https://lain.bgm.tv/r/400/pic/cover/l/ad/25/444557_P66C6.jpg",
+    path: "/a/kg-5"
+  },
+  {
+    id: 6,
+    name: "swebok",
+    image: "https://lain.bgm.tv/pic/cover/l/67/d1/876_dCfrd.jpg",
+    path: "/swebok/2004"
+  },
+];
+
+const kgData = () => ({
+  "6": getSwebokKg(),
+});
+
+function getAllOwnKg() {
+  return Promise.resolve({
+    data: kgList(),
+  });
+}
+
+function getAllStarKg() {
+  return Promise.resolve({
+    data: kgList(),
+  });
+}
+
+function getAllKgCanView() {
+  return Promise.resolve({
+    data: kgList(),
+  });
+}
+
+function getAllKgCanEdit() {
+  return Promise.resolve({
+    data: kgList(),
+  });
+}
+
+function getKgById(id) {
+  return Promise.resolve({
+    data: kgData()[id],
+  });
+}
+
+const kgAPIs = {
+  getAllOwnKg,
+  getAllStarKg,
+  getAllKgCanEdit,
+  getAllKgCanView,
+  getKgById,
+};
+
+export default kgAPIs;

+ 60 - 0
src/mock/kg/swebok.js

@@ -0,0 +1,60 @@
+import {json2kg} from "@/mock/kg/util";
+
+const swebok2004 = {
+  软件需求: {
+    软件需求基础: null,
+    需求过程: null,
+    需求获取: null,
+    需求分析: null,
+    需求规格说明: null,
+    需求确认: null,
+    实际考虑: null,
+  },
+  软件设计: {
+    软件设计基础: null,
+    软件设计关键问题: null,
+    软件结构与体系结构: null,
+    软件设计质量的分析与评价: null,
+    软件设计符号: null,
+    软件设计的策略与方法: null,
+  },
+  软件构造: {
+    软件构造基础: null,
+    管理构造: null,
+    实际考虑: null,
+  },
+  软件测试: {
+    软件测试基础: null,
+    测试级别: null,
+    测试技术: null,
+    需求分析: null,
+    与测试相关的度量: null,
+    测试过程: null,
+  },
+  软件维护: {
+    软件维护基础: null,
+    软件维护的关键问题: null,
+    维护过程: null,
+    维护技术: null,
+  },
+};
+
+export function getSwebokKg() {
+  const entities = [];
+  const relations = [];
+  entities.push({
+    id: 0,
+    name: "swebok2004",
+  });
+  json2kg(0, swebok2004, entities, relations);
+  return {
+    kg: {
+      id: 6,
+      name: "swebok",
+      image: "https://lain.bgm.tv/pic/cover/l/67/d1/876_dCfrd.jpg",
+      path: "/swebok/2004"
+    },
+    entities,
+    relations,
+  };
+}

+ 23 - 0
src/mock/kg/util.js

@@ -0,0 +1,23 @@
+export function json2kg(source, value, entities, relations) {
+  if (value === null) {
+    return;
+  }
+  if (value instanceof Array) {
+    return;
+  }
+  if (value instanceof Object) {
+    for (let key of Object.keys(value)) {
+      const len = entities.length;
+      relations.push({
+        source,
+        target: len,
+        name: "contain",
+      });
+      entities.push({
+        id: len,
+        name: key,
+      });
+      json2kg(len, value[key], entities, relations);
+    }
+  }
+}

+ 57 - 1
src/router/index.js

@@ -95,7 +95,63 @@ const routes = [
         path: "knowledgeImport",
         name: "KnowledgeImport",
         component: () => import("@/views/Bok/Main/KnowledgeImport"),
-      }
+      },
+      {
+        path: '/kg',
+        name: 'KG',
+        component: () => import("@/views/KG/home"),
+        redirect: "/kg/owner",
+        children: [
+          {
+            path: "owner",
+            name: "owner",
+            component: () => import("@/views/KG/home/owner"),
+          },
+          {
+            path: "collaborator",
+            name: "collaborator",
+            component: () => import("@/views/KG/home/collaborator"),
+          },
+          {
+            path: "star",
+            name: "star",
+            component: () => import("@/views/KG/home/star"),
+          },
+        ]
+      },
+      {
+        path: "/createkg",
+        name: "createKG",
+        component: () => import("@/views/KG/create"),
+        redirect: "/createkg/simple",
+        children: [
+          {
+            path: "simple",
+            name: "simple",
+            component: () => import("@/views/KG/create/simple"),
+          },
+          {
+            path: "import",
+            name: "import",
+            component: () => import("@/views/KG/create/import"),
+          },
+          {
+            path: "merge",
+            name: "merge",
+            component: () => import("@/views/KG/create/merge"),
+          },
+          {
+            path: "model",
+            name: "model",
+            component: () => import("@/views/KG/create/model"),
+          },
+        ]
+      },
+      {
+        path: "/kg/:id",
+        name: "KgView",
+        component: () => import("@/views/KG/kg/index.vue"),
+      },
     ],
   },
 ];

+ 38 - 0
src/utils/cookie.js

@@ -0,0 +1,38 @@
+/**
+ * @description 保存cookie
+ * @param {Object} json 需要存储cookie的对象
+ * @param {Number} days 默认存储多少天
+ */
+export function setCookie(json, days) {
+  // 设置过期时间
+  let data = new Date(
+    new Date().getTime() + days * 24 * 60 * 60 * 1000
+  ).toUTCString();
+
+  for (const key in json) {
+    document.cookie = key + "=" + json[key] + "; expires=" + data;
+  }
+}
+
+/**
+ * @description 获取cookie
+ * @param {String} key 需要获取cookie的key
+ */
+export function getCookie(key) {
+  const arr = document.cookie.match(new RegExp("(^| )" + key + "=([^;]*)(;|$)"));
+  if (arr != null) {
+    return unescape(arr[2]);
+  } else {
+    return null;
+  }
+}
+
+/**
+ * @description 删除cookie
+ * @param {String} name 需要删除cookie的key
+ */
+export function clearCookie(name) {
+  let json = {};
+  json[name] = "";
+  setCookie(json, -1);
+}

+ 24 - 0
src/utils/mapper.js

@@ -0,0 +1,24 @@
+export const properties = {
+  entity: ["id", "name", "knowledgeId"],
+  relation: ["id", "name", "source", "target", "origin"],
+};
+
+const idProperty = ["source", "target"];
+
+function to(o, property) {
+  let res = {};
+  for (let p of property) {
+    if (idProperty.includes(p)) {
+      res[p] = o[p].id;
+    } else {
+      res[p] = o[p];
+    }
+  }
+  return res;
+}
+
+const mapper = {
+  to,
+}
+
+export default mapper;

+ 18 - 0
src/utils/time.js

@@ -0,0 +1,18 @@
+function prefixCompletion(number) {
+  return number < 10 ? `0${number}` : `${number}`;
+}
+
+/**
+ *
+ */
+function suffix() {
+  const date = new Date();
+  return `${date.getFullYear()}${prefixCompletion(date.getMonth() + 1)}${prefixCompletion(date.getDate())}${prefixCompletion(date.getHours())}${prefixCompletion(date.getMinutes())}${prefixCompletion(date.getSeconds())}`;
+}
+
+
+const timeAPIs = {
+  suffix,
+};
+
+export default timeAPIs;

+ 5 - 0
src/views/Bok/Main/KnowledgeRepo.vue

@@ -86,6 +86,10 @@
                         </certification-card>
                     </span>
 
+                    <!-- 其他知识,markdown -->
+                    <sapn v-else-if="tab.value === 'other'">
+                    </sapn>
+
                     <el-backtop :bottom="50">
                         <div
                             style="height: 100%;width: 100%;background-color: #f2f5f6;box-shadow: 0 0 6px rgba(0,0,0, .12);line-height: 40px;">
@@ -133,6 +137,7 @@ export default {
                 { label: '综述文献', value: 'literature' },
                 { label: '专著', value: 'monograph' },
                 { label: '认证', value: 'certification' },
+                { label: '其他知识', value: 'other' },
             ],
 
             totalNum: 1,

+ 17 - 9
src/views/Bok/SideBar.vue

@@ -12,6 +12,14 @@
         <i class="el-icon-s-data"></i>
         <template #title>知识树</template>
       </el-menu-item>
+      <el-menu-item index="kg">
+        <i class="el-icon-folder" />
+        <span slot="title">知识图谱</span>
+      </el-menu-item>
+      <el-menu-item index="createkg">
+        <i class="el-icon-circle-plus-outline" />
+        <span slot="title">知识图谱生成</span>
+      </el-menu-item>
       <el-menu-item index="knowledgeRepo">
         <i class="el-icon-box"></i>
         <template #title>知识库</template>
@@ -28,10 +36,10 @@
         <i class="el-icon-search"></i>
         <template #title>题目搜索</template>
       </el-menu-item>
-      <!-- <el-menu-item index="operation">
+      <el-menu-item index="operation">
         <i class="el-icon-folder-add"></i>
         <template #title>新建题目</template>
-      </el-menu-item> -->
+      </el-menu-item>
       <el-menu-item index="knowledgeGraph" v-if="false">
         <i class="el-icon-connection"></i>
         <template #title>知识图谱</template>
@@ -40,26 +48,26 @@
         <i class="el-icon-document"></i>
         <template #title>试卷袋</template>
       </el-menu-item>
-      <!-- <el-menu-item index="check" v-if="role">
+      <el-menu-item index="check" v-if="role">
         <i class="el-icon-s-check"></i>
         <template #title>题目审核</template>
-      </el-menu-item> -->
-      <!-- <el-menu-item index="questionRepository">
+      </el-menu-item>
+      <el-menu-item index="questionRepository">
         <i class="el-icon-files"></i>
         <template #title>题库</template>
-      </el-menu-item> -->
+      </el-menu-item>
       <el-menu-item index="my">
         <i class="el-icon-user"></i>
-        <template #title>我的交互记录</template>
+        <template #title>收藏</template>
       </el-menu-item>
       <el-menu-item index="setting" v-if="false">
         <i class="el-icon-setting"></i>
         <template #title>设置</template>
       </el-menu-item>
-      <!-- <el-menu-item index="instructions">
+      <el-menu-item index="instructions">
         <i class="el-icon-question"></i>
         <template #title>使用说明</template>
-      </el-menu-item> -->
+      </el-menu-item>
     </el-menu>
   </div>
 </template>

+ 75 - 0
src/views/KG/create/import/index.vue

@@ -0,0 +1,75 @@
+<script>
+export default {
+  name: "import",
+  data() {
+    return {
+      options: [{
+        value: 'file',
+        label: '上传文件'
+      }, {
+        value: 'script',
+        label: '输入脚本'
+      },],
+      selector: "file",
+
+      inputScript: "",
+    };
+  }
+}
+</script>
+
+<template>
+  <div class="import">
+    <div class="import-selector">
+      <el-select v-model="selector" placeholder="请选择">
+        <el-option
+          v-for="item in options"
+          :key="item.value"
+          :label="item.label"
+          :value="item.value">
+        </el-option>
+      </el-select>
+    </div>
+    <div class="upload">
+      <div v-if="selector===`file`">
+        <el-upload
+          :auto-upload="false"
+          action="#"
+          class="upload-demo"
+          drag>
+          <i class="el-icon-upload"></i>
+          <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
+        </el-upload>
+        <el-button class="btn-confirm">确定</el-button>
+      </div>
+      <div v-if="selector===`script`">
+        <el-input v-model="inputScript"
+                  :autosize="{ minRows: 3}"
+                  maxlength="500"
+                  placeholder="请输入需要解析的文本"
+                  show-word-limit
+                  type="textarea">
+        </el-input>
+        <el-button class="btn-confirm">确定</el-button>
+      </div>
+    </div>
+  </div>
+</template>
+
+<style lang="less" scoped>
+.import {
+  .import-selector {
+    text-align: left;
+    height: fit-content;
+    width: fit-content;
+  }
+
+  .upload {
+    margin-top: var(--gap-2);
+  }
+
+  .btn-confirm {
+    margin-top: var(--gap-2);
+  }
+}
+</style>

+ 53 - 0
src/views/KG/create/index.vue

@@ -0,0 +1,53 @@
+<script>
+
+export default {
+  name: "create",
+  data() {
+    return {
+      activeTab: "",
+    };
+  },
+  mounted() {
+    this.activeTab = this.$route.path.split("/").pop();
+  },
+  methods: {
+    handleTabClick(tab) {
+      this.$router.push({name: tab.name});
+    }
+  },
+}
+</script>
+
+<template>
+  <div class="create">
+    <el-tabs v-model="activeTab" @tab-click="handleTabClick">
+      <el-tab-pane label="简单生成" name="simple">
+        <router-view/>
+      </el-tab-pane>
+      <el-tab-pane label="导入生成" name="import">
+        <router-view/>
+      </el-tab-pane>
+      <el-tab-pane label="合并生成" name="merge">
+        <router-view/>
+      </el-tab-pane>
+      <el-tab-pane label="模型生成" name="model">
+        <router-view/>
+      </el-tab-pane>
+    </el-tabs>
+  </div>
+</template>
+
+<style lang="less" scoped>
+.create {
+  :deep(.el-tabs) {
+    position: relative;
+    height: 100%;
+  }
+
+  :deep(.el-tabs__content) {
+    position: relative;
+    height: calc(100% - 40px - 15px);
+    overflow-y: scroll;
+  }
+}
+</style>

+ 15 - 0
src/views/KG/create/merge/index.vue

@@ -0,0 +1,15 @@
+<script>
+export default {
+  name: "merge",
+}
+</script>
+
+<template>
+  <div>
+    <span>请选择要合并的图谱。</span>
+  </div>
+</template>
+
+<style lang="less" scoped>
+
+</style>

+ 113 - 0
src/views/KG/create/model/index.vue

@@ -0,0 +1,113 @@
+<script>
+export default {
+  name: "model",
+  data() {
+    return {
+      tableData: [{
+        id: 4,
+        time: '2016-05-02',
+        name: '模型1',
+        path: '/model/模型1'
+      }, {
+        id: 1,
+        time: '2016-05-04',
+        name: '模型2',
+        path: '/模型2'
+      }, {
+        id: 2,
+        time: '2016-05-01',
+        name: '模型23',
+        path: '/model/shanghai/模型23'
+      }, {
+        id: 3,
+        time: '2016-05-03',
+        name: '模型243',
+        path: '/model/shanghai/模型243'
+      }],
+
+      options: [{
+        value: 'my',
+        label: '我的模型'
+      }, {
+        value: "open",
+        label: "公共模型",
+      },],
+      selector: "my",
+
+      currentModel: undefined,
+
+      inputTxt: "",
+    };
+  },
+}
+</script>
+
+<template>
+  <div class="model">
+    <div class="model-table-header">
+      <el-select v-model="selector" placeholder="请选择">
+        <el-option
+          v-for="item in options"
+          :key="item.value"
+          :label="item.label"
+          :value="item.value">
+        </el-option>
+      </el-select>
+      <el-button type="primary">新建模型</el-button>
+    </div>
+    <div class="model-table mt-2">
+      <el-table :data="tableData" border style="width: 100%">
+        <el-table-column label="模型名称" prop="name">
+        </el-table-column>
+        <el-table-column label="模型路径" prop="path">
+        </el-table-column>
+        <el-table-column label="创建时间" prop="time">
+        </el-table-column>
+      </el-table>
+    </div>
+    <el-divider/>
+    <div class="model-create">
+      <div style="display: flex;justify-content: space-between">
+        <el-select v-model="currentModel" placeholder="选择模型">
+          <el-option
+            v-for="item in tableData"
+            :key="`table-data-${item.id}`"
+            :label="item.name"
+            :value="item.id">
+          </el-option>
+        </el-select>
+        <div></div>
+      </div>
+      <div class="mt-2">
+        <el-input v-model="inputTxt"
+                  :autosize="{ minRows: 3}"
+                  maxlength="500"
+                  placeholder="请输入需要解析的文本"
+                  show-word-limit
+                  type="textarea">
+        </el-input>
+        <div class="mt-2">
+          <el-button>确定</el-button>
+        </div>
+      </div>
+    </div>
+  </div>
+</template>
+
+<style lang="less" scoped>
+.model {
+  .model-table-header {
+    display: flex;
+    justify-content: space-between;
+  }
+
+  .model-table {
+    cursor: pointer;
+  }
+
+  .model-create {
+    margin-top: var(--gap-4);
+    text-align: center;
+  }
+}
+</style>

+ 315 - 0
src/views/KG/create/simple/index.vue

@@ -0,0 +1,315 @@
+<script>
+import APIs from "@/api";
+
+export default {
+  name: "simple",
+  data() {
+    return {
+      inputTxt: "阿拉伯数字是一种数字系统,通常用于书写数字。阿拉伯数字包括0、1、2、3、4、5、6、7、8、9这些基本数字。这个数字系统起源于印度,后来传播到阿拉伯世界,因此得名为阿拉伯数字。\n" +
+        "\n" +
+        "阿拉伯数字在世界范围内被广泛使用,取代了罗马数字等其他数字系统。它们具有简单明了、易读易写的特点,被用于数学、计算、计量和其他领域。在阿拉伯数字中,每个数字的位置表示其权重,例如十位、百位、千位等。\n" +
+        "\n" +
+        "阿拉伯数字的基本形式是:0、1、2、3、4、5、6、7、8、9。通过组合这些数字,可以表示任意整数。",
+      sentences: [],
+      sentenceIndex: 0,
+
+      tupleKeys: ['source', 'relation', 'target'],
+      tupleValues: {
+        source: "",
+        relation: "",
+        target: "",
+      },
+
+      dragTag: null,
+
+      entities: [],
+      relations: [],
+
+      form: {
+        name: "",
+      }
+    };
+  },
+  methods: {
+    /**
+     *
+     * @returns {Promise<void>}
+     */
+    async parseTxt() {
+      if (this.inputTxt) {
+        const res = await APIs.parseTxt(this.inputTxt);
+        if (res && res.data) {
+          this.sentences = res.data;
+          this.sentenceIndex = 0;
+        }
+      } else {
+        this.$message.error("未输入解析文本");
+      }
+    },
+
+    /**
+     *
+     * @param tag
+     */
+    handleTagDragStart(tag) {
+      this.dragTag = tag;
+    },
+
+    /**
+     *
+     * @param tupleKey
+     */
+    handleTagDrop(tupleKey) {
+      this.tupleValues[tupleKey] += this.dragTag;
+    },
+
+    /**
+     *
+     */
+    addTuple() {
+      const [entities, relations] = [this.entities, this.relations];
+      const {source, relation, target} = this.tupleValues;
+      const sentence = this.sentences[this.sentenceIndex];
+      if (entities.indexOf(source) === -1) {
+        entities.push(source);
+      }
+      if (entities.indexOf(target) === -1) {
+        entities.push(target);
+      }
+      relations.push({
+        source: entities.indexOf(source),
+        name: relation,
+        target: entities.indexOf(target),
+        origin: sentence[0], // sentence = [origin, words]
+        head: source,
+        tail: target,
+      });
+      this.tupleValues = {
+        source: "",
+        relation: "",
+        target: "",
+      };
+    },
+
+    createKg() {
+      this.$refs['kg-form'].validate(async (valid) => {
+        if (valid) {
+          const createData = (await APIs.createKg({
+            name: `/${this.form.name}`,
+          })).data;
+          if (createData?.error) {
+            this.$message.error(createData.message);
+            return;
+          }
+          const [entities, relations] = [this.entities, this.relations];
+          const initData = (await APIs.initKg({
+            id: createData.id,
+            entities: entities.map(e => ({
+              name: e
+            })),
+            relations,
+          })).data;
+          if (initData?.error) {
+            this.$message.error(initData.message);
+            return;
+          }
+          await this.$router.push(`/kg/${initData}`);
+        } else {
+          return false;
+        }
+      });
+    },
+
+    clearTuple() {
+      this.tupleValues = {
+        source: "",
+        relation: "",
+        target: "",
+      };
+    }
+  },
+}
+</script>
+
+<template>
+  <div class="kg-creator-txt">
+    <div class="kg-creator-txt-input">
+      <el-input v-model="inputTxt"
+                :autosize="{ minRows: 3}"
+                maxlength="500"
+                placeholder="请输入需要解析的文本"
+                show-word-limit
+                type="textarea">
+      </el-input>
+    </div>
+    <el-button @click="parseTxt">解析</el-button>
+    <div v-if="sentences.length"
+         class="sentences">
+      <i class="el-icon-bottom"/>
+      <div class="sentence">
+        <el-button :disabled="sentenceIndex === 0"
+                   circle icon="el-icon-arrow-left"
+                   size="mini"
+                   @click="sentenceIndex--"/>
+        <div class="sentence-body">{{ sentences[sentenceIndex][0] }}</div>
+        <el-button :disabled="sentenceIndex === sentences.length - 1"
+                   circle
+                   icon="el-icon-arrow-right" size="mini"
+                   @click="sentenceIndex++"/>
+      </div>
+      <br/>
+      <div class="words justify-center">
+        <span>分词-<span style="color: var(--info-primary)">选择标签拖入下方拼接</span>:</span>
+        <div v-for="(item,index) in sentences[sentenceIndex][1]" :key="index"
+             class="word"
+             draggable="true"
+             @dragstart="handleTagDragStart(item)">
+          <el-tag>
+            {{ item }}
+          </el-tag>
+        </div>
+      </div>
+      <br/>
+      <div class="tuple">
+        <div
+          class="tuple-item"
+          @dragover.prevent=""
+          @drop.capture="handleTagDrop('source')">
+          <el-card>
+            source
+            <el-select v-model="tupleValues['source']" allow-create filterable>
+              <el-option
+                v-for="item in entities"
+                :key="`source-${item}`"
+                :label="item"
+                :value="item">
+              </el-option>
+            </el-select>
+          </el-card>
+        </div>
+        <div
+          class="tuple-item"
+          @dragover.prevent=""
+          @drop.capture="handleTagDrop('relation')">
+          <el-card>
+            relation
+            <el-input v-model="tupleValues['relation']"/>
+          </el-card>
+        </div>
+        <div
+          class="tuple-item"
+          @dragover.prevent=""
+          @drop.capture="handleTagDrop('target')">
+          <el-card>
+            target
+            <el-select v-model="tupleValues['target']" allow-create filterable>
+              <el-option
+                v-for="item in entities"
+                :key="`target-${item}`"
+                :label="item"
+                :value="item">
+              </el-option>
+            </el-select>
+          </el-card>
+        </div>
+      </div>
+      <div>
+        <el-button @click="addTuple">add</el-button>
+        <el-button @click="clearTuple">clear</el-button>
+      </div>
+      <i class="el-icon-bottom"/>
+      <el-form ref="kg-form" :model="form" label-position="right" label-width="75px">
+        <el-form-item :required="true" label="名称" prop="name">
+          <el-input v-model="form.name" autocomplete="off"></el-input>
+        </el-form-item>
+        <el-form-item label="实体">
+          <div class="words justify-start">
+            <div v-for="(item,index) in entities"
+                 :key="`entity-${index}`"
+                 class="word">
+              <el-tag>
+                {{ item }}
+              </el-tag>
+            </div>
+          </div>
+        </el-form-item>
+        <el-form-item label="关系">
+          <div class="words justify-start">
+            <div v-for="(item,index) in relations"
+                 :key="`relation-${index}`"
+                 class="word">
+              <el-tag>
+                {{ `${item.source}->${item.target}` }}
+              </el-tag>
+            </div>
+          </div>
+        </el-form-item>
+      </el-form>
+      <el-button @click="createKg">create</el-button>
+    </div>
+  </div>
+</template>
+
+<style lang="less" scoped>
+.kg-creator-txt {
+  //padding: 0 var(--gap-2) var(--gap-2);
+
+  &-input {
+    margin-bottom: var(--gap-2);
+  }
+
+  .sentences {
+    width: 100%;
+    position: relative;
+  }
+
+  .sentence {
+    display: flex;
+    justify-content: center;
+    line-height: 28.5px; // element button mini height
+    font-style: italic;
+  }
+
+  .sentence-body {
+    margin: 0 calc(4 * var(--gap));
+  }
+
+  .el-form-item__label {
+    text-align: start;
+  }
+
+  .words {
+    display: flex;
+    line-height: 32px; // element tag small height
+    flex-wrap: wrap;
+  }
+
+  .word {
+    margin: 0 5px;
+  }
+
+  .tuple {
+    width: 100%;
+    position: relative;
+    display: flex;
+    justify-content: space-around;
+    margin-bottom: var(--gap-2);
+
+    &-item {
+      width: 30%;
+    }
+  }
+
+  .data-block {
+    width: 50%;
+  }
+
+  .data-block + .data-block {
+    border-left: var(--border-one) 1px solid;
+  }
+
+  .el-select {
+    width: 100%;
+  }
+}
+</style>

+ 49 - 0
src/views/KG/home/collaborator/index.vue

@@ -0,0 +1,49 @@
+<script>
+import KgCard from "@/components/KgCard.vue";
+import mockAPIs from "@/mock";
+
+export default {
+  name: "collaborator",
+  components: {KgCard},
+  data() {
+    return {
+      collaborate: "view",
+
+      kgListCanView: [],
+      kgListCanEdit: [],
+    }
+  },
+  async mounted() {
+    this.kgListCanView = (await mockAPIs.getAllKgCanView()).data;
+    this.kgListCanEdit = (await mockAPIs.getAllKgCanEdit()).data.reverse();
+  },
+}
+</script>
+
+<template>
+  <div class="collaborator">
+    <div class="flex justify-between">
+      <el-select v-model="collaborate" placeholder="选择视图">
+        <el-option label="可查看" value="view"></el-option>
+        <el-option label="可编辑" value="edit"></el-option>
+      </el-select>
+      <div></div>
+    </div>
+    <div v-if="collaborate===`view`" class="kg-card-list">
+      <kg-card v-for="item in kgListCanView"
+               :key="`kg-view-${item.id}`"
+               :kg="item"/>
+    </div>
+    <div v-if="collaborate===`edit`" class="kg-card-list">
+      <kg-card v-for="item in kgListCanEdit"
+               :key="`kg-edit-${item.id}`"
+               :kg="item"/>
+    </div>
+  </div>
+</template>
+
+<style lang="less" scoped>
+.collaborator {
+
+}
+</style>

+ 50 - 0
src/views/KG/home/index.vue

@@ -0,0 +1,50 @@
+<template>
+  <div class="home">
+    <el-tabs v-model="activeTab" @tab-click="tab=>$router.push({name: tab.name})">
+      <el-tab-pane label="我创建的" name="owner">
+        <router-view/>
+      </el-tab-pane>
+      <el-tab-pane label="我协作的" name="collaborator">
+        <router-view/>
+      </el-tab-pane>
+      <el-tab-pane label="我收藏的" name="star">
+        <router-view/>
+      </el-tab-pane>
+    </el-tabs>
+  </div>
+</template>
+
+<script>
+export default {
+  name: 'Home',
+  data() {
+    return {
+      activeTab: "owner",
+    }
+  },
+  methods: {},
+}
+</script>
+
+<style lang="less" scoped>
+.home {
+  :deep(.el-tabs) {
+    position: relative;
+    height: 100%;
+  }
+
+  :deep(.el-tabs__content) {
+    position: relative;
+    height: calc(100% - 40px - 15px);
+    overflow-y: scroll;
+  }
+}
+</style>
+
+<style lang="less">
+.kg-card-list {
+  display: flex;
+  flex-wrap: wrap;
+  position: relative;
+}
+</style>

+ 42 - 0
src/views/KG/home/owner/index.vue

@@ -0,0 +1,42 @@
+<script>
+import KgCard from "@/components/KgCard.vue";
+import mockAPIs from "@/mock";
+import KgTree from "@/components/KgTree.vue";
+
+export default {
+  name: "owner",
+  components: { KgTree, KgCard },
+  data() {
+    return {
+      view: "card",
+
+      kgList: [],
+    }
+  },
+  async mounted() {
+    this.kgList = (await mockAPIs.getAllOwnKg()).data;
+  },
+}
+</script>
+
+<template>
+  <div class="owner">
+    <div class="flex justify-between">
+      <el-select v-model="view" placeholder="选择视图">
+        <el-option label="缩略视图" value="card"></el-option>
+        <el-option label="文件视图" value="fileList"></el-option>
+      </el-select>
+      <div></div>
+    </div>
+    <div v-if="view === `card`" class="kg-card-list">
+      <kg-card v-for="item in kgList" :key="`kg-own-${item.id}`" :kg="item" />
+    </div>
+    <div v-if="view === `fileList`" class="mt-2">
+      <kg-tree :kg-list="kgList" />
+    </div>
+  </div>
+</template>
+
+<style lang="less" scoped>
+.owner {}
+</style>

+ 44 - 0
src/views/KG/home/star/index.vue

@@ -0,0 +1,44 @@
+<script>
+import KgCard from "@/components/KgCard.vue";
+import mockAPIs from "@/mock";
+import KgTree from "@/components/KgTree.vue";
+
+export default {
+  name: "star",
+  components: {KgTree, KgCard},
+  data() {
+    return {
+      view: "card",
+
+      staredKgList: [],
+    };
+  },
+  async mounted() {
+    this.staredKgList = (await mockAPIs.getAllStarKg()).data.reverse();
+  },
+}
+</script>
+
+<template>
+  <div class="star">
+    <div class="flex justify-between">
+      <el-select v-model="view" placeholder="选择视图">
+        <el-option label="缩略视图" value="card"></el-option>
+        <el-option label="文件视图" value="fileList"></el-option>
+      </el-select>
+      <div></div>
+    </div>
+    <div v-if="view===`card`" class="kg-card-list">
+      <kg-card v-for="item in staredKgList"
+               :key="`kg-star-${item.id}`"
+               :kg="item"/>
+    </div>
+    <div v-if="view===`fileList`" class="mt-2">
+      <kg-tree :kg-list="staredKgList"/>
+    </div>
+  </div>
+</template>
+
+<style lang="less" scoped>
+
+</style>

+ 282 - 0
src/views/KG/kg/index.vue

@@ -0,0 +1,282 @@
+<script>
+import Kg from "@/components/Kg.vue";
+import APIs from "@/api/kg";
+import mapper, {properties} from "@/utils/mapper";
+import timeAPIs from "@/utils/time";
+import mockAPIs from "@/mock";
+
+export default {
+  name: "KgView",
+  components: {Kg},
+  data() {
+    return {
+      valid: false,
+
+      kg: {
+        name: undefined,
+      },
+      entities: null,
+      relations: null,
+
+      leftSwitch: false,
+      rightSwitch: false,
+
+      entity: {
+        id: undefined,
+        name: undefined,
+        knowledgeId: undefined,
+      },
+
+      relation: {
+        id: undefined,
+        source: undefined,
+        name: undefined,
+        target: undefined,
+        origin: undefined,
+      },
+    };
+  },
+  async mounted() {
+    await this.init();
+  },
+  methods: {
+    async init() {
+      // const res = (await APIs.getKgById(this.$route.params.id)).data;
+      const res = (await mockAPIs.getKgById(this.$route.params.id)).data;
+      console.log(res);
+      if (res?.error) {
+        this.$message.error(res.error);
+        return;
+      }
+      this.kg = res.kg;
+      this.entities = res.entities;
+      this.relations = res.relations;
+      this.valid = true;
+    },
+
+    switchLeft() {
+      let left = document.getElementsByClassName("left")[0];
+      left.style.left = this.leftSwitch ? "-250px" : "0";
+      this.leftSwitch = !this.leftSwitch;
+    },
+
+    switchRight() {
+      let right = document.getElementsByClassName("right")[0];
+      right.style.right = this.rightSwitch ? "-250px" : "0";
+      this.rightSwitch = !this.rightSwitch;
+    },
+
+    handleNodeClick(node) {
+      this.entity = node;
+    },
+
+    handleLinkClick(link) {
+      this.relation = link;
+    },
+
+    async updateEntity(entity) {
+      if (!entity.name) {
+        this.$message.error("! entity.name");
+        return;
+      }
+      const data = (await APIs.updateEntity(mapper.to(entity, properties.entity))).data;
+      if (data?.error) {
+        this.$message.error(data.message);
+        return;
+      }
+      this.$refs.kg.updateNode(entity);
+    },
+
+    async updateRelation(relation) {
+      if (!relation.name) {
+        this.$message.error("! relation.name");
+      }
+      const data = (await APIs.updateRelation(mapper.to(relation, properties.relation))).data;
+      if (data?.error) {
+        this.$message.error(data.message);
+        return;
+      }
+      this.$refs.kg.updateLink(relation);
+    },
+
+    async exportKgData() {
+      const data = (await APIs.getKgById(this.$route.params.id)).data;
+      const url = URL.createObjectURL(
+        new Blob([JSON.stringify(data, null, 2)], {
+          type: "application/json",
+        })
+      );
+      const a = document.createElement('a');
+      a.style.display = 'none';
+      a.href = url;
+      a.download = this.kg.name;
+      document.body.appendChild(a);
+      a.click();
+      setTimeout(function () {
+        document.body.removeChild(a);
+        window.URL.revokeObjectURL(url);
+      }, 0);
+    },
+
+    async handleModelBtnClick() {
+      const data = (await APIs.generateModelRe({
+        modelVO: {
+          name: `${this.kg.name}-model-${timeAPIs.suffix()}`,
+          kgId: this.kg.id,
+        },
+        // todo: customize
+        // trainRate: 0.6
+        // testRate: 0.2
+        // validRate: 0.2
+      })).data;
+      console.log(data);
+    }
+  },
+}
+</script>
+
+<template>
+  <div class="kg-view">
+    <kg v-if="valid" ref="kg" :entities="entities" :relations="relations" :unique-key="kg.id"
+        @LinkClick="handleLinkClick" @NodeClick="handleNodeClick"/>
+    <div class="left absolute">
+      <el-button :icon="leftSwitch ? 'el-icon-arrow-left':'el-icon-arrow-right'" circle class="left-switch absolute"
+                 size="mini" @click="switchLeft"/>
+      <div class="left-main">
+        <h3>功能区</h3>
+        <el-divider/>
+        <div class="kg-info">
+          <h4>图谱</h4>
+          <el-descriptions :column="1">
+            <el-descriptions-item label="位置">
+              <el-link>{{ kg.path }}</el-link>
+            </el-descriptions-item>
+            <el-descriptions-item label="名称">
+              <el-link>{{ kg.name }}</el-link>
+            </el-descriptions-item>
+          </el-descriptions>
+          <el-button @click="$router.push( {
+            name: 'home',
+            params: {
+              kgListVisible: true,
+            }
+          } )">返回列表
+          </el-button>
+          <el-button>
+            更新信息
+          </el-button>
+        </div>
+        <el-divider/>
+        <div>
+          <h4>应用</h4>
+          <el-button>Q&A</el-button>
+          <el-button>Recommend</el-button>
+        </div>
+        <el-divider/>
+        <div>
+          <h4>文件</h4>
+          <el-button @click="exportKgData">数据导出</el-button>
+          <el-button>img</el-button>
+        </div>
+        <el-divider/>
+        <div>
+          <h4>模型</h4>
+          <el-button @click="handleModelBtnClick">Model</el-button>
+          <el-button>Test</el-button>
+        </div>
+        <el-divider/>
+      </div>
+    </div>
+
+    <div class="right absolute">
+      <el-button :icon="rightSwitch ? 'el-icon-arrow-right':'el-icon-arrow-left'" circle class="right-switch absolute"
+                 size="mini"
+                 @click="switchRight"/>
+      <div class="right-main">
+        <h3>编辑区</h3>
+        <el-divider/>
+        <div>
+          <h4>实体</h4>
+          <el-descriptions :column="1">
+            <el-descriptions-item label="名称">
+              <el-link>{{ entity.name }}</el-link>
+            </el-descriptions-item>
+            <el-descriptions-item label="知识">
+              <el-link>{{ entity.knowledgeId || `无` }}</el-link>
+            </el-descriptions-item>
+          </el-descriptions>
+          <el-button :disabled="entity.id===undefined" @click="updateEntity(entity)">update</el-button>
+        </div>
+        <el-divider/>
+        <div>
+          <h4>关系</h4>
+          <el-descriptions :column="1">
+            <el-descriptions-item label="内容">
+              <el-link>{{ relation.name }}</el-link>
+            </el-descriptions-item>
+            <el-descriptions-item label="原句">
+              <el-link>{{ relation.origin }}</el-link>
+            </el-descriptions-item>
+          </el-descriptions>
+          <el-button :disabled="relation.id===undefined" @click="updateRelation(relation)">update</el-button>
+        </div>
+        <el-divider/>
+      </div>
+    </div>
+  </div>
+</template>
+
+<style lang="less" scoped>
+.kg-view {
+  height: calc(100vh - var(--header-height));
+  overflow: hidden;
+  position: relative;
+  background: whitesmoke;
+
+  .left {
+    left: -250px;
+    top: 0;
+    height: 100%;
+    width: 250px;
+    box-sizing: border-box;
+    background: white;
+    //box-shadow: 1px 0 var(--gap) var(--info-gray);
+    transition: all 0.5s;
+  }
+
+  .left-switch {
+    right: 0;
+    top: 0;
+    transform: translate(50%, 65%);
+  }
+
+  .left-main {
+    padding: 0 var(--gap-2);
+  }
+
+  .right {
+    right: -250px;
+    top: 0;
+    height: 100%;
+    width: 250px;
+    box-sizing: border-box;
+    background: white;
+    //box-shadow: -1px 0 var(--gap) var(--info-gray);
+    transition: all 0.5s;
+  }
+
+  .right-switch {
+    left: 0;
+    top: 0;
+    transform: translate(-50%, 65%);
+  }
+
+  .right-main {
+    padding: 0 var(--gap-2);
+  }
+
+  .el-descriptions {
+    padding: 0 var(--gap-2);
+  }
+}
+</style>