当前位置:   article > 正文

neo4j 知识图谱_作业二:用neo4j构建知识图谱

flinkc cdc neo4j

一、neo4j 基本安装思路,及查询资料。(待补充)

二、什么是知识图谱?(待补充)

三、构建如下知识图谱。

94b18aacc293514ee1f698f50d894a8e.png

第一步:如上图,按照岗位->岗位细分方向->岗位技术要求基本思路不重复地创建所有节点。

  • 语法解释:
  1. CREATE (le:Person {name:"Euler"}),[1]
  2. (db:Person {name:"Bernoulli"}),
  3. (le)-[:KNOWS {since:1768}]->(db)[2]
  4. RETURN le, db[3]
  • 具体代码:
  1. create (:job {name:"自动化办公"}),(:job {name:"Web开发"}),(:job {name:"爬虫"}),(:job {name:"数据分析"}),(:job {name:"大数据"}),(:job {name:"人工智能"}),
  2. (:knowledge {name:"网络"}),(:knowledge {name:"HTML"}),(:knowledge {name:"xpath"}),(:knowledge {name:"CSS"}),(:knowledge {name:"linux"}),
  3. (:knowledge {name:"Windowns办公软件"}),(:knowledge {name:"所属行业的业务知识"}),(:knowledge {name:"Python"}),(:knowledge {name:"统计"}),
  4. (:knowledge {name:"高数"}),(:knowledge {name:"机器学习"}),(:knowledge {name:"深度学习"}),
  5. (:position_direction {name:"视觉"}),(:position_direction {name:"语音"}),(:position_direction {name:"NLP"}),(:position_direction {name:"推荐"}),
  6. (:position_direction {name:"离线计算"}),(:position_direction {name:"实时计算"}),
  7. (:knowledge {name:"Hive"}),(:knowledge {name:"HBase"}),(:knowledge {name:"Scala"}),(:knowledge {name:"Spark"}),(:knowledge {name:"Hadhoop"}),
  8. (:knowledge {name:"JAVA"}),(:knowledge {name:"Storm"}),(:knowledge {name:"kafka"}),(:knowledge {name:" Flink"}) ,(:knowledge {name:"flume "}) ,
  9. (:knowledge {name:"文件处理"}) ,(:knowledge {name:"Flask"}) ,(:knowledge {name:"Django"}) ,
  10. (:knowledge {name:"Requests"}) ,(:knowledge {name:"Bs4"}) ,(:knowledge {name:"scrapy"}) ,(:knowledge {name:"MYSQL"}) ,(:knowledge {name:"MongoBD"})

第二步:据岗位、岗位细分方向、岗位技术要求之间关系,创建各节点间关系(match(先查到)...create(然后创建节点间关系)...return(返回结果)... )。

  • 语法解释:
  1. MATCH (director:Person)-[:DIRECTED]->(movie)
  2. WHERE director.name = "Steven Spielberg"
  3. RETURN movie.title
  • 具体代码:
  1. 创建“自动化办公”知识图谱
  1. match (a:job {name:"自动化办公"}),(b:knowledge {name:"Python"}) create (a)-[r:TechnicalRequiremention {name:""}]->(b)
  2. return a,b

63a53e1770d10bd4e699e08e2390c921.png

2. 创建“Web开发”知识图谱

  1. match (a:job {name:"Web开发"}),(b:knowledge {name:"Python"}),(c:knowledge {name:"linux"})
  2. create (a)-[r:TechnicalRequiremention {name:""}]->(b), (a)-[o:TechnicalRequiremention {name:""}]->(c)
  3. return a,b,c

3. 创建“爬虫”知识图谱

  1. match (a:job {name:"爬虫"}),(b:knowledge {name:"网络"}),(c:knowledge {name:"HTML"}),(d:knowledge {name:"xpath"}),(e:knowledge {name:"CSS"}) ,(f:knowledge {name:"linux"})
  2. create (a)-[:TechnicalRequiremention {name:""}]->(b),(a)-[:TechnicalRequiremention {name:""}]->(c),(a)-[:TechnicalRequiremention {name:""}]->(f),
  3. (c)-[:TechnicalDRequiremention {name:""}]->(d),(c)-[:TechnicalDRequiremention {name:""}]->(e)
  4. return a,b,c,d,e,f

cb5157abd9eb02bd2d3594da3759caf8.png

4. 创建“数据分析”知识图谱

  1. match (a:job {name:"数据分析"}),(b:knowledge {name:"Python"}),(c:knowledge {name:"linux"}),(d:knowledge {name:"Windowns办公软件"}),
  2. (e:knowledge {name:"所属行业的业务知识"}) ,(f:knowledge {name:"统计"})
  3. create (a)-[:TechnicalRequiremention {name:""}]->(b),(a)-[:TechnicalRequiremention {name:""}]->(c),(a)-[:TechnicalRequiremention {name:""}]->(d),
  4. (a)-[:TechnicalDRequiremention {name:""}]->(e),(a)-[:TechnicalDRequiremention {name:""}]->(f)
  5. return a,b,c,d,e,f

1cbe8e6a6356c33a213dcf9b5d597ae0.png

