Class: World

Inherits:
Object
  • Object
show all
Defined in:
lib/asker/data/world.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(concepts, show_progress = true) ⇒ World

Returns a new instance of World.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/asker/data/world.rb', line 8

def initialize(concepts, show_progress=true)
  find_neighbors_for_every_concept(concepts)

  @concepts   = {}
  @filenames  = []
  @contexts   = []
  @image_urls = {}

  concepts.each do |c|
    if c.process
      @concepts[c.name] = c
      @filenames << c.filename
      @contexts  << c.context
    end
  end
  @filenames.uniq!
  @contexts.uniq!

  threads = []
  concepts.each do |c|
    print('.') if show_progress
    # puts "[DEBUG] #{c.name}\n"
    # filter = [ c.name.clone ] + c.context.clone
    filter = c.name.clone
    threads << Thread.new { @image_urls[c.name] = ImageUrlLoader::load(filter) }
  end
  @contexts.each do |filter|
    print('.') if show_progress
    threads << Thread.new { @image_urls[ filter.join('.').to_s ] = ImageUrlLoader::load(filter) }
  end
  threads.each { |t| t.join } # wait for all threads to finish
  print("\n") if show_progress
end

Instance Attribute Details

#conceptsObject (readonly)

Returns the value of attribute concepts.



6
7
8
# File 'lib/asker/data/world.rb', line 6

def concepts
  @concepts
end

#contextsObject (readonly)

Returns the value of attribute contexts.



6
7
8
# File 'lib/asker/data/world.rb', line 6

def contexts
  @contexts
end

#filenamesObject (readonly)

Returns the value of attribute filenames.



6
7
8
# File 'lib/asker/data/world.rb', line 6

def filenames
  @filenames
end

#image_urlsObject (readonly)

Returns the value of attribute image_urls.



6
7
8
# File 'lib/asker/data/world.rb', line 6

def image_urls
  @image_urls
end

Instance Method Details

#find_neighbors_for_every_concept(concepts) ⇒ Object



42
43
44
45
46
47
48
49
50
51
# File 'lib/asker/data/world.rb', line 42

def find_neighbors_for_every_concept(concepts)
  concepts.each do |i|
    concepts.each do |j|
      if (i.id!=j.id) then
        i.try_adding_neighbor(j)
        i.try_adding_references(j)
      end
    end
  end
end