Databases Reference
In-Depth Information
Avon'
) is connected to the literary domain as a result of its being Shakespeare's birthplace
(Shakespeare was
BORN_IN
Stratford). It is connected to the theatrical domain insofar
as it is home to the RSC (the RSC is
BASED_IN
Stratford). To learn more about Stratford
upon Avon's geography, we can follow its outgoing
COUNTRY
relationship to discover it
is in England.
Note how the graph reduces instances of duplicated data across do‐
mains.
Stratford upon Avon
, for example, participates in all three
domains.
The property graph makes it possible to capture more complex geospatial data. Looking
at the Theatre Royal, for example, we see that it is located on
Grey Street
, which is in
the
CITY
of Newcastle, which is in the
COUNTY
of Tyne and Wear, which ultimately is in
the
COUNTRY
of England—just like Stratford upon Avon.
Relationships help both partition a graph into separate domains
and
connect those
domains. As we can see from this relatively simple example, the property graph model
makes it easy to unite different domains—each with its own particular entities, prop‐
erties, and relationships—in a way that not only makes each domain accessible, but also
generates insight from the connections between domains.
Labeling Nodes
We've used relationships here to structure the graph and establish the semantic context
for each node. By following an outgoing
WROTE_REVIEW
relationship, for example, we
understand that the node at the end of that relationship represents a review. But this is
a rather weak method for indicating what kind of domain abstraction a node represents.
How might we improve it?
Today, to satisfy this need, many users of Neo4j add
type
or
label
properties to their
nodes. This is an ad hoc solution to the problem, with no direct support at the level of
the query languages and APIs. Forthcoming releases of Neo4j, however, will present
users with an enhanced property graph that incorporates labels as first-class citizens of
the data model. Labelling allows us to attach one or more labels to a node; using these
labels we can then determine which roles or functions a node fulfills. On top of that,
we'll be able to ask the graph to find nodes labeled
User
, or
Customer
, or even nodes
labeled both
User
and
Customer
. Subsequent releases will allow us to associate con‐
straints with labels, further enhancing our ability to represent and reason about our
domain. The first release of the enhanced data model is scheduled to occur around the
time this topic goes to press.