factbase 0.9.1 → 0.9.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d4918d14dba9ff6a434de85e418f0f8249b4e3ea2e3bf7ae1c7cd1ed0836b20c
4
- data.tar.gz: 2810d6061d951226e42b51f8d0f6afb27698ad16bdda448088a7dff7dd930937
3
+ metadata.gz: 2b0b91a22c7ec63e9ec1b98bc325006645243b11d2b0fa1ca591f005c5e7b34e
4
+ data.tar.gz: 60014d07339a593674ec768b63c99a4a993f7b22a0a6f1eb1386e8137c90db30
5
5
  SHA512:
6
- metadata.gz: 975e9b4c4deda01bd2177c44adbf9049b784ffa76e17b3718f9a6103582eda766c5ae9df7eb92235acaa25823ed8a5bfa42cfd5245a11182132d977c2851ff65
7
- data.tar.gz: 914915154434ed8265aad9c1cda22e8e6dbd14ba3f2248478f45579418aa4dcb90752550eab337c80936faba9e384dd09b44539a6ff74278b71d4298b2efc858
6
+ metadata.gz: 82e2abb7c56c198486d512ee9145c22399f01342107b4ebac14556977f87d8811908230522473b926057b04f355e890e391c313e488580cf1a1bb17b658e1dd7
7
+ data.tar.gz: 03225a085c0acb3d9bc57ddaf71ed4c2a878c1cafc88858b39ee0872ff29348ad28d772506eca16fbf6f2183e9a55ddb56e77899b49289f15d72bc92193d6b98
data/Gemfile CHANGED
@@ -6,11 +6,13 @@
6
6
  source 'https://rubygems.org'
7
7
  gemspec
8
8
 
9
- gem 'minitest', '5.25.4', require: false
9
+ gem 'minitest', '5.25.5', require: false
10
10
  gem 'minitest-reporters', '1.7.1', require: false
11
+ gem 'os', '>0', require: false
12
+ gem 'qbash', '>0', require: false
11
13
  gem 'rake', '13.2.1', require: false
12
14
  gem 'rspec-rails', '7.1.1', require: false
13
- gem 'rubocop', '1.73.2', require: false
15
+ gem 'rubocop', '1.74.0', require: false
14
16
  gem 'rubocop-minitest', '>0', require: false
15
17
  gem 'rubocop-performance', '>0', require: false
16
18
  gem 'rubocop-rake', '>0', require: false
data/Gemfile.lock CHANGED
@@ -58,6 +58,9 @@ GEM
58
58
  diff-lcs (1.6.0)
59
59
  docile (1.4.1)
60
60
  drb (2.2.1)
61
+ elapsed (0.0.1)
62
+ loog (> 0)
63
+ tago (> 0)
61
64
  erubi (1.13.1)
62
65
  i18n (1.14.7)
63
66
  concurrent-ruby (~> 1.0)
@@ -74,7 +77,7 @@ GEM
74
77
  crass (~> 1.0.2)
75
78
  nokogiri (>= 1.12.0)
76
79
  loog (0.6.0)
77
- minitest (5.25.4)
80
+ minitest (5.25.5)
78
81
  minitest-reporters (1.7.1)
79
82
  ansi
80
83
  builder
@@ -88,6 +91,7 @@ GEM
88
91
  racc (~> 1.4)
89
92
  nokogiri (1.18.3-x86_64-linux-gnu)
90
93
  racc (~> 1.4)
94
+ os (1.1.4)
91
95
  others (0.0.3)
92
96
  parallel (1.26.3)
93
97
  parser (3.3.7.1)
@@ -99,6 +103,11 @@ GEM
99
103
  psych (5.2.3)
100
104
  date
101
105
  stringio
106
+ qbash (0.4.0)
107
+ backtrace (> 0)
108
+ elapsed (> 0)
109
+ loog (> 0)
110
+ tago (> 0)
102
111
  racc (1.8.1)
103
112
  rack (3.1.12)
104
113
  rack-session (2.1.0)
@@ -148,7 +157,7 @@ GEM
148
157
  rspec-mocks (~> 3.13)
149
158
  rspec-support (~> 3.13)
150
159
  rspec-support (3.13.2)
