官术网_书友最值得收藏!

The property graph model

In Neo4j, we use a property graph model to represent information. The property graph model is an extension of the graphs from mathematics. The following figure gives an example of how data from Figure 1.1 can be represented in Neo4j:

Figure 1.2: Nodes, relationships and properties

The preceding figure introduces the following concepts that we use to model a property graph:

  • Nodes: Entities are modelled as nodes. In Figure 1.2, London, Bob, Alice are all entities.
  • Labels: These are used to represent the role of the node in our domain. A node can have multiple labels at the same time. Apart from adding more meaning to nodes, labels are also used to add constraints and indices that are local to the particular label. In the preceding figure, :Person and :Location are the two labels that we used. We can add an index or constraint on name for each of these labels, which will result in two separate indices—one for :Location and the other for :Person.
  • Relationships: These depict directed, semantically relevant connections between two nodes. A relationship in Neo4j will always have a start node, an end node, and a single type. While relationships need to be created with a direction, we can ignore the direction while traversing them. :LIVES_IN and :IS_MARRIED_TO in Figure 1.2 are relationship types.
  • Properties: These are key-value pairs that contain information about the node or relationship. In the previous figure, name and since are both properties that pulge more information about the node or relationship they are associated with. Neo4j can accept any Java Virtual Machine (JVM) type as a property, including but not limited to, date, string, double, and arrays.

This property graph model allows us to model data as close to the real world as possible.

The resultant model is simpler and more expressive. It also explicitly calls out relationships. In contrast to an RDBMS, which uses foreign keys to imply relationships, having them explicitly defined allows us to retrieve data by traversing relationships to find the information we need. This is a deliberate, practical algorithmic approach that uses the connectedness of data, rather than relying on some index lookups or joins to find the related data. Explicit relationships also make the property graph model a natural fit for most problem domains, as they are interconnected.

主站蜘蛛池模板: 葵青区| 河间市| 靖西县| 西安市| 民县| 隆尧县| 永丰县| 宁陵县| 潼南县| 泾川县| 兰坪| 宁都县| 即墨市| 钦州市| 保康县| 连江县| 万全县| 泽普县| 云南省| 岑巩县| 荃湾区| 区。| 井研县| 定襄县| 财经| 尼木县| 兴文县| 尤溪县| 正蓝旗| 平塘县| 德江县| 青阳县| 龙井市| 桃源县| 康平县| 隆昌县| 吴桥县| 唐河县| 加查县| 宿松县| 微博|