Class: StageD
Overview
range d1-d4: d1choice, d1none-misspelled, d1none
Instance Method Summary collapse
Methods inherited from BaseStage
#concept, #images, #initialize, #lang, #name, #names, #neighbors, #num, #random_image_for, #texts, #type
Constructor Details
This class inherits a constructor from BaseStage
Instance Method Details
#run ⇒ Object
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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/asker/ai/stages/stage_d.rb', line 11 def run # Stage D: process every definition, I mean every <def> tag questions = [] return questions unless concept.type == "text" lang = concept.lang # for every <text> do this concept.texts.each do |t| # s => concept name, none and neighbors s = Set.new [name(:raw), lang.text_for(:none)] concept.neighbors.each { |n| s.add n[:concept].name(:decorated) } a = s.to_a # Question choose between 4 options if s.count > 3 q = Question.new(:choice) q.name = "#{name(:id)}-#{num}-d1choose" q.text = random_image_for(name(:raw)) + lang.text_for(:d1, t) q.good = name(:raw) q.bads << lang.text_for(:none) q.bads << a[2] q.bads << a[3] questions << q end # Question choose between 4 options, good none (Syntax error) if s.count > 3 q = Question.new(:choice) q.name = "#{name(:id)}-#{num}-d1none-misspelled" q.text = random_image_for(name(:raw)) + lang.text_for(:d1, t) q.good = lang.text_for(:none) q.bads << lang.do_mistake_to(name(:raw)) q.bads << a[2] q.bads << a[3] q.feedback = "Option misspelled!: #{name(:raw)}" questions << q end s.delete(name(:raw)) a = s.to_a # Question choose between 4 options, good none if s.count > 3 q = Question.new(:choice) q.name = "#{name(:id)}-#{num}-d1none" q.text = random_image_for(name(:raw)) + lang.text_for(:d1, t) q.good = lang.text_for(:none) q.bads << a[1] q.bads << a[2] q.bads << a[3] questions << q end # Question choice => mispelled q = Question.new(:choice) q.name = "#{name(:id)}-#{num}-d2def-misspelled" q.text = random_image_for(name(:raw)) + lang.text_for(:d2, name(:decorated), lang.do_mistake_to(t)) q.good = lang.text_for(:misspelling) q.bads << lang.text_for(:true) q.bads << lang.text_for(:false) q.feedback = "Definition text misspelled!: #{t}" questions << q # Question choice => name mispelled q = Question.new(:choice) q.name = "#{name(:id)}-#{num}-d2name-misspelled" q.text = random_image_for(name(:raw)) + lang.text_for(:d2, lang.do_mistake_to(name(:raw)), t) q.good = lang.text_for(:misspelling) q.bads << lang.text_for(:true) q.bads << lang.text_for(:false) q.feedback = "Concept name misspelled!: #{name(:raw)}" questions << q # Question choice => true q = Question.new(:choice) q.name = "#{name(:id)}-#{num}-d2true-misspelled" q.text = random_image_for(name(:raw)) + lang.text_for(:d2, name(:raw), t) q.good = lang.text_for(:true) q.bads << lang.text_for(:misspelling) q.bads << lang.text_for(:false) questions << q # Question boolean => true q = Question.new(:boolean) q.name = "#{name(:id)}-#{num}-d2true" q.text = random_image_for(name(:raw)) + lang.text_for(:d2, name(:raw), t) q.good = "TRUE" questions << q # Question choice => false if a.size > 1 q = Question.new(:choice) q.name = "#{name(:id)}-#{num}-d2false-misspelled" q.text = random_image_for(name(:raw)) + lang.text_for(:d2, a[1], t) q.good = lang.text_for(:false) q.bads << lang.text_for(:misspelling) q.bads << lang.text_for(:true) questions << q # Question boolean => false q = Question.new(:boolean) q.name = "#{name(:id)}-#{num}-d2false" q.text = random_image_for(name(:raw)) + lang.text_for(:d2, a[1], t) q.good = "FALSE" questions << q end # Question hidden name questions q = Question.new(:short) q.name = "#{name(:id)}-#{num}-d3hidden" q.text = random_image_for(name(:raw)) + lang.text_for(:d3, lang.hide_text(name(:raw)), t) q.shorts << name(:raw) q.shorts << name(:raw).tr("-", " ").tr("_", " ") concept.names.each { |n| q.shorts << n if n != name } questions << q # Question filtered text questions filtered = lang.text_with_connectors(t) indexes = filtered[:indexes] groups = indexes.combination(4).to_a.shuffle max = (indexes.size / 4).to_i groups[0, max].each do |e| e.sort! q = Question.new(:match) q.shuffle_off q.name = "#{name}-#{num}-d4filtered" s = lang.build_text_from_filtered(filtered, e) q.text = random_image_for(name(:raw)) + lang.text_for(:d4, name(:raw), s) e.each_with_index do |value, index| q.matching << [(index + 1).to_s, filtered[:words][value][:word].downcase] end questions << q end end questions end |