lsc 1 päivä sitten
vanhempi
commit
f79cff1ab8
3 muutettua tiedostoa jossa 129 lisäystä ja 2 poistoa
  1. 1 1
      package-lock.json
  2. 122 0
      pbl.js
  3. 6 1
      yarn.lock

+ 1 - 1
package-lock.json

@@ -6852,7 +6852,7 @@
         "playwright": "^1.53.0",
         "prettier": "^3.3.3",
         "querystring": "^0.2.1",
-        "r2r-js": "^0.4.34",
+        "r2r-js": "^0.4.43",
         "r2r-webdev-template": "file:",
         "react": "^18",
         "react-dom": "^18",

+ 122 - 0
pbl.js

@@ -186,6 +186,23 @@ router.route("/getFile").all(async (req, res, next) => {
     }
 });
 
+//获取文档列表
+router.route("/getFileR2r").all(async (req, res, next) => {
+    //mode的处理
+    if (req.body[0]) {
+        let fileid = decodeURIComponent(req.body[0].fileids).split(",");
+        try {
+            const response = await client.documents.list({ ids: fileid });
+
+
+            res.status(200).json({ result: response.results });
+        } catch (error) {
+            res.status(500).json({ error: error instanceof Error ? error.message : "An error occurred" });
+        }
+    }
+});
+
+
 //获取文档列表
 router.route("/getFileD").all(async (req, res, next) => {
     //mode的处理
@@ -762,6 +779,111 @@ router.route("/getRelationships").all(async (req, res, next) => {
     }
 });
 
+//提取整个文件夹的关系
+router.route("/resetGraphs").all(async (req, res, next) => {
+    if (req.body[0]) {
+        try {
+            // const response = await client.graphs.pull({
+            //     collectionId: req.body[0].collectionId,
+            // });
+            const response = await client.graphs.reset({
+                collectionId: req.body[0].collectionId,
+            });
+            
+            res.status(200).json({ result: response });
+
+        } catch (error) {
+            res.status(500).json({ error: error instanceof Error ? error.message : "An error occurred" });
+        }
+
+    }
+});
+
+//获取整个文件夹的关系
+router.route("/getRelationshipsGraphs").all(async (req, res, next) => {
+    if (req.body[0]) {
+        try {
+            await client.graphs.pull({
+                collectionId: req.body[0].collectionId,
+            });
+            const response = await client.graphs.listRelationships({
+                collectionId: req.body[0].collectionId,
+                offset: req.body[0].page ? req.body[0].page : 0,
+                limit: 1000
+            });
+            res.status(200).json({ result: response });
+
+        } catch (error) {
+            res.status(500).json({ error: error instanceof Error ? error.message : "An error occurred" });
+        }
+
+    }
+});
+
+
+//提取知识图谱
+router.route("/getGraphs").all(async (req, res, next) => {
+    console.log(req.body);
+    
+    //mode的处理
+    if (req.body[0]) {
+        try {
+            //创建临时文件夹
+            const folder = await client.collections.create({
+                name: "临时文件夹",
+                description: "临时文件夹"
+            });
+            let folderid = folder.results.id
+            console.log(folder.results.id);
+            
+            //将要提取的文件添加到临时文件夹
+            let documentids = decodeURIComponent(req.body[0].fileids).split(",");
+            // 使用 Promise.all 确保所有添加操作都被执行
+            await Promise.all(documentids.map(documentid =>
+                client.collections.addDocument({
+                    id: folderid,
+                    documentId: documentid
+                }).catch(error => {
+                    console.error("移动文件时发生错误:", error);
+                })
+            ));
+
+            //将临时文件夹提取知识图谱
+            await client.graphs.pull({
+                collectionId: folderid
+            });
+            let offset = 0;
+            let results = [];
+            let totalEntries = 0;
+            do {
+                const response = await client.graphs.listRelationships({
+                    collectionId: folderid,
+                    offset: offset,
+                    limit: 1000
+                });
+                results = results.concat(response.results);
+                totalEntries = response.totalEntries;
+                offset += 1000;
+            } while (offset < totalEntries);
+
+            //移除临时文件夹的文件
+            const files = await client.collections.listDocuments({ id: folderid, offset: 0, limit: 999 });
+            await Promise.all(files.results.map(file =>
+                client.collections.removeDocument({ id: folderid, documentId: file.id })
+            ));
+
+            //删除临时文件夹
+            await client.collections.delete({ id: folderid });
+
+            res.status(200).json({ result: results });
+
+        } catch (error) {
+            res.status(500).json({ error: error instanceof Error ? error.message : "An error occurred" });
+        }
+
+    }
+});
+
 //获取实体和关系
 router.route("/getEntitiesAndRelationships").all(async (req, res, next) => {
     if (req.body[0]) {

+ 6 - 1
yarn.lock

@@ -1233,6 +1233,11 @@
   "resolved" "https://registry.npmmirror.com/fs.realpath/-/fs.realpath-1.0.0.tgz"
   "version" "1.0.0"
 
+"fsevents@^2.3.2", "fsevents@~2.3.2", "fsevents@2.3.2":
+  "integrity" "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA=="
+  "resolved" "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz"
+  "version" "2.3.2"
+
 "function-bind@^1.1.2":
   "integrity" "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA=="
   "resolved" "https://registry.npmmirror.com/function-bind/-/function-bind-1.1.2.tgz"
@@ -2179,7 +2184,7 @@
     "pg" "^8.13.1"
     "playwright" "^1.53.0"
     "querystring" "^0.2.1"
-    "r2r-js" "^0.4.34"
+    "r2r-js" "^0.4.43"
     "r2r-webdev-template" "file:"
     "react" "^18"
     "react-dom" "^18"