factbase 0.14.3 → 0.14.5
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/.github/workflows/typos.yml +1 -1
- data/Gemfile.lock +1 -3
- data/lib/factbase/indexed/indexed_term.rb +42 -0
- data/lib/factbase/light.rb +4 -0
- data/lib/factbase/version.rb +1 -1
- data/test/factbase/indexed/test_indexed_term.rb +34 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fdee6a1a98e26f25786c6f9bffbaf201d39639b52bf8933beaa4a8053860dfde
|
4
|
+
data.tar.gz: ca5ccea23c49c9ffc45d4cebf77b798bb42a527d599533d854836bf47276a532
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 37a08deb9fba4cc348861fe67dd680328b635f10366f193baf9e4f955118e60a1439562416d2e7bd5e5e140243250a6daec6ce72049ad40132b987c55c16ff88
|
7
|
+
data.tar.gz: c4dd0a22cfa88b3c2b4d5c87c672fe0cbbd81959dc0c96e6d8e3b4bdacec3c5ef3448b5832b9b91378d4fe4629cae72ec6af71de05ad029052478068fe6626cd
|
data/.github/workflows/typos.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -72,7 +72,7 @@ GEM
|
|
72
72
|
psych (>= 4.0.0)
|
73
73
|
regexp_parser (2.10.0)
|
74
74
|
rexml (3.4.1)
|
75
|
-
rubocop (1.79.
|
75
|
+
rubocop (1.79.2)
|
76
76
|
json (~> 2.3)
|
77
77
|
language_server-protocol (~> 3.17.0.2)
|
78
78
|
lint_roller (~> 1.1.0)
|
@@ -82,7 +82,6 @@ GEM
|
|
82
82
|
regexp_parser (>= 2.9.3, < 3.0)
|
83
83
|
rubocop-ast (>= 1.46.0, < 2.0)
|
84
84
|
ruby-progressbar (~> 1.7)
|
85
|
-
tsort (>= 0.2.0)
|
86
85
|
unicode-display_width (>= 2.4.0, < 4.0)
|
87
86
|
rubocop-ast (1.46.0)
|
88
87
|
parser (>= 3.3.7.2)
|
@@ -113,7 +112,6 @@ GEM
|
|
113
112
|
threads (0.4.1)
|
114
113
|
backtrace (~> 0)
|
115
114
|
concurrent-ruby (~> 1.0)
|
116
|
-
tsort (0.2.0)
|
117
115
|
unicode-display_width (3.1.4)
|
118
116
|
unicode-emoji (~> 4.0, >= 4.0.4)
|
119
117
|
unicode-emoji (4.0.4)
|
@@ -74,6 +74,48 @@ module Factbase::IndexedTerm
|
|
74
74
|
(maps & []) | j
|
75
75
|
end
|
76
76
|
end
|
77
|
+
when :gt
|
78
|
+
if @operands.first.is_a?(Symbol) && _scalar?(@operands[1])
|
79
|
+
prop = @operands.first.to_s
|
80
|
+
cache_key = [maps.object_id, @operands.first, :sorted]
|
81
|
+
if @idx[cache_key].nil?
|
82
|
+
@idx[cache_key] = []
|
83
|
+
maps.to_a.each do |m|
|
84
|
+
values = m[prop]
|
85
|
+
next if values.nil?
|
86
|
+
values.each do |v|
|
87
|
+
@idx[cache_key] << [v, m]
|
88
|
+
end
|
89
|
+
end
|
90
|
+
@idx[cache_key].sort_by! { |pair| pair[0] }
|
91
|
+
end
|
92
|
+
threshold = @operands[1].is_a?(Symbol) ? params[@operands[1].to_s]&.first : @operands[1]
|
93
|
+
return nil if threshold.nil?
|
94
|
+
i = @idx[cache_key].bsearch_index { |pair| pair[0] > threshold } || @idx[cache_key].size
|
95
|
+
result = @idx[cache_key][i..].map { |pair| pair[1] }.uniq
|
96
|
+
(maps & []) | result
|
97
|
+
end
|
98
|
+
when :lt
|
99
|
+
if @operands.first.is_a?(Symbol) && _scalar?(@operands[1])
|
100
|
+
prop = @operands.first.to_s
|
101
|
+
cache_key = [maps.object_id, @operands.first, :sorted]
|
102
|
+
if @idx[cache_key].nil?
|
103
|
+
@idx[cache_key] = []
|
104
|
+
maps.to_a.each do |m|
|
105
|
+
values = m[prop]
|
106
|
+
next if values.nil?
|
107
|
+
values.each do |v|
|
108
|
+
@idx[cache_key] << [v, m]
|
109
|
+
end
|
110
|
+
end
|
111
|
+
@idx[cache_key].sort_by! { |pair| pair[0] }
|
112
|
+
end
|
113
|
+
threshold = @operands[1].is_a?(Symbol) ? params[@operands[1].to_s]&.first : @operands[1]
|
114
|
+
return nil if threshold.nil?
|
115
|
+
i = @idx[cache_key].bsearch_index { |pair| pair[0] >= threshold } || @idx[cache_key].size
|
116
|
+
result = @idx[cache_key][0...i].map { |pair| pair[1] }.uniq
|
117
|
+
(maps & []) | result
|
118
|
+
end
|
77
119
|
when :and
|
78
120
|
r = nil
|
79
121
|
if @operands.all? { |o| o.op == :eq } && @operands.size > 1 \
|
data/lib/factbase/light.rb
CHANGED
data/lib/factbase/version.rb
CHANGED
@@ -103,4 +103,38 @@ class TestIndexedTerm < Factbase::Test
|
|
103
103
|
n = term.predict(maps, {})
|
104
104
|
assert_nil(n)
|
105
105
|
end
|
106
|
+
|
107
|
+
def test_predicts_on_gt
|
108
|
+
term = Factbase::Term.new(:gt, [:foo, 42])
|
109
|
+
idx = {}
|
110
|
+
term.redress!(Factbase::IndexedTerm, idx:)
|
111
|
+
maps = Factbase::Taped.new([
|
112
|
+
{ 'foo' => [10] },
|
113
|
+
{ 'foo' => [43] },
|
114
|
+
{ 'foo' => [42] },
|
115
|
+
{ 'foo' => [100, 5] },
|
116
|
+
{ 'bar' => [50] },
|
117
|
+
{ 'foo' => [41, 42, 43] }
|
118
|
+
])
|
119
|
+
n = term.predict(maps, {})
|
120
|
+
assert_equal(3, n.size)
|
121
|
+
assert_kind_of(Factbase::Taped, n)
|
122
|
+
end
|
123
|
+
|
124
|
+
def test_predicts_on_lt
|
125
|
+
term = Factbase::Term.new(:lt, [:foo, 42])
|
126
|
+
idx = {}
|
127
|
+
term.redress!(Factbase::IndexedTerm, idx:)
|
128
|
+
maps = Factbase::Taped.new([
|
129
|
+
{ 'foo' => [10] },
|
130
|
+
{ 'foo' => [43] },
|
131
|
+
{ 'foo' => [42] },
|
132
|
+
{ 'foo' => [100, 5] },
|
133
|
+
{ 'bar' => [50] },
|
134
|
+
{ 'foo' => [41, 42, 43] }
|
135
|
+
])
|
136
|
+
n = term.predict(maps, {})
|
137
|
+
assert_equal(3, n.size)
|
138
|
+
assert_kind_of(Factbase::Taped, n)
|
139
|
+
end
|
106
140
|
end
|