Neo4j aura 官方网站快速入门新手教精读-从官方教程学习知识图谱

时间:2024-03-04 19:55:18

Neo4j 官方网站快速入门新手教精读

       本文旨在为Neo4j新手提供一份全面的入门指南。除了基础的文本解释,我在里面还插入了每一步骤的详细截图或者自己画的图,从官方了解知识肯定比自己乱看要权威一些,有看不懂的不要纠结了解大概意思即可,随着知识的积累最后会顿悟的,这里面的内容好多机翻不出来的或者不好理解的我根据对相关知识的了解人工进行了润色,如果有表达不准确或者不清楚的地方,非常欢迎批评指正,共同进步。

Neo4j Aura 是一个完全托管的图形数据库服务,它提供了一个高度可扩展、安全和操作简便的环境,使用户能够轻松构建和维护基于图形的数据模型和应用程序。

https://neo4j.com/cloud/platform/aura-graph-database/?ref=neo4j-home-hero
在这里插入图片描述

文章目录

  • Neo4j 官方网站快速入门新手教精读
    • 1. Learn the basics 基础了解
    • 2. What is a graph? 图是什么?
    • 3. Nodes, properties, relationships 节点,属性,关系
      • 3.1 Nodes and properties 节点和属性
      • 3.2 Relationships 关系
    • 4. Re-imagining a classic (Northwind) 回顾经典图数据集(北风)
    • 5. Finish the Northwind import 完成北风数据集的导入
      • 5.1 Preview your data import 预览导入数据
      • 5.2 Explore your data 探索您的数据
    • 6. Explore your graph 探索你的图
      • 6.1 Searching for data in Explore 在Explore中搜索数据
    • 7. Advanced exploration 先进的展示
    • 8. Basic Querying 基础查询
    • 9. Writing your first query 写你的第一个查询
    • 10. A more advanced query更高级的查询
    • 11. Next steps 下一步
      • 11.1 Next steps with Cypher 关于Cypher语言的下一步
      • 11.2 Creating applications 创建应用
      • 11.3 Go further with GraphAcademy 在GraphAcademy上更近一步
  • 教程中给出的网站汇总
  • 结束

1. Learn the basics 基础了解

       This guide teaches you about the power of graph databases. It is the recommended starting place for all new users as it touches upon the concepts and tools you need to work with graphs.
       本指南将向您介绍图数据库的强大功能。它是所有新用户的推荐入门指南,因为它设计到使用图所需要的概念和工具。

在这里插入图片描述

What you will learn
你将会学到什么
This guide takes around 10 minutes and by the end of it you will able to:
本指南大约需要十分钟,在结束时候您能够学到

  • Understand the graph property model and what problems it can help you solve.
    明白图的性质以及它能帮助你解决什么问题
  • Convert an understanding of relational database model to a graph
    将对一个关系数据库的理解转化为一个图
  • Import and model data from CSV file and map them to a graph.
    把CSV格式的文件导入图数据库,并将其建模成一个图
  • Visually explore that data, without code, in a graph.
    在图中直观的查看这些数据,且不需要代码
  • Write your first simple graph queries using Cypher
    使用Cypher命令,来进行一个简单的图数据库的查询

Get started!

让我们开始

       You are going to use the classic relational dataset known as Northwind and bring the fictional company into graph-enabled future.
       你将使用名为NotrhWind的经典关系数据库,并将一个虚拟公司带入一个图使能的未来。

2. What is a graph? 图是什么?

在这里插入图片描述

Concepts 图的概念

       A graph database stores nodes(Supplier, Product, etc) and their relationship(e,g, Supplier SUPPLIES Product).
       一个图数据库存包含着两种元素,节点(供应商,产品,等等) 以及他们的关系 (供应商供应产品)

       Other types of databases may use tables and documents, but in a graph, data is stored in the same way as you may sketch ideas on a whiteborad.
       其他类型的数据库可以能使用的是表格和文档,但是在图数据库存储数据的方式和您在白板上勾画想法的方式相同。

在这里插入图片描述

In a graph, where the relationships are stored, many powerful operations are faster and simpler.
在一个图数据库中,在存储一些关时,很多操作更加快速和便捷

Schema-free形式*

       In a relational database, you must define your schema (the structure of the data). In a graph, your data is managed without restricting it to a predefined schema. This allows more flexibility in thinking about the data and in evolving it.
       在一个关系数据库中,你必须定义一个数据格式,在一个图数据库中,你的数据并没有需要严格遵守的格式限制,因此在考虑数据的时候可以更灵活和发散。

3. Nodes, properties, relationships 节点,属性,关系

       The nodes and relationships in your graph can have types and properties.
       在我们的图数据库中的节点和关系可以有类别属性