5. 创建“人工智能”知识图谱

  1. match (a:job {name:"人工智能"}),(ab:knowledge {name:"Python"}),(b:knowledge {name:"高数"}),(c:knowledge {name:"统计"}),(d:knowledge {name:"机器学习"}),
  2. (e:knowledge {name:"linux"}),(f:knowledge {name:"深度学习"}),(o:position_direction {name:"视觉"}),(p:position_direction {name:"语音"}),
  3. (q:position_direction {name:"NLP"}),(i:position_direction {name:"推荐"})
  4. create (a)-[:TechnicalRequiremention {name:""}]->(ab),(a)-[:TechnicalRequiremention {name:""}]->(b),(b)-[:TechnicalDRequiremention {name:""}]->(c),
  5. (c)-[:TechnicalDRequiremention {name:""}]->(d),(d)-[:TechnicalDRequiremention {name:""}]->(e) ,(d)-[:TechnicalDRequiremention {name:""}]->(f) ,
  6. (f)-[:position_direction {name:""}]->(o) ,(f)-[:position_direction {name:""}]->(p),(f)-[:position_direction {name:""}]->(q),(f)-[:position_direction {name:""}]->(i)
  7. return a,ab,b,c,d,e,f,o,p,q,i

62d36dd3b3c78b90fffbda461cfb8f20.png

6. 创建“大数据”知识图谱

  1. match (a:job {name:"大数据"}),(b:position_direction {name:"离线计算"}),(c:position_direction {name:"实时计算"}), (d:knowledge {name:"linux"}),
  2. (e:knowledge {name:"Hive"}),(f:knowledge {name:"HBase"}),(o:knowledge {name:"Scala"}),(p:knowledge {name:"Spark"}),(q:knowledge {name:"Hadhoop"}),
  3. (i:knowledge {name:"JAVA"}),(s:knowledge {name:"Storm"}),(t:knowledge {name:"kafka"}),(u:knowledge {name:" Flink"}),(v:knowledge {name:"flume "}) ,
  4. (w:knowledge {name:"Python"}),(x:knowledge {name:"文件处理"}) ,(y:knowledge {name:"Flask"}) ,(z:knowledge {name:"Django"}) ,
  5. (aa:knowledge {name:"Requests"}) ,(bb:knowledge {name:"Bs4"}) ,(cc:knowledge {name:"scrapy"}) ,(dd:knowledge {name:"MYSQL"}) ,(ee:knowledge {name:"MongoBD"})
  6. create (a)-[:position_direction {name:""}]->(b),(a)-[:position_direction {name:""}]->(c),(a)-[:TechnicalRequiremention {name:""}]->(d),
  7. (b)-[:TechnicalRequiremention {name:""}]->(e) ,(b)-[:TechnicalRequiremention {name:""}]->(f) ,(b)-[:TechnicalRequiremention {name:""}]->(o) ,
  8. (o)-[:TechnicalDRequiremention {name:""}]->(p),(b)-[:TechnicalRequiremention {name:""}]->(q) ,
  9. (c)-[:TechnicalRequiremention {name:""}]->(i) ,(i)-[:TechnicalDRequiremention {name:""}]->(q),(i)-[:TechnicalDRequiremention {name:""}]->(s),
  10. (i)-[:TechnicalDRequiremention {name:""}]->(t),(i)-[:TechnicalDRequiremention {name:""}]->(u),(i)-[:TechnicalDRequiremention {name:""}]->(v),
  11. (w)-[:TechnicalDRequiremention {name:""}]->(x),(x)-[:TechnicalDRequiremention {name:""}]->(y),(x)-[:TechnicalDRequiremention {name:""}]->(z),
  12. (y)-[:TechnicalDRequiremention {name:""}]->(dd),(z)-[:TechnicalDRequiremention {name:""}]->(dd),(w)-[:TechnicalDRequiremention {name:""}]->(aa),
  13. (aa)-[:TechnicalDRequiremention {name:""}]->(bb),(bb)-[:TechnicalDRequiremention {name:""}]->(cc),(cc)-[:TechnicalDRequiremention {name:""}]->(dd),
  14. (cc)-[:TechnicalDRequiremention {name:""}]->(ee),(w)-[:TechnicalDRequiremention {name:""}]->(dd),(w)-[:TechnicalDRequiremention {name:""}]->(ee),
  15. (w)-[:TechnicalDRequiremention {name:""}]->(e),(w)-[:TechnicalDRequiremention {name:""}]->(f)
  16. return a,b,c,d,e,f,o,p,q,i,s,t,u,v,w,x,y,z,aa,bb,cc,dd,ee

bcc17e94c2782578748152d35a2d244e.png

第三步:结果查询(match (n) return n)。

8a6914d33b0c44423dc5661925757346.png

四、总结。
neo4j创建两节点关系时,可能会出现语法重复执行或节点间关系命名错误,需删除节点间其中关系。

【1】先删关系,再删节点

0e0f522aa6fe1d968be8cef6383313b2.png

【2】当记不得关系名时,type(r)可以查到关系名

726712e7c28bfa8c508c7a95a7da4965.png

【3】彻底删除节点标签名,需要删除前期对该标签名建立的索引

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/369653
推荐阅读
相关标签
  

闽ICP备14008679号