languages/ruby/lib/oso/polar/query.rb
def start # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
        Enumerator.new do |yielder| # rubocop:disable Metrics/BlockLength
          loop do # rubocop:disable Metrics/BlockLength
            event = ffi_query.next_event
            case event.kind
            when 'Done'
              break
            when 'Result'
              yielder << event.data['bindings'].transform_values { |v| host.to_ruby(v) }
            when 'MakeExternal'
              handle_make_external(event.data)
            when 'ExternalCall'
              call_id = event.data['call_id']
              instance = event.data['instance']
              attribute = event.data['attribute']
              args = event.data['args']
              handle_call(attribute, call_id: call_id, instance: instance, args: args)
            when 'ExternalIsSubSpecializer'
              instance_id = event.data['instance_id']
              left_tag = event.data['left_class_tag']
              right_tag = event.data['right_class_tag']
              answer = host.subspecializer?(instance_id, left_tag: left_tag, right_tag: right_tag)
              question_result(answer, call_id: event.data['call_id'])
            when 'ExternalIsa'
              instance = event.data['instance']
              class_tag = event.data['class_tag']
              answer = host.isa?(instance, class_tag: class_tag)
              question_result(answer, call_id: event.data['call_id'])
            when 'ExternalUnify'
              left_instance_id = event.data['left_instance_id']
              right_instance_id = event.data['right_instance_id']
              answer = host.unify?(left_instance_id, right_instance_id)
              question_result(answer, call_id: event.data['call_id'])
            when 'Debug'
              puts event.data['message'] if event.data['message']
              print 'debug> '
              begin
                input = $stdin.readline.chomp.chomp(';')
              rescue EOFError
                next
              end
              command = JSON.dump(host.to_polar(input))
              ffi_query.debug_command(command)
            else
              raise "Unhandled event: #{JSON.dump(event.inspect)}"
            end
          end
        end.lazy
      end
# Create a generator that can be polled to advance the query loop.
#
# @yieldparam [Hash<String, Object>]
# @return [Enumerator]
# @raise [Error] if any of the FFI calls raise one.
Create a generator that can be polled to advance the query loop.
Create a generator that can be polled to advance the query loop .
def start 
        Enumerator.new do |yielder| 
          loop do 
            event = ffi_query.next_event
            case event.kind
            when 'Done'
              break
            when 'Result'
              yielder << event.data['bindings'].transform_values { |v| host.to_ruby(v) }
            when 'MakeExternal'
              handle_make_external(event.data)
            when 'ExternalCall'
              call_id = event.data['call_id']
              instance = event.data['instance']
              attribute = event.data['attribute']
              args = event.data['args']
              handle_call(attribute, call_id: call_id, instance: instance, args: args)
            when 'ExternalIsSubSpecializer'
              instance_id = event.data['instance_id']
              left_tag = event.data['left_class_tag']
              right_tag = event.data['right_class_tag']
              answer = host.subspecializer?(instance_id, left_tag: left_tag, right_tag: right_tag)
              question_result(answer, call_id: event.data['call_id'])
            when 'ExternalIsa'
              instance = event.data['instance']
              class_tag = event.data['class_tag']
              answer = host.isa?(instance, class_tag: class_tag)
              question_result(answer, call_id: event.data['call_id'])
            when 'ExternalUnify'
              left_instance_id = event.data['left_instance_id']
              right_instance_id = event.data['right_instance_id']
              answer = host.unify?(left_instance_id, right_instance_id)
              question_result(answer, call_id: event.data['call_id'])
            when 'Debug'
              puts event.data['message'] if event.data['message']
              print 'debug> '
              begin
                input = $stdin.readline.chomp.chomp(';')
              rescue EOFError
                next
              end
              command = JSON.dump(host.to_polar(input))
              ffi_query.debug_command(command)
            else
              raise "Unhandled event: #{JSON.dump(event.inspect)}"
            end
          end
        end.lazy
      end
def start Enumerator . new do | yielder | loop do event = ffi_query . next_event case event . kind when 'Done' break when 'Result' yielder << event . data [ 'bindings' ] . transform_values { | v | host . to_ruby ( v ) } when 'MakeExternal' handle_make_external ( event . data ) when 'ExternalCall' call_id = event . data [ 'call_id' ] instance = event . data [ 'instance' ] attribute = event . data [ 'attribute' ] args = event . data [ 'args' ] handle_call ( attribute , call_id : call_id , instance : instance , args : args ) when 'ExternalIsSubSpecializer' instance_id = event . data [ 'instance_id' ] left_tag = event . data [ 'left_class_tag' ] right_tag = event . data [ 'right_class_tag' ] answer = host . subspecializer? ( instance_id , left_tag : left_tag , right_tag : right_tag ) question_result ( answer , call_id : event . data [ 'call_id' ] ) when 'ExternalIsa' instance = event . data [ 'instance' ] class_tag = event . data [ 'class_tag' ] answer = host . isa? ( instance , class_tag : class_tag ) question_result ( answer , call_id : event . data [ 'call_id' ] ) when 'ExternalUnify' left_instance_id = event . data [ 'left_instance_id' ] right_instance_id = event . data [ 'right_instance_id' ] answer = host . unify? ( left_instance_id , right_instance_id ) question_result ( answer , call_id : event . data [ 'call_id' ] ) when 'Debug' puts event . data [ 'message' ] if event . data [ 'message' ] print 'debug> ' begin input = $stdin . readline . chomp . chomp ( ';' ) rescue EOFError next end command = JSON . dump ( host . to_polar ( input ) ) ffi_query . debug_command ( command ) else raise "Unhandled event: #{JSON.dump(event.inspect)}" end end end . lazy end
Create a generator that can be polled to advance the query loop.
Create a generator that can be polled to advance the query loop .
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength # rubocop:disable Metrics/BlockLength # rubocop:disable Metrics/BlockLength
None
Enumerator
[Error] if any of the FFI calls raise one.
[ Error ] if any of the FFI calls raise one .
None