3.1 Nodes and properties 节点和属性

       Nodes can be tagged with labels, representing their different roles in your dataset (e.g. Supplier, Employee, Customer). They can also have any number of key-value pairs as properties (e.g. name:"Camembert Pierrot").
       节点可以用标签来标记,表示他们在数据集中的不同角色例如(供应商员工客户),节点也可以包含任意数量的键值对作为属性例如(名字:Camembert Pierrot)

3.2 Relationships 关系

       Relationships provide directed, typed, or attributed, connections between two node entities (e.g. Shipper SHIPS Order).
       关系提供了两个节点之间的指向,类型,所属关系,例如(托运人的船舶订单)

       Relationships always have a direction, a type, a start node, and an end node. They can also have properties, just like nodes.
       关系包包含一个指向一个类型一个起始节点一个指向节点,且关系和节点一样依然包含一些属性。

       Nodes can have any number of relationships without sacrificing performance.
       节点可以包含任何数量的关系且不用牺牲任何的已经表现出的信息。

       Although relationships are always directed, they can be navigated efficiently in any direction. In this example, you can find who shipped an order and you can also reverse that and find what orders were shipped.
       尽管关系总是有方向的,但是他可以沿着任何方向进行有效的查找。在这个例子中,你可以查找谁发了一个订单,也也可以反向查找这个订单是由谁发送的

4. Re-imagining a classic (Northwind) 回顾经典图数据集(北风)

在这里插入图片描述
The classic Northwind dataset represents an online shop.
北风数据集表示的是一个在线商店

product category supplier

You are now going to transform this relational database into a graph database
现在你要把这个关系数据集转换成图数据集

product graph

       You can see the CSV files from Northwind’s tables represented as a graph model. The mappings for these files are already prepared for you.
       你可以看到北风数据集中的CSV文件表示的图,里面的映射关系文件当中都已经为你准备好了。

       Notice the relationships connecting the nodes, e.g. a Customer PURCHASED an Order and the Order ORDERS Products.
       注意链接节点的这些关系,例如:顾客购买了订单,订单订购了产品

在这里插入图片描述

5. Finish the Northwind import 完成北风数据集的导入

在这里插入图片描述

       For each node and relationship in the model you can see which parts of the CSV file are mapped to which properties
       对生成的图中的节点和关系,你可以看到哪部分的CSV文件映射到了哪种属性

       Source and target IDs from the original join tables or foreign keys are used to create relationships to connect nodes
       原始连接表或外键中的源ID和目标ID被用来创建关系以连接节点(白话就说用是CSV中有节点和关系还有属性读出来之后生成了图)

       The model is interactive; you can click around and explore its nodes and relationships.
       该模型是交互式的;您可以单击并探索其节点和关系。

5.1 Preview your data import 预览导入数据

       You can see a preview of the data import by clicking the Preview button.
可以点右上的预览按钮来查看数据导入的预览

在这里插入图片描述

       This allows you to check node labels, the property names and values, and the relationship types and directions.
       通过点击这个按键,可以检查导入的文件的节点标签、属性名称和值,以及关系类型和方向。(点里面的Preview all)

在这里插入图片描述

       If you’re satisfied, click the Run import button to load your data into your graph.
如果你满意的话,点击Run import按钮去把你的数据加载到图里

在这里插入图片描述
在这里插入图片描述

       If something goes wrong, keep in mind that the tool can import the same data multiple times and you can reset your database to blank in the AuraDB Console.
       如果报错了的话,注意这个工具(指 Run Import 按钮)可以多次导入相同数据 然后你可以把你的数据库在AuraDB Console中清空。

5.2 Explore your data 探索您的数据

       After you have imported the Northwind dataset, click the Start Exploring button in the report popup or switch to the Explore tab.
       导入北风数据集后,单击报告弹出框中的开始探索按钮或切换到探索选项卡。

在这里插入图片描述
       Next you are going to see the power of graph visualization.
       之后你会看到图可视化的力量。

6. Explore your graph 探索你的图

With the data in a graph, it is time to get familiar with the Explore tab.
有了图表中的数据,是时候熟悉Explore选项卡了。

       The Show me a graph Search Phrase runs automatically to show an example subset of the data. The visualized graph represents the relationships in the data in an intuitive way.
       (刚点击完 Explore results 之后)Show me a graph 搜索短语会自动运行,以显示数据的一个示例子集。可视化图以直观的方式表示数据之间的关系。

       You can also run the Show me a graph example Search Phrase yourself by typing the Show me a graph in the top-left search bar.
       你也可以自己在左上角的搜索栏里自己手动输入Show me a graph 然后运行。

在这里插入图片描述

