mementus 0.5.6 → 0.5.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -1
- data/lib/mementus/breadth_first_search.rb +2 -2
- data/lib/mementus/depth_first_search.rb +1 -1
- data/lib/mementus/graph.rb +3 -3
- data/lib/mementus/library/story_graph.rb +2 -0
- data/lib/mementus/node_proxy.rb +5 -4
- data/lib/mementus/pipeline/step.rb +2 -2
- data/lib/mementus/structure/adjacency_list.rb +12 -4
- data/lib/mementus/structure/incidence_list.rb +10 -6
- data/lib/mementus/version.rb +1 -1
- data/spec/graph_spec.rb +1 -1
- data/spec/node_proxy_spec.rb +4 -4
- data/spec/structure/indexed_graph_example.rb +9 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 75d9e45b6f61e81a565778acd8ca1a93a763d8fb
|
4
|
+
data.tar.gz: 1ce3f1e3a209c02a36fcb84600ac565896a47b6f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 94efd5b8b753183f713b8eb2b66970de1c697b53af99631aa1e31606460b71fd6a0008f5c83e8bdda327243a55b420c494c91e134b799b1bf4780c66a3771f1b
|
7
|
+
data.tar.gz: 1296fc4d4dd27f4d268b8365241ed0e0c383449c4b79a52ada9f7b0b3f721ef4039d62ee7937289e73f405a04e35d86e2bf8d2e7e30c7488df60c0b91b120cc8
|
data/.travis.yml
CHANGED
@@ -14,14 +14,14 @@ module Mementus
|
|
14
14
|
private
|
15
15
|
|
16
16
|
def visit(id, &block)
|
17
|
-
@queue.concat(@graph.
|
17
|
+
@queue.concat(@graph.outgoing(id))
|
18
18
|
|
19
19
|
while next_node = @queue.shift
|
20
20
|
next if @visited[next_node]
|
21
21
|
|
22
22
|
@visited[next_node] = true
|
23
23
|
block.call(next_node)
|
24
|
-
@queue.concat(@graph.
|
24
|
+
@queue.concat(@graph.outgoing(next_node.id))
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
data/lib/mementus/graph.rb
CHANGED
@@ -52,7 +52,7 @@ module Mementus
|
|
52
52
|
@structure.nodes(match)
|
53
53
|
end
|
54
54
|
|
55
|
-
def
|
55
|
+
def outgoing(id, match=nil)
|
56
56
|
@structure.adjacent(id, match)
|
57
57
|
end
|
58
58
|
|
@@ -60,8 +60,8 @@ module Mementus
|
|
60
60
|
@structure.incoming(id, match)
|
61
61
|
end
|
62
62
|
|
63
|
-
def
|
64
|
-
@structure.
|
63
|
+
def outgoing_edges(id, match=nil)
|
64
|
+
@structure.outgoing_edges(id, match)
|
65
65
|
end
|
66
66
|
|
67
67
|
def incoming_edges(id, match=nil)
|
@@ -29,6 +29,7 @@ module Mementus
|
|
29
29
|
edge.from = "start"
|
30
30
|
edge.to = "happy-ending"
|
31
31
|
edge.props[:text] = "Choose wisely."
|
32
|
+
edge.props[:happiness] = 1
|
32
33
|
end
|
33
34
|
|
34
35
|
create_edge do |edge|
|
@@ -37,6 +38,7 @@ module Mementus
|
|
37
38
|
edge.from = "start"
|
38
39
|
edge.to = "tragic-ending"
|
39
40
|
edge.props[:text] = "Choose poorly."
|
41
|
+
edge.props[:happiness] = -1
|
40
42
|
end
|
41
43
|
end
|
42
44
|
end
|
data/lib/mementus/node_proxy.rb
CHANGED
@@ -33,16 +33,17 @@ module Mementus
|
|
33
33
|
@graph.each_adjacent(@node.id, &block)
|
34
34
|
end
|
35
35
|
|
36
|
-
def
|
37
|
-
@graph.
|
36
|
+
def outgoing(match=nil)
|
37
|
+
@graph.outgoing(@node.id, match)
|
38
38
|
end
|
39
39
|
|
40
40
|
def incoming(match=nil)
|
41
41
|
@graph.incoming(@node.id, match)
|
42
42
|
end
|
43
43
|
|
44
|
-
|
45
|
-
|
44
|
+
# TODO: Fix
|
45
|
+
def outgoing_edges(match=nil)
|
46
|
+
@graph.outgoing_edges(@node.id, match)
|
46
47
|
end
|
47
48
|
end
|
48
49
|
end
|
@@ -60,7 +60,7 @@ module Mementus
|
|
60
60
|
# Traverse to the outgoing nodes adjacent to the source elements.
|
61
61
|
def out(match=nil)
|
62
62
|
outgoing_nodes = source.inject([]) do |result, node|
|
63
|
-
result.concat(node.
|
63
|
+
result.concat(node.outgoing(match))
|
64
64
|
end
|
65
65
|
|
66
66
|
Step.new(outgoing_nodes)
|
@@ -78,7 +78,7 @@ module Mementus
|
|
78
78
|
# Traverse to the outgoing edges from the source elements.
|
79
79
|
def out_e(match=nil)
|
80
80
|
outgoing_edges = source.inject([]) do |result, node|
|
81
|
-
result.concat(graph.
|
81
|
+
result.concat(graph.outgoing_edges(node.id, match))
|
82
82
|
end
|
83
83
|
|
84
84
|
Step.new(outgoing_edges)
|
@@ -25,19 +25,27 @@ module Mementus
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def set_edge(edge)
|
28
|
-
set_node(edge.from) unless has_node?(edge.from)
|
29
|
-
set_node(edge.to) unless has_node?(edge.to)
|
28
|
+
set_node(edge.from) unless has_node?(edge.from.id)
|
29
|
+
set_node(edge.to) unless has_node?(edge.to.id)
|
30
30
|
|
31
31
|
@index[edge.from.id].add(edge.to.id)
|
32
32
|
@index[edge.to.id].add(edge.from.id) unless directed?
|
33
33
|
end
|
34
34
|
|
35
35
|
def has_node?(node)
|
36
|
-
|
36
|
+
if node.is_a?(Mementus::Node) || node.is_a?(Mementus::NodeProxy)
|
37
|
+
@index.key?(node.id)
|
38
|
+
else
|
39
|
+
@index.key?(node)
|
40
|
+
end
|
37
41
|
end
|
38
42
|
|
39
43
|
def has_edge?(edge)
|
40
|
-
|
44
|
+
if edge.is_a?(Mementus::Edge) || edge.is_a?(Mementus::EdgeProxy)
|
45
|
+
has_node?(edge.from.id) && @index[edge.from.id].include?(edge.to.id)
|
46
|
+
else
|
47
|
+
raise 'Edge IDs are not supported by this data structure'
|
48
|
+
end
|
41
49
|
end
|
42
50
|
|
43
51
|
def node(id)
|
@@ -24,7 +24,11 @@ module Mementus
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def has_node?(node)
|
27
|
-
|
27
|
+
if node.is_a?(Mementus::Node) || node.is_a?(Mementus::NodeProxy)
|
28
|
+
@nodes.key?(node.id)
|
29
|
+
else
|
30
|
+
@nodes.key?(node)
|
31
|
+
end
|
28
32
|
end
|
29
33
|
|
30
34
|
def has_edge?(edge)
|
@@ -40,8 +44,8 @@ module Mementus
|
|
40
44
|
end
|
41
45
|
|
42
46
|
def set_edge(edge)
|
43
|
-
set_node(edge.from) unless has_node?(edge.from)
|
44
|
-
set_node(edge.to) unless has_node?(edge.to)
|
47
|
+
set_node(edge.from) unless has_node?(edge.from.id)
|
48
|
+
set_node(edge.to) unless has_node?(edge.to.id)
|
45
49
|
|
46
50
|
@edges[edge.id] = EdgeProxy.new(edge, self)
|
47
51
|
@outgoing[edge.from.id] << edge.to.id
|
@@ -119,7 +123,7 @@ module Mementus
|
|
119
123
|
adjacent(id, match, :in)
|
120
124
|
end
|
121
125
|
|
122
|
-
def
|
126
|
+
def incident_edges(id, match=nil, direction=:out)
|
123
127
|
directional_index = case direction
|
124
128
|
when :out then @outgoing_e
|
125
129
|
when :in then @incoming_e
|
@@ -141,11 +145,11 @@ module Mementus
|
|
141
145
|
end
|
142
146
|
|
143
147
|
def outgoing_edges(id, match=nil)
|
144
|
-
|
148
|
+
incident_edges(id, match, :out)
|
145
149
|
end
|
146
150
|
|
147
151
|
def incoming_edges(id, match=nil)
|
148
|
-
|
152
|
+
incident_edges(id, match, :in)
|
149
153
|
end
|
150
154
|
end
|
151
155
|
end
|
data/lib/mementus/version.rb
CHANGED
data/spec/graph_spec.rb
CHANGED
data/spec/node_proxy_spec.rb
CHANGED
@@ -1,23 +1,23 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Mementus::NodeProxy do
|
4
|
-
specify '#
|
4
|
+
specify '#outgoing' do
|
5
5
|
graph = Mementus::Graph.new do
|
6
6
|
set_edge(edge_1_2)
|
7
7
|
set_edge(edge_1_3)
|
8
8
|
end
|
9
9
|
|
10
10
|
node_proxy = Mementus::NodeProxy.new(node_1, graph)
|
11
|
-
expect(node_proxy.
|
11
|
+
expect(node_proxy.outgoing.map { |node| node.id }).to eq([node_2.id, node_3.id])
|
12
12
|
end
|
13
13
|
|
14
|
-
specify '#
|
14
|
+
specify '#outgoing_edges' do
|
15
15
|
graph = Mementus::Graph.new do
|
16
16
|
set_edge(edge_1_2)
|
17
17
|
set_edge(edge_1_3)
|
18
18
|
end
|
19
19
|
|
20
20
|
node_proxy = Mementus::NodeProxy.new(node_1, graph)
|
21
|
-
expect(node_proxy.
|
21
|
+
expect(node_proxy.outgoing_edges.map { |edge| edge.to.id }).to eq([node_2.id, node_3.id])
|
22
22
|
end
|
23
23
|
end
|
@@ -30,16 +30,23 @@ shared_examples_for "an indexed graph data structure" do
|
|
30
30
|
end
|
31
31
|
|
32
32
|
describe '#has_node?' do
|
33
|
-
it 'tests for the presence of a given node' do
|
33
|
+
it 'tests for the presence of a given node by value' do
|
34
34
|
node = Mementus::Node.new(id: 1)
|
35
35
|
structure.set_node(node)
|
36
36
|
|
37
37
|
expect(structure.has_node?(node)).to be true
|
38
38
|
end
|
39
|
+
|
40
|
+
it 'tests for the presence of a given node by id' do
|
41
|
+
node = Mementus::Node.new(id: 1)
|
42
|
+
structure.set_node(node)
|
43
|
+
|
44
|
+
expect(structure.has_node?(1)).to be true
|
45
|
+
end
|
39
46
|
end
|
40
47
|
|
41
48
|
describe '#has_edge?' do
|
42
|
-
it 'tests for the presence of a given edge' do
|
49
|
+
it 'tests for the presence of a given edge by value' do
|
43
50
|
edge = Mementus::Edge.new(from: Mementus::Node.new(id: 1), to: Mementus::Node.new(id: 2))
|
44
51
|
structure.set_edge(edge)
|
45
52
|
|
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.5.
|
4
|
+
version: 0.5.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- maetl
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-10-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|