Module: Confabulator::ConfabulatorLanguage::Choice3
- Defined in:
- lib/confabulator/language.rb
Instance Method Summary collapse
- #choices(kb, no_weighting = false) ⇒ Object
- #confabulate(kb = nil) ⇒ Object
- #tree(kb = nil) ⇒ Object
Instance Method Details
#choices(kb, no_weighting = false) ⇒ Object
114 115 116 117 118 119 120 121 |
# File 'lib/confabulator/language.rb', line 114 def choices(kb, no_weighting = false) elems = [] ((no_weighting || first_sentence.weight.empty?) ? 1 : first_sentence.weight.value).times { elems << first_sentence.sentence } rest_sentences.elements.each do |s| ((no_weighting || s.weight.empty?) ? 1 : s.weight.value).times { elems << s.sentence_or_empty } end elems end |
#confabulate(kb = nil) ⇒ Object
123 124 125 126 |
# File 'lib/confabulator/language.rb', line 123 def confabulate(kb = nil) elems = choices(kb) elems[elems.length * rand].confabulate(kb) end |
#tree(kb = nil) ⇒ Object
128 129 130 131 |
# File 'lib/confabulator/language.rb', line 128 def tree(kb = nil) elems = choices(kb, true) { :choices => elems.map {|e| Confabulator::Parser.remove_singleton_arrays(e.tree(kb)) } } end |