151
- rubocop (1.73.2)
160
+ rubocop (1.74.0)
152
161
  json (~> 2.3)
153
162
  language_server-protocol (~> 3.17.0.2)
154
163
  lint_roller (~> 1.1.0)
@@ -214,11 +223,13 @@ PLATFORMS
214
223
 
215
224
  DEPENDENCIES
216
225
  factbase!
217
- minitest (= 5.25.4)
226
+ minitest (= 5.25.5)
218
227
  minitest-reporters (= 1.7.1)
228
+ os (> 0)
229
+ qbash (> 0)
219
230
  rake (= 13.2.1)
220
231
  rspec-rails (= 7.1.1)
221
- rubocop (= 1.73.2)
232
+ rubocop (= 1.74.0)
222
233
  rubocop-minitest (> 0)
223
234
  rubocop-performance (> 0)
224
235
  rubocop-rake (> 0)
data/README.md CHANGED
@@ -209,33 +209,33 @@ This is the result of the benchmark:
209
209
  <!-- benchmark_begin -->
210
210
  ```text
211
211
  user system total real
212
- insert 20000 facts 0.625135 0.006294 0.631429 ( 0.631443)
213
- export 20000 facts 0.023877 0.000991 0.024868 ( 0.024873)
214
- import 411050 bytes (20000 facts) 0.034864 0.004984 0.039848 ( 0.039853)
215
- insert 10 facts 0.045526 0.002959 0.048485 ( 0.048490)
216
- query 10 times w/txn 2.221776 0.028103 2.249879 ( 2.249996)
217
- query 10 times w/o txn 0.842098 0.002019 0.844117 ( 0.844159)
218
- modify 10 attrs w/txn 2.056211 0.014021 2.070232 ( 2.070541)
219
- delete 10 facts w/txn 0.770236 0.003988 0.774224 ( 0.774272)
220
- (and (eq what 'issue-was-closed') (exists... -> 200 2.805609 0.003005 2.808614 ( 2.808765)
221
- (and (eq what 'issue-was-closed') (exists... -> 200/txn 2.812425 0.002000 2.814425 ( 2.814779)
222
- (and (eq what 'issue-was-closed') (exists... -> zero 4.288405 0.000001 4.288406 ( 4.288758)
223
- (and (eq what 'issue-was-closed') (exists... -> zero/txn 4.320962 0.008005 4.328967 ( 4.329469)
224
- (gt time '2024-03-23T03:21:43Z') 0.116707 0.001996 0.118703 ( 0.118716)
225
- (gt cost 50) 0.093508 0.000004 0.093512 ( 0.093517)
226
- (eq title 'Object Thinking 5000') 0.006989 0.000000 0.006989 ( 0.006990)
227
- (and (eq foo 42.998) (or (gt bar 200) (absent zzz))) 0.060383 0.000002 0.060385 ( 0.060385)
228
- (eq id (agg (always) (max id))) 0.357125 0.000994 0.358119 ( 0.358130)
229
- (join "c<=cost,b<=bar" (eq id (agg (always) (max id)))) 1.350979 0.000001 1.350980 ( 1.351072)
230
- delete! 0.054491 0.000004 0.054495 ( 0.054497)
231
- Taped.append() x50000 0.048166 0.001997 0.050163 ( 0.050167)
232
- Taped.each() x125 1.347655 0.002002 1.349657 ( 1.349747)
233
- Taped.delete_if() x375 0.846874 0.000003 0.846877 ( 0.846926)
212
+ insert 20000 facts 0.584859 0.005297 0.590156 ( 0.590186)
213
+ export 20000 facts 0.018342 0.005935 0.024277 ( 0.024282)
214
+ import 410974 bytes (20000 facts) 0.028027 0.004994 0.033021 ( 0.033026)
215
+ insert 10 facts 0.041771 0.000989 0.042760 ( 0.042763)
216
+ query 10 times w/txn 2.020294 0.038146 2.058440 ( 2.059555)
217
+ query 10 times w/o txn 0.727753 0.001014 0.728767 ( 0.728806)
218
+ modify 10 attrs w/txn 1.919959 0.014025 1.933984 ( 1.934328)
219
+ delete 10 facts w/txn 0.739267 0.000000 0.739267 ( 0.739299)
220
+ (and (eq what 'issue-was-closed') (exists... -> 200 2.717595 0.003012 2.720607 ( 2.720777)
221
+ (and (eq what 'issue-was-closed') (exists... -> 200/txn 2.732913 0.002012 2.734925 ( 2.735227)
222
+ (and (eq what 'issue-was-closed') (exists... -> zero 4.149053 0.001010 4.150063 ( 4.150436)
223
+ (and (eq what 'issue-was-closed') (exists... -> zero/txn 4.116972 0.001001 4.117973 ( 4.119644)
224
+ (gt time '2024-03-23T03:21:43Z') 0.107332 0.000002 0.107334 ( 0.107336)
225
+ (gt cost 50) 0.094454 0.000000 0.094454 ( 0.094458)
226
+ (eq title 'Object Thinking 5000') 0.003828 0.000000 0.003828 ( 0.003830)
227
+ (and (eq foo 42.998) (or (gt bar 200) (absent zzz))) 0.055983 0.000000 0.055983 ( 0.055986)
228
+ (eq id (agg (always) (max id))) 0.329920 0.001995 0.331915 ( 0.332005)
229
+ (join "c<=cost,b<=bar" (eq id (agg (always) (max id)))) 1.448262 0.002005 1.450267 ( 1.450350)
230
+ delete! 0.056928 0.000000 0.056928 ( 0.056932)
231
+ Taped.append() x50000 0.035070 0.001000 0.036070 ( 0.036074)
232
+ Taped.each() x125 1.310450 0.000000 1.310450 ( 1.310521)
233
+ Taped.delete_if() x375 0.819224 0.000001 0.819225 ( 0.819270)
234
234
  ```
