moory 1.2.6 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/moory.rb +0 -2
- data/lib/moory/version.rb +1 -1
- metadata +2 -6
- data/examples/consequences.rb +0 -77
- data/examples/inductive.rb +0 -82
- data/lib/moory/filter.rb +0 -50
- data/lib/moory/logistic.rb +0 -130
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 983f866752e2c583a5c679b6657a4d4263a40b95518a908ab519579df8b0996d
|
|
4
|
+
data.tar.gz: 1210a2dd052315e9cdf7e394dc81fd1ed3ee768a536b6bb49d7ea65a02c7fc8c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f49ae820cf34be0c9294dd11dd005feb109d6c70c01bc1691719ab7b6b39b03a24a7777b985b63adb6fbbd3db8be939b43f1d219599125c90285df131d1c273d
|
|
7
|
+
data.tar.gz: a94c117a2cab75ed66b1283e92139ad433c3b8751a1c11a809a5196a135d02d937bb6922b0c24b7ef6e1e539c9b9a1aad44d8383a416beac98fb2322601d03c2
|
data/Gemfile.lock
CHANGED
data/lib/moory.rb
CHANGED
data/lib/moory/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: moory
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Adam W. Grant
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2018-08-
|
|
11
|
+
date: 2018-08-16 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -70,14 +70,10 @@ files:
|
|
|
70
70
|
- bin/console
|
|
71
71
|
- bin/setup
|
|
72
72
|
- examples/ab_star.rb
|
|
73
|
-
- examples/consequences.rb
|
|
74
73
|
- examples/decoder.rb
|
|
75
|
-
- examples/inductive.rb
|
|
76
74
|
- lib/moory.rb
|
|
77
75
|
- lib/moory/decoder.rb
|
|
78
|
-
- lib/moory/filter.rb
|
|
79
76
|
- lib/moory/loader.rb
|
|
80
|
-
- lib/moory/logistic.rb
|
|
81
77
|
- lib/moory/machine.rb
|
|
82
78
|
- lib/moory/pair.rb
|
|
83
79
|
- lib/moory/recogniser.rb
|
data/examples/consequences.rb
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
require 'moory'
|
|
2
|
-
|
|
3
|
-
pipcv_config = {
|
|
4
|
-
basis: 'basis',
|
|
5
|
-
specs: {
|
|
6
|
-
'basis' => {
|
|
7
|
-
rules: """
|
|
8
|
-
^ : constant : $
|
|
9
|
-
|
|
10
|
-
^ : variable : $
|
|
11
|
-
|
|
12
|
-
^ : prefix / open / defer : Δ
|
|
13
|
-
|
|
14
|
-
^ : ( / parenthetical / defer : Δ
|
|
15
|
-
|
|
16
|
-
$ : infix / open / defer : Δ
|
|
17
|
-
|
|
18
|
-
Δ : term : $
|
|
19
|
-
""",
|
|
20
|
-
},
|
|
21
|
-
'open' => {
|
|
22
|
-
rules: """
|
|
23
|
-
^ : constant / term / reconvene : $
|
|
24
|
-
|
|
25
|
-
^ : variable / term / reconvene : $
|
|
26
|
-
|
|
27
|
-
^ : prefix / open / defer : Δ
|
|
28
|
-
|
|
29
|
-
^ : ( / parenthetical / defer : Δ
|
|
30
|
-
|
|
31
|
-
$ : infix / open / defer : Δ
|
|
32
|
-
|
|
33
|
-
Δ : term / term / reconvene : $
|
|
34
|
-
""",
|
|
35
|
-
},
|
|
36
|
-
'parenthetical' => {
|
|
37
|
-
rules: """
|
|
38
|
-
^ : constant : C
|
|
39
|
-
|
|
40
|
-
^ : variable : C
|
|
41
|
-
|
|
42
|
-
^ : prefix / open / defer : Δ
|
|
43
|
-
|
|
44
|
-
^ : ( / parenthetical / defer : Δ
|
|
45
|
-
|
|
46
|
-
^ : ) / void / reconvene : $
|
|
47
|
-
|
|
48
|
-
C : infix / open / defer : Δ
|
|
49
|
-
|
|
50
|
-
C : ) / term / reconvene : $
|
|
51
|
-
|
|
52
|
-
Δ : term : C
|
|
53
|
-
"""
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
logistic = Moory::Logistic::Controller.new(pipcv_config)
|
|
59
|
-
|
|
60
|
-
pp logistic.issue('(')
|
|
61
|
-
pp logistic.issue('(')
|
|
62
|
-
pp logistic.issue('prefix')
|
|
63
|
-
pp logistic.issue('constant')
|
|
64
|
-
pp logistic.issue('infix')
|
|
65
|
-
pp logistic.issue('prefix')
|
|
66
|
-
pp logistic.issue('(')
|
|
67
|
-
pp logistic.issue('variable')
|
|
68
|
-
pp logistic.issue('infix')
|
|
69
|
-
pp logistic.issue('prefix')
|
|
70
|
-
pp logistic.issue('(')
|
|
71
|
-
pp logistic.issue('variable')
|
|
72
|
-
pp logistic.issue(')')
|
|
73
|
-
pp logistic.issue(')')
|
|
74
|
-
pp logistic.issue(')')
|
|
75
|
-
pp logistic.issue(')')
|
|
76
|
-
pp logistic.issue('infix')
|
|
77
|
-
pp logistic.issue('variable')
|
data/examples/inductive.rb
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
require 'moory'
|
|
2
|
-
|
|
3
|
-
pipcv_config = {
|
|
4
|
-
basis: 'basis',
|
|
5
|
-
specs: {
|
|
6
|
-
'basis' => {
|
|
7
|
-
rules: """
|
|
8
|
-
^ : constant : $
|
|
9
|
-
|
|
10
|
-
^ : variable : $
|
|
11
|
-
|
|
12
|
-
^ : prefix / open / defer : Δ
|
|
13
|
-
|
|
14
|
-
^ : ( / parenthetical / defer : Δ
|
|
15
|
-
|
|
16
|
-
$ : infix / open / defer : Δ
|
|
17
|
-
|
|
18
|
-
Δ : term : $
|
|
19
|
-
""",
|
|
20
|
-
},
|
|
21
|
-
'open' => {
|
|
22
|
-
rules: """
|
|
23
|
-
^ : constant / term / reconvene : $
|
|
24
|
-
|
|
25
|
-
^ : variable / term / reconvene : $
|
|
26
|
-
|
|
27
|
-
^ : prefix / open / defer : Δ
|
|
28
|
-
|
|
29
|
-
^ : ( / parenthetical / defer : Δ
|
|
30
|
-
|
|
31
|
-
$ : infix / open / defer : Δ
|
|
32
|
-
|
|
33
|
-
Δ : term / term / reconvene : $
|
|
34
|
-
""",
|
|
35
|
-
},
|
|
36
|
-
'parenthetical' => {
|
|
37
|
-
rules: """
|
|
38
|
-
^ : constant : C
|
|
39
|
-
|
|
40
|
-
^ : variable : C
|
|
41
|
-
|
|
42
|
-
^ : prefix / open / defer : Δ
|
|
43
|
-
|
|
44
|
-
^ : ( / parenthetical / defer : Δ
|
|
45
|
-
|
|
46
|
-
^ : ) / void / reconvene : $
|
|
47
|
-
|
|
48
|
-
C : infix / open / defer : Δ
|
|
49
|
-
|
|
50
|
-
C : ) / term / reconvene : $
|
|
51
|
-
|
|
52
|
-
Δ : term : C
|
|
53
|
-
"""
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
logistic = Moory::Logistic::Controller.new(pipcv_config)
|
|
59
|
-
|
|
60
|
-
%w{
|
|
61
|
-
(
|
|
62
|
-
(
|
|
63
|
-
prefix
|
|
64
|
-
constant
|
|
65
|
-
infix
|
|
66
|
-
prefix
|
|
67
|
-
(
|
|
68
|
-
variable
|
|
69
|
-
infix
|
|
70
|
-
prefix
|
|
71
|
-
(
|
|
72
|
-
variable
|
|
73
|
-
)
|
|
74
|
-
)
|
|
75
|
-
)
|
|
76
|
-
)
|
|
77
|
-
infix
|
|
78
|
-
}.each do |w|
|
|
79
|
-
logistic.issue(w)
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
pp logistic.deferrals
|
data/lib/moory/filter.rb
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
module Moory
|
|
2
|
-
class Filter < Moory::Logistic::Unit
|
|
3
|
-
attr_writer :consumer
|
|
4
|
-
attr_writer :quarantine
|
|
5
|
-
attr_reader :buffer
|
|
6
|
-
|
|
7
|
-
IGNORE = [' ', "\t", "\n"]
|
|
8
|
-
DEFAULT_CONSUMER = $stdout.method(:puts)
|
|
9
|
-
IGNORE_UNKNOWN = proc { |c| warn "Warning! Ignoring unknown character: #{c}" }
|
|
10
|
-
|
|
11
|
-
def initialize(rules:, consumer:DEFAULT_CONSUMER, quarantine:IGNORE_UNKNOWN)
|
|
12
|
-
@buffer = ""
|
|
13
|
-
@consumer = consumer
|
|
14
|
-
@quarantine = quarantine
|
|
15
|
-
super(rules: rules)
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def configure(rules)
|
|
19
|
-
super
|
|
20
|
-
repertoire.learn(name: 'produce', item: method(:produce))
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def issue(stimulus)
|
|
24
|
-
return if IGNORE.include?(stimulus)
|
|
25
|
-
|
|
26
|
-
@buffer << stimulus
|
|
27
|
-
super
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
def produce(output)
|
|
31
|
-
consumer.call(@buffer)
|
|
32
|
-
@buffer = ""
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
private
|
|
36
|
-
|
|
37
|
-
def bad_stimulus(stimulus)
|
|
38
|
-
quarantine.call(stimulus)
|
|
39
|
-
@buffer = @buffer.slice(0..-2)
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
def consumer
|
|
43
|
-
@consumer || DEFAULT_CONSUMER
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
def quarantine
|
|
47
|
-
@quarantine || IGNORE_UNKNOWN
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
end
|
data/lib/moory/logistic.rb
DELETED
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
module Moory
|
|
2
|
-
module Logistic
|
|
3
|
-
module NilExtensions
|
|
4
|
-
refine NilClass do
|
|
5
|
-
def <<(other);end
|
|
6
|
-
end
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
class Unit
|
|
10
|
-
include Moory::Efferent
|
|
11
|
-
|
|
12
|
-
def initialize(rules:, initial:'^')
|
|
13
|
-
@initial = initial
|
|
14
|
-
configure(rules)
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def issue(stimulus)
|
|
18
|
-
understand?(stimulus) ?
|
|
19
|
-
super :
|
|
20
|
-
bad_stimulus(stimulus)
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def prime
|
|
24
|
-
@state = @initial
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
private
|
|
28
|
-
|
|
29
|
-
def configure(rules)
|
|
30
|
-
Moory::Loader.load(rules:rules, machine:self)
|
|
31
|
-
prime
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
def bad_stimulus(stimulus)
|
|
35
|
-
raise "Unexpected #{stimulus}"
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
class Controller
|
|
40
|
-
using NilExtensions
|
|
41
|
-
|
|
42
|
-
def initialize(config)
|
|
43
|
-
@config = config
|
|
44
|
-
prepare_units
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
def prepare_units
|
|
48
|
-
create_units
|
|
49
|
-
wire_units
|
|
50
|
-
focus_on(@config[:basis])
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
def units
|
|
54
|
-
@units ||= {}
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
def active_unit
|
|
58
|
-
units[@focus]
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
def deferrals
|
|
62
|
-
@deferrals ||= []
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
def issue(stimulus)
|
|
66
|
-
@consequences = []
|
|
67
|
-
|
|
68
|
-
understand?(stimulus) ?
|
|
69
|
-
distribute(stimulus) :
|
|
70
|
-
nil
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
def understand?(stimulus)
|
|
74
|
-
active_unit.understand?(stimulus)
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
private
|
|
78
|
-
|
|
79
|
-
def create_units
|
|
80
|
-
@config[:specs].each do |name, spec|
|
|
81
|
-
units.store(name, Unit.new(spec))
|
|
82
|
-
end
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
def wire_units
|
|
86
|
-
units.values.each do |v|
|
|
87
|
-
v.repertoire.cram({
|
|
88
|
-
'defer' => method(:defer),
|
|
89
|
-
'reconvene' => method(:reconvene),
|
|
90
|
-
})
|
|
91
|
-
end
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
def focus_on(unit_name)
|
|
95
|
-
@focus = unit_name
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
def distribute(stimulus)
|
|
99
|
-
active_unit.issue(stimulus)
|
|
100
|
-
@consequences
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
def defer(unit_name)
|
|
104
|
-
@consequences << :defer
|
|
105
|
-
|
|
106
|
-
deferrals.push(
|
|
107
|
-
{
|
|
108
|
-
name: @focus.clone,
|
|
109
|
-
state: units[@focus].state.clone
|
|
110
|
-
}
|
|
111
|
-
)
|
|
112
|
-
focus_on(unit_name)
|
|
113
|
-
active_unit.prime
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
def reconvene(stimulus=nil)
|
|
117
|
-
raise "Cannot reconvene without prior deferral" if deferrals.empty?
|
|
118
|
-
|
|
119
|
-
@consequences << :reconvene
|
|
120
|
-
|
|
121
|
-
deferrals.pop.tap do |last_deferral|
|
|
122
|
-
focus_on(last_deferral[:name])
|
|
123
|
-
active_unit.state = last_deferral[:state]
|
|
124
|
-
end
|
|
125
|
-
|
|
126
|
-
active_unit.issue(stimulus) if stimulus
|
|
127
|
-
end
|
|
128
|
-
end
|
|
129
|
-
end
|
|
130
|
-
end
|