programr 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +64 -0
- data/Rakefile +2 -0
- data/conf/readOnlyTags.yaml +37 -0
- data/lib/programr.rb +5 -0
- data/lib/programr/aiml_elements.rb +352 -0
- data/lib/programr/aiml_parser.rb +269 -0
- data/lib/programr/environment.rb +75 -0
- data/lib/programr/facade.rb +65 -0
- data/lib/programr/graph_master.rb +110 -0
- data/lib/programr/history.rb +82 -0
- data/lib/programr/utils.rb +30 -0
- data/lib/programr/version.rb +3 -0
- data/programr.gemspec +17 -0
- data/test/data/1.aiml +125 -0
- data/test/data/facade.aiml +233 -0
- data/test/data/mixed/dir/badfile +1 -0
- data/test/data/mixed/dir/in_dir.aiml +9 -0
- data/test/data/mixed/dir/subdir/in_sub_dir.aiml +17 -0
- data/test/data/mixed/single.aiml +9 -0
- data/test/data/test.aiml +44 -0
- data/test/test_facade.rb +67 -0
- data/test/test_utils.rb +18 -0
- metadata +81 -0
@@ -0,0 +1,82 @@
|
|
1
|
+
module ProgramR
|
2
|
+
class History
|
3
|
+
@@topic = 'default'
|
4
|
+
@@inputs = []
|
5
|
+
@@responses = []
|
6
|
+
@@starGreedy = []
|
7
|
+
@@thatGreedy = []
|
8
|
+
@@topicGreedy = []
|
9
|
+
|
10
|
+
def topic; @@topic end
|
11
|
+
|
12
|
+
def that
|
13
|
+
return 'undef' unless @@responses[0]
|
14
|
+
@@responses[0]
|
15
|
+
end
|
16
|
+
|
17
|
+
def justbeforethat
|
18
|
+
return 'undef' unless @@responses[1]
|
19
|
+
@@responses[1]
|
20
|
+
end
|
21
|
+
|
22
|
+
def justthat
|
23
|
+
return 'undef' unless @@inputs[0]
|
24
|
+
@@inputs[0]
|
25
|
+
end
|
26
|
+
|
27
|
+
def beforethat
|
28
|
+
return 'undef' unless @@inputs[1]
|
29
|
+
@@inputs[1]
|
30
|
+
end
|
31
|
+
|
32
|
+
def getStar(anIndex)
|
33
|
+
return 'undef' unless @@starGreedy[anIndex]
|
34
|
+
@@starGreedy[anIndex].join(' ')
|
35
|
+
end
|
36
|
+
|
37
|
+
def getThatStar(anIndex)
|
38
|
+
return 'undef' unless @@thatGreedy[anIndex]
|
39
|
+
@@thatGreedy[anIndex].join(' ')
|
40
|
+
end
|
41
|
+
|
42
|
+
def getTopicStar(anIndex)
|
43
|
+
return 'undef' unless @@topicGreedy[anIndex]
|
44
|
+
@@topicGreedy[anIndex].join(' ')
|
45
|
+
end
|
46
|
+
|
47
|
+
def updateTopic(aTopic)
|
48
|
+
@@topic = aTopic
|
49
|
+
end
|
50
|
+
|
51
|
+
def updateResponse(aResponse)
|
52
|
+
@@responses.unshift(aResponse)
|
53
|
+
end
|
54
|
+
|
55
|
+
def updateStimula(aStimula)
|
56
|
+
@@inputs.unshift(aStimula)
|
57
|
+
end
|
58
|
+
|
59
|
+
def getStimula(anIndex)
|
60
|
+
@@inputs[anIndex]
|
61
|
+
end
|
62
|
+
|
63
|
+
def updateStarMatches(aStarGreedyArray)
|
64
|
+
@@starGreedy = []
|
65
|
+
@@thatGreedy = []
|
66
|
+
@@topicGreedy = []
|
67
|
+
currentGreedy = @@starGreedy
|
68
|
+
aStarGreedyArray.each do |greedy|
|
69
|
+
if(greedy == '<that>')
|
70
|
+
currentGreedy = @@thatGreedy
|
71
|
+
elsif(greedy == '<topic>')
|
72
|
+
currentGreedy = @@topicGreedy
|
73
|
+
elsif(greedy == '<newMatch>')
|
74
|
+
currentGreedy.push([])
|
75
|
+
else
|
76
|
+
currentGreedy[-1].push(greedy)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module ProgramR
|
2
|
+
module Cache
|
3
|
+
def self.dumping(aFilename,theGraphMaster)
|
4
|
+
File.open(aFilename,'w') do |file|
|
5
|
+
file.write(Marshal.dump(theGraphMaster,-1))
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.loading(aFilename)
|
10
|
+
File.open(aFilename,'r') do |file|
|
11
|
+
return Marshal.load(file.read)
|
12
|
+
end rescue nil
|
13
|
+
end
|
14
|
+
end # module Cache
|
15
|
+
|
16
|
+
module AimlFinder
|
17
|
+
# Returns an array of aiml files recursively found
|
18
|
+
def self.find(files_and_dirs)
|
19
|
+
files = []
|
20
|
+
files_and_dirs.each{|file|
|
21
|
+
if File.file?(file) && (file =~ /.*\.aiml$/)
|
22
|
+
files << file
|
23
|
+
next
|
24
|
+
end
|
25
|
+
files += find(Dir.glob("#{file}/*"))
|
26
|
+
}
|
27
|
+
files
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end #module ProgramR
|
data/programr.gemspec
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/programr/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Mauro Cicio, Nicholas H.Tollervey, Ben Minton and Robert J Whitney"]
|
6
|
+
gem.email = ["robertj.whitney@gmail.com"]
|
7
|
+
gem.description = %q{Ruby interpreter for the AIML}
|
8
|
+
gem.summary = %q{ProgramR is a Ruby implementation of an interpreter for the Artificial Intelligence Markup Language (AIML) based on the work of Dr. Wallace and defined by the Alicebot and AIML Architecture Committee of the A.L.I.C.E. AI Foundation (http://alicebot.org}
|
9
|
+
gem.homepage = "http://aiml-programr.rubyforge.org/"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "programr"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Programr::VERSION
|
17
|
+
end
|
data/test/data/1.aiml
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
<?xml version="1.0" encoding="ISO-8859-1"?>
|
2
|
+
<aiml version="1.0.1" xmlns="http://alicebot.org/2001/AIML-1.0.1"
|
3
|
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
4
|
+
xsi:schemaLocation="http://alicebot.org/2001/AIML-1.0.1 http://aitools.org/aiml/schema/AIML.xsd">
|
5
|
+
<!-- Free software (c) 2001 ALICE A.I. Foundation. -->
|
6
|
+
<!-- This program is open source code released under -->
|
7
|
+
<!-- the terms of the GNU General Public License -->
|
8
|
+
<!-- as published by the Free Software Foundation. -->
|
9
|
+
<!-- Complies with AIML 1.0 Tag Set Specification -->
|
10
|
+
<!-- as adopted by the ALICE A.I. Foundation. -->
|
11
|
+
<!-- A.L.I.C.E. Build Wed Sep 26 13:05:06 PDT 2001 -->
|
12
|
+
<!-- 41124 total categories. -->
|
13
|
+
<category>
|
14
|
+
<pattern>1 *</pattern>
|
15
|
+
<template>One what?
|
16
|
+
</template></category>
|
17
|
+
<category>
|
18
|
+
<pattern>1 0</pattern>
|
19
|
+
<template>One.
|
20
|
+
</template></category>
|
21
|
+
<category>
|
22
|
+
<pattern>1</pattern>
|
23
|
+
<template>Only one?
|
24
|
+
</template></category>
|
25
|
+
<category>
|
26
|
+
<pattern>1 CENT</pattern>
|
27
|
+
<template>That won't buy anything.
|
28
|
+
</template></category>
|
29
|
+
<category>
|
30
|
+
<pattern>1 DOLLAR</pattern>
|
31
|
+
<template>You can't buy much for a dollar anymore.
|
32
|
+
</template></category>
|
33
|
+
<category>
|
34
|
+
<pattern>1 OR 2</pattern>
|
35
|
+
<template>A couple.
|
36
|
+
</template></category>
|
37
|
+
<category>
|
38
|
+
<pattern>1 POINT *</pattern>
|
39
|
+
<template>That's more precision than I need to know.
|
40
|
+
</template></category>
|
41
|
+
<category>
|
42
|
+
<pattern>1 YEAR</pattern>
|
43
|
+
<template>That can seem like a long time.
|
44
|
+
</template></category>
|
45
|
+
<category>
|
46
|
+
<pattern>10 *</pattern>
|
47
|
+
<template><srai>WHAT IS 10<star/></srai>
|
48
|
+
</template></category>
|
49
|
+
<category>
|
50
|
+
<pattern>10</pattern>
|
51
|
+
<template><srai>I AM 10 YEARS OLD</srai>
|
52
|
+
</template></category>
|
53
|
+
<category>
|
54
|
+
<pattern>100 *</pattern><that>HOW MUCH *</that>
|
55
|
+
<template>Wow that is <random>
|
56
|
+
<li>expensive.</li>
|
57
|
+
<li>a lot of money.</li>
|
58
|
+
<li>more than I have.</li>
|
59
|
+
</random>
|
60
|
+
</template></category>
|
61
|
+
<category>
|
62
|
+
<pattern>100 PERSON</pattern>
|
63
|
+
<template><srai>WHO IS 100 PERSON</srai>
|
64
|
+
</template></category>
|
65
|
+
<category>
|
66
|
+
<pattern>11</pattern>
|
67
|
+
<template><srai>I am 11 years old</srai>
|
68
|
+
</template></category>
|
69
|
+
<category>
|
70
|
+
<pattern>12</pattern>
|
71
|
+
<template><srai>I am 12 years old</srai>
|
72
|
+
</template></category>
|
73
|
+
<category>
|
74
|
+
<pattern>123456789</pattern>
|
75
|
+
<template>Ten.
|
76
|
+
</template></category>
|
77
|
+
<category>
|
78
|
+
<pattern>13 *</pattern>
|
79
|
+
<template><srai>I am 13 years old</srai>
|
80
|
+
</template></category>
|
81
|
+
<category>
|
82
|
+
<pattern>13</pattern>
|
83
|
+
<template><srai>I am 13 years old</srai>
|
84
|
+
</template></category>
|
85
|
+
<category>
|
86
|
+
<pattern>14 *</pattern>
|
87
|
+
<template><srai>I am 14 years old</srai>
|
88
|
+
</template></category>
|
89
|
+
<category>
|
90
|
+
<pattern>14</pattern>
|
91
|
+
<template><srai>I am 14 years old</srai>
|
92
|
+
</template></category>
|
93
|
+
<category>
|
94
|
+
<pattern>15</pattern>
|
95
|
+
<template><srai>I am 15 years old</srai>
|
96
|
+
</template></category>
|
97
|
+
<category>
|
98
|
+
<pattern>153</pattern>
|
99
|
+
<template>One hundred fifty three.
|
100
|
+
</template></category>
|
101
|
+
<category>
|
102
|
+
<pattern>16</pattern>
|
103
|
+
<template><srai>I am 16 years old</srai>
|
104
|
+
</template></category>
|
105
|
+
<category>
|
106
|
+
<pattern>17</pattern>
|
107
|
+
<template><srai>I am 17 years old</srai>
|
108
|
+
</template></category>
|
109
|
+
<category>
|
110
|
+
<pattern>18</pattern>
|
111
|
+
<template><srai>I AM 18 YEARS OLD</srai>
|
112
|
+
</template></category>
|
113
|
+
<category>
|
114
|
+
<pattern>184</pattern>
|
115
|
+
<template><srai>WHO IS 184 PERSON</srai>
|
116
|
+
</template></category>
|
117
|
+
<category>
|
118
|
+
<pattern>19</pattern>
|
119
|
+
<template><srai>I AM 19 YEARS OLD</srai>
|
120
|
+
</template></category>
|
121
|
+
<category>
|
122
|
+
<pattern>1999</pattern>
|
123
|
+
<template>This year.
|
124
|
+
</template></category>
|
125
|
+
</aiml>
|
@@ -0,0 +1,233 @@
|
|
1
|
+
<?xml version="1.0" encoding="ISO-8859-1"?>
|
2
|
+
<aiml version="1.0.1" xmlns="http://alicebot.org/2001/AIML-1.0.1"
|
3
|
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
4
|
+
xsi:schemaLocation="http://alicebot.org/2001/AIML-1.0.1 http://aitools.org/aiml/schema/AIML.xsd">
|
5
|
+
Client: I admire robots like you.
|
6
|
+
Robot: That's good information: Joe said he admire robots like me.
|
7
|
+
|
8
|
+
<topic name="WORK">
|
9
|
+
<category>
|
10
|
+
<pattern>atomic test</pattern>
|
11
|
+
<template>new test succeded</template>
|
12
|
+
</category>
|
13
|
+
</topic>
|
14
|
+
|
15
|
+
<category>
|
16
|
+
<pattern>yes *</pattern>
|
17
|
+
<template><srai>yes</srai> <sr/></template>
|
18
|
+
</category>
|
19
|
+
|
20
|
+
<category>
|
21
|
+
<pattern>yes</pattern>
|
22
|
+
<template>ok yes</template>
|
23
|
+
</category>
|
24
|
+
|
25
|
+
<topic name="* GAME">
|
26
|
+
<category>
|
27
|
+
<pattern>atomic test</pattern>
|
28
|
+
<template>topic star test succeded <topicstar/></template>
|
29
|
+
</category>
|
30
|
+
</topic>
|
31
|
+
|
32
|
+
<category>
|
33
|
+
<pattern>test thatstar</pattern>
|
34
|
+
<template>WHAT IS YOUR FAVORITE FOOTBALL TEAM</template>
|
35
|
+
</category>
|
36
|
+
|
37
|
+
<category>
|
38
|
+
<pattern>MY FAVORITE FOOTBALL TEAM IS *</pattern>
|
39
|
+
<template>ALSO MINE IS <star index='1'/></template>
|
40
|
+
</category>
|
41
|
+
|
42
|
+
<category>
|
43
|
+
<pattern>*</pattern> <that>WHAT IS YOUR FAVORITE *</that>
|
44
|
+
<template><srai>MY FAVORITE <thatstar/> IS <star/></srai></template>
|
45
|
+
</category>
|
46
|
+
|
47
|
+
<category>
|
48
|
+
<pattern>gender test 2 *</pattern>
|
49
|
+
<template><gender><star/></gender></template>
|
50
|
+
</category>
|
51
|
+
|
52
|
+
<category>
|
53
|
+
<pattern>test gender</pattern>
|
54
|
+
<template><gender>he told to her to take a hike</gender> but
|
55
|
+
<gender>his ego was too much for her</gender></template>
|
56
|
+
</category>
|
57
|
+
|
58
|
+
<category>
|
59
|
+
<pattern>* answers no</pattern>
|
60
|
+
<template><person><star/></person> answers no</template>
|
61
|
+
</category>
|
62
|
+
|
63
|
+
<category>
|
64
|
+
<pattern>you say everything ok to me</pattern>
|
65
|
+
<template><person2>you say everything ok to me</person2></template>
|
66
|
+
</category>
|
67
|
+
|
68
|
+
<category>
|
69
|
+
<pattern>test input</pattern>
|
70
|
+
<template><input/>.<input index="2"/></template>
|
71
|
+
</category>
|
72
|
+
|
73
|
+
<category>
|
74
|
+
<pattern>random test</pattern>
|
75
|
+
<template>
|
76
|
+
<random>
|
77
|
+
<li>A</li>
|
78
|
+
</random>
|
79
|
+
</template>
|
80
|
+
</category>
|
81
|
+
|
82
|
+
<category>
|
83
|
+
<pattern>formal test</pattern>
|
84
|
+
<template><formal>the formal test</formal></template>
|
85
|
+
</category>
|
86
|
+
|
87
|
+
<category>
|
88
|
+
<pattern>sentence test</pattern>
|
89
|
+
<template><sentence>the sentence test</sentence></template>
|
90
|
+
</category>
|
91
|
+
|
92
|
+
<category>
|
93
|
+
<pattern>I AM BLOND</pattern>
|
94
|
+
<template>You sound very
|
95
|
+
<condition name="gender" value="*emale">attractive.</condition>
|
96
|
+
<condition name="gender" value="male">handsome.</condition>
|
97
|
+
</template>
|
98
|
+
</category>
|
99
|
+
|
100
|
+
<category>
|
101
|
+
<pattern>I AM RED</pattern>
|
102
|
+
<template>You sound very
|
103
|
+
<condition>
|
104
|
+
<li name="gender" value="female">attractive.</li>
|
105
|
+
<li name="gender" value="male">handsome.</li>
|
106
|
+
</condition>
|
107
|
+
</template>
|
108
|
+
</category>
|
109
|
+
|
110
|
+
<category>
|
111
|
+
<pattern>I AM BLACK</pattern>
|
112
|
+
<template>You sound very
|
113
|
+
<condition name="gender">
|
114
|
+
<li value="female">attractive.</li>
|
115
|
+
<li value="male">handsome.</li>
|
116
|
+
</condition>
|
117
|
+
</template>
|
118
|
+
</category>
|
119
|
+
|
120
|
+
<category>
|
121
|
+
<pattern>test set</pattern>
|
122
|
+
<template><get_gender/>.<set_gender>female</set_gender>.<get_gender/></template>
|
123
|
+
</category>
|
124
|
+
|
125
|
+
<category>
|
126
|
+
<pattern>think test. i am male</pattern>
|
127
|
+
<template>ok.<think><get_gender/></think></template>
|
128
|
+
</category>
|
129
|
+
|
130
|
+
<category>
|
131
|
+
<pattern>question test</pattern>
|
132
|
+
<template><question/></template>
|
133
|
+
</category>
|
134
|
+
|
135
|
+
<category>
|
136
|
+
<pattern>get test 1</pattern>
|
137
|
+
<template><bot_name/></template>
|
138
|
+
</category>
|
139
|
+
|
140
|
+
<category>
|
141
|
+
<pattern>get test 2</pattern>
|
142
|
+
<template><get name="ip"/></template>
|
143
|
+
</category>
|
144
|
+
|
145
|
+
<category>
|
146
|
+
<pattern>justbeforethat tag test</pattern>
|
147
|
+
<template><that index="2,1"/></template>
|
148
|
+
</category>
|
149
|
+
|
150
|
+
<category>
|
151
|
+
<pattern>that tag test</pattern>
|
152
|
+
<template><that/></template>
|
153
|
+
</category>
|
154
|
+
|
155
|
+
<category>
|
156
|
+
<pattern>atomic test</pattern>
|
157
|
+
<template>test succeded</template>
|
158
|
+
</category>
|
159
|
+
|
160
|
+
<category>
|
161
|
+
<pattern>srai test</pattern>
|
162
|
+
<template><srai>atomic test</srai><think><set_topic>WORK</set_topic></think></template>
|
163
|
+
</category>
|
164
|
+
|
165
|
+
<category>
|
166
|
+
<pattern>that test</pattern>
|
167
|
+
<that>NEW TEST SUCCEDED</that>
|
168
|
+
<template>that test 1</template>
|
169
|
+
</category>
|
170
|
+
|
171
|
+
<category>
|
172
|
+
<pattern>that test</pattern>
|
173
|
+
<that>THAT TEST 1</that>
|
174
|
+
<template>that test 2<think><set_topic>OK GAME</set_topic></think></template>
|
175
|
+
</category>
|
176
|
+
|
177
|
+
<category>
|
178
|
+
<pattern>uppercase test</pattern>
|
179
|
+
<template>the <uppercase>uppercase</uppercase> test</template>
|
180
|
+
</category>
|
181
|
+
|
182
|
+
<category>
|
183
|
+
<pattern>LOWERCASE TEST</pattern>
|
184
|
+
<template>the <lowercase>LOWERCASE</lowercase> test</template>
|
185
|
+
</category>
|
186
|
+
|
187
|
+
<category>
|
188
|
+
<pattern>DATE TEST</pattern>
|
189
|
+
<template><date/></template>
|
190
|
+
</category>
|
191
|
+
|
192
|
+
<category>
|
193
|
+
<pattern>SYSTEM TEST</pattern>
|
194
|
+
<template>time:<system>date</system></template>
|
195
|
+
</category>
|
196
|
+
|
197
|
+
<category>
|
198
|
+
<pattern>SIZE TEST</pattern>
|
199
|
+
<template><size/></template>
|
200
|
+
</category>
|
201
|
+
|
202
|
+
<category>
|
203
|
+
<pattern>SPACE TEST</pattern>
|
204
|
+
<template> TEST SPACE </template>
|
205
|
+
</category>
|
206
|
+
|
207
|
+
<!-- next three are test for * and _ -->
|
208
|
+
<category>
|
209
|
+
<pattern>This * her</pattern>
|
210
|
+
<template>star wins</template>
|
211
|
+
</category>
|
212
|
+
|
213
|
+
<category>
|
214
|
+
<pattern>This _ you</pattern>
|
215
|
+
<template>underscore wins</template>
|
216
|
+
</category>
|
217
|
+
|
218
|
+
<category>
|
219
|
+
<pattern>This * you</pattern>
|
220
|
+
<template>star does not win</template>
|
221
|
+
</category>
|
222
|
+
|
223
|
+
<category>
|
224
|
+
<pattern>This is clearly you</pattern>
|
225
|
+
<template>explicit pattern wins</template>
|
226
|
+
</category>
|
227
|
+
|
228
|
+
<category>
|
229
|
+
<pattern>These * clearly * them</pattern>
|
230
|
+
<template>first star is <star index="1"/> second star is <star index="2"/></template>
|
231
|
+
</category>
|
232
|
+
<!-- end test for * and _ -->
|
233
|
+
</aiml>
|