mementus 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mementus/graph_builder.rb +2 -34
- data/lib/mementus/mutable_graph.rb +11 -0
- data/lib/mementus/mutators.rb +37 -0
- data/lib/mementus/version.rb +1 -1
- data/lib/mementus.rb +2 -0
- data/spec/graph_spec.rb +0 -12
- data/spec/mutable_graph_spec.rb +116 -0
- metadata +7 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f193ed0050a256b3b529dd997fafe002fbe7697e
|
4
|
+
data.tar.gz: e928862b3e4e55e1ce0ac1050eec7457238a7ce2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c9f0a1203c8cc72cbcaeb26383f8f38181f50863267f71fe64c3f429cb007fcc311cf8a380cc06690df3b9e1a3340c65c269c19775723b580cac78c782e33ecd
|
7
|
+
data.tar.gz: c0495f33c80d74d81212df81f9314eb198f8c40e5e18bf5cc10697934f72ec9279f0e1e4be2488a46c63f5f90160f00652afbe0533c2fb812b3483d99ebcb7ac
|
@@ -1,45 +1,13 @@
|
|
1
1
|
module Mementus
|
2
2
|
class GraphBuilder
|
3
|
+
include Mutators
|
4
|
+
|
3
5
|
def initialize(is_directed)
|
4
6
|
@structure = Structure::IncidenceList.new(is_directed)
|
5
7
|
@node_ids = IntegerId.new
|
6
8
|
@edge_ids = IntegerId.new
|
7
9
|
end
|
8
10
|
|
9
|
-
def set_node(node)
|
10
|
-
@structure.set_node(node)
|
11
|
-
node
|
12
|
-
end
|
13
|
-
|
14
|
-
def set_edge(edge)
|
15
|
-
@structure.set_edge(edge)
|
16
|
-
edge
|
17
|
-
end
|
18
|
-
|
19
|
-
def add_node(id: nil, label: nil, props: {})
|
20
|
-
id = @node_ids.next_id unless id
|
21
|
-
set_node(Node.new(id: id, label: label, props: props))
|
22
|
-
end
|
23
|
-
|
24
|
-
def add_edge(id: nil, from: nil, to: nil, label: nil, props: {})
|
25
|
-
id = @edge_ids.next_id unless id
|
26
|
-
set_edge(Edge.new(id: id, from: from, to: to, label: label, props: props))
|
27
|
-
end
|
28
|
-
|
29
|
-
def create_node(&block)
|
30
|
-
builder = NodeBuilder.new
|
31
|
-
yield builder
|
32
|
-
builder.id = @node_ids.next_id unless builder.id
|
33
|
-
set_node(builder.to_node)
|
34
|
-
end
|
35
|
-
|
36
|
-
def create_edge(&block)
|
37
|
-
builder = EdgeBuilder.new
|
38
|
-
yield builder
|
39
|
-
builder.id = @edge_ids.next_id unless builder.id
|
40
|
-
set_edge(builder.to_edge)
|
41
|
-
end
|
42
|
-
|
43
11
|
def graph
|
44
12
|
@structure
|
45
13
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Mementus
|
2
|
+
module Mutators
|
3
|
+
def set_node(node)
|
4
|
+
@structure.set_node(node)
|
5
|
+
node
|
6
|
+
end
|
7
|
+
|
8
|
+
def set_edge(edge)
|
9
|
+
@structure.set_edge(edge)
|
10
|
+
edge
|
11
|
+
end
|
12
|
+
|
13
|
+
def add_node(id: nil, label: nil, props: {})
|
14
|
+
id = @node_ids.next_id unless id
|
15
|
+
set_node(Node.new(id: id, label: label, props: props))
|
16
|
+
end
|
17
|
+
|
18
|
+
def add_edge(id: nil, from: nil, to: nil, label: nil, props: {})
|
19
|
+
id = @edge_ids.next_id unless id
|
20
|
+
set_edge(Edge.new(id: id, from: from, to: to, label: label, props: props))
|
21
|
+
end
|
22
|
+
|
23
|
+
def create_node(&block)
|
24
|
+
builder = NodeBuilder.new
|
25
|
+
yield builder
|
26
|
+
builder.id = @node_ids.next_id unless builder.id
|
27
|
+
set_node(builder.to_node)
|
28
|
+
end
|
29
|
+
|
30
|
+
def create_edge(&block)
|
31
|
+
builder = EdgeBuilder.new
|
32
|
+
yield builder
|
33
|
+
builder.id = @edge_ids.next_id unless builder.id
|
34
|
+
set_edge(builder.to_edge)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/mementus/version.rb
CHANGED
data/lib/mementus.rb
CHANGED
data/spec/graph_spec.rb
CHANGED
@@ -123,18 +123,6 @@ describe Mementus::Graph do
|
|
123
123
|
end
|
124
124
|
end
|
125
125
|
|
126
|
-
specify '#create_edge -> with props' do
|
127
|
-
graph = Mementus::Graph.new do
|
128
|
-
create_edge do |edge|
|
129
|
-
edge.from = 'A'
|
130
|
-
edge.to = 'B'
|
131
|
-
edge.props = {
|
132
|
-
name: 'Relationship'
|
133
|
-
}
|
134
|
-
end
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
126
|
specify '#has_node?' do
|
139
127
|
graph = Mementus::Graph.new do
|
140
128
|
set_node(node_1)
|
@@ -0,0 +1,116 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Mementus::MutableGraph do
|
4
|
+
specify '#new' do
|
5
|
+
graph = Mementus::MutableGraph.new
|
6
|
+
|
7
|
+
expect(graph.nodes_count).to eq(0)
|
8
|
+
expect(graph.edges_count).to eq(0)
|
9
|
+
end
|
10
|
+
|
11
|
+
specify '#set_node' do
|
12
|
+
graph = Mementus::MutableGraph.new
|
13
|
+
graph.set_node(node_1)
|
14
|
+
|
15
|
+
expect(graph.nodes_count).to eq(1)
|
16
|
+
expect(graph.edges_count).to eq(0)
|
17
|
+
end
|
18
|
+
|
19
|
+
specify '#add_node' do
|
20
|
+
graph = Mementus::MutableGraph.new
|
21
|
+
graph.add_node(id: 1)
|
22
|
+
|
23
|
+
expect(graph.nodes_count).to eq(1)
|
24
|
+
expect(graph.edges_count).to eq(0)
|
25
|
+
expect(graph.node(1).id).to eq(1)
|
26
|
+
end
|
27
|
+
|
28
|
+
specify '#add_node -> with auto id' do
|
29
|
+
graph = Mementus::MutableGraph.new
|
30
|
+
graph.add_node
|
31
|
+
|
32
|
+
expect(graph.node(1).id).to eq(1)
|
33
|
+
end
|
34
|
+
|
35
|
+
specify '#add_node -> with props' do
|
36
|
+
graph = Mementus::MutableGraph.new
|
37
|
+
graph.add_node(props: { title: 'Vertex' })
|
38
|
+
|
39
|
+
expect(graph.node(1)[:title]).to eq('Vertex')
|
40
|
+
end
|
41
|
+
|
42
|
+
specify '#create_node' do
|
43
|
+
graph = Mementus::MutableGraph.new
|
44
|
+
graph.create_node do |node|
|
45
|
+
node.id = 20
|
46
|
+
node.label = :vertex
|
47
|
+
node.props[:title] = 'Vertex'
|
48
|
+
end
|
49
|
+
|
50
|
+
expect(graph.nodes_count).to eq(1)
|
51
|
+
expect(graph.edges_count).to eq(0)
|
52
|
+
|
53
|
+
graph.node(20).tap do |node|
|
54
|
+
expect(node.id).to eq(20)
|
55
|
+
expect(node.label).to eq(:vertex)
|
56
|
+
expect(node[:title]).to eq('Vertex')
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
specify '#set_edge' do
|
61
|
+
graph = Mementus::MutableGraph.new
|
62
|
+
graph.set_edge(edge_1_2)
|
63
|
+
|
64
|
+
expect(graph.nodes_count).to eq(2)
|
65
|
+
expect(graph.edges_count).to eq(1)
|
66
|
+
expect(graph.node(1).id).to eq(1)
|
67
|
+
expect(graph.node(2).id).to eq(2)
|
68
|
+
end
|
69
|
+
|
70
|
+
specify '#add_edge' do
|
71
|
+
graph = Mementus::MutableGraph.new
|
72
|
+
graph.add_edge(id: 3, from: 1, to: 2)
|
73
|
+
|
74
|
+
expect(graph.nodes_count).to eq(2)
|
75
|
+
expect(graph.edges_count).to eq(1)
|
76
|
+
expect(graph.node(1).id).to eq(1)
|
77
|
+
expect(graph.node(2).id).to eq(2)
|
78
|
+
expect(graph.edge(3).id).to eq(3)
|
79
|
+
end
|
80
|
+
|
81
|
+
specify '#add_edge -> with auto id' do
|
82
|
+
graph = Mementus::MutableGraph.new
|
83
|
+
graph.add_edge(from: 1, to: 2)
|
84
|
+
|
85
|
+
expect(graph.edge(1).id).to eq(1)
|
86
|
+
end
|
87
|
+
|
88
|
+
specify '#add_edge -> with props' do
|
89
|
+
graph = Mementus::MutableGraph.new
|
90
|
+
graph.add_edge(from: 1, to: 2, props: { title: 'Relationship' })
|
91
|
+
|
92
|
+
expect(graph.edge(1)[:title]).to eq('Relationship')
|
93
|
+
end
|
94
|
+
|
95
|
+
specify '#create_edge' do
|
96
|
+
graph = Mementus::MutableGraph.new
|
97
|
+
graph.create_edge do |edge|
|
98
|
+
edge.id = 123
|
99
|
+
edge.label = :relationship
|
100
|
+
edge.from = 'A'
|
101
|
+
edge.to = 'B'
|
102
|
+
edge.props[:name] = 'Relationship'
|
103
|
+
end
|
104
|
+
|
105
|
+
expect(graph.nodes_count).to eq(2)
|
106
|
+
expect(graph.edges_count).to eq(1)
|
107
|
+
|
108
|
+
graph.edge(123).tap do |edge|
|
109
|
+
expect(edge.id).to eq(123)
|
110
|
+
expect(edge.label).to eq(:relationship)
|
111
|
+
expect(edge.from.id).to eq('A')
|
112
|
+
expect(edge.to.id).to eq('B')
|
113
|
+
expect(edge[:name]).to eq('Relationship')
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mementus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- maetl
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-12-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -79,6 +79,8 @@ files:
|
|
79
79
|
- lib/mementus/library.rb
|
80
80
|
- lib/mementus/library/herschel_graph.rb
|
81
81
|
- lib/mementus/library/story_graph.rb
|
82
|
+
- lib/mementus/mutable_graph.rb
|
83
|
+
- lib/mementus/mutators.rb
|
82
84
|
- lib/mementus/node.rb
|
83
85
|
- lib/mementus/node_builder.rb
|
84
86
|
- lib/mementus/node_proxy.rb
|
@@ -102,6 +104,7 @@ files:
|
|
102
104
|
- spec/graph_spec.rb
|
103
105
|
- spec/herschel_spec.rb
|
104
106
|
- spec/integer_id_spec.rb
|
107
|
+
- spec/mutable_graph_spec.rb
|
105
108
|
- spec/node_proxy_spec.rb
|
106
109
|
- spec/node_spec.rb
|
107
110
|
- spec/pipeline/step_spec.rb
|
@@ -134,7 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
134
137
|
version: '0'
|
135
138
|
requirements: []
|
136
139
|
rubyforge_project:
|
137
|
-
rubygems_version: 2.6.
|
140
|
+
rubygems_version: 2.6.13
|
138
141
|
signing_key:
|
139
142
|
specification_version: 4
|
140
143
|
summary: Graph data structure toolkit for Ruby applications.
|
@@ -146,6 +149,7 @@ test_files:
|
|
146
149
|
- spec/graph_spec.rb
|
147
150
|
- spec/herschel_spec.rb
|
148
151
|
- spec/integer_id_spec.rb
|
152
|
+
- spec/mutable_graph_spec.rb
|
149
153
|
- spec/node_proxy_spec.rb
|
150
154
|
- spec/node_spec.rb
|
151
155
|
- spec/pipeline/step_spec.rb
|
@@ -158,4 +162,3 @@ test_files:
|
|
158
162
|
- spec/structure/mutable_graph_example.rb
|
159
163
|
- spec/structure/property_graph_example.rb
|
160
164
|
- spec/traversal_spec.rb
|
161
|
-
has_rdoc:
|