Class: StageD
Instance Method Summary collapse
-
#run ⇒ Object
range d1-d4.
Methods inherited from BaseStage
Constructor Details
This class inherits a constructor from BaseStage
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class BaseStage
Instance Method Details
#run ⇒ Object
range d1-d4
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 149 150 151 152 153 154 155 156 157 158 |
# 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 type == 'text' # for every <text> do this texts.each do |t| s=Set.new [name(:raw), lang.text_for(:none)] 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 and type=="text" then 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 then 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 boolean => TRUE #q = Question.new(:boolean) #q.name="#{name}-#{num}-d2true" #q.text=random_image_for(name) + lang.text_for(:d2,name,t) #q.good="TRUE" #questions << q q = Question.new(:choice) q.name="#{name(:id)}-#{num}-d2def-mispelled" 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 mispelled!: #{t}" questions << q if type=="text" q = Question.new(:choice) q.name="#{name(:id)}-#{num}-d2name-mispelled" 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 mispelled!: #{name(:raw)}" questions << q end q = Question.new(:choice) q.name="#{name(:id)}-#{num}-d2true" 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 if a.size>1 then 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 end #Question type <a4desc>: boolean => FALSE #if neighbors.count>0 then # q = Question.new(:boolean) # q.name="#{name}-#{num}-d2false" # q.text=random_image_for(name) + lang.text_for(:d2, neighbors[0][:concept].name, t) # q.good="FALSE" # questions << q #end if type=="text" #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).gsub("-"," ").gsub("_"," ") names.each do |n| q.shorts << n if n!=name end questions << q end # indexes = [] # exclude = ["[", "]", "(", ")", "\"" ] # filtered[:words].each_with_index do |item,index| # flag=true # exclude.each { |e| flag=false if (item[:word].include?(e)) } # indexes << index if flag # end #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 return questions end |