当前位置: 首页 > article >正文

Neo4j入门案例:三星堆

创建一个关于三星堆的知识图谱可以是一个非常有趣的项目,它可以帮助理解如何使用Neo4j来存储和查询复杂的关系数据。三星堆文化以其独特的青铜器、金器和其他文物而闻名,这为我们提供了一个丰富的历史背景来构建知识图谱。

数据模型定义

实体类型(节点)
  1. 遗址 (Site)
  2. 文物 (Artifact)
  3. 考古学家 (Archaeologist)
  4. 文化 (Culture)
  5. 时期 (Period)
  6. 材料 (Material)
关系类型
  1. 发现于 (DiscoveredAt)
  2. 属于 (BelongsTo)
  3. 研究者 (ResearchedBy)
  4. 存在于 (ExistsIn)
  5. 制成于 (MadeOf)

数据准备

假设我们有如下数据:

  • 遗址: “三星堆遗址”
  • 文物: “青铜大立人”,“黄金面具”,“玉琮”,“象牙”,“铜神树”
  • 考古学家: “李某某”,“张某某”
  • 文化: “三星堆文化”
  • 时期: “新石器时代晚期至商周时期”
  • 材料: “青铜”,“黄金”,“玉石”,“象牙”

创建知识图谱

创建节点
CREATE (s:Site {name: "三星堆遗址"})
CREATE (c:Culture {name: "三星堆文化"})
CREATE (p:Period {name: "新石器时代晚期至商周时期"})
CREATE (a1:Artifact {name: "青铜大立人", description: "三星堆出土的重要文物之一"})
CREATE (a2:Artifact {name: "黄金面具", description: "三星堆出土的精美黄金制品"})
CREATE (a3:Artifact {name: "玉琮", description: "三星堆出土的玉质文物"})
CREATE (a4:Artifact {name: "象牙", description: "三星堆出土的象牙制品"})
CREATE (a5:Artifact {name: "铜神树", description: "三星堆出土的青铜树形器"})
CREATE (m1:Material {name: "青铜"})
CREATE (m2:Material {name: "黄金"})
CREATE (m3:Material {name: "玉石"})
CREATE (m4:Material {name: "象牙"})
CREATE (r1:Archaeologist {name: "李某某", institution: "四川大学考古学院"})
CREATE (r2:Archaeologist {name: "张某某", institution: "北京大学考古文博学院"})
创建关系
MATCH (a1:Artifact), (s:Site)
WHERE a1.name = "青铜大立人" AND s.name = "三星堆遗址"
CREATE (a1)-[:DiscoveredAt]->(s)

MATCH (a1:Artifact), (c:Culture)
WHERE a1.name = "青铜大立人" AND c.name = "三星堆文化"
CREATE (a1)-[:BelongsTo]->(c)

MATCH (a1:Artifact), (p:Period)
WHERE a1.name = "青铜大立人" AND p.name = "新石器时代晚期至商周时期"
CREATE (a1)-[:ExistsIn]->(p)

MATCH (a1:Artifact), (m1:Material)
WHERE a1.name = "青铜大立人" AND m1.name = "青铜"
CREATE (a1)-[:MadeOf]->(m1)

MATCH (a2:Artifact), (s:Site)
WHERE a2.name = "黄金面具" AND s.name = "三星堆遗址"
CREATE (a2)-[:DiscoveredAt]->(s)

MATCH (a2:Artifact), (c:Culture)
WHERE a2.name = "黄金面具" AND c.name = "三星堆文化"
CREATE (a2)-[:BelongsTo]->(c)

MATCH (a2:Artifact), (p:Period)
WHERE a2.name = "黄金面具" AND p.name = "新石器时代晚期至商周时期"
CREATE (a2)-[:ExistsIn]->(p)

MATCH (a2:Artifact), (m2:Material)
WHERE a2.name = "黄金面具" AND m2.name = "黄金"
CREATE (a2)-[:MadeOf]->(m2)

MATCH (a3:Artifact), (s:Site)
WHERE a3.name = "玉琮" AND s.name = "三星堆遗址"
CREATE (a3)-[:DiscoveredAt]->(s)

MATCH (a3:Artifact), (c:Culture)
WHERE a3.name = "玉琮" AND c.name = "三星堆文化"
CREATE (a3)-[:BelongsTo]->(c)

MATCH (a3:Artifact), (p:Period)
WHERE a3.name = "玉琮" AND p.name = "新石器时代晚期至商周时期"
CREATE (a3)-[:ExistsIn]->(p)

MATCH (a3:Artifact), (m3:Material)
WHERE a3.name = "玉琮" AND m3.name = "玉石"
CREATE (a3)-[:MadeOf]->(m3)

MATCH (a4:Artifact), (s:Site)
WHERE a4.name = "象牙" AND s.name = "三星堆遗址"
CREATE (a4)-[:DiscoveredAt]->(s)

