Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
data/neo4j.dump
38 changes: 31 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,37 @@
➜ 3022202376 tree
# 知识图谱管理系统

.
## 环境要求
jdk 11
nodejs 22.19.0
angular_cli 20.3.2
neo4j 4.4
express 4.18.2
AntV_G6 4.3.3

├── code code of project
## 安装依赖
在 ./code/backend 目录运行

├── data data set
npm install
npm install express@4.18.2
npm install --save @antv/g6@4.3.3

├── member_info.txt information of group members
## 加载数据
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indicate the version of neo4j which is 4.4.41

1. 确保neo4j处于停机状态
2. 在neo4j/bin目录下运行如下命令

├── report.mp4 report videm
neo4j-admin load --from="<dumo文件路径>" --database=neo4j --force

└── report.ppt report slides
## 启动服务
1. 在neo4j的/bin目录运行

neo4j.bat console

2. 在./code/backend目录运行

npm run dev

3. 在./code/frontend目录运行

python -m http.server 8000

4. 从8000端口访问管理界面
28 changes: 0 additions & 28 deletions code/backend/README.md

This file was deleted.

23 changes: 13 additions & 10 deletions code/backend/routes/edges.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// routes/edges.js
const express = require('express');
const router = express.Router();
const edgeService = require('../services/edge.service');
Expand All @@ -11,22 +10,22 @@ const edgeService = require('../services/edge.service');
router.get('/', async (req, res) => {
try {
const {
limit = 100,
limit = 10000,
skip = 0,
type
} = req.query;

console.log(`边路由接收参数: limit=${limit}, skip=${skip}, type=${type}`);

let edges;

if (type) {
// 如果提供了类型参数,按类型过滤
edges = await edgeService.getEdgesByType(
type,
parseInt(limit),
parseInt(skip)
);
} else {
// 否则获取所有关系
edges = await edgeService.getAllEdges(
parseInt(limit),
parseInt(skip)
Expand All @@ -36,7 +35,12 @@ router.get('/', async (req, res) => {
res.json({
success: true,
count: edges.length,
data: edges
data: edges,
meta: {
limit: parseInt(limit),
skip: parseInt(skip),
total: edges.length
}
});
} catch (error) {
console.error('获取关系列表失败:', error);
Expand Down Expand Up @@ -88,7 +92,6 @@ router.post('/', async (req, res) => {
try {
const { startNodeId, endNodeId, type, properties } = req.body;

// 验证必要参数
if (!startNodeId || !endNodeId || !type) {
return res.status(400).json({
success: false,
Expand Down Expand Up @@ -128,7 +131,6 @@ router.put('/:id', async (req, res) => {
const { id } = req.params;
const { properties } = req.body;

// 验证必要参数
if (!properties) {
return res.status(400).json({
success: false,
Expand Down Expand Up @@ -169,6 +171,8 @@ router.put('/:id', async (req, res) => {
router.delete('/:id', async (req, res) => {
try {
const { id } = req.params;
console.log(`删除关系路由: ID=${id}, 类型=${typeof id}`);

const deleted = await edgeService.deleteEdge(id);

if (!deleted) {
Expand Down Expand Up @@ -200,7 +204,7 @@ router.delete('/:id', async (req, res) => {
router.get('/type/:type', async (req, res) => {
try {
const { type } = req.params;
const { limit = 100, skip = 0 } = req.query;
const { limit = 10000, skip = 0 } = req.query;

const edges = await edgeService.getEdgesByType(
type,
Expand Down Expand Up @@ -233,11 +237,10 @@ router.get('/node/:nodeId', async (req, res) => {
const { nodeId } = req.params;
const {
direction = 'both',
limit = 100,
limit = 10000,
skip = 0
} = req.query;

// 验证方向参数
const validDirections = ['incoming', 'outgoing', 'both'];
if (!validDirections.includes(direction)) {
return res.status(400).json({
Expand Down
10 changes: 0 additions & 10 deletions code/backend/routes/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
const express = require('express');
const router = express.Router();

// 引入各个子路由模块
const nodesRouter = require('./nodes');
const edgesRouter = require('./edges');

// 根路径欢迎信息
router.get('/', (req, res) => {
res.json({
success: true,
Expand All @@ -20,7 +18,6 @@ router.get('/', (req, res) => {
});
});

// 健康检查端点
router.get('/health', (req, res) => {
res.json({
success: true,
Expand All @@ -30,7 +27,6 @@ router.get('/health', (req, res) => {
});
});

// API信息端点
router.get('/api', (req, res) => {
res.json({
success: true,
Expand Down Expand Up @@ -59,14 +55,10 @@ router.get('/api', (req, res) => {
});
});

// 使用节点路由
router.use('/nodes', nodesRouter);

// 使用边路由
router.use('/edges', edgesRouter);

// 404处理 - 使用更兼容的方式处理不存在的API端点
// 为所有可能的路径定义处理程序,而不是使用通配符
router.get('*', (req, res) => {
handle404(req, res);
});
Expand All @@ -83,7 +75,6 @@ router.delete('*', (req, res) => {
handle404(req, res);
});

// 404处理函数
function handle404(req, res) {
res.status(404).json({
success: false,
Expand All @@ -98,7 +89,6 @@ function handle404(req, res) {
});
}

// 错误处理中间件
router.use((err, req, res, next) => {
console.error('服务器错误:', err);
res.status(500).json({
Expand Down
22 changes: 14 additions & 8 deletions code/backend/routes/nodes.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// routes/nodes.js
const express = require('express');
const router = express.Router();
const nodeService = require('../services/node.service');
Expand All @@ -11,11 +10,14 @@ const nodeService = require('../services/node.service');
router.get('/', async (req, res) => {
try {
const {
limit = 100,
limit = 10000, // 修改默认值为10000
skip = 0,
label
} = req.query;

// 添加调试日志
console.log(`节点路由接收参数: limit=${limit}, skip=${skip}, label=${label}`);

let nodes;

if (label) {
Expand All @@ -36,7 +38,12 @@ router.get('/', async (req, res) => {
res.json({
success: true,
count: nodes.length,
data: nodes
data: nodes,
meta: {
limit: parseInt(limit),
skip: parseInt(skip),
total: nodes.length
}
});
} catch (error) {
console.error('获取节点列表失败:', error);
Expand Down Expand Up @@ -123,7 +130,6 @@ router.put('/:id', async (req, res) => {
const { id } = req.params;
const { properties } = req.body;

// 验证必要参数
if (!properties) {
return res.status(400).json({
success: false,
Expand All @@ -135,8 +141,8 @@ router.put('/:id', async (req, res) => {

res.json({
success: true,
message: '节点更新成功',
data: node
message: '节点删除成功',
deletedCount: 1 // 明确返回删除的数量
});
} catch (error) {
console.error('更新节点失败:', error);
Expand Down Expand Up @@ -195,7 +201,7 @@ router.delete('/:id', async (req, res) => {
router.get('/search/:key/:value', async (req, res) => {
try {
const { key, value } = req.params;
const { limit = 100, skip = 0 } = req.query;
const { limit = 10000, skip = 0 } = req.query;

const nodes = await nodeService.searchNodes(
key,
Expand Down Expand Up @@ -227,7 +233,7 @@ router.get('/search/:key/:value', async (req, res) => {
router.get('/label/:label', async (req, res) => {
try {
const { label } = req.params;
const { limit = 100, skip = 0 } = req.query;
const { limit = 10000, skip = 0 } = req.query;

const nodes = await nodeService.getNodesByLabel(
label,
Expand Down
8 changes: 3 additions & 5 deletions code/backend/server.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require('dotenv').config(); // 加载.env环境变量
require('dotenv').config();
const express = require('express');
const cors = require('cors');
const routes = require('./routes'); // 导入所有路由
const routes = require('./routes');

const app = express();
const PORT = process.env.PORT || 3000;
Expand All @@ -28,8 +28,7 @@ app.use(cors({
}));
app.use(express.json()); // 解析JSON请求体

// 路由
app.use('/api', routes); // 所有API路由都以/api开头
app.use('/api', routes);

// 全局错误处理中间件
app.use((err, req, res, next) => {
Expand All @@ -41,7 +40,6 @@ app.use((err, req, res, next) => {
});
});

// 启动服务器
app.listen(PORT, () => {
console.log(`后端服务器已启动在 http://localhost:${PORT}`);
});
Loading