Skip to content

Commit

Permalink
add wandering earth demo
Browse files Browse the repository at this point in the history
  • Loading branch information
qishipengqsp authored and tugraph committed Jun 6, 2023
1 parent ed1e31a commit d035308
Show file tree
Hide file tree
Showing 21 changed files with 512 additions and 0 deletions.
5 changes: 5 additions & 0 deletions wandering_earth/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
log
lgraph.pid
lgraph_db
.import_tmp
tmp
50 changes: 50 additions & 0 deletions wandering_earth/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# 关于

这是一个tugraph的Demo,背景是流浪地球的故事宇宙

**关键词**:tugraph demo、流浪地球

## Demo场景设计

Demo背景基于流浪地球1、流浪地球2的故事背景进行设计
- 基于剧情,设计了图结构,包含组织、角色、天体与设施3类点,事件、关系两类边
- 根据剧情准备了对应Schema的数据
- 准备了一些query,提出一些关于剧情的问题

## 目录结构

- rawdata: 原始剧情数据和schema定义文件
- case.cypher: 查询相关的Cypher语句
- control.sh: 控制TuGraph Server启动停止的脚本
- lgraph_standalone.json: TuGraph Server启动的配置文件

## 使用说明

前置条件:TuGraph已安装

### 数据导入

- 根据数据存放目录对应修改import.json里面的DATA_PATH
- 参考control.sh中的load函数,加载数据
- 参考control.sh中的start函数,启动TuGraph服务
- 启动TuGraph服务后,访问${HOST_IP}:7071,打开web页面,确认数据是否导入成功

### Cypher查询

参考TuGraph文档,在TuGraph的Web页面前端输入Cypher进行查询

## 使用展示

### 数据导入的展示

![data](./images/data.png)

### 查询展示

#### 查询木星危机的所有事件经过

![data](./images/cypher1.png)

#### 查询木星危机的所有事件经过

![data](./images/cypher2.png)
16 changes: 16 additions & 0 deletions wandering_earth/case.cypher
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// 人物关系回顾
MATCH (n)-[e:关系]-(m) RETURN e

// 太空电梯危机
MATCH (n)-[e]-(m) where e.title="太空电梯危机" RETURN e

// 月球危机
MATCH (n)-[e]-(m) where e.title="月球危机" RETURN e

// 木星危机
MATCH (n)-[e]-(m) where e.title="木星危机" RETURN e

// 至少涉及到2次危机
MATCH (n)-[e1]-(m)-[e2]-(p)
where e1.title REGEXP ".*危机" and e2.title REGEXP ".*危机" and e1.title <> e2.title
RETURN e1, e2
40 changes: 40 additions & 0 deletions wandering_earth/control.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# /bin/bash

set -x

TUGRAPH_PATH=${HOME}/project/tugraph-db/build/output
TUGRAPH_WEB=${TUGRAPH_PATH}/resource

function start {
${TUGRAPH_PATH}/lgraph_server -c ./lgraph_standalone.json --web ${TUGRAPH_WEB} -d start
}

function stop {
${TUGRAPH_PATH}/lgraph_server -c ./lgraph_standalone.json -d stop
}

function load {
${TUGRAPH_PATH}/lgraph_import -c ./rawdata/import.json -d lgraph_db --overwrite true --graph default --verbose 2
}

function remove {
rm -rf lgraph_db .import_tmp
}

function restart {
stop
start
}

function reload {
remove
load
}

function reboot {
stop
reload && sleep 2 && start
}

