Hello, Subgraph

Subgraphs are the primary structures used within Geoff to hold collections of data. These are simply standalone pieces of graph data consisting of nodes and relationships. The following diagram shows a subgraph which illustrates a relationship between the ubiquitous Alice and Bob:

Alice KNOWS Bob

Here, we are modelling a very simple structure consisting of two nodes and one relationship. Within Geoff, each node or relationship is represented by a rule. If we begin with the Alice node, we see it is straightforward to translate this into such a rule:

(A) {"name": "Alice"}

A rule is made up of one mandatory and one optional component. The first component - (A) in the example above - is known as the descriptor and is a string holding a "drawing" of the entity we are representing. The second, optional component is a set of key:value pairs simply known as data and represented here in JSON format. As mentioned in the introduction, these components may be contained in a number of different ways - the following lines show alternative but equivalent representations in both pure JSON and XML:

# JSON string
"(A) {\"name\": \"Alice\"}"

# JSON array
[
  "(A)", {"name": "Alice"}
]

# XML
<rule>
  <descriptor>(A)</descriptor>
  <data>
    <datum key="name" value="Alice" />
  </data>
</rule>

Relationships are modelled similarly to nodes but use a slightly longer descriptor format. The rules below describe the entire example subgraph including both nodes and the relationship between them:

(A) {"name": "Alice"}
(B) {"name": "Bob"}
(A)-[:KNOWS]->(B)

The relationship descriptor draws an unnamed relationship of type "KNOWS" in square brackets connected to its start and end nodes - (A) and (B) - by an ASCII art arrow. This notation should be familiar to users of the Cypher query language. It is also worth noting that this example does not attach any data to the relationship, which serves to highlight its optional nature.