Class: World
- Inherits:
-
Object
- Object
- World
- Defined in:
- lib/asker/data/world.rb
Instance Attribute Summary collapse
-
#concepts ⇒ Object
readonly
Returns the value of attribute concepts.
-
#contexts ⇒ Object
readonly
Returns the value of attribute contexts.
-
#filenames ⇒ Object
readonly
Returns the value of attribute filenames.
-
#image_urls ⇒ Object
readonly
Returns the value of attribute image_urls.
Instance Method Summary collapse
- #find_neighbors_for_every_concept(concepts) ⇒ Object
-
#initialize(concepts, show_progress = true) ⇒ World
constructor
A new instance of World.
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
#concepts ⇒ Object (readonly)
Returns the value of attribute concepts.
6 7 8 |
# File 'lib/asker/data/world.rb', line 6 def concepts @concepts end |
#contexts ⇒ Object (readonly)
Returns the value of attribute contexts.
6 7 8 |
# File 'lib/asker/data/world.rb', line 6 def contexts @contexts end |
#filenames ⇒ Object (readonly)
Returns the value of attribute filenames.
6 7 8 |
# File 'lib/asker/data/world.rb', line 6 def filenames @filenames end |
#image_urls ⇒ Object (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 |