class ConceptQL::FakeAnnotater

Constants

DOMAINS

Attributes

statement[R]

Public Class Methods

new(statement) click to toggle source
# File lib/conceptql/fake_annotater.rb, line 66
def initialize(statement)
  @statement = statement
end

Public Instance Methods

annotate() click to toggle source
# File lib/conceptql/fake_annotater.rb, line 70
def annotate
  traverse(statement)
end
fetch_domains(label) click to toggle source
# File lib/conceptql/fake_annotater.rb, line 115
def fetch_domains(label)
  recorded_domains[label]
end
previous_domains(arr) click to toggle source
# File lib/conceptql/fake_annotater.rb, line 104
def previous_domains(arr)
  extract = if arr.first == :recall
    [fetch_domains(arr[1])].compact
  elsif arr.last.is_a?(Hash) && arr.last[:left]
    [arr.last[:left]]
  else
    arr.select { |e| e.is_a?(Array) }
  end
  extract.map { |e| e.last[:annotation][:counts].keys }.flatten.compact.uniq
end
recorded_domains() click to toggle source
# File lib/conceptql/fake_annotater.rb, line 125
def recorded_domains
  @recorded_domains ||= {}
end
save_domains(op) click to toggle source
# File lib/conceptql/fake_annotater.rb, line 119
def save_domains(op)
  label = op.last[:label]
  return unless label
  recorded_domains[label] = op
end
traverse(stmt) click to toggle source
# File lib/conceptql/fake_annotater.rb, line 74
def traverse(stmt)
  stmt.recurse(Array, Hash) do |arr_or_hash|
    if arr_or_hash.is_a?(Array)
      arr_or_hash.unshift(arr_or_hash.shift.to_sym)
      domains = DOMAINS[arr_or_hash.first.to_sym]
      unless domains
        domains = previous_domains(arr_or_hash)
      else
        domains = [domains].flatten
      end
      annotate_hash = if arr_or_hash.last.is_a?(Hash)
        arr_or_hash.last[:annotation] ||= {}
      else
        annotate_hash = {}
        arr_or_hash.push(annotation: annotate_hash)
        annotate_hash
      end
      annotate_hash[:counts] = {}
      domains.each do |domain|
        annotate_hash[:counts][domain] = {}
      end
      save_domains(arr_or_hash)
    else
      arr_or_hash.deep_rekey!
      arr_or_hash[:annotation] ||= {}
    end
    arr_or_hash
  end
end