Class: ConceptAI

Inherits:
Object
  • Object
show all
Includes:
AI
Defined in:
lib/asker/ai/concept_ai.rb

Overview

Add more info to every Concept instance. Encapsulating AI data => questions

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from AI

#exclude_questions, #make_questions, #make_questions_stages_bsf, #make_questions_stages_di, #make_questions_stages_t, #string_has_this_tags?

Methods included from AICalculate

#calculate_nearness_between_texts, #get_list1_and_list2_from, #reorder_list_with_row

Constructor Details

#initialize(concept, world) ⇒ ConceptAI

Returns a new instance of ConceptAI.



16
17
18
19
20
21
22
23
# File 'lib/asker/ai/concept_ai.rb', line 16

def initialize(concept, world)
  @concept = concept
  @world = world
  @questions = {d: [], b: [], f: [], i: [], s: [], t: []}
  @excluded_questions = {d: [], b: [], f: [], i: [], s: [], t: []}
  @num = 0 # Add a unique number to every question
  make_questions
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object

If a method call is missing, then delegate to concept parent.



32
33
34
35
# File 'lib/asker/ai/concept_ai.rb', line 32

def method_missing(method, *args, &block)
  raise "[DEBUG] ConceptAI.#{method}(#{args})"
  @concept.send(method, *args, &block)
end

Instance Attribute Details

#conceptObject (readonly)

Returns the value of attribute concept.



12
13
14
# File 'lib/asker/ai/concept_ai.rb', line 12

def concept
  @concept
end

#excluded_questionsObject (readonly)

Returns the value of attribute excluded_questions.



14
15
16
# File 'lib/asker/ai/concept_ai.rb', line 14

def excluded_questions
  @excluded_questions
end

#questionsObject (readonly)

Returns the value of attribute questions.



13
14
15
# File 'lib/asker/ai/concept_ai.rb', line 13

def questions
  @questions
end

Instance Method Details

#numObject



25
26
27
28
29
# File 'lib/asker/ai/concept_ai.rb', line 25

def num
  # Generates and return new "num" value
  @num += 1
  @num.to_s
end

#random_image_for(_conceptname) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/asker/ai/concept_ai.rb', line 37

def random_image_for(_conceptname)
  # Generates random image URL
  return "" if rand <= ProjectData.instance.get(:threshold)

  keys = @world.image_urls.keys
  keys.shuffle!
  values = @world.image_urls[keys[0]] # keys[0] could be conceptname
  return "" if values.nil?

  values.shuffle!
  "<img src=\"#{values[0]}\" alt=\"image\"><br/>"
end