reflekt 1.0.5 → 1.0.6
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/lib/{Accessor.rb → accessor.rb} +0 -0
- data/lib/{Action.rb → action.rb} +6 -6
- data/lib/{ActionStack.rb → action_stack.rb} +0 -0
- data/lib/{Clone.rb → clone.rb} +0 -0
- data/lib/{Config.rb → config.rb} +0 -0
- data/lib/{Control.rb → control.rb} +3 -3
- data/lib/experiment.rb +81 -0
- data/lib/{Meta.rb → meta.rb} +0 -0
- data/lib/meta/{ArrayMeta.rb → array_meta.rb} +1 -1
- data/lib/meta/{BooleanMeta.rb → boolean_meta.rb} +1 -1
- data/lib/meta/{FloatMeta.rb → float_meta.rb} +1 -1
- data/lib/meta/{IntegerMeta.rb → integer_meta.rb} +1 -1
- data/lib/meta/{NullMeta.rb → null_meta.rb} +1 -1
- data/lib/meta/{StringMeta.rb → string_meta.rb} +1 -1
- data/lib/{MetaBuilder.rb → meta_builder.rb} +2 -2
- data/lib/{Reflection.rb → reflection.rb} +8 -55
- data/lib/{Reflekt.rb → reflekt.rb} +20 -20
- data/lib/{Renderer.rb → renderer.rb} +0 -0
- data/lib/{Rule.rb → rule.rb} +1 -1
- data/lib/{RuleSet.rb → rule_set.rb} +3 -3
- data/lib/{Aggregator.rb → rule_set_aggregator.rb} +3 -3
- data/lib/rules/{ArrayRule.rb → array_rule.rb} +1 -1
- data/lib/rules/{BooleanRule.rb → boolean_rule.rb} +1 -1
- data/lib/rules/{FloatRule.rb → float_rule.rb} +1 -1
- data/lib/rules/{IntegerRule.rb → integer_rule.rb} +1 -1
- data/lib/rules/{NullRule.rb → null_rule.rb} +1 -1
- data/lib/rules/{StringRule.rb → string_rule.rb} +1 -1
- metadata +29 -28
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: fdefbebdb9516a1fdd8b20c2a5239ae9e2dcc1cb27e5a430589a155a80ccde55
|
|
4
|
+
data.tar.gz: 1c7e77b9ab430f971d9d69332161647762f9065bd73ef4440da0c588520cdd1d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 854ac0d582aef56603e8edae7d11371de656cdb044cf6d94a7d6359c440bfd2430ff8eb4456dcc882bf299be681d82735000062decc1274a36e91d6c269afa4a
|
|
7
|
+
data.tar.gz: '05850d0849fbd0e74026e40497761c3355ea67fedc00cb7c2918362d2250b328dd36887a1ffbc2af83bc54787a0a482b258e6eedf66465abbdf6e2df04a604c7'
|
|
File without changes
|
data/lib/{Action.rb → action.rb}
RENAMED
|
@@ -19,7 +19,7 @@ class Action
|
|
|
19
19
|
attr_accessor :parent
|
|
20
20
|
attr_accessor :child
|
|
21
21
|
attr_accessor :control
|
|
22
|
-
attr_accessor :
|
|
22
|
+
attr_accessor :experiments
|
|
23
23
|
attr_accessor :is_reflecting
|
|
24
24
|
attr_accessor :is_base
|
|
25
25
|
|
|
@@ -28,7 +28,7 @@ class Action
|
|
|
28
28
|
#
|
|
29
29
|
# @param object [Object] The calling object.
|
|
30
30
|
# @param method [Symbol] The calling method.
|
|
31
|
-
# @param reflect_amount [Integer] The number of
|
|
31
|
+
# @param reflect_amount [Integer] The number of experiments to create per action.
|
|
32
32
|
# @param stack [ActionStack] The shadow action call stack.
|
|
33
33
|
##
|
|
34
34
|
def initialize(caller_object, method, reflect_amount, stack)
|
|
@@ -51,7 +51,7 @@ class Action
|
|
|
51
51
|
|
|
52
52
|
# Reflections.
|
|
53
53
|
@control = nil
|
|
54
|
-
@
|
|
54
|
+
@experiments = Array.new(reflect_amount)
|
|
55
55
|
|
|
56
56
|
# State.
|
|
57
57
|
if @stack.peek() == nil
|
|
@@ -64,8 +64,8 @@ class Action
|
|
|
64
64
|
|
|
65
65
|
end
|
|
66
66
|
|
|
67
|
-
def
|
|
68
|
-
@
|
|
67
|
+
def has_empty_experiments?
|
|
68
|
+
@experiments.include? nil
|
|
69
69
|
end
|
|
70
70
|
|
|
71
71
|
##
|
|
@@ -79,7 +79,7 @@ class Action
|
|
|
79
79
|
if is_reflecting?
|
|
80
80
|
return false
|
|
81
81
|
end
|
|
82
|
-
if
|
|
82
|
+
if has_empty_experiments?
|
|
83
83
|
return false
|
|
84
84
|
end
|
|
85
85
|
return true
|
|
File without changes
|
data/lib/{Clone.rb → clone.rb}
RENAMED
|
File without changes
|
data/lib/{Config.rb → config.rb}
RENAMED
|
File without changes
|
|
@@ -18,15 +18,15 @@
|
|
|
18
18
|
# - :error [Symbol] The control reflection produces a system error.
|
|
19
19
|
################################################################################
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
require_relative 'reflection'
|
|
22
|
+
require_relative 'meta_builder'
|
|
23
23
|
|
|
24
24
|
class Control < Reflection
|
|
25
25
|
|
|
26
26
|
##
|
|
27
27
|
# Reflect on a method.
|
|
28
28
|
#
|
|
29
|
-
#
|
|
29
|
+
# Create a shadow action.
|
|
30
30
|
# @param *args [Dynamic] The method's arguments.
|
|
31
31
|
##
|
|
32
32
|
def reflect(*args)
|
data/lib/experiment.rb
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
################################################################################
|
|
2
|
+
# A snapshot of random data.
|
|
3
|
+
#
|
|
4
|
+
# @note
|
|
5
|
+
# A reflection's random values are generated from aggregated control rule sets.
|
|
6
|
+
#
|
|
7
|
+
# @nomenclature
|
|
8
|
+
# args, inputs/output and meta represent different stages of a value.
|
|
9
|
+
#
|
|
10
|
+
# @hierachy
|
|
11
|
+
# 1. Action
|
|
12
|
+
# 2. Experiment <- YOU ARE HERE
|
|
13
|
+
# 3. Meta
|
|
14
|
+
#
|
|
15
|
+
# @status
|
|
16
|
+
# - :pass [Symbol] The reflection passes the rules.
|
|
17
|
+
# - :fail [Symbol] The reflection fails the rules or produces a system error.
|
|
18
|
+
# - :error [Symbol] The control reflection produces a system error.
|
|
19
|
+
################################################################################
|
|
20
|
+
|
|
21
|
+
require_relative 'reflection'
|
|
22
|
+
require_relative 'meta_builder'
|
|
23
|
+
|
|
24
|
+
class Experiment < Reflection
|
|
25
|
+
|
|
26
|
+
##
|
|
27
|
+
# Reflect on a method.
|
|
28
|
+
#
|
|
29
|
+
# Create a shadow action.
|
|
30
|
+
# @param *args [Dynamic] The method's arguments.
|
|
31
|
+
##
|
|
32
|
+
def reflect(*args)
|
|
33
|
+
|
|
34
|
+
# Get aggregated rule sets.
|
|
35
|
+
input_rule_sets = @aggregator.get_input_rule_sets(@klass, @method)
|
|
36
|
+
output_rule_set = @aggregator.get_output_rule_set(@klass, @method)
|
|
37
|
+
|
|
38
|
+
# Fail when no trained rule sets.
|
|
39
|
+
if input_rule_sets.nil?
|
|
40
|
+
@status = :fail
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# When arguments exist.
|
|
44
|
+
unless args.size == 0
|
|
45
|
+
|
|
46
|
+
# Create random arguments from aggregated rule sets.
|
|
47
|
+
unless input_rule_sets.nil?
|
|
48
|
+
args = randomize(args, input_rule_sets)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# Create metadata for each argument.
|
|
52
|
+
# TODO: Create metadata for other inputs such as instance variables.
|
|
53
|
+
@inputs = MetaBuilder.create_many(args)
|
|
54
|
+
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# Action method with random arguments.
|
|
58
|
+
begin
|
|
59
|
+
|
|
60
|
+
# Run reflection.
|
|
61
|
+
output = @clone.send(@method, *args)
|
|
62
|
+
@output = MetaBuilder.create(output)
|
|
63
|
+
|
|
64
|
+
# Validate output against aggregated control rule sets.
|
|
65
|
+
unless output_rule_set.nil?
|
|
66
|
+
unless @aggregator.test_output(output, output_rule_set)
|
|
67
|
+
@status = :fail
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# When a system error occurs.
|
|
72
|
+
rescue StandardError => message
|
|
73
|
+
|
|
74
|
+
@status = :fail
|
|
75
|
+
@message = message
|
|
76
|
+
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
end
|
data/lib/{Meta.rb → meta.rb}
RENAMED
|
File without changes
|
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
# @see lib/meta for each meta.
|
|
6
6
|
################################################################################
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
require_relative 'meta'
|
|
9
9
|
# Require all meta.
|
|
10
|
-
Dir[File.join(__dir__, 'meta', '*.rb')].each { |file|
|
|
10
|
+
Dir[File.join(__dir__, 'meta', '*.rb')].each { |file| require_relative file }
|
|
11
11
|
|
|
12
12
|
class MetaBuilder
|
|
13
13
|
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
################################################################################
|
|
2
|
-
# A snapshot of random data.
|
|
2
|
+
# A snapshot of real or random data.
|
|
3
3
|
#
|
|
4
|
-
# @
|
|
5
|
-
# A reflection's random value is within the bounds of aggregated control rule sets
|
|
6
|
-
# as well as as the arg type being inputted into the current control reflection.
|
|
4
|
+
# @pattern Abstract class
|
|
7
5
|
#
|
|
8
6
|
# @nomenclature
|
|
9
7
|
# args, inputs/output and meta represent different stages of a value.
|
|
@@ -19,19 +17,19 @@
|
|
|
19
17
|
# - :error [Symbol] The control reflection produces a system error.
|
|
20
18
|
################################################################################
|
|
21
19
|
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
require_relative 'clone'
|
|
21
|
+
require_relative 'meta_builder'
|
|
24
22
|
|
|
25
23
|
class Reflection
|
|
26
24
|
|
|
27
25
|
attr_reader :status
|
|
28
26
|
|
|
29
27
|
##
|
|
30
|
-
# Create a
|
|
28
|
+
# Create a reflection.
|
|
31
29
|
#
|
|
32
30
|
# @param action [Action] The Action that created this Reflection.
|
|
33
31
|
# @param number [Integer] Multiple Reflections can be created per Action.
|
|
34
|
-
# @param aggregator [
|
|
32
|
+
# @param aggregator [RuleSetAggregator] The aggregated RuleSet for this class/method.
|
|
35
33
|
##
|
|
36
34
|
def initialize(action, number, aggregator)
|
|
37
35
|
|
|
@@ -64,56 +62,11 @@ class Reflection
|
|
|
64
62
|
##
|
|
65
63
|
# Reflect on a method.
|
|
66
64
|
#
|
|
67
|
-
#
|
|
65
|
+
# Create a shadow action.
|
|
68
66
|
# @param *args [Dynamic] The method's arguments.
|
|
69
67
|
##
|
|
70
68
|
def reflect(*args)
|
|
71
|
-
|
|
72
|
-
# Get aggregated rule sets.
|
|
73
|
-
input_rule_sets = @aggregator.get_input_rule_sets(@klass, @method)
|
|
74
|
-
output_rule_set = @aggregator.get_output_rule_set(@klass, @method)
|
|
75
|
-
|
|
76
|
-
# Fail when no trained rule sets.
|
|
77
|
-
if input_rule_sets.nil?
|
|
78
|
-
@status = :fail
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
# When arguments exist.
|
|
82
|
-
unless args.size == 0
|
|
83
|
-
|
|
84
|
-
# Create random arguments from aggregated rule sets.
|
|
85
|
-
unless input_rule_sets.nil?
|
|
86
|
-
args = randomize(args, input_rule_sets)
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
# Create metadata for each argument.
|
|
90
|
-
# TODO: Create metadata for other inputs such as instance variables.
|
|
91
|
-
@inputs = MetaBuilder.create_many(args)
|
|
92
|
-
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
# Action method with random arguments.
|
|
96
|
-
begin
|
|
97
|
-
|
|
98
|
-
# Run reflection.
|
|
99
|
-
output = @clone.send(@method, *args)
|
|
100
|
-
@output = MetaBuilder.create(output)
|
|
101
|
-
|
|
102
|
-
# Validate output against aggregated control rule sets.
|
|
103
|
-
unless output_rule_set.nil?
|
|
104
|
-
unless @aggregator.test_output(output, output_rule_set)
|
|
105
|
-
@status = :fail
|
|
106
|
-
end
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
# When a system error occurs.
|
|
110
|
-
rescue StandardError => message
|
|
111
|
-
|
|
112
|
-
@status = :fail
|
|
113
|
-
@message = message
|
|
114
|
-
|
|
115
|
-
end
|
|
116
|
-
|
|
69
|
+
# Implemented by Control and Experiment.
|
|
117
70
|
end
|
|
118
71
|
|
|
119
72
|
##
|
|
@@ -19,16 +19,16 @@
|
|
|
19
19
|
require 'set'
|
|
20
20
|
require 'erb'
|
|
21
21
|
require 'rowdb'
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
22
|
+
require_relative 'accessor'
|
|
23
|
+
require_relative 'action'
|
|
24
|
+
require_relative 'action_stack'
|
|
25
|
+
require_relative 'config'
|
|
26
|
+
require_relative 'control'
|
|
27
|
+
require_relative 'experiment'
|
|
28
|
+
require_relative 'renderer'
|
|
29
|
+
require_relative 'rule_set_aggregator'
|
|
30
30
|
# Require all rules.
|
|
31
|
-
Dir[File.join(__dir__, 'rules', '*.rb')].each { |file|
|
|
31
|
+
Dir[File.join(__dir__, 'rules', '*.rb')].each { |file| require_relative file }
|
|
32
32
|
|
|
33
33
|
module Reflekt
|
|
34
34
|
|
|
@@ -75,7 +75,7 @@ module Reflekt
|
|
|
75
75
|
# The first method call in the action creates a reflection.
|
|
76
76
|
# Then method calls are shadow actions which return to the reflection.
|
|
77
77
|
##
|
|
78
|
-
if action.
|
|
78
|
+
if action.has_empty_experiments? && !action.is_reflecting?
|
|
79
79
|
action.is_reflecting = true
|
|
80
80
|
|
|
81
81
|
# Create control.
|
|
@@ -94,19 +94,19 @@ module Reflekt
|
|
|
94
94
|
# Save control as a reflection.
|
|
95
95
|
@@reflekt.db.get("reflections").push(control.serialize())
|
|
96
96
|
|
|
97
|
-
# Multiple
|
|
98
|
-
action.
|
|
97
|
+
# Multiple experiments per action.
|
|
98
|
+
action.experiments.each_with_index do |value, index|
|
|
99
99
|
|
|
100
|
-
# Create
|
|
101
|
-
|
|
102
|
-
action.
|
|
100
|
+
# Create experiment.
|
|
101
|
+
experiment = Experiment.new(action, index + 1, @@reflekt.aggregator)
|
|
102
|
+
action.experiments[index] = experiment
|
|
103
103
|
|
|
104
|
-
# Execute
|
|
105
|
-
|
|
104
|
+
# Execute experiment.
|
|
105
|
+
experiment.reflect(*args)
|
|
106
106
|
@reflekt_counts[method] = @reflekt_counts[method] + 1
|
|
107
107
|
|
|
108
|
-
# Save
|
|
109
|
-
@@reflekt.db.get("reflections").push(
|
|
108
|
+
# Save experiment.
|
|
109
|
+
@@reflekt.db.get("reflections").push(experiment.serialize())
|
|
110
110
|
|
|
111
111
|
end
|
|
112
112
|
|
|
@@ -202,7 +202,7 @@ module Reflekt
|
|
|
202
202
|
@@reflekt.stack = ActionStack.new()
|
|
203
203
|
|
|
204
204
|
# Create aggregated rule sets.
|
|
205
|
-
@@reflekt.aggregator =
|
|
205
|
+
@@reflekt.aggregator = RuleSetAggregator.new(@@reflekt.config.meta_map)
|
|
206
206
|
@@reflekt.aggregator.train(db[:controls])
|
|
207
207
|
|
|
208
208
|
# Create renderer.
|
|
File without changes
|
data/lib/{Rule.rb → rule.rb}
RENAMED
|
@@ -6,14 +6,14 @@
|
|
|
6
6
|
# - Builder
|
|
7
7
|
#
|
|
8
8
|
# @hierachy
|
|
9
|
-
# 1.
|
|
9
|
+
# 1. RuleSetAggregator
|
|
10
10
|
# 2. RuleSet <- YOU ARE HERE
|
|
11
11
|
# 3. Rule
|
|
12
12
|
################################################################################
|
|
13
13
|
|
|
14
14
|
require 'set'
|
|
15
|
-
|
|
16
|
-
require_relative '
|
|
15
|
+
require_relative 'meta_builder'
|
|
16
|
+
require_relative 'meta/null_meta.rb'
|
|
17
17
|
|
|
18
18
|
class RuleSet
|
|
19
19
|
|
|
@@ -5,14 +5,14 @@
|
|
|
5
5
|
# @pattern Singleton
|
|
6
6
|
#
|
|
7
7
|
# @hierachy
|
|
8
|
-
# 1.
|
|
8
|
+
# 1. RuleSetAggregator <- YOU ARE HERE
|
|
9
9
|
# 2. RuleSet
|
|
10
10
|
# 3. Rule
|
|
11
11
|
################################################################################
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
require_relative 'rule_set'
|
|
14
14
|
|
|
15
|
-
class
|
|
15
|
+
class RuleSetAggregator
|
|
16
16
|
|
|
17
17
|
##
|
|
18
18
|
# @param meta_map [Hash] The rules that apply to each meta type.
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: reflekt
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.
|
|
4
|
+
version: 1.0.6
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Maedi Prichard
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2020-12-
|
|
11
|
+
date: 2020-12-24 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rowdb
|
|
@@ -30,32 +30,33 @@ executables: []
|
|
|
30
30
|
extensions: []
|
|
31
31
|
extra_rdoc_files: []
|
|
32
32
|
files:
|
|
33
|
-
- lib/
|
|
34
|
-
- lib/
|
|
35
|
-
- lib/
|
|
36
|
-
- lib/
|
|
37
|
-
- lib/
|
|
38
|
-
- lib/
|
|
39
|
-
- lib/
|
|
40
|
-
- lib/
|
|
41
|
-
- lib/
|
|
42
|
-
- lib/
|
|
43
|
-
- lib/
|
|
44
|
-
- lib/
|
|
45
|
-
- lib/
|
|
46
|
-
- lib/
|
|
47
|
-
- lib/
|
|
48
|
-
- lib/
|
|
49
|
-
- lib/
|
|
50
|
-
- lib/
|
|
51
|
-
- lib/
|
|
52
|
-
- lib/
|
|
53
|
-
- lib/
|
|
54
|
-
- lib/rules/
|
|
55
|
-
- lib/rules/
|
|
56
|
-
- lib/rules/
|
|
57
|
-
- lib/rules/
|
|
58
|
-
- lib/rules/
|
|
33
|
+
- lib/accessor.rb
|
|
34
|
+
- lib/action.rb
|
|
35
|
+
- lib/action_stack.rb
|
|
36
|
+
- lib/clone.rb
|
|
37
|
+
- lib/config.rb
|
|
38
|
+
- lib/control.rb
|
|
39
|
+
- lib/experiment.rb
|
|
40
|
+
- lib/meta.rb
|
|
41
|
+
- lib/meta/array_meta.rb
|
|
42
|
+
- lib/meta/boolean_meta.rb
|
|
43
|
+
- lib/meta/float_meta.rb
|
|
44
|
+
- lib/meta/integer_meta.rb
|
|
45
|
+
- lib/meta/null_meta.rb
|
|
46
|
+
- lib/meta/string_meta.rb
|
|
47
|
+
- lib/meta_builder.rb
|
|
48
|
+
- lib/reflection.rb
|
|
49
|
+
- lib/reflekt.rb
|
|
50
|
+
- lib/renderer.rb
|
|
51
|
+
- lib/rule.rb
|
|
52
|
+
- lib/rule_set.rb
|
|
53
|
+
- lib/rule_set_aggregator.rb
|
|
54
|
+
- lib/rules/array_rule.rb
|
|
55
|
+
- lib/rules/boolean_rule.rb
|
|
56
|
+
- lib/rules/float_rule.rb
|
|
57
|
+
- lib/rules/integer_rule.rb
|
|
58
|
+
- lib/rules/null_rule.rb
|
|
59
|
+
- lib/rules/string_rule.rb
|
|
59
60
|
- lib/web/README.md
|
|
60
61
|
- lib/web/bundle.js
|
|
61
62
|
- lib/web/gitignore.txt
|