From 1fbf9c9f7e9ffb1b15e4c2e352d85b1686674778 Mon Sep 17 00:00:00 2001 From: David Ballester Mena Date: Thu, 8 Aug 2019 20:17:20 +0200 Subject: [PATCH] feat(text): remove multiple nodes as valid graph --- src/services/graph-grammar.js | 6 +-- src/services/graph-grammar.spec.js | 71 ------------------------------ 2 files changed, 3 insertions(+), 74 deletions(-) diff --git a/src/services/graph-grammar.js b/src/services/graph-grammar.js index 8c553fb..0ec1581 100644 --- a/src/services/graph-grammar.js +++ b/src/services/graph-grammar.js @@ -9,7 +9,7 @@ Grapher { path = partialPath+ node --partials - | node+ --nodes + | node --node partialPath = node link @@ -82,8 +82,8 @@ class GraphGrammar { groups: groups.map(mapGroup).filter((item, index, groups) => groups.findIndex((candidate) => candidate.name === item.name) === index), }; }, - path_nodes: (nodes) => { - const entities = _flattenDeep(nodes.eval()); + path_node: (node) => { + const entities = node.eval(); return { nodes: entities.filter(({ type }) => type === 'node').map(mapNode), groups: entities diff --git a/src/services/graph-grammar.spec.js b/src/services/graph-grammar.spec.js index a3066a4..10b4b9e 100644 --- a/src/services/graph-grammar.spec.js +++ b/src/services/graph-grammar.spec.js @@ -28,11 +28,6 @@ describe('graph-grammar', () => { expect(matchResult.succeeded()).toBeTruthy(); }); - it('matches multiple nodes', () => { - const matchResult = graphGrammar.match('(foo)(bar)(baz)'); - expect(matchResult.succeeded()).toBeTruthy(); - }); - it('matches simple paths', () => { const matchResult = graphGrammar.match('(foo)->(bar)'); expect(matchResult.succeeded()).toBeTruthy(); @@ -106,24 +101,6 @@ describe('graph-grammar', () => { }); }); - it('turns multiple nodes into an object with a multiple nodes', () => { - const result = graphGrammar.eval(graphGrammar.match('(foo)(bar)(baz)')); - expect(result).toEqual({ - nodes: [ - { - id: 'foo', - }, - { - id: 'bar', - }, - { - id: 'baz', - }, - ], - groups: [], - }); - }); - it('creates a link with the specified label', () => { const result = graphGrammar.eval(graphGrammar.match('(foo)-[baz]->(bar)')); expect(result.links).toEqual([ @@ -275,54 +252,6 @@ describe('graph-grammar', () => { }); }); - it('turns two nodes with repeated groups into a node and non-repeated groups', () => { - const result = graphGrammar.eval(graphGrammar.match('(foo:bar:baz)(qux:bar:quux)')); - expect(result).toEqual({ - nodes: [ - { - id: 'foo', - groups: [ - { - id: expect.anything(), - name: 'bar', - }, - { - id: expect.anything(), - name: 'baz', - }, - ], - }, - { - id: 'qux', - groups: [ - { - id: expect.anything(), - name: 'bar', - }, - { - id: expect.anything(), - name: 'quux', - }, - ], - }, - ], - groups: [ - { - id: expect.anything(), - name: 'bar', - }, - { - id: expect.anything(), - name: 'baz', - }, - { - id: expect.anything(), - name: 'quux', - }, - ], - }); - }); - it('turns a simple path with groups into those nodes, link and groups', () => { const result = graphGrammar.eval(graphGrammar.match('(foo)-[:qux]->(bar)')); expect(result).toEqual({