第二周作业:
利用Neo4j构建知识图谱内容,熟悉Cypher查询语言。
思路:以岗位为中心,按照 岗位->知识->岗位方向 的流程来构建节点和关系。
注意:中途会涉及到同一个节点,由于create语句会重复创建属性相同的节点,而merge语句会检测是否重复。因此在创建节点的时候选取的是merge语句,而不是create语句。
先构建 "自动化办公" 线路相关的节点以及关系。
创建相关节点。
merge (:Job{name:"AutoOffice"})
merge (:Knowledge{name:"PythonBasic"})
merge (:Knowledge{name:"FileDispose"})
再创建节点的关系,
自动化办公->Python基础->文件处理。
match (a:Job{name:"AutoOffice"}),(p:Knowledge{name:"PythonBasic"}) create (a)-[:AutoOfficePath]->(p) return a,p
match (p:Knowledge{name:"PythonBasic"}),(f:Knowledge{name:"FileDispose"}) create (p)-[:AutoOfficePath]->(f) return p,f
看一看效果图。
MATCH p=()-[r:AutoOfficePath]->() RETURN p LIMIT 25
接着创建 "Web开发" 线路相关的节点以及关系。
创建相关节点。
merge (:Job{name:"WebDev"})
merge (:Knowledge{name:"PythonBasic"})
merge (:Knowledge{name:"Linux"})
merge (:Knowledge{name:"FileDispose"})
merge (:Knowledge{name:"Flask"})
merge (:Knowledge{name:"Django"})
merge (:Knowledge{name:"MySQL"})
创建节点的关系,Web开发->Linux。
match (w:Job{name:"WebDev"}),(l:Knowledge{name:"Linux"}) create (w)-[:WebDevPath]->(l) return w,l
创建节点关系,
Web开发->Python基础->文件处理->Flask->MySQL ,
Web开发->Python基础->文件处理->Django->MySQL 。
match (w:Job{name:"WebDev"}),(p:Knowledge{name:"PythonBasic"}) create (w)-[:WebDevPath]->(p) return w,p
match (p:Knowledge{name:"PythonBasic"}),(f:Knowledge{name:"FileDispose"}) create (p)-[:WebDevPath]->(f) return p,f
match (f:Knowledge{name:"FileDispose"}),(flask:Knowledge{name:"Flask"}) create (f)-[:WebDevPath]->(flask) return f,flask
match (f:Knowledge{name:"FileDispose"}),(d:Knowledge{name:"Django"}) create (f)-[:WebDevPath]->(d) return f,d
match (f:Knowledge{name:"Flask"}),(m:Knowledge{name:"MySQL"}) create (f)-[:WebDevPath]->(m) return f,m
match (d:Knowledge{name:"Django"}),(m:Knowledge{name:"MySQL"}) create (d)-[:WebDevPath]->(m) return d,m
看一看效果图。
MATCH p=()-[r:WebDevPath]->() RETURN p LIMIT 25
接着创建 "爬虫" 路线相关节点和关系。
创建相关节点。
merge (:Job{name:"SpiderWork"})
merge (:Knowledge{name:"Linux"})
merge (:Knowledge{name:"CSS"})
merge (:Knowledge{name:"HTML"})
merge (:Knowledge{name:"Xpath"})
merge (:Knowledge{name:"NetWork"})
merge (:Knowledge{name:"PythonBasic"})
merge (:Knowledge{name:"Requests"})
merge (:Knowledge{name:"bs4"})
merge (:Knowledge{name:"Scrapy"})
merge (:Knowledge{name:"MySQL"})
merge (:Knowledge{name:"MongoDB"})
创建节点关系,
爬虫->网络 ,
match (s:Job{name:"SpiderWork"}),(n:Knowledge{name:"NetWork"}) create (s)-[:SpiderWorkPath]->(n) return s,n
爬虫->HTML->Xpath ,
爬虫->HTML->CSS ,
match (s:Job{name:"SpiderWork"}),(h:Knowledge{name:"HTML"}) create (s)-[:SpiderWorkPath]->(h) return s,h
match (h:Knowledge{name:"HTML"}),(x:Knowledge{name:"Xpath"}) create (h)-[:SpiderWorkPath]->(x) return h,x
match (h:Knowledge{name:"HTML"}),(c:Knowledge{name:"CSS"}) create (h)-[:SpiderWorkPath]->(c) return h,c
爬虫->Linux ,
match (s:Job{name:"SpiderWork"}),(l:Knowledge{name:"Linux"}) create (s)-[:SpiderWorkPath]->(l) return s,l
爬虫->Python基础->Requests->bs4->Scrapy->MySQL ,
爬虫->Python基础->Requests->bs4->Scrapy->MongoDB 。
match (s:Job{name:"SpiderWork"}),(p:Knowledge{name:"PythonBasic"}) create (s)-[:SpiderWorkPath]->(p) return s,p
match (p:Knowledge{name:"PythonBasic"}),(r:Knowledge{name:"Requests"}) create (p)-[:SpiderWorkPath]->(r) return p,r
match (r:Knowledge{name:"Requests"}),(b:Knowledge{name:"bs4"}) create (r)-[:SpiderWorkPath]->(b) return r,b
match (b:Knowledge{name:"bs4"}),(s:Knowledge{name:"Scrapy"}) create (b)-[:SpiderWorkPath]->(s) return b,s
match (s:Knowledge{name:"Scrapy"}),(m:Knowledge{name:"MySQL"}) create (s)-[:SpiderWorkPath]->(m) return s,m
match (s:Knowledge{name:"Scrapy"}),(m:Knowledge{name:"MongoDB"}) create (s)-[:SpiderWorkPath]->(m) return s,m
看一看效果图。
MATCH p=()-[r:SpiderWorkPath]->() RETURN p LIMIT 25
创建 ''数据分析" 线路相关的节点和关系。
创建相关节点。
merge (:Job{name:"DataAnalyse"})
merge (:Knowledge{name:"Linux"})
merge (:Knowledge{name:"WindowsOffice"})
merge (:Knowledge{name:"Professional"})
merge (:Knowledge{name:"Statistics"})
merge (:Knowledge{name:"PythonBasic"})
merge (:Knowledge{name:"Hive"})
merge (:Knowledge{name:"HBase"})
merge (:Knowledge{name:"MongoDB"})
merge (:Knowledge{name:"MySQL"})
创建节点关系,
数据分析->统计,
match (d:Job{name:"DataAnalyse"}),(s:Knowledge{name:"Statistics"}) create (d)-[:DataAnalysePath]->(s) return d,s
数据分析->Windows办公软件,
match (d:Job{name:"DataAnalyse"}),(w:Knowledge{name:"WindowsOffice"}) create (d)-[:DataAnalysePath]->(w) return d,w
数据分析->所属行业的业务知识,
match (d:Job{name:"DataAnalyse"}),(p:Knowledge{name:"Professional"}) create (d)-[:DataAnalysePath]->(p) return d,p
数据分析->Linux,
match (d:Job{name:"DataAnalyse"}),(l:Knowledge{name:"Linux"}) create (d)-[:DataAnalysePath]->(l) return d,l
数据分析->Python基础->MySQL,
数据分析->Python基础->MongoDB,
数据分析->Python基础->HBase,
数据分析->Python基础->Hive。
match (d:Job{name:"DataAnalyse"}),(p:Knowledge{name:"PythonBasic"}) create (d)-[:DataAnalysePath]->(p) return d,p
match (p:Knowledge{name:"PythonBasic"}),(m:Knowledge{name:"MySQL"}) create (p)-[:DataAnalysePath]->(m) return p,m
match (p:Knowledge{name:"PythonBasic"}),(m:Knowledge{name:"MongoDB"}) create (p)-[:DataAnalysePath]->(m) return p,m
match (p:Knowledge{name:"PythonBasic"}),(h:Knowledge{name:"HBase"}) create (p)-[:DataAnalysePath]->(h) return p,h
match (p:Knowledge{name:"PythonBasic"}),(h:Knowledge{name:"Hive"}) create (p)-[:DataAnalysePath]->(h) return p,h
看一看效果图。
MATCH p=()-[r:DataAnalysePath]->() RETURN p LIMIT 25
创建 ''人工智能" 线路相关的节点和关系。
创建相关节点。
merge (:Job{name:"AI"})
merge (:Knowledge{name:"Math"})
merge (:Knowledge{name:"Statistics"})
merge (:Knowledge{name:"PythonBasic"})
merge (:Knowledge{name:"MachineLearning"})
merge (:Knowledge{name:"Linux"})
merge (:Knowledge{name:"DeepLearning"})
merge (:CareerDirection{name:"Visual"})
merge (:CareerDirection{name:"Voice"})
merge (:CareerDirection{name:"NLP"})
merge (:CareerDirection{name:"Recommend"})
创建节点关系,
人工智能->Python基础,
match (a:Job{name:"AI"}),(p:Knowledge{name:"PythonBasic"}) create (a)-[:AIPath]->(p) return a,p
人工智能->高数->统计->机器学习->Linux,
人工智能->高数->统计->机器学习->深度学习->视觉,
人工智能->高数->统计->机器学习->深度学习->语音,
人工智能->高数->统计->机器学习->深度学习->NLP,
人工智能->高数->统计->机器学习->深度学习->推荐,
match (a:Job{name:"AI"}),(m:Knowledge{name:"Math"}) create (a)-[:AIPath]->(m) return a,m
match (m:Knowledge{name:"Math"}),(s:Knowledge{name:"Statistics"}) create (m)-[:AIPath]->(s) return m,s
match (s:Knowledge{name:"Statistics"}),(m:Knowledge{name:"MachineLearning"}) create (s)-[:AIPath]->(m) return s,m
match (m:Knowledge{name:"MachineLearning"}),(l:Knowledge{name:"Linux"}) create (m)-[:AIPath]->(l) return m,l
match (m:Knowledge{name:"MachineLearning"}),(d:Knowledge{name:"DeepLearning"}) create (m)-[:AIPath]->(d) return m,d
match (d:Knowledge{name:"DeepLearning"}),(v:CareerDirection{name:"Visual"}) create (d)-[:AIPath]->(v) return d,v
match (d:Knowledge{name:"DeepLearning"}),(v:CareerDirection{name:"Voice"}) create (d)-[:AIPath]->(v) return d,v
match (d:Knowledge{name:"DeepLearning"}),(n:CareerDirection{name:"NLP"}) create (d)-[:AIPath]->(n) return d,n
match (d:Knowledge{name:"DeepLearning"}),(r:CareerDirection{name:"Recommend"}) create (d)-[:AIPath]->(r) return d,r
看一看效果图。
MATCH p=()-[r:AIPath]->() RETURN p LIMIT 25
创建 ''大数据" 线路相关的节点和关系。
创建相关节点,
merge (:Job{name:"BigData"})
merge (:Knowledge{name:"Linux"})
merge (:CareerDirection{name:"RealTimeComputing"})
merge (:CareerDirection{name:"OfflineCalculation"})
merge (:Knowledge{name:"Scala"})
merge (:Knowledge{name:"Spark"})
merge (:Knowledge{name:"Hadoop"})
merge (:Knowledge{name:"Hive"})
merge (:Knowledge{name:"HBase"})
merge (:Knowledge{name:"Java"})
merge (:Knowledge{name:"FLink"})
merge (:Knowledge{name:"flume"})
merge (:Knowledge{name:"Kafka"})
merge (:Knowledge{name:"Storm"})
创建节点关系,
大数据->Linux,
match (b:Job{name:"BigData"}),(l:Knowledge{name:"Linux"}) create (b)-[:BigDataPath]->(l) return b,l
大数据->离线计算->Hive,
大数据->离线计算->HBase,
大数据->离线计算->Scala->Spark,
大数据->离线计算->Hadoop,
match (b:Job{name:"BigData"}),(o:CareerDirection{name:"OfflineCalculation"}) create (b)-[:BigDataPath]->(o) return b,o
match (o:CareerDirection{name:"OfflineCalculation"}),(h:Knowledge{name:"Hive"}) create (o)-[:BigDataPath]->(h) return o,h
match (o:CareerDirection{name:"OfflineCalculation"}),(h:Knowledge{name:"HBase"}) create (o)-[:BigDataPath]->(h) return o,h
match (o:CareerDirection{name:"OfflineCalculation"}),(s:Knowledge{name:"Scala"}) create (o)-[:BigDataPath]->(s) return o,s
match (s:Knowledge{name:"Scala"}),(sp:Knowledge{name:"Spark"}) create (s)-[:BigDataPath]->(sp) return s,sp
match (o:CareerDirection{name:"OfflineCalculation"}),(h:Knowledge{name:"Hadoop"}) create (o)-[:BigDataPath]->(h) return o,h
大数据->实时计算->Java,
大数据->实时计算->Java->Hadoop,
大数据->实时计算->Java->FLink,
大数据->实时计算->Java->flume,
大数据->实时计算->Java->Kafka,
大数据->实时计算->Java->Storm,
match (b:Job{name:"BigData"}),(r:CareerDirection{name:"RealTimeComputing"}) create (b)-[:BigDataPath]->(r) return b,r
match (r:CareerDirection{name:"RealTimeComputing"}),(j:Knowledge{name:"Java"}) create (r)-[:BigDataPath]->(j) return r,j
match (j:Knowledge{name:"Java"}),(h:Knowledge{name:"Hadoop"}) create (j)-[:BigDataPath]->(h) return j,h
match (j:Knowledge{name:"Java"}),(f:Knowledge{name:"FLink"}) create (j)-[:BigDataPath]->(f) return j,f
match (j:Knowledge{name:"Java"}),(f:Knowledge{name:"flume"}) create (j)-[:BigDataPath]->(f) return j,f
match (j:Knowledge{name:"Java"}),(k:Knowledge{name:"Kafka"}) create (j)-[:BigDataPath]->(k) return j,k
match (j:Knowledge{name:"Java"}),(s:Knowledge{name:"Storm"}) create (j)-[:BigDataPath]->(s) return j,s
看一看效果图。
MATCH p=()-[r:BigDataPath]->() RETURN p LIMIT 25
后附上完整的知识图谱。