235
235
 
236
236
  The results were calculated in [this GHA job][benchmark-gha]
237
- on 2025-03-12 at 13:25,
237
+ on 2025-03-14 at 09:14,
238
238
  on Linux with 4 CPUs.
239
239
  <!-- benchmark_end -->
240
240
 
241
- [benchmark-gha]: https://github.com/yegor256/factbase/actions/runs/13812482648
241
+ [benchmark-gha]: https://github.com/yegor256/factbase/actions/runs/13853425019
data/Rakefile CHANGED
@@ -3,9 +3,12 @@
3
3
  # SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
4
4
  # SPDX-License-Identifier: MIT
5
5
 
6
+ require 'qbash'
6
7
  require 'rubygems'
7
8
  require 'rake'
8
9
  require 'rake/clean'
10
+ require 'shellwords'
11
+ require 'os'
9
12
 
10
13
  def name
11
14
  @name ||= File.basename(Dir['*.gemspec'].first, '.*')
@@ -15,7 +18,7 @@ def version
15
18
  Gem::Specification.load(Dir['*.gemspec'].first).version
16
19
  end
17
20
 
18
- task default: %i[clean test rubocop yard]
21
+ task default: %i[clean test picks reqs rubocop yard]
19
22
 
20
23
  require 'rake/testtask'
21
24
  desc 'Run all unit tests'
@@ -27,6 +30,22 @@ Rake::TestTask.new(:test) do |test|
27
30
  test.verbose = false
28
31
  end
29
32
 
33
+ desc 'Run them via Ruby, one by one'
34
+ task :picks do
35
+ next if OS.windows?
36
+ Dir['test/**/*.rb'].each do |f|
37
+ qbash("bundle exec ruby #{Shellwords.escape(f)}", log: $stdout)
38
+ end
39
+ end
40
+
41
+ desc 'Require them via Ruby, one by one'
42
+ task :reqs do
43
+ next if OS.windows?
44
+ Dir['lib/**/*.rb'].each do |f|
45
+ qbash("bundle exec ruby #{Shellwords.escape(f)}", log: $stdout)
46
+ end
47
+ end
48
+
30
49
  require 'yard'
31
50
  desc 'Build Yard documentation'
32
51
  YARD::Rake::YardocTask.new do |t|
@@ -74,6 +74,14 @@ class Factbase::Taped
74
74
  @added = added
75
75
  end
76
76
 
77
+ def keys
78
+ @origin.keys
79
+ end
80
+
81
+ def map(&)
82
+ @origin.map(&)
83
+ end
84
+
77
85
  def [](key)
78
86
  v = @origin[key]