6.1 Searching for data in Explore 在Explore中搜索数据

       You can use simple search phrases based on your node labels and relationship types to visualize your graph. If you ran the example Search Phrase, you should clear the scene before you continue. Right-click anywhere on the canvas and select Clear Scene or Ctrl+Bksp/Cmd+Bksp.
       你可以基于你自己的节点标签和关系来用一个简单的搜索词可视化你的图,如果你运行一个示例搜索词,在你进行操作之前要把屏幕情况,右键(我实际操作下来应该是左键点击)随便点击图显示框中的任何一个位置然后按住Ctrl+Bksp/Cmd+Bksp删除。

       If you enter Category<tab> and then press return; it fetches and displays all categories. You can now explore and expand the graph visualization.
       如果你先按<tab>然后安enter就能获取和显示所有类别。现在你可以继续探索和延申图的可视化。

       This is a great way to discover interesting relationships and formulate questions about your data.
       这是发现你的数据中有趣的联系和规范化问题的一个好的方式(说实话这句没太明白)。

       Another useful feature is to select two nodes (Ctrl-Click/Cmd-Click) and select Paths → Shortest Path from the right-click context menu on one of them.
       另一个有用的特性是按住ctrl选择两个节点,然后后右键的菜单中选择path,然后选择Shortest Path最短路径。(右键的时候鼠标要在节点上,然后点了Shortest Path其实也无事发生,就闪了两下比较鸡肋)

在这里插入图片描述
在这里插入图片描述

       You can select all Categories by clicking on their box in the right side legend and then choose Expand → All in the context menu to see all the products contained in these categories.
       你可以用过右侧的框内看到所有类别,然后点击这个类别就可以看到这个类别的提示。
在这里插入图片描述

       The context menu also offers many more options like editing, partial expansion, clearing the scene, or dismissing (un-)selected nodes.
       上下文菜单还提供了许多选项,如编辑、部分展开、清除场景或取消(取消)所选节点。(我理解他指的上下文菜单应该是这里,右上角可以删除节点)

在这里插入图片描述

7. Advanced exploration 先进的展示

       In the bottom-right of Explore you can switch between the default force-based layout and a hierarchical layout.
       在Explore的右下角,您可以在默认的布局和分层布局之间切换。

在这里插入图片描述
在这里插入图片描述

       You can style your data in the right legend using colors, icons, sizes, and captions, and even apply rules for these.
       你可以在右侧的列表框章设置颜色图标标题,甚至应用的一些规则。

       Click on Category in the legend panel and pick a different color, icon, and/or size for your nodes.
       点击图例面板中的Category,为你的节点选择不同的颜色、图标和/或大小。
在这里插入图片描述

       Selected nodes and relationships are highlighted and counted in the legend panel and shown in the card view in the lower left corner. There you can explore your data structurally.
       选择了节点和关系之后可以高亮对应的元素且后面有计数(只有点后面有数字的它才亮,这句我直接总结归纳了)

在这里插入图片描述
       Explore also offers options to filter your on-screen nodes with a advanced filter menu, and even rudimentary user programming by storing Cypher phrases to reuse later.
       Explore还提供了使用高级过滤菜单过滤屏幕节点的选项,甚至还提供了通过存储Cypher短语以供以后重用的基本用户编程。

8. Basic Querying 基础查询

Switch to the Query tab, if you haven’t already done so.
切回查询页面Query,如果你还没切换的话。
在这里插入图片描述

       In the first entry (database) in the left column, you can see the count of nodes and relationship types. Click on “(Product)” - the database uses a minimal query to get several elements labeled “Product”.
       在左侧栏的第一个条目(数据库)中,可以看到节点和关系类型的计数。点击“(Product)”——数据库使用一个最小的查询获取带有“Product”标签的几个元素。

在这里插入图片描述

MATCH (n:Product)
RETURN n
LIMIT 25

       The result nodes are visualized in the graph view, and you can double-click nodes to see their neighbors.
       结果节点显示在Graph中,可以通过双击节点来查看它们的临近的节点。

       In the right properties side-panel you can inspect more properties. You can also style nodes (size, color, caption) by clicking on the (Product) label on top.
       在右侧是属性滑动窗口中,你可以查看更多的属性,也可以通过点击窗口中的Pruduct自定义节点的尺寸颜色标题

在这里插入图片描述

       Results can also be shown in a tabular view by clicking the table view option. Nodes and relationships are visualized in a JSON structure. That view is shown by default if you return only scalar values.
       还可以通过单击table view选项在表格视图中显示结果。节点和关系在JSON结构中可视化。如果只返回标量值,则默认显示该视图。

在这里插入图片描述

9. Writing your first query 写你的第一个查询

       Like any other database, Neo4j can be queried with a query language.
       就像其他数据库一样,Neo4j依旧有一个查询语言。

       Neo4j’s graph query language is called Cypher and is very well-suited for finding patterns. Unlike SQL, there is no reliance on writing complex joins
       Neo4j’s 图查询语言叫 Cypher 并且其非常合适用于寻找模型。不像SQL,其并不依赖于编写复杂链接。

       In Cypher, you represent the graph patterns that you’ve seen in Import and Explore with ascii-art.
       在 Cypher 中, 你可以用ascii-art表示你在ImportExplore中看到的图形模式。