# load or reload
$1
Binary file added wandering_earth/images/cypher1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added wandering_earth/images/cypher2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added wandering_earth/images/data.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions wandering_earth/lgraph_standalone.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"host": "0.0.0.0",
"port": 7071,
"enable_rpc": true,
"rpc_port": 9091,
"verbose": 2,
"log_dir": "./log/",
"ssl_auth": false,
"server_key": "./server-key.pem",
"server_cert": "./server-cert.pem"
}
250 changes: 250 additions & 0 deletions wandering_earth/rawdata/import.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,250 @@
{
"files": [
{
"columns": [
"birthYear",
"name",
"description"
],
"format": "CSV",
"label": "角色",
"path": "./rawdata/角色.csv"
},
{
"columns": [
"name",
"description"
],
"format": "CSV",
"label": "组织",
"path": "./rawdata/组织.csv"
},
{
"columns": [
"name",
"description"
],
"format": "CSV",
"label": "天体与设施",
"path": "./rawdata/天体与设施.csv"
},
{
"DST_ID": "角色",
"SRC_ID": "角色",
"columns": [
"SRC_ID",
"DST_ID",
"name"
],
"format": "CSV",
"label": "关系",
"path": "./rawdata/关系_角色_角色.csv"
},
{
"DST_ID": "组织",
"SRC_ID": "角色",
"columns": [
"SRC_ID",
"DST_ID",
"name"
],
"format": "CSV",
"label": "关系",
"path": "./rawdata/关系_角色_组织.csv"
},
{
"DST_ID": "天体与设施",
"SRC_ID": "角色",
"columns": [
"SRC_ID",
"DST_ID",
"name"
],
"format": "CSV",
"label": "关系",
"path": "./rawdata/关系_角色_天体与设施.csv"
},
{
"DST_ID": "角色",
"SRC_ID": "角色",
"columns": [
"SRC_ID",
"DST_ID",
"no",
"name",
"title",
"year"
],
"format": "CSV",
"label": "事件关系",
"path": "./rawdata/事件_角色_角色.csv"
},
{
"DST_ID": "组织",
"SRC_ID": "角色",
"columns": [
"SRC_ID",
"DST_ID",
"no",
"name",
"title",
"year"
],
"format": "CSV",
"label": "事件关系",
"path": "./rawdata/事件_角色_组织.csv"
},
{
"DST_ID": "天体与设施",
"SRC_ID": "角色",
"columns": [
"SRC_ID",
"DST_ID",
"no",
"name",
"title",
"year"
],
"format": "CSV",
"label": "事件关系",
"path": "./rawdata/事件_角色_天体与设施.csv"
},
{
"DST_ID": "角色",
"SRC_ID": "组织",
"columns": [
"SRC_ID",
"DST_ID",
"no",
"name",
"title",
"year"
],
"format": "CSV",
"label": "事件关系",
"path": "./rawdata/事件_组织_角色.csv"
},
{
"DST_ID": "天体与设施",
"SRC_ID": "组织",
"columns": [
"SRC_ID",
"DST_ID",
"no",
"name",
"title",
"year"
],
"format": "CSV",
"label": "事件关系",
"path": "./rawdata/事件_组织_天体与设施.csv"
},
{
"DST_ID": "天体与设施",
"SRC_ID": "天体与设施",
"columns": [
"SRC_ID",
"DST_ID",
"no",
"name",
"title",
"year"
],
"format": "CSV",
"label": "事件关系",
"path": "./rawdata/事件_天体与设施_天体与设施.csv"
}
],
"schema": [
{
"label": "天体与设施",
"primary": "name",
"properties": [
{
"name": "name",
"type": "STRING"
},
{
"name": "description",
"type": "STRING",
"optional": true
}
],
"type": "VERTEX"
},
{
"label": "组织",
"primary": "name",
"properties": [
{
"name": "name",
"type": "STRING"
},
{
"name": "description",
"type": "STRING",
"optional": true
}
],
"type": "VERTEX"
},
{
"label": "角色",
"primary": "name",
"properties": [
{
"name": "birthYear",
"optional": true,
"type": "INT32"
},
{
"name": "name",
"type": "STRING"
},
{
"name": "description",
"optional": true,
"type": "STRING"
}
],
"type": "VERTEX"
},
{
"label": "关系",
"properties": [
{
"name": "name",
"optional": true,
"type": "STRING"
}
],
"type": "EDGE"
},
{
"label": "事件关系",
"properties": [
{
"name": "title",
"optional": true,
"type": "STRING"
},
{
"name": "year",
"optional": true,
"type": "INT32"
},
{
"name": "no",
"optional": false,
"type": "INT32"
},
{
"name": "name",
"optional": true,
"type": "STRING"
}
],
"type": "EDGE"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"方舟空间站","地球",6,"6 方舟空间站坠毁至地面","太空电梯危机",2044

"月球","地球",4,"4 月球即将坠向地球","月球危机",2058

"地球","木星",5,"5 距离过近导致地震,木星危机开始","木星危机",2075
"国际空间站","木星",20,"20 爆炸后点燃了混合了地球空气的木星","木星危机",2075
"木星","地球",21,"21 燃烧后的冲击波推开地球,木星危机解除,地球继续流浪","木星危机",2075
7 changes: 7 additions & 0 deletions wandering_earth/rawdata/事件_组织_天体与设施.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"联合政府","月球",5,"5 决定用相控阵核弹炸毁月球","月球危机",2058
"联合政府","地球",6,"6 决定重启互联网提前流浪地球","月球危机",2058
"联合政府","地球",15,"15 成功点火推理地球开始流浪","月球危机",2058

"救援小队","杭州行星发动机",8,"8 护送火石前往,遭遇二次地震","木星危机",2075
"救援小队","杭州行星发动机",9,"9 运输车在地震中损毁,弃车步行前往,路上韩子昂牺牲","木星危机",2075
"救援小队","苏拉威西行星发动机",10,"10 在杭州任务失败后,运送火石前往苏拉威西","木星危机",2075
Loading

0 comments on commit d035308

Please sign in to comment.