github.com/cayleygraph/cayley@v0.7.7/docs/glossary.md (about) 1 # Glossary of Terms 2 3 _Note: this definitions in this glossary are sequenced so that they build on each other, one to the next, rather than alphabetically._ 4 5 ## triple 6 7 1. a data entity composed of subject-predicate-object, like "Bob is 35" or "Bob knows Fred". \(A predicate in traditional grammar...is seen as a property that a subject has or is characterized by.\) [source](https://en.wikipedia.org/wiki/Triplestore) and \[source\]\([https://en.wikipedia.org/wiki/Predicate\_\(grammar\)\#Predicates\_in\_traditional\_grammar](https://en.wikipedia.org/wiki/Predicate_%28grammar%29#Predicates_in_traditional_grammar)\) 8 9 ## triplestore 10 11 1. a purpose-built database for the storage and retrieval of triples... [source](https://en.wikipedia.org/wiki/Triplestore) 12 13 ## quad 14 15 1. where triples have the form `{subject, predicate, object}`, quads would have a form along the lines of `{subject, predicate, object, context}` [source](https://en.wikipedia.org/wiki/Named_graph#Named_graphs_and_quads) 16 2. You can add context or extra values to triples that identifies them and makes it easy to define subgraphs, or named properties. [source](https://neo4j.com/blog/rdf-triple-store-vs-labeled-property-graph-difference/) 17 3. From [Cayley godoc](https://godoc.org/github.com/cayleygraph/quad#Quad): 18 19 ```go 20 type Quad struct { 21 Subject Value `json:“subject”` 22 Predicate Value `json:“predicate”` 23 Object Value `json:“object”` 24 Label Value `json:“label,omitempty”` 25 } 26 ``` 27 28 ## link 29 30 1. Another name for a triple, since it "links" any two nodes. 31 2. Given the triple `{A, knows, C}` you would say in graph terminology that `A` and `C` are "vertices" while `knows` is an "edge". You would also say that `A`, `knows`, and `C` are all "nodes", and they are "linked" to one another by the triple. 32 33 ## IRI 34 35 1. IRI is an RDF Internationalized Resource Identifier. [source](https://godoc.org/github.com/cayleygraph/quad#IRI) 36 2. An IRI \(Internationalized Resource Identifier\) within an RDF graph is a Unicode string that conforms to the syntax defined in RFC 3987. [source](https://www.w3.org/TR/rdf11-concepts/#h3_section-IRIs) 37 3. IRIs are a generalization of URIs that permits a wider range of Unicode characters. Every absolute URI and URL is an IRI, but not every IRI is an URI. [source](https://www.w3.org/TR/rdf11-concepts/#h3_section-IRIs) 38 39 ## RDF 40 41 1. [Resource Description Framework](https://en.wikipedia.org/wiki/Resource_Description_Framework), basically a set of standards defined around quads 42 2. An RDF triple consists of three components: 43 1. the subject, which is an IRI or a blank node 44 2. the predicate, which is an IRI 45 3. the object, which is an IRI, a literal or a blank node [source](https://www.w3.org/TR/rdf11-concepts/#h3_section-triples) 46 47 ## RDF store, quad store, named graph, semantic graph database 48 49 1. ...persisting RDF — storing it — became a thing, and these stores were called triple stores. Next they were called quad stores and included information about context and named graphs, then RDF stores, and most recently they call themselves “semantic graph database.” [source](https://neo4j.com/blog/rdf-triple-store-vs-labeled-property-graph-difference/) 50 2. Adding a name to the triple makes a "quad store" or named graph. [source](https://en.wikipedia.org/wiki/Triplestore#Related_database_types) 51 52 ## Cayley 53 54 1. Cayley is a quad store that supports multiple storage backends. It supports multiple query languages for traversing and filtering the named graphs formed by its quads, and it has associated tooling such as a CLI, HTTP server, and so on. 55 56 ## Gizmo 57 58 1. A [Gremlin/TinkerPop](http://tinkerpop.apache.org/)-inspired query language for Cayley. Looks a lot like JavaScript, the syntax is documented [here](https://github.com/cayleygraph/cayley/blob/master/docs/GizmoAPI.md#graphv). 59 60 ## g.V\(\) 61 62 1. For Gremlin/TinkerPop, [g.V\(\) returns a list of all the vertices in the graph](http://tinkerpop.apache.org/docs/3.3.3/tutorials/gremlins-anatomy/#_graphtraversalsource) 63 2. `.v()` is for "Vertex" in Gizmo, and it is used like `pathObject = graph.Vertex([nodeId],[nodeId]...)` \(see \[\[path\|\#path\]\]\) 64 65 ## inbound/outbound predicate 66 67 1. Inbound/outbound refers to the direction of a relation via a predicate. In the case of the triple "A follows B", "follows" is an outbound predicate for `A` and an inbound predicate for `B`. 68 69 In/out predicates can be expressed in a query language, for example using the format `resultSet = subject.out(predicate)` to discover matching `Object`s. In the case of the triple "A follows B", `A.out(“follows”)` would return a set of nodes which contains `B`. An excellent example of this sort of query format is given in the Gremlin/TinkerPop homepage example: 70 71 ```javascript 72 What are the names of projects that were created by two friends? 73 g.V().match( 74 as(“a”).out(“knows”).as(“b”), 75 as(“a”).out(“created”).as(“c”), 76 as(“b”).out(“created”).as(“c”), 77 as(“c”).in(“created”).count().is(2)). 78 select(“c”).by(“name”) 79 ``` 80 81 ## direction 82 83 1. Direction specifies a node's position within a quad. [source](https://godoc.org/github.com/cayleygraph/quad#Direction) 84 85 ```go 86 const ( 87 Any Direction = iota 88 Subject 89 Predicate 90 Object 91 Label 92 ) 93 ``` 94 95 2. Direction is passed to the `Get` method of a quad to access one of its four parts, see [quad.Get\(d Direction\) Value](https://godoc.org/github.com/cayleygraph/quad#Quad.Get) 96 3. The term "Direction" comes about from the concept of traversing a graph. Take for example the triple `{A, follows, B}` and supposing you "select" the predicate `follows`. Now you want to traverse the graph, so you move in the `Object` direction, and you now have `B` selected. Whereas the high-level [path](glossary.md#path) abstraction for queries uses inbound/outbound predicates to represent movement on the graph, the bottom-level [iterator](glossary.md#iterator) mechanic uses Direction. 97 98 ## path 99 100 1. Paths are just a set of helpers to build a query, but they are not that good for building something more complex. You can try using [Shapes](glossary.md#shape) for this - it will give you a full control of what the query actually does. [source](https://discourse.cayley.io/t/a-variety-of-questions/1183/2) 101 2. Path represents either a morphism \(a pre-defined path stored for later use\), or a concrete path, consisting of a morphism and an underlying QuadStore. [source](https://godoc.org/github.com/cayleygraph/cayley/graph/path#Path) 102 3. Underlying code: 103 104 ```go 105 type Path struct { 106 stack []morphism 107 qs graph.QuadStore 108 baseContext pathContext 109 } 110 111 type morphism struct { 112 IsTag bool 113 Reversal func(*pathContext) (morphism, *pathContext) 114 Apply applyMorphism 115 tags []string 116 } 117 118 type applyMorphism func(shape.Shape, *pathContext) (shape.Shape, *pathContext) 119 ``` 120 121 So, as previously stated, the [path](https://godoc.org/github.com/cayleygraph/cayley/graph/path) package is just helper methods on top of the [shape](https://godoc.org/github.com/cayleygraph/cayley/graph/shape) package. 122 123 ## morphism 124 125 1. Morphism is basically a path that is not attached to any particular quadstore or a particular starting point in the graph. Morphisms are meant to be used as a query part that can be applied to other queries to follow a path specified in the Morphism. 126 127 A good example will be a `FollowRecursive` function that will apply a single morphism multiple times to get to all nodes that can be traversed recursively. [source](https://discourse.cayley.io/t/a-variety-of-questions/1183/2) 128 129 ## iterator 130 131 1. So a graph query is roughly represented as a tree of iterators – things 132 133 that implement graph.Iterator. An iterator is \(loosely\) a stand-in for a 134 135 set of things that match a particular portion of the graph. [source](https://discourse.cayley.io/t/7-7-14-question-about-iterator/62) 136 137 ## subiterator 138 139 1. So a graph query is roughly represented as a tree of iterators...Evaluation is merely calling Next\(\) repeatedly on the iterator at the top of the tree. Subiterators, then, are the branches and leaves of the tree. [source](https://discourse.cayley.io/t/7-7-14-question-about-iterator/62) 140 2. Example of converting the Cayley-Gremlin-Go-API query `g.V(“B”).In(“follows”).All()` into an iterator tree: 141 * **HasA** \(subject\) – gets the things in the subject field for: 142 * **And** – the intersection of: 143 * **LinksTo \(predicate\)** links that have the predicate of…: 144 * Fixed iterator containing “follows” – … just the node “follows”. 145 * **LinksTo \(object\)** links that have the object field of: 146 * Fixed iterator containing “B” – … just the node “B” 147 148 ## LinkTo iterator 149 150 1. A LinksTo takes a subiterator of nodes, and contains an iteration of links which "link to" those nodes in a given direction. ... Can be seen as the dual of the HasA iterator. [source](https://github.com/cayleygraph/cayley/blob/1f53d04893ea9b2736e9b2277bbba3f47b88711a/graph/iterator/linksto.go#L17) 151 * Next\(\)ing a LinksTo is straightforward -- iterate through all links to things in the subiterator, and then advance the subiterator, and do it again. 152 * To restate in pseudo-code; `results` is what would be returned in successive `Next()` calls: 153 154 ```go 155 var results []quad.Quad 156 for _, node := range linkTo.subIterator { 157 for _, quad := range allQuads { 158 if quad.Get(linkTo.direction) == node { 159 results = append(results, quad) 160 } 161 } 162 } 163 ``` 164 * Contains\(\)ing a LinksTo means, given a link, take the direction we care about and check if it's in our subiterator. 165 * To restate in pseudo-code: 166 167 ```go 168 for _, node := range linkTo.subIterator { 169 if theLink.Get(linkTo.direction) == node { 170 return true 171 } 172 } 173 return false 174 ``` 175 176 ## HasA iterator 177 178 1. The HasA takes a subiterator of links, and acts as an iterator of nodes in the given direction. The name comes from the idea that a "link HasA subject" or a "link HasA predicate". [source](https://github.com/cayleygraph/cayley/blob/41bf496d9dfe622b385c1482789480df8b106472/graph/iterator/hasa.go#L17) 179 * Next\(\), [We have a subiterator we can get a value from, and we can take that resultant quad, pull our direction out of it, and return that.](https://github.com/cayleygraph/cayley/blob/41bf496d9dfe622b385c1482789480df8b106472/graph/iterator/hasa.go#L206) 180 181 ```go 182 var results []quad.Value 183 for _, quad := range hasA.subIterator { 184 results = append(results, quad.Get(hasA.direction)) 185 } 186 ``` 187 188 * Contains\(\) 189 190 ```go 191 for _, quad := range hasA.subIterator { 192 if quad.Get(hasA.direction) == theNode { 193 return true 194 } 195 } 196 return false 197 ``` 198 199 ## shape 200 201 1. Shape represent a query tree shape. [source](https://godoc.org/github.com/cayleygraph/cayley/graph/shape#Shape) 202 203 ```go 204 type Shape interface { 205 BuildIterator(qs graph.QuadStore) graph.Iterator 206 Optimize(r Optimizer) (Shape, bool) 207 } 208 ``` 209 210 2. This is the most interesting part of the query system - it describes how exactly the query looks like. ... This package also describes different query optimizations that are not specific to a backend. ... You can write a query using either Paths, Shapes or raw Iterators... [source](https://discourse.cayley.io/t/a-variety-of-questions/1183/2) 211 3. A Shape seems to be an abstract representation of a query, a level above Iterators and a level below Paths. You can perform various operations on it \(traverse inbound/outbound predicates, find unions and intersections, etc.\) and most importantly build a tree of Iterators from it, which will do the mechanical act of processing quads to find results. 212 213 ## token 214 215 1. In the context of a [quad store](https://godoc.org/github.com/cayleygraph/cayley/graph#QuadStore), a [graph.Value](https://godoc.org/github.com/cayleygraph/cayley/graph#Value). However the backend wishes to implement it, a Value is merely a token to a quad or a node that the backing store itself understands, and the base iterators pass around. 216 217 For example, in a very traditional, graphd-style graph, these are int64s \(guids of the primitives\). In a very direct sort of graph, these could be pointers to structs, or merely quads, or whatever works best for the backing store. 218 219 ## reification 220 221 1. “With reification, we create a metagraph on top of our graph that represents the statement that we have here. We create a new node that represents a statement and points at the subject...” [source](https://neo4j.com/blog/rdf-triple-store-vs-labeled-property-graph-difference/) 222 2. Reifying a relationship means viewing it as an entity. The purpose of reifying a relationship is to make it explicit, when additional information needs to be added to it. 223 224 Viewing a relationship as an entity, one can say that the entity reifies the relationship. This is called reification of a relationship. Like any other entity, it must be an instance of an entity type. [source](https://en.wikipedia.org/wiki/Reification_) 225