ASCII艺术是一种利用ASCII字符集中的字符进行创作,通过排列组合这些字符来构造出图像或文本视觉表现的计算机艺术形式。

       Parentheses (p:Product {name:'Camembert Pierrot'}) form “circles” around nodes and arrows -[:SUPPLIES]-> depicts relationships.
       圆括号(p:Product {name:'Camembert Pierrot'})在节点周围形成“圆圈”,箭头-[:SUPPLIES]->表示关系。

       You draw in text what you would draw on the whiteboard.
       用文本画图和你在白板上画图一样。

       These patterns are used to find, create, and update graph data.
       这种模式被用于取创造更新和查找数据。

       You’ve already seen the MATCH (n:Product) RETURN n LIMIT 25 statement that was run previously.
       你以及看过MATCH (n:Product) RETURN n LIMIT 25指令之前跑出来的效果

       Now click on the statement to edit it and change the pattern and result to:
       现在点击语句进行编辑,并将模式和结果更改为:

MATCH (n:Product)<-[r:SUPPLIES]-(s:Supplier)
RETURN n,r,s
LIMIT 25

Congratulations, you’ve written and run your first Cypher query!
恭喜你你完成了第一个Cypher 查询。

10. A more advanced query更高级的查询

For the last part of this guide you get the opportunity to try some more powerful queries.
最后一部分会知道你有机会去尝试一些更高级的查询。

First, this query finds all products ordered by a customer and who supplies them.
首先,该查询查找客户订购的所有产品及其供应商。

MATCH path=(c:Customer)-[:PURCHASED]->()-[:ORDERS]->(:Product)<-[:SUPPLIES]-(:Supplier)
WHERE c.companyName = 'Blauer See Delikatessen'
RETURN path;

在这里插入图片描述

example

you can also see how many products in the Produce category each customer ordered.
您还可以看到每个客户订购了“农产品”类别中的产品数量。

在这里插入图片描述

11. Next steps 下一步

Congratulations on completing this tutorial.
祝贺你完成了本教程

       You can do more with the Northwind dataset or you can reset your instance in AuraDB Console and import your own data.
       您可以使用Northwind数据集做更多的事情,或者您可以在AuraDB Console中重置实例并导入您自己的数据。

       For your next steps, a suggestion is to look at furthering your Cypher knowledge or building an application using Neo4j’s popular language drivers.
       对于接下来的步骤,建议您进一步了解Cypher知识或使用Neo4j的流行语言驱动程序构建应用程序。

11.1 Next steps with Cypher 关于Cypher语言的下一步

To learn more about Cypher, check out the interactive GraphAcademy course
为了进一步了解Cypher,可以看一下这个图学术课程

https://graphacademy.neo4j.com/categories/beginners/

在这里插入图片描述

and have a look at the Cypher Cheat Sheet
还有这个 Cypher Cheat Sheet

在这里插入图片描述

11.2 Creating applications 创建应用

       As you get more familiar with Cypher, you can use the
       如果你已经熟悉了Cypher,你可以使用 C#, Go, Java, JavaScript, and Python 语言构建您的应用
在这里插入图片描述

or use our GraphQL or Spring Data Neo4j integrations for building APIs.
或者使用我们的GraphQL或Spring Data Neo4j集成来构建APIs。

https://docs.spring.io/spring-data/neo4j/reference/

在这里插入图片描述

11.3 Go further with GraphAcademy 在GraphAcademy上更近一步

       GraphAcademy is provided by Neo4j and offers in-depth courses on many aspects of graph databases. Check out the GraphAcademy website
       GraphAcademy由Neo4j提供,提供关于图数据库许多方面的深入课程。请查看 GraphAcademy网站

https://graphacademy.neo4j.com/

在这里插入图片描述

教程中给出的网站汇总

GraphAcademy course https://graphacademy.neo4j.com/categories/beginners/
Cypher Cheat Sheet https://neo4j.com/docs/cypher-cheat-sheet/5/auradb-enterprise/
Neo4jAPI https://neo4j.com/docs/getting-started/languages-guides/
GraphQLhttps://neo4j.com/product/graphql-library/
Spring Data Neo4jhttps://docs.spring.io/spring-data/neo4j/reference/
GraphAcademyhttps://graphacademy.neo4j.com/

结束

       反正知识图谱这个东西了解基本概念不难,学起来反正不是很容易,也希望各位不要灰心,看了半天啥也不明白是非常正常的情况,接下来一段时间内我应该会更新大模型和知识图谱的相关内容,积极分享。