79
87
  v = TapedArray.new(v, @origin.object_id, @added) if v.is_a?(Array)
data/lib/factbase/term.rb CHANGED
@@ -45,37 +45,37 @@ class Factbase::Term
45
45
  attr_reader :operands
46
46
 
47
47
  require_relative 'terms/math'
48
- include Factbase::Term::Math
48
+ include Factbase::Math
49
49
 
50
50
  require_relative 'terms/logical'
51
- include Factbase::Term::Logical
51
+ include Factbase::Logical
52
52
 
53
53
  require_relative 'terms/aggregates'
54
- include Factbase::Term::Aggregates
54
+ include Factbase::Aggregates
55
55
 
56
56
  require_relative 'terms/strings'
57
- include Factbase::Term::Strings
57
+ include Factbase::Strings
58
58
 
59
59
  require_relative 'terms/casting'
60
- include Factbase::Term::Casting
60
+ include Factbase::Casting
61
61
 
62
62
  require_relative 'terms/meta'
63
- include Factbase::Term::Meta
63
+ include Factbase::Meta
64
64
 
65
65
  require_relative 'terms/aliases'
66
- include Factbase::Term::Aliases
66
+ include Factbase::Aliases
67
67
 
68
68
  require_relative 'terms/ordering'
69
- include Factbase::Term::Ordering
69
+ include Factbase::Ordering
70
70
 
71
71
  require_relative 'terms/defn'
72
- include Factbase::Term::Defn
72
+ include Factbase::Defn
73
73
 
74
74
  require_relative 'terms/system'
75
- include Factbase::Term::System
75
+ include Factbase::System
76
76
 
77
77
  require_relative 'terms/debug'
78
- include Factbase::Term::Debug
78
+ include Factbase::Debug
79
79
 
80
80
  # Ctor.
81
81
  # @param [Symbol] operator Operator
@@ -10,7 +10,7 @@ require_relative '../../factbase'
10
10
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
11
11
  # Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
12
12
  # License:: MIT
13
- module Factbase::Term::Aggregates
13
+ module Factbase::Aggregates
14
14
  def min(_fact, maps, _fb)
15
15
  assert_args(1)
16
16
  _best(maps) { |v, b| v < b }
@@ -10,7 +10,7 @@ require_relative '../../factbase'
10
10
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
11
11
  # Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
12
12
  # License:: MIT
13
- module Factbase::Term::Aliases
13
+ module Factbase::Aliases
14
14
  def as(fact, maps, fb)
15
15
  assert_args(2)
16
16
  a = @operands[0]
@@ -10,7 +10,7 @@ require_relative '../../factbase'
10
10
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
11
11
  # Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
12
12
  # License:: MIT
13
- module Factbase::Term::Casting
13
+ module Factbase::Casting
14
14
  def to_string(fact, maps, fb)
15
15
  assert_args(1)
16
16
  vv = _values(0, fact, maps, fb)
@@ -10,7 +10,7 @@ require_relative '../../factbase'
10
10
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
11
11
  # Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
12
12
  # License:: MIT
13
- module Factbase::Term::Debug
13
+ module Factbase::Debug
14
14
  def traced(fact, maps, fb)
15
15
  assert_args(1)
16
16
  t = @operands[0]
@@ -10,7 +10,7 @@ require_relative '../../factbase'
10
10
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
11
11
  # Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
12
12
  # License:: MIT
13
- module Factbase::Term::Defn
13
+ module Factbase::Defn
14
14
  def defn(_fact, _maps, _fb)
15
15
  assert_args(2)
16
16
  fn = @operands[0]
@@ -10,7 +10,7 @@ require_relative '../../factbase'
10
10
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
11
11
  # Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
12
12
  # License:: MIT
13
- module Factbase::Term::Logical
13
+ module Factbase::Logical
14
14
  # Always returns true, regardless of the fact
15
15
  # @param [Factbase::Fact] _fact The fact (unused)
16
16
  # @param [Array<Factbase::Fact>] _maps All maps available (unused)
@@ -10,7 +10,7 @@ require_relative '../../factbase'
10
10
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
11
11
  # Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
12
12
  # License:: MIT
13
- module Factbase::Term::Math
13
+ module Factbase::Math
14
14
  def plus(fact, maps, fb)
