Class: ProgramR::Facade
- Inherits:
-
Object
- Object
- ProgramR::Facade
- Defined in:
- lib/programr/facade.rb
Instance Method Summary collapse
- #dumping(theCacheFilename = 'cache') ⇒ Object
- #get_reaction(stimula, firstStimula = true) ⇒ Object
-
#initialize(cache = nil) ⇒ Facade
constructor
A new instance of Facade.
- #learn(files) ⇒ Object
- #loading(theCacheFilename = 'cache') ⇒ Object
- #merging(theCacheFilename = 'cache') ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(cache = nil) ⇒ Facade
Returns a new instance of Facade.
8 9 10 11 12 |
# File 'lib/programr/facade.rb', line 8 def initialize(cache = nil) @graph_master = GraphMaster.new @parser = AimlParser.new(@graph_master) @history = History.new end |
Instance Method Details
#dumping(theCacheFilename = 'cache') ⇒ Object
28 29 30 |
# File 'lib/programr/facade.rb', line 28 def dumping(theCacheFilename='cache') Cache::dumping(theCacheFilename,@graph_master) end |
#get_reaction(stimula, firstStimula = true) ⇒ Object
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 |
# File 'lib/programr/facade.rb', line 32 def get_reaction(stimula,firstStimula=true) starGreedy = [] #TODO verify if case insensitive. Cross check with parser #@history.updateStimula(stimula.upcase) if(firstStimula) @history.updateStimula(stimula.upcase) if(firstStimula) thinkIsActive = false reaction = @graph_master.get_reaction(stimula.upcase, @history.that, @history.topic,starGreedy) @history.updateStarMatches(starGreedy) res = '' reaction.each{|tocken| if(tocken.class == Srai) tocken = get_reaction(tocken.pattern,false) @history.updateStarMatches(starGreedy) end if tocken.class == Think thinkIsActive = ! thinkIsActive next end value = tocken.to_s res += value unless(thinkIsActive) } #TODO verify if case insensitive. Cross check with main program & parser @history.updateResponse(res.strip.upcase) if(firstStimula) return res.strip end |
#learn(files) ⇒ Object
14 15 16 |
# File 'lib/programr/facade.rb', line 14 def learn(files) AimlFinder::find(files).each{|f| File.open(f,'r'){|f| @parser.parse f} } end |
#loading(theCacheFilename = 'cache') ⇒ Object
18 19 20 21 |
# File 'lib/programr/facade.rb', line 18 def loading(theCacheFilename='cache') cache = Cache::loading(theCacheFilename) @graph_master = cache if cache end |
#merging(theCacheFilename = 'cache') ⇒ Object
23 24 25 26 |
# File 'lib/programr/facade.rb', line 23 def merging(theCacheFilename='cache') cache = Cache::loading(theCacheFilename) @graph_master.merge(cache) if cache end |
#to_s ⇒ Object
59 60 61 |
# File 'lib/programr/facade.rb', line 59 def to_s @graph_master.to_s end |