@nelson-ai/graph-traversal
v1.0.1
Published
Gremlin-like graph traversal for JSON-LD
Downloads
20
Readme
Edge Factory Graph Traversal library
This is a graph traversal library, loosely inspired from Gremlin.
Main differences with Gremlin
Gremlin uses a property graph, where edges may have properties. Since Edge Factory is in JSON-LD (aka RDF), edges are predicates and cannot embed attributes.
In the Edge Factory graph,
type
is mandatory. We leverage this by auto-indexing on types.
Playing
We provide a REPL to play with the edge-graph. You can start it by running npm run repl
.
You can then start playing with the API. For example, to
Examples
- fetch all classes that inherit
edgeo:Thing
> g.v('edgeo:Thing').in('subClassOf').get('id')
- get the id and label of Asset instances
> g.t('Asset').get('id', 'label')
- get the levers, count them, add some conditions
> g.t('Lever').count()
> g.t('Lever').has('timeHorizon', 12).count()
> g.v('edger:process1').out('levers').get('id', 'timeHorizon')
> g.v('edger:process1').out('levers').count()
> g.v('edger:process1').out('levers').has('timeHorizon', 12).count()
> g.v('edger:process1').out('levers').has('timeHorizon', 12).get('id', 'timeHorizon')
API
TODO: list all API methods
Gotchas :
g.v
- id => return a Vertex
- array of id => return a VertexList
VertexList.filter
The data received by a filter function is a Vertex, not a POJO. Use get() to access data fields...
const r = g.v('test:edge')
.in('worksFor')
.filter(p => p.get().age < 30)
.get('id', 'age');