Class: ProgramR::Person2

Inherits:
Object
  • Object
show all
Defined in:
lib/programr/aiml_elements.rb

Constant Summary collapse

@@environment =
Environment.new
@@swap =
{'me' => 'you', 'you' => 'me'}

Instance Method Summary collapse

Constructor Details

#initializePerson2

Returns a new instance of Person2.



262
# File 'lib/programr/aiml_elements.rb', line 262

def initialize; @sentence = [] end

Instance Method Details

#add(anObj) ⇒ Object



263
# File 'lib/programr/aiml_elements.rb', line 263

def add(anObj); @sentence.push(anObj) end

#executeObject Also known as: to_s



264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
# File 'lib/programr/aiml_elements.rb', line 264

def execute
  res = ''
  @sentence.each{|tocken|
    res += tocken.to_s
  }
  gender = @@environment.get('gender')
  res.gsub(/\b((with|to|of|for|give|gave|giving) (you|me)|you|i)\b/i){
    if($3)
      $2.downcase+' '+@@swap[$3.downcase]
    elsif($1.downcase == 'you')
      'i'
    elsif($1.downcase == 'i')
      'you'
    end
  }
end

#inspectObject



281
# File 'lib/programr/aiml_elements.rb', line 281

def inspect(); "person2 -> #{execute}" end