class World

World data

Attributes

concepts[R]
contexts[R]
filenames[R]
image_urls[R]

Public Class Methods

new(concepts, show_progress = true) click to toggle source

Initialize World object @param concepts (Array) @param show_progress (Boolean)

# File lib/asker/data/world.rb, line 16
def initialize(concepts, show_progress = true)
  find_neighbors_for_every_concept(concepts)
  @concepts, @filenames, @contexts = get_lists_from(concepts)
  @image_urls = find_url_images_from_internet(show_progress)
end

Public Instance Methods

find_neighbors_for_every_concept(concepts) click to toggle source

For every concept… find its neighbors @param concepts (Array)

# File lib/asker/data/world.rb, line 25
def find_neighbors_for_every_concept(concepts)
  concepts.each do |i|
    concepts.each do |j|
      if i.id != j.id
        i.try_adding_neighbor(j)
        i.try_adding_references(j)
      end
    end
  end
end

Private Instance Methods

find_url_images_from_internet(show_progress) click to toggle source

rubocop:disable Metrics/MethodLength rubocop:disable Metrics/AbcSize

# File lib/asker/data/world.rb, line 58
def find_url_images_from_internet(show_progress)
  param = Application.instance.config['global']['internet'] || 'yes'
  return {} unless param == 'yes'

  Logger.verbose "\n[INFO] Loading data from Internet" if show_progress
  threads = []
  searchs = []
  urls = {}

  @concepts&.each_key { |key| searchs << key }
  @contexts.each { |filter| searchs << filter.join(' ').to_s }
  searchs.each do |search|
    print('.') if show_progress
    threads << Thread.new { urls[search] = ImageUrlLoader.load(search) }
  end
  threads.each(&:join) # wait for all threads to finish
  print("\n") if show_progress
  urls
end
get_lists_from(input) click to toggle source

rubocop:disable Metrics/MethodLength

# File lib/asker/data/world.rb, line 39
def get_lists_from(input)
  concepts = {}
  filenames = []
  contexts = []
  input.each do |c|
    next unless c.process

    concepts[c.name] = c
    filenames << c.filename
    contexts  << c.context
  end
  filenames.uniq!
  contexts.uniq!
  [concepts, filenames, contexts]
end