Top Level Namespace
Defined Under Namespace
Modules: Judges Classes: Object
Instance Method Summary collapse
-
#each_once(fb, query, judge: $judge) ⇒ Object
Returns a decorated global factbase, which only touches facts once.
-
#each_tuple_once(fb, *queries, judge: $judge) ⇒ Object
Returns a decorated global factbase, which only touches a tuple once.
- #each_tuple_once_txn(fb, *queries, judge: $judge) ⇒ Object
-
#elapsed(loog) ⇒ Object
Copyright © 2024 Yegor Bugayenko.
-
#if_absent(fb) {|f| ... } ⇒ Object
Injects a fact if it’s absent in the factbase.
Instance Method Details
#each_once(fb, query, judge: $judge) ⇒ Object
Returns a decorated global factbase, which only touches facts once.
27 28 29 30 31 32 33 34 |
# File 'lib/judges/fb/once.rb', line 27 def each_once(fb, query, judge: $judge) return to_enum(__method__, fb, query, judge:) unless block_given? q = "(and #{query} (not (eq seen '#{judge}')))" fb.query(q).each do |f| yield f f.seen = judge end end |
#each_tuple_once(fb, *queries, judge: $judge) ⇒ Object
Returns a decorated global factbase, which only touches a tuple once.
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/judges/fb/once.rb', line 37 def each_tuple_once(fb, *queries, judge: $judge) return to_enum(__method__, fb, *queries, judge:) unless block_given? qq = queries.map { |q| "(and #{q} (not (eq seen '#{judge}')))" } Factbase::Tuples.new(fb, qq).each do |fs| yield fs fs.each do |f| f.seen = judge end end end |
#each_tuple_once_txn(fb, *queries, judge: $judge) ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/judges/fb/once.rb', line 48 def each_tuple_once_txn(fb, *queries, judge: $judge) fb.txn do |fbt| each_tuple_once(fb, *queries, judge:) do |fs| yield [fbt] + fs end end end |
#elapsed(loog) ⇒ Object
Copyright © 2024 Yegor Bugayenko
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/judges/elapsed.rb', line 23 def elapsed(loog) start = Time.now begin yield rescue UncaughtThrowError => e tag = e.tag throw e unless tag.is_a?(Symbol) loog.info("#{tag} in #{format('%.02f', Time.now - start)}s") end end |
#if_absent(fb) {|f| ... } ⇒ Object
Injects a fact if it’s absent in the factbase.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/judges/fb/if_absent.rb', line 27 def if_absent(fb) attrs = {} f = Judges::Accumulator.new(attrs) yield f q = attrs.map do |k, v| vv = v.to_s if v.is_a?(String) vv = "'#{vv.gsub('"', '\\\\"').gsub("'", "\\\\'")}'" elsif v.is_a?(Time) vv = v.utc.iso8601 end "(eq #{k} #{vv})" end.join(' ') q = "(and #{q})" return unless fb.query(q).each.to_a.empty? n = fb.insert attrs.each { |k, v| n.send("#{k}=", v) } n end |