MATCH (a4:Artifact), (c:Culture)
WHERE a4.name = "象牙" AND c.name = "三星堆文化"
CREATE (a4)-[:BelongsTo]->(c)

MATCH (a4:Artifact), (p:Period)
WHERE a4.name = "象牙" AND p.name = "新石器时代晚期至商周时期"
CREATE (a4)-[:ExistsIn]->(p)

MATCH (a4:Artifact), (m4:Material)
WHERE a4.name = "象牙" AND m4.name = "象牙"
CREATE (a4)-[:MadeOf]->(m4)

MATCH (a5:Artifact), (s:Site)
WHERE a5.name = "铜神树" AND s.name = "三星堆遗址"
CREATE (a5)-[:DiscoveredAt]->(s)

MATCH (a5:Artifact), (c:Culture)
WHERE a5.name = "铜神树" AND c.name = "三星堆文化"
CREATE (a5)-[:BelongsTo]->(c)

MATCH (a5:Artifact), (p:Period)
WHERE a5.name = "铜神树" AND p.name = "新石器时代晚期至商周时期"
CREATE (a5)-[:ExistsIn]->(p)

MATCH (a5:Artifact), (m1:Material)
WHERE a5.name = "铜神树" AND m1.name = "青铜"
CREATE (a5)-[:MadeOf]->(m1)

MATCH (r1:Archaeologist), (a1:Artifact)
WHERE r1.name = "李某某" AND a1.name = "青铜大立人"
CREATE (a1)-[:ResearchedBy]->(r1)

MATCH (r1:Archaeologist), (a2:Artifact)
WHERE r1.name = "李某某" AND a2.name = "黄金面具"
CREATE (a2)-[:ResearchedBy]->(r1)

MATCH (r2:Archaeologist), (a3:Artifact)
WHERE r2.name = "张某某" AND a3.name = "玉琮"
CREATE (a3)-[:ResearchedBy]->(r2)

MATCH (r2:Archaeologist), (a4:Artifact)
WHERE r2.name = "张某某" AND a4.name = "象牙"
CREATE (a4)-[:ResearchedBy]->(r2)

MATCH (r2:Archaeologist), (a5:Artifact)
WHERE r2.name = "张某某" AND a5.name = "铜神树"
CREATE (a5)-[:ResearchedBy]->(r2)

查询及推理

查询示例
  •  查找所有在三星堆遗址发现的文物
1MATCH (a:Artifact)-[r:DiscoveredAt]->(s:Site) WHERE s.name = "三星堆遗址"
2RETURN a.name
  • 找出某个考古学家研究的所有文物
  • 1MATCH (a:Artifact)-[r:ResearchedBy]->(r1:Archaeologist) WHERE r1.name = "李某某"
    2RETURN a.name
  • 分析特定时期内出现的文物类型及其材料分布情况
1MATCH (a:Artifact)-[r1:ExistsIn]->(p:Period) WHERE p.name = "新石器时代晚期至商周时期"
2OPTIONAL MATCH (a)-[r2:MadeOf]->(m:Material)
3RETURN a.name, collect(m.name) AS Materials

这些查询可以帮助理解如何从知识图谱中提取有用的信息,并进行进一步的研究。


http://www.kler.cn/a/306987.html

相关文章:

  • JavaScript——函数、事件与BOM对象
  • C++数据结构算法学习
  • PCL 点云分割 基于CPC算法的分割
  • 【在Linux世界中追寻伟大的One Piece】多路转接epoll
  • css:没错又是我
  • Python数据分析NumPy和pandas(二十九、其他Python可视化工具)
  • 基于Springboot的校园防疫管理系统的设计与实现
  • 【爬虫软件】小红书按关键词批量采集笔记,含笔记正文、转评赞藏等!
  • Linux whereis和which的区别
  • 光伏板热斑缺陷检测数据集
  • RocketMQ出现The broker does not support consumer to filter message by SQL92
  • JUC学习笔记(三)
  • 计算机网络(六) —— http协议详解
  • 黑马十天精通MySQL知识点
  • 【佳学基因检测】在EXCEL中,如何获取A列的第9-29个字符,将其填入另一列中
  • 华为ensp中vlan与静态路由技术的实现
  • 『功能项目』伤害数字UI显示【53】
  • 基于SpringBoot+Vue+MySQL的校园健康驿站管理系统
  • Baumer工业相机堡盟工业相机如何通过NEOAPI SDK获取相机当前数据吞吐量(Python)
  • Java | Leetcode Java题解之第406题根据身高重建队列
  • ARACom Proxy Class API 概念
  • 鸿蒙介绍、鸿蒙编程环境、基本组件、页面跳转学习
  • CPU 和 GPU:为什么GPU更适合深度学习?
  • PostgreSQL 日常SQL语句查询记录
  • linux网络编程——UDP编程
  • 预测日前电价:回顾最先进的算法、最佳实践和公开基准——阅读笔记