Skip to content

Commit

Permalink
docs(guides): split out path-types.md from path-composition.md guide
Browse files Browse the repository at this point in the history
  • Loading branch information
akollegger committed Dec 10, 2020
1 parent 66a19a7 commit 88ebbb9
Show file tree
Hide file tree
Showing 24 changed files with 705 additions and 303 deletions.
100 changes: 14 additions & 86 deletions docs/_guides/path-composition.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,100 +4,28 @@ title: Path Composition

Paths are like self-aware lists -- they contain ordered elements _and_ information about themselves.

The canonical example is [U.S. Route 66](https://en.wikipedia.org/wiki/U.S._Route_66), an historic highway
popularized in songs, movies and books. The route is both a series of roads connecting locations, and
a thing-in-itself. Where does information about Route 66 go? On the path itself.

`[route66:Historic:Highway {established: date`1926-11-26`} (santaMonica)-->(beverlyHills)-->(chicago)]`
The California segment of Route-66:

## Type Definitions
```
[ route66inCA:Historic:Highway {established: date`1926-11-26`}
(santaMonica)-->(losAngeles)-->(pasadena)-->
(eastPasadena)-->(monrovia)-->(azusa)-->
(upland)-->(sanBernadino)-->(devore)-->
(cajonJunction)-->(victorville)-->(barstow)
]
```

### Paths
### Paths all the way down (or up)

Paths are either empty or the composition of two paths.

~~~
data Path = empty | path (Path) (Path)
empty :: Path
path :: Path --> Path --> Path
~~~

### Graph elements

Graph elements are special cases of a Path.

A Node is a Path of length.

~~~
type Node = Path
node :: Empty --> Empty --> Node
~~~


An Edge is a Path of length 1 containing two Nodes.
~~~
type Edge = Path
edge :: Node --> Node --> Edge
~~~

### Path sequence

A Path Sequence is an ordered list of Paths. The elements are composed pairwise to produce the final Path representation. The order of pairing is left-to-right.

~~~
type PathSequence = List Path
foldPath :: PathSequence --> Path
~~~

### Graphs

The classic graph 𝔾 = (𝕍, 𝔼) is derived from Paths.

In Gram, 𝕍 is an ordered set of nodes. The position of any

𝔼 is a set of edges which compose any two nodes (or the same node twice) from the `NodeSet`. The order of appearance within a Path represents a sort of additive history for the graph elements. Record values and labels are merged forward.

~~~
type NodeSet = List Node
nodes :: Path --> List Node
~~~
~~~
type EdgeSet = List Edge
edges :: Path --> List Edge
~~~

~~~
type Graph = { nodes :: NodeSet, edges :: EdgeSet, paths :: PathSeq }
~~~

## Path Notation

Gram uses two complementary notations for paths:

1. Cypher node patterns: alternating nodes and edges
2. Path composition: two paths composed into a new path

Both notations can compose the these kinds of paths:

| kind | use |
| <-- | oriented to the left |
| --> | oriented to the right |
| —— | oriented in either direction |
| , | pairwise association |


| | Empty | Node | Edge | Path |
| Cypher path | | `(n)` | `(n1)-[e]->(n2)` | `p = ()-->(),()<--()` |
| Path composition | `[ø]` | `[n ø ø]` | `[e --> n1 n2]` | `[p , p1 p2]` |

Cypher path notation is easier to read. Path composition is harder to read. The notation can be mixed to annotate information about a cypher path. These three notations are equivalent:

Cypher path p = (n1)-[e1]->(n2)<-[e2]-(n3)
Path composition [p [e1 --> n1 [e2 <-- n2 n3] ] ]
Mixed notation [p (n1)-[e1]->(n2)<-[e2]-(n3)]


---

### _Footnotes_

- [Mostly Adequate guide to Hindley-Milner type system](https://mostly-adequate.gitbooks.io/mostly-adequate-guide/content/ch07.html)
- [Cypher data patterns](https://neo4j.com/docs/cypher-manual/current/syntax/patterns/#cypher-pattern-related-nodes)
innovated the ascii-art representation of round graph nodes `(a)` and interrupted arrows `-[e]->` for graph relationships.
- [Thing-in-itself](https://en.wikipedia.org/wiki/Thing-in-itself) (misused here) is a deepr notion about existence and observation.
119 changes: 119 additions & 0 deletions docs/_guides/path-types.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
---
title: Path Types
---

Paths are like self-aware lists -- they contain ordered elements _and_ information about themselves.

The canonical example is [U.S. Route 66](https://en.wikipedia.org/wiki/U.S._Route_66), an historic highway
popularized in songs, movies and books. The route is both a series of roads connecting locations, and
a thing-in-itself. Where does information about Route 66 go? On the path itself.

The California segment of Route-66:

```
[ route66inCA:Historic:Highway {established: date`1926-11-26`}
(santaMonica)-->(losAngeles)-->(pasadena)-->
(eastPasadena)-->(monrovia)-->(azusa)-->
(upland)-->
]
```

### Paths all the way down (or up)



## Type Definitions

### Paths

Paths are either empty or the composition of two paths.

~~~
data Path = empty | path (Path) (Path)
empty :: Path
path :: Path --> Path --> Path
~~~

### Graph elements

Graph elements are special cases of a Path.

A Node is a Path of length 0.

~~~
type Node = Path
node :: Empty --> Empty --> Node
~~~


An Edge is a Path of length 1 containing two Nodes.
~~~
type Edge = Path
edge :: Node --> Node --> Edge
~~~

### Path sequence

A Path Sequence is an ordered list of Paths. The elements are composed pairwise to produce the final Path representation. The order of pairing is left-to-right.

~~~
type PathSequence = List Path
foldPath :: PathSequence --> Path
~~~

### Graphs

The classic graph 𝔾 = (𝕍, 𝔼) is derived from Paths.

In Gram, 𝕍 is an ordered set of nodes. The position of any

𝔼 is a set of edges which compose any two nodes (or the same node twice) from the `NodeSet`. The order of appearance within a Path represents a sort of additive history for the graph elements. Record values and labels are merged forward.

~~~
type NodeSet = List Node
nodes :: Path --> List Node
~~~
~~~
type EdgeSet = List Edge
edges :: Path --> List Edge
~~~

~~~
type Graph = { nodes :: NodeSet, edges :: EdgeSet, paths :: PathSeq }
~~~

## Path Notation

Gram uses two complementary notations for paths:

1. Cypher node patterns: alternating nodes and edges
2. Path composition: two paths composed into a new path

Both notations can compose the these kinds of paths:

| kind | use |
| <-- | oriented to the left |
| --> | oriented to the right |
| —— | oriented in either direction |
| , | pairwise association |


| | Empty | Node | Edge | Path |
| Cypher path | | `(n)` | `(n1)-[e]->(n2)` | `p = ()-->(),()<--()` |
| Path composition | `[ø]` | `[n ø ø]` | `[e --> n1 n2]` | `[p , p1 p2]` |

Cypher path notation is easier to read. Path composition is harder to read. The notation can be mixed to annotate information about a cypher path. These three notations are equivalent:

Cypher path p = (n1)-[e1]->(n2)<-[e2]-(n3)
Path composition [p [e1 --> n1 [e2 <-- n2 n3] ] ]
Mixed notation [p (n1)-[e1]->(n2)<-[e2]-(n3)]


---

### _Footnotes_

- [Thing-in-itself](https://en.wikipedia.org/wiki/Thing-in-itself) (misused here) is a deepr notion about existence and observation.
- [Mostly Adequate guide to Hindley-Milner type system](https://mostly-adequate.gitbooks.io/mostly-adequate-guide/content/ch07.html)
- [Cypher data patterns](https://neo4j.com/docs/cypher-manual/current/syntax/patterns/#cypher-pattern-related-nodes)
innovated the ascii-art representation of round graph nodes `(a)` and interrupted arrows `-[e]->` for graph relationships.
4 changes: 2 additions & 2 deletions docs/_site/api/interfaces/gram_ast.dateliteral.html
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ <h3>tag</h3>
<aside class="tsd-sources">
<p>Overrides <a href="gram_ast.taggedtextliteral.html">TaggedTextLiteral</a>.<a href="gram_ast.taggedtextliteral.html#tag">tag</a></p>
<ul>
<li>Defined in packages/gram-ast/src/index.ts:494</li>
<li>Defined in packages/gram-ast/src/index.ts:492</li>
</ul>
</aside>
</section>
Expand All @@ -204,7 +204,7 @@ <h3>type</h3>
<p>Inherited from <a href="gram_ast.taggedtextliteral.html">TaggedTextLiteral</a>.<a href="gram_ast.taggedtextliteral.html#type">type</a></p>
<p>Overrides <a href="gram_ast.textliteral.html">TextLiteral</a>.<a href="gram_ast.textliteral.html#type">type</a></p>
<ul>
<li>Defined in packages/gram-ast/src/index.ts:472</li>
<li>Defined in packages/gram-ast/src/index.ts:470</li>
</ul>
</aside>
</section>
Expand Down
4 changes: 2 additions & 2 deletions docs/_site/api/interfaces/gram_ast.datetimeliteral.html
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ <h3>tag</h3>
<aside class="tsd-sources">
<p>Overrides <a href="gram_ast.taggedtextliteral.html">TaggedTextLiteral</a>.<a href="gram_ast.taggedtextliteral.html#tag">tag</a></p>
<ul>
<li>Defined in packages/gram-ast/src/index.ts:533</li>
<li>Defined in packages/gram-ast/src/index.ts:531</li>
</ul>
</aside>
</section>
Expand All @@ -206,7 +206,7 @@ <h3>type</h3>
<p>Inherited from <a href="gram_ast.taggedtextliteral.html">TaggedTextLiteral</a>.<a href="gram_ast.taggedtextliteral.html#type">type</a></p>
<p>Overrides <a href="gram_ast.textliteral.html">TextLiteral</a>.<a href="gram_ast.textliteral.html#type">type</a></p>
<ul>
<li>Defined in packages/gram-ast/src/index.ts:472</li>
<li>Defined in packages/gram-ast/src/index.ts:470</li>
</ul>
</aside>
</section>
Expand Down
4 changes: 2 additions & 2 deletions docs/_site/api/interfaces/gram_ast.durationliteral.html
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ <h3>tag</h3>
<aside class="tsd-sources">
<p>Overrides <a href="gram_ast.taggedtextliteral.html">TaggedTextLiteral</a>.<a href="gram_ast.taggedtextliteral.html#tag">tag</a></p>
<ul>
<li>Defined in packages/gram-ast/src/index.ts:556</li>
<li>Defined in packages/gram-ast/src/index.ts:554</li>
</ul>
</aside>
</section>
Expand All @@ -204,7 +204,7 @@ <h3>type</h3>
<p>Inherited from <a href="gram_ast.taggedtextliteral.html">TaggedTextLiteral</a>.<a href="gram_ast.taggedtextliteral.html#type">type</a></p>
<p>Overrides <a href="gram_ast.textliteral.html">TextLiteral</a>.<a href="gram_ast.textliteral.html#type">type</a></p>
<ul>
<li>Defined in packages/gram-ast/src/index.ts:472</li>
<li>Defined in packages/gram-ast/src/index.ts:470</li>
</ul>
</aside>
</section>
Expand Down
36 changes: 14 additions & 22 deletions docs/_site/api/interfaces/gram_ast.taggedtextliteral.html
Original file line number Diff line number Diff line change
Expand Up @@ -106,19 +106,15 @@ <h1>Interface TaggedTextLiteral</h1>
</div><div class="tsd-comment tsd-typography tsd-comment-text">
<p>Some well-known tags:</p>
<ul>
<li>&quot;md<code># Hello World</code>&quot;</li>
<li>&quot;html<code>&lt;h1&gt;Hello World&lt;/h1&gt;</code>&quot;</li>
<li>&quot;date<code>2020-07-14</code>&quot;</li>
<li>&quot;time<code>17:35:42</code>&quot;</li>
<li>&quot;uri<code>https://gram-data.github.io</code>&quot;</li>
<li>&quot;wkt`POINT(-83.123 42.123)&quot;</li>
<li><code>md\</code># Hello World``</li>
<li><code>html\</code><h1>Hello World</h1>``</li>
<li><code>date\</code>2020-07-14```</li>
<li><code>time\</code>17:35:42``</li>
<li><code>uri\</code><a href="https://gram-data.github.io%5C%60">https://gram-data.github.io\`</a></li>
<li><code>wkt\</code>POINT(-83.123 42.123)``</li>
</ul>
</div><div class="tsd-comment tsd-typography tsd-comment-tags">
<dl class="tsd-comment-tags"><dt>see</dt>
<dd><p><a href="gram_ast.dateliteral.html">DateLiteral</a></p>
</dd><dt>see</dt>
<dd><p>{@link GeospatialLiteral}</p>
</dd><dt>see</dt>
<dd><p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals" class="external">Wikipedia Template literals</a></p>
</dd></dl>
</div></section>
Expand Down Expand Up @@ -168,19 +164,15 @@ <h3 class="tsd-before-signature">Indexable</h3>
</div><div class="tsd-comment tsd-typography tsd-comment-text">
<p>Some well-known tags:</p>
<ul>
<li>&quot;md<code># Hello World</code>&quot;</li>
<li>&quot;html<code>&lt;h1&gt;Hello World&lt;/h1&gt;</code>&quot;</li>
<li>&quot;date<code>2020-07-14</code>&quot;</li>
<li>&quot;time<code>17:35:42</code>&quot;</li>
<li>&quot;uri<code>https://gram-data.github.io</code>&quot;</li>
<li>&quot;wkt`POINT(-83.123 42.123)&quot;</li>
<li><code>md\</code># Hello World``</li>
<li><code>html\</code><h1>Hello World</h1>``</li>
<li><code>date\</code>2020-07-14```</li>
<li><code>time\</code>17:35:42``</li>
<li><code>uri\</code><a href="https://gram-data.github.io%5C%60">https://gram-data.github.io\`</a></li>
<li><code>wkt\</code>POINT(-83.123 42.123)``</li>
</ul>
</div><div class="tsd-comment tsd-typography tsd-comment-tags">
<dl class="tsd-comment-tags"><dt>see</dt>
<dd><p><a href="gram_ast.dateliteral.html">DateLiteral</a></p>
</dd><dt>see</dt>
<dd><p>{@link GeospatialLiteral}</p>
</dd><dt>see</dt>
<dd><p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals" class="external">Wikipedia Template literals</a></p>
</dd></dl>
</div>
Expand Down Expand Up @@ -242,7 +234,7 @@ <h3>tag</h3>
<div class="tsd-signature tsd-kind-icon">tag<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">string</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in packages/gram-ast/src/index.ts:477</li>
<li>Defined in packages/gram-ast/src/index.ts:475</li>
</ul>
</aside>
<div class="tsd-comment tsd-typography tsd-comment-shorttext">
Expand All @@ -258,7 +250,7 @@ <h3>type</h3>
<aside class="tsd-sources">
<p>Overrides <a href="gram_ast.textliteral.html">TextLiteral</a>.<a href="gram_ast.textliteral.html#type">type</a></p>
<ul>
<li>Defined in packages/gram-ast/src/index.ts:472</li>
<li>Defined in packages/gram-ast/src/index.ts:470</li>
</ul>
</aside>
</section>
Expand Down
4 changes: 2 additions & 2 deletions docs/_site/api/interfaces/gram_ast.timeintervalliteral.html
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ <h3>tag</h3>
<aside class="tsd-sources">
<p>Overrides <a href="gram_ast.taggedtextliteral.html">TaggedTextLiteral</a>.<a href="gram_ast.taggedtextliteral.html#tag">tag</a></p>
<ul>
<li>Defined in packages/gram-ast/src/index.ts:582</li>
<li>Defined in packages/gram-ast/src/index.ts:580</li>
</ul>
</aside>
</section>
Expand All @@ -212,7 +212,7 @@ <h3>type</h3>
<p>Inherited from <a href="gram_ast.taggedtextliteral.html">TaggedTextLiteral</a>.<a href="gram_ast.taggedtextliteral.html#type">type</a></p>
<p>Overrides <a href="gram_ast.textliteral.html">TextLiteral</a>.<a href="gram_ast.textliteral.html#type">type</a></p>
<ul>
<li>Defined in packages/gram-ast/src/index.ts:472</li>
<li>Defined in packages/gram-ast/src/index.ts:470</li>
</ul>
</aside>
</section>
Expand Down
4 changes: 2 additions & 2 deletions docs/_site/api/interfaces/gram_ast.timeliteral.html
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ <h3>tag</h3>
<aside class="tsd-sources">
<p>Overrides <a href="gram_ast.taggedtextliteral.html">TaggedTextLiteral</a>.<a href="gram_ast.taggedtextliteral.html#tag">tag</a></p>
<ul>
<li>Defined in packages/gram-ast/src/index.ts:513</li>
<li>Defined in packages/gram-ast/src/index.ts:511</li>
</ul>
</aside>
</section>
Expand All @@ -204,7 +204,7 @@ <h3>type</h3>
<p>Inherited from <a href="gram_ast.taggedtextliteral.html">TaggedTextLiteral</a>.<a href="gram_ast.taggedtextliteral.html#type">type</a></p>
<p>Overrides <a href="gram_ast.textliteral.html">TextLiteral</a>.<a href="gram_ast.textliteral.html#type">type</a></p>
<ul>
<li>Defined in packages/gram-ast/src/index.ts:472</li>
<li>Defined in packages/gram-ast/src/index.ts:470</li>
</ul>
</aside>
</section>
Expand Down
Loading

0 comments on commit 88ebbb9

Please sign in to comment.