Class: ProgramR::Facade

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

Instance Method Summary collapse

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_sObject



59
60
61
# File 'lib/programr/facade.rb', line 59

def to_s
  @graph_master.to_s
end