15
15
  _arithmetic(:+, fact, maps, fb)
16
16
  end
@@ -10,7 +10,7 @@ require_relative '../../factbase'
10
10
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
11
11
  # Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
12
12
  # License:: MIT
13
- module Factbase::Term::Meta
13
+ module Factbase::Meta
14
14
  def exists(fact, _maps, _fb)
15
15
  assert_args(1)
16
16
  !_by_symbol(0, fact).nil?
@@ -10,7 +10,7 @@ require_relative '../../factbase'
10
10
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
11
11
  # Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
12
12
  # License:: MIT
13
- module Factbase::Term::Ordering
13
+ module Factbase::Ordering
14
14
  def prev(fact, maps, fb)
15
15
  assert_args(1)
16
16
  before = @prev
@@ -10,7 +10,7 @@ require_relative '../../factbase'
10
10
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
11
11
  # Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
12
12
  # License:: MIT
13
- module Factbase::Term::Strings
13
+ module Factbase::Strings
14
14
  def concat(fact, maps, fb)
15
15
  (0..@operands.length - 1).map { |i| _values(i, fact, maps, fb)&.first }.join
16
16
  end
@@ -10,7 +10,7 @@ require_relative '../../factbase'
10
10
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
11
11
  # Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
12
12
  # License:: MIT
13
- module Factbase::Term::System
13
+ module Factbase::System
14
14
  def env(fact, maps, fb)
15
15
  assert_args(2)
16
16
  n = _values(0, fact, maps, fb)[0]
data/lib/factbase.rb CHANGED
@@ -82,7 +82,7 @@ require 'yaml'
82
82
  # License:: MIT
83
83
  class Factbase
84
84
  # Current version of the gem (changed by .rultor.yml on every release)
85
- VERSION = '0.9.1'
85
+ VERSION = '0.9.2' unless const_defined?(:VERSION)
86
86
 
87
87
  # An exception that may be thrown in a transaction, to roll it back.
88
88
  class Rollback < StandardError; end
@@ -3,6 +3,7 @@
3
3
  # SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
4
4
  # SPDX-License-Identifier: MIT
5
5
 
6
+ require 'loog'
6
7
  require_relative '../../test__helper'
7
8
  require_relative '../../../lib/factbase/term'
8
9
  require_relative '../../../lib/factbase/syntax'
@@ -44,7 +44,12 @@ class TestQuery < Factbase::Test
44
44
  size = q['size']
45
45
  assert_equal(size, fb.query(qry).each.to_a.size, "#{base}: #{qry} at #{badge}")
46
46
  fb.txn do |fbt|
47
- assert_equal(size, fbt.query(qry).each.to_a.size, "#{base}: #{qry} at #{badge} (in txn)")
47
+ facts = fbt.query(qry).each.to_a
48
+ assert_equal(size, facts.size, "#{base}: #{qry} at #{badge} (in txn)")
49
+ facts.each do |fact|
50
+ refute_empty(fact.all_properties)
51
+ refute_nil(fact.to_s)
52
+ end
48
53
  end
49
54
  else
50
55
  ret = q['one']
@@ -245,6 +250,22 @@ class TestQuery < Factbase::Test
245
250
  'cached+indexed+plain' => Factbase::CachedFactbase.new(Factbase::IndexedFactbase.new(Factbase.new(maps))),
246
251
  'sync+cached+indexed+plain' => Factbase::SyncFactbase.new(
247
252
  Factbase::CachedFactbase.new(Factbase::IndexedFactbase.new(Factbase.new(maps)))
253
+ ),
254
+ 'all+plain' => Factbase::Tallied.new(
255
+ Factbase::Pre.new(
256
+ Factbase::Rules.new(
257
+ Factbase::Inv.new(
258
+ Factbase::SyncFactbase.new(
259
+ Factbase::CachedFactbase.new(
260
+ Factbase::IndexedFactbase.new(
261
+ Factbase.new(maps)
262
+ )
263
+ )
264
+ )
265
+ ) { nil },
266
+ '(always)'
267
+ )
268
+ ) { nil }
248
269
  )
249
270
  }.each(&)
250
271
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: factbase
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 0.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-03-12 00:00:00.000000000 Z
10
+ date: 2025-03-14 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: backtrace