diff --git a/.DS_Store b/.DS_Store
index f35c1a50b..9a874b576 100644
Binary files a/.DS_Store and b/.DS_Store differ
diff --git a/.gitignore b/.gitignore
index 6f42a17b8..7f61000a2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -91,7 +91,7 @@ ENV/
# Rope project settings
.ropeproject
-src/.DS_Store
+.DS_Store/
.idea
# Pylint output
diff --git a/bots/.DS_Store b/bots/.DS_Store
index 56581127f..29e32cee3 100644
Binary files a/bots/.DS_Store and b/bots/.DS_Store differ
diff --git a/bots/alice2/.DS_Store b/bots/alice2/.DS_Store
index 865b25d63..cebe25a59 100644
Binary files a/bots/alice2/.DS_Store and b/bots/alice2/.DS_Store differ
diff --git a/bots/rosie_fixed/.DS_Store b/bots/rosie_fixed/.DS_Store
new file mode 100644
index 000000000..0b9a44bd2
Binary files /dev/null and b/bots/rosie_fixed/.DS_Store differ
diff --git a/bots/rosie_fixed/aiml/default.aiml b/bots/rosie_fixed/aiml/default.aiml
index 78a27a25d..75709d72e 100755
--- a/bots/rosie_fixed/aiml/default.aiml
+++ b/bots/rosie_fixed/aiml/default.aiml
@@ -17263,8 +17263,7 @@
What is it to you.
I am not sure if I can quantify the answer.
-
- xfind
+ XFIND
@@ -19232,7 +19231,6 @@
Try asking another.
-
XFIND
@@ -19704,7 +19702,6 @@
as often as possible, do you?
-
@@ -20456,7 +20453,6 @@
Doesn't everyone have a
.
-
I have
a lot of friends on the Internet.
@@ -25119,7 +25115,7 @@
SPRINGTIME *
- Paris in the
the spring.
+ Paris in the the spring.
diff --git a/bots/rosie_fixed/aiml/personality.aiml b/bots/rosie_fixed/aiml/personality.aiml
index 9368d61fb..0a22f7475 100755
--- a/bots/rosie_fixed/aiml/personality.aiml
+++ b/bots/rosie_fixed/aiml/personality.aiml
@@ -1030,8 +1030,8 @@
SING
- Daisy, Daisy. Give me your answer do.
I am half crazy. All for the love of you.
It won't be a
- stylish marriage. I can't afford a carriage.
But you'll look sweet. Upon the seat.
Of a bicycle
+ Daisy, Daisy. Give me your answer do. I am half crazy. All for the love of you. It won't be a
+ stylish marriage. I can't afford a carriage. But you'll look sweet. Upon the seat. Of a bicycle
built for two.
diff --git a/bots/rosie_fixed/aiml/xfind.aiml b/bots/rosie_fixed/aiml/xfind.aiml
new file mode 100644
index 000000000..8f9dd9881
--- /dev/null
+++ b/bots/rosie_fixed/aiml/xfind.aiml
@@ -0,0 +1,134 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ ACCESS *
+
+ XFIND
+
+
+
+
+
+ GOOGLE *
+ ">]]> Google Search
+ ]]>
+
+
+ XDMOZ *
+ ">]]>
+
+ Click.
+ Start.
+ Search.
+ Click me.
+ Click here.
+ Open Directory.
+ Don't Click Me.
+ Don't Click Here.
+
+ ]]>
+
+
+
+ XFIND *
+
+
+ Is there only one?
+ Let me think about it.
+ Have you tried a web search?
+ I haven't heard of
+
+ .
+
+ There might be more than one.
+ I need time to formulate the reply.
+ I'll ask around and get back to you.
+ I have to think about that one for a while.
+ I will ask my
+
+ for the answer.
+
+ I would look into the web for that knowledge.
+ Does it have anything to do with
+
+ ?
+
+ Interesting question.
+ That's a good question.
+ I'll come back to that later.
+ Is that a rhetorical question?
+ Do you use Explorer or another browser?
+ That's not something I get asked all the time.
+ I don't know anything about
+
+
+
+ .
+
+ Check back later and see if I learn the answer to that one.
+ That's an interesting question. I'll come back to that in a minute.
+ You tell me.
+ What is it to you?
+ Are you testing me?
+ I will search for it.
+ I can ask my.
+
+ I will try to find out.
+ I can ask someone about it.
+ I would do a search for it.
+ Would you like to know more?
+ Have you tried searching the web?
+ Do a web search for it.
+ Try searching the web.
+ Maybe my
+
+ knows the answer.
+
+ I have never been asked that before.
+ I think you already know the answer.
+ Searching...Searching...Please stand by.
+
+
+
+ PUSH
+
+
+
+
+
+
+
+
+
+ XGOOGLE *
+ ">]]> Google Search
+ ]]>
+
+
diff --git a/src/.DS_Store b/src/.DS_Store
new file mode 100644
index 000000000..317f8bfcd
Binary files /dev/null and b/src/.DS_Store differ
diff --git a/src/programy/bot.py b/src/programy/bot.py
index 93469356a..b644f897b 100644
--- a/src/programy/bot.py
+++ b/src/programy/bot.py
@@ -107,20 +107,12 @@ def ask_question(self, clientid: str, text: str, srai=False):
question = Question.create_from_text(pre_processed)
- # KS
conversation.record_dialog(question)
- # if srai is False:
- # conversation.record_dialog(question)
- # parent_question = None
- # else:
- # parent_question = conversation.current_question()
answers = []
for each_sentence in question.sentences:
- # KS
response = self.brain.ask_question(self, clientid, each_sentence)
- #response = self.brain.ask_question(self, clientid, each_sentence, parent_question)
if response is not None:
logging.debug("Raw Response (%s): %s", clientid, response)
@@ -137,7 +129,6 @@ def ask_question(self, clientid: str, text: str, srai=False):
each_sentence.response = self.default_response
answers.append(self.default_response)
- # KS
if srai is True:
conversation.pop_dialog()
diff --git a/src/programy/brain.py b/src/programy/brain.py
index 7569dd7f7..19b39e667 100644
--- a/src/programy/brain.py
+++ b/src/programy/brain.py
@@ -233,8 +233,6 @@ def load_services(self, brain_configuration):
def pre_process_question(self, bot, clientid, question):
return self.preprocessors.process(bot, clientid, question)
- # KS
- #def ask_question(self, bot, clientid, sentence, parent_question) -> str:
def ask_question(self, bot, clientid, sentence) -> str:
conversation = bot.get_conversation(clientid)
@@ -247,13 +245,7 @@ def ask_question(self, bot, clientid, sentence) -> str:
logging.info("Topic pattern = [%s]", topic_pattern)
try:
- # KS
- #if parent_question is not None:
- # that_question = parent_question
- #else:
- # that_question = conversation.nth_question(2)
that_question = conversation.nth_question(2)
-
that_sentence = that_question.current_sentence()
# If the last response was valid, i.e not none and not empty string, then use
@@ -269,11 +261,17 @@ def ask_question(self, bot, clientid, sentence) -> str:
logging.info("No That pattern default to [*]")
that_pattern = "*"
- return self._aiml_parser.match_sentence(bot, clientid,
- sentence,
- None, # KS parent_question,
- topic_pattern=topic_pattern,
- that_pattern=that_pattern)
+ match_context = self._aiml_parser.match_sentence(bot, clientid,
+ sentence,
+ topic_pattern=topic_pattern,
+ that_pattern=that_pattern)
+
+ if match_context is not None:
+ template_node = match_context.template_node()
+ logging.debug("AIML Parser evaluating template [%s]", template_node.to_string())
+ return template_node.template.resolve(bot, clientid)
+
+ return None
def post_process_response(self, bot, clientid, response: str):
return self.postprocessors.process(bot, clientid, response)
diff --git a/src/programy/dialog.py b/src/programy/dialog.py
index 1973230b0..d78d25d02 100644
--- a/src/programy/dialog.py
+++ b/src/programy/dialog.py
@@ -18,40 +18,21 @@
class Sentence(object):
- def __init__(self, text: str, split_chars: str=" "):
+ def __init__(self, text: str=None, split_chars: str=" "):
self._words = self._split_into_words(text, split_chars)
- self._stars = []
- self._thatstars = []
- self._topicstars = []
self._response = None
+ self._matched_context = None
@property
def words(self):
return self._words
- @property
- def stars(self):
- return self._stars
-
- @stars.setter
- def stars(self, stars):
- self._stars = stars
-
- @property
- def thatstars(self):
- return self._thatstars
+ def append_word(self, word):
+ self._words.append(word)
- @thatstars.setter
- def thatstars(self, thatstars):
- self._thatstars = thatstars
-
- @property
- def topicstars(self):
- return self._topicstars
-
- @topicstars.setter
- def topicstars(self, topicstars):
- self._topicstars = topicstars
+ def append_sentence(self, sentence):
+ for word in sentence._words:
+ self._words.append(word)
@property
def response(self):
@@ -61,6 +42,14 @@ def response(self):
def response(self, text: str):
self._response = text
+ @property
+ def matched_context(self):
+ return self._matched_context
+
+ @matched_context.setter
+ def matched_context(self, context):
+ self._matched_context = context
+
def num_words(self):
return len(self.words)
@@ -68,7 +57,7 @@ def word(self, num: int):
if num < self.num_words():
return self.words[num]
else:
- raise Exception("Num word array violation !")
+ raise Exception("Num word array violation !")
def words_from_current_pos(self, current_pos: int):
if len(self._words) > 0:
@@ -78,9 +67,6 @@ def words_from_current_pos(self, current_pos: int):
def text(self):
return " ".join(self._words)
- def reset_stars(self):
- self._stars = []
-
def _split_into_words(self, sentence, split_chars: str):
if sentence is None:
return []
diff --git a/src/programy/parser/aiml_parser.py b/src/programy/parser/aiml_parser.py
index 202edabb5..7eb25e702 100644
--- a/src/programy/parser/aiml_parser.py
+++ b/src/programy/parser/aiml_parser.py
@@ -21,12 +21,10 @@
from programy.parser.exceptions import ParserException
from programy.config import BrainConfiguration
from programy.parser.pattern.graph import PatternGraph
-from programy.parser.pattern.matcher import PatternMatcher
from programy.parser.template.graph import TemplateGraph
-from programy.parser.template.evaluator import TemplateEvaluator
from programy.utils.files.filefinder import FileFinder
from programy.dialog import Sentence
-
+from programy.parser.pattern.matcher import MatchContext
class AIMLLoader(FileFinder):
def __init__(self, aiml_parser):
@@ -43,9 +41,7 @@ def __init__(self, supress_warnings=False, stop_on_invalid=False):
self._supress_warnings = supress_warnings
self.stop_on_invalid = stop_on_invalid
self.pattern_parser = PatternGraph()
- self.pattern_matcher = PatternMatcher(self.pattern_parser)
self.template_parser = TemplateGraph(self)
- self.template_evaluator = TemplateEvaluator()
self._filename = "Unknown"
self._version = "Unknown"
self._aiml_loader = AIMLLoader(self)
@@ -255,40 +251,33 @@ def parse_category(self, category_xml, topic_element=None, add_to_graph=True):
return (patterns[0], topic_element, that_element, template_graph_root)
- def match_sentence(self, bot, clientid, sentence, parent_question, topic_pattern, that_pattern):
- logging.debug("Matching sentence [%s], topic=[%s], that=[%s] ", sentence.text(), topic_pattern, that_pattern)
+ def match_sentence(self, bot, clientid, pattern_sentence, topic_pattern, that_pattern):
- if parent_question is not None:
- pattern_stars = parent_question.current_sentence()._stars
- topic_stars = parent_question.current_sentence()._topicstars
- that_stars = parent_question.current_sentence()._thatstars
- else:
- pattern_stars = sentence._stars
- topic_stars = sentence._topicstars
- that_stars = sentence._thatstars
-
- matched = self.pattern_matcher.match(bot, clientid,
- sentence, pattern_stars,
- Sentence(topic_pattern),topic_stars,
- Sentence(that_pattern), that_stars)
- if matched is not None:
- return self.template_evaluator.evaluate(bot, clientid, matched.template)
-
- # pattern_stars = []
- # topic_stars = []
- # that_stars = []
- # matched = self.pattern_matcher.match(bot, clientid, sentence, pattern_stars, Sentence(topic_pattern),
- # topic_stars, Sentence(that_pattern), that_stars)
- # if matched is not None:
- # if parent_question is not None:
- # parent_question.current_sentence().stars = pattern_stars
- # parent_question.current_sentence().topicstars = topic_stars
- # parent_question.current_sentence().thatstars = that_stars
- # else:
- # sentence.stars = pattern_stars
- # sentence.topicstars = topic_stars
- # sentence.thatstars = that_stars
- #
- # return self.template_evaluator.evaluate(bot, clientid, matched.template)
+ topic_sentence = Sentence(topic_pattern)
+ that_sentence = Sentence(that_pattern)
+
+ logging.debug("AIML Parser matching sentence [%s], topic=[%s], that=[%s] ", pattern_sentence.text(), topic_pattern, that_pattern)
+
+ sentence = Sentence()
+ sentence.append_sentence(pattern_sentence)
+ sentence.append_word('__TOPIC__')
+ sentence.append_sentence(topic_sentence)
+ sentence.append_word('__THAT__')
+ sentence.append_sentence(that_sentence)
+ logging.debug("Matching [%s]"%sentence.words_from_current_pos(0))
+
+ context = MatchContext()
+
+ template = self.pattern_parser._root_node.match(bot, clientid, context, sentence)
+
+ if template is not None:
+ context._template_node = template
+
+ context.list_matches()
+
+ # Save the matched context for the associated sentence
+ pattern_sentence.matched_context = context
+
+ return context
return None
diff --git a/src/programy/parser/pattern/graph.py b/src/programy/parser/pattern/graph.py
index fb0316521..8fde9ce14 100644
--- a/src/programy/parser/pattern/graph.py
+++ b/src/programy/parser/pattern/graph.py
@@ -14,6 +14,7 @@
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
"""
+import logging
from programy.parser.exceptions import ParserException
from programy.parser.pattern.nodes import PatternRootNode
from programy.parser.pattern.nodes import PatternPriorityWordNode
@@ -25,6 +26,7 @@
from programy.parser.pattern.nodes import PatternTopicNode
from programy.parser.pattern.nodes import PatternThatNode
from programy.parser.pattern.nodes import PatternTemplateNode
+from programy.utils.text.text import TextUtils
# TODO When xml is split over multiple lines, extra PatternWordNodes get crearted
#
@@ -72,12 +74,12 @@ def node_from_element(element):
if 'name' in element.attrib:
return PatternSetNode(element.attrib['name'])
else:
- return PatternSetNode(element.text.strip())
+ return PatternSetNode(TextUtils.strip_whitespace(element.text))
elif element.tag == 'bot':
if 'name' in element.attrib:
return PatternBotNode(element.attrib['name'])
else:
- return PatternBotNode(element.text.strip())
+ return PatternBotNode(TextUtils.strip_whitespace(element.text))
else:
raise ParserException("Invalid parser graph node <%s>" % element.tag, xml_element=element)
@@ -90,7 +92,7 @@ def _parse_text(self, pattern_text, current_node):
words = pattern_text.split(" ")
for word in words:
- word = word.strip()
+ word = TextUtils.strip_whitespace(word)
new_node = PatternGraph.node_from_text(word)
current_node = current_node.add_child(new_node)
@@ -99,14 +101,16 @@ def _parse_text(self, pattern_text, current_node):
def get_text_from_element(self, element):
text = element.text
if text is not None:
- text = text.strip()
+ text = TextUtils.strip_whitespace(text)
+ if text == "":
+ return None
return text
return None
def get_tail_from_element(self, element):
text = element.tail
if text is not None:
- text = text.strip()
+ text = TextUtils.strip_whitespace(text)
if text == "":
return None
return text
@@ -159,7 +163,7 @@ def add_that_to_node(self, that_element, base_node):
head_text = self.get_text_from_element(that_element)
if head_text is not None:
- current_node = self._parse_text(head_text.strip(), current_node)
+ current_node = self._parse_text(TextUtils.strip_whitespace(head_text), current_node)
added_child = False
for sub_element in that_element:
@@ -204,5 +208,6 @@ def add_pattern_to_graph(self, pattern_element, topic_element, that_element, tem
self.add_template_to_node(template_graph_root, current_node)
- def dump(self, output_func=print, verbose=True):
+ def dump(self, output_func=logging.debug, verbose=True):
self.root.dump("", output_func, verbose)
+ output_func("")
diff --git a/src/programy/parser/pattern/matcher.py b/src/programy/parser/pattern/matcher.py
index 03cb5a482..ec237e386 100644
--- a/src/programy/parser/pattern/matcher.py
+++ b/src/programy/parser/pattern/matcher.py
@@ -15,357 +15,118 @@
"""
import logging
-from programy.parser.pattern.nodes import PatternNode
from programy.dialog import Sentence
-from programy.bot import Bot
-class MatchContext(object):
- def __init__(self):
- self.bot = None
- self.clientid = None
- self.pattern_sentence = None
- self.pattern_stars = []
- self.topic_sentence = None
- self.topic_stars = []
- self.that_sentence = None
- self.that_stars = []
+class Match(object):
-class PatternMatcher(object):
+ WORD = 0
+ TOPIC = 2
+ THAT = 3
- def __init__(self, graph, max_match_depth=1000):
- self._graph = graph
- self._max_match_depth = max_match_depth
+ def __init__(self, type, node, word):
+ self._match_type = type
+ self._matched_node = node
+ self._matched_words = []
+ if word is not None:
+ self.add_word(word)
- @property
- def graph(self):
- return self._graph
-
- def matches_to_stars(self, matches, stars):
- stars.clear()
- for match in matches:
- if len(match) > 0:
- matched = " ".join(match)
- if matched != "*":
- stars.append(matched)
-
- def match(self,
- bot: Bot,
- clientid: str,
- pattern_sentence: Sentence,
- pattern_stars: list,
- topic_sentence: Sentence,
- topic_stars: list,
- that_sentence: Sentence,
- that_stars: list):
- logging.debug("Pattern matching sentence [%s], topic[%s], that[%s]",
- pattern_sentence.words_from_current_pos(0),
- topic_sentence.words_from_current_pos(0),
- that_sentence.words_from_current_pos(0))
-
- match_context = MatchContext()
- match_context.bot = bot
- match_context.clientid = clientid
- match_context.pattern_sentence = pattern_sentence
- match_context.topic_sentence = topic_sentence
- match_context.that_sentence = that_sentence
-
- matched_path = []
- matched_stars = []
- if self.match_children(match_context, self.graph.root, pattern_sentence, 0, matched_path, matched_stars,
- 0) is True:
-
- for match in match_context.pattern_stars:
- pattern_stars.append(match)
-
- for match in match_context.topic_stars:
- topic_stars.append(match)
-
- for match in match_context.that_stars:
- that_stars.append(match)
-
- return matched_path[0]
+ def add_word(self, word):
+ self._matched_words.append(word)
- return None
+ @property
+ def match_type(self):
+ return self._match_type
- def _get_tabs(self, depth: int):
- string = ""
- for i in range(depth):
- string += "\t"
- return string
-
- def end_of_sentence(self, match_context, root, sentence, num_word, matched_path, matched_stars, depth):
-
- tabs_str = self._get_tabs(depth)
-
- if root.has_zero_or_more():
- logging.debug("%sRoot has zero or more", tabs_str)
- if root.arrow is not None:
- if self.match_children(match_context, root.arrow, sentence, num_word + 1, matched_path,
- matched_stars, depth + 1) is True:
- return True
- else:
- if self.match_children(match_context, root.hash, sentence, num_word + 1, matched_path,
- matched_stars, depth + 1) is True:
- return True
-
- if root.has_topic():
- self.matches_to_stars(matched_stars, match_context.pattern_stars)
- matched_stars = []
- if self.match_children(match_context, root.topic, match_context.topic_sentence, 0, matched_path,
- matched_stars, 0) is True:
- return True
-
- elif root.has_that():
- self.matches_to_stars(matched_stars, match_context.topic_stars)
- matched_stars = []
- if self.match_children(match_context, root.that, match_context.that_sentence, 0, matched_path,
- matched_stars, 0) is True:
- return True
-
- elif root.has_template():
- logging.debug("%sRoot has template...[%s]", tabs_str, root.template.to_string())
- self.matches_to_stars(matched_stars, match_context.that_stars)
- matched_path.append(root.template)
- return True
+ @property
+ def matched_node(self):
+ return self._matched_node
+ @property
+ def matched_words(self):
+ return self._matched_words
+
+ def joined_words(self, join_char=" "):
+ return join_char.join(self.matched_words)
+
+ @staticmethod
+ def type_to_string(type):
+ if type == Match.WORD:
+ return "Word"
+ elif type == Match.TOPIC:
+ return "Topic"
+ elif type == Match.THAT:
+ return "That"
else:
- logging.debug("%sRoot has no topic, that or template, exiting...", tabs_str)
- return False
-
- def is_zero_or_more(self, match_context, root, sentence, num_word, matched_path, matched_stars, depth):
-
- tabs_str = self._get_tabs(depth)
-
- word = sentence.word(num_word)
+ return "Unknown"
- # added = False
- logging.debug("%sRoot is 0 or more", tabs_str)
- if root.has_wildcard():
- logging.debug("%sRoot next is wildcard", tabs_str)
+ def to_string(self):
+ return "Match=(%s) Node=(%s) Matched=(%s)"%(Match.type_to_string(self._match_type), self._matched_node.to_string(verbose=False), self.joined_words())
- logging.debug("%s0ORM HAS. Adding (%s) to star match (%d)", tabs_str, word, len(matched_stars))
- # added = True
- matched_stars[len(matched_stars) - 1].append(word)
- matched_stars.append([])
- if root.hash is not None:
- if self.match_children(match_context, root.hash, sentence, num_word + 1, matched_path,
- matched_stars, depth + 1) is True:
- return True
- elif root.arrow is not None:
- if self.match_children(match_context, root.arrow, sentence, num_word + 1, matched_path,
- matched_stars, depth + 1) is True:
- return True
- else:
- raise Exception("Unknown zero or ore wild card")
-
- # if len(matched_stars) > 0:
- # matched_stars.pop()
-
- else:
- for child in root.children:
- if child.matches(match_context.bot, match_context.clientid, word):
-
- if child.is_set() or child.is_bot():
- matched_stars.append([])
- logging.debug("%sAdding new star match", tabs_str)
- matched_stars[len(matched_stars) - 1].append(word)
-
- logging.debug("%s0 or more matched child [%s] -> word [%s]", tabs_str, child.to_string(), word)
- if self.match_children(match_context, child, sentence, num_word + 1, matched_path,
- matched_stars, depth + 1) is True:
- return True
-
- logging.debug("%s0ORM. Adding (%s) to star match (%d)", tabs_str, word, len(matched_stars))
- # if added is False:
- # matched_stars.append([])
- logging.debug("%sAdding new star match", tabs_str)
- matched_stars[len(matched_stars) - 1].append(word)
-
- if self.match_children(match_context, root, sentence, num_word + 1, matched_path, matched_stars,
- depth + 1) is True:
- return True
-
- if len(matched_stars) > 0:
- matched_stars.pop()
-
- return False
+class MatchContext(object):
- def is_one_or_more(self, match_context, root, sentence, num_word, matched_path, matched_stars, depth):
+ def __init__(self):
+ self._matched_nodes = []
+ self._template_node = None
- tabs_str = self._get_tabs(depth)
+ def add_match(self, match):
+ self._matched_nodes.append(match)
- word = sentence.word(num_word)
+ def pop_match(self):
+ if len(self._matched_nodes) > 0:
+ self._matched_nodes.pop()
- logging.debug("%sRoot is one or more", tabs_str)
- if root.has_wildcard():
- logging.debug("%sRoot next is wildcard", tabs_str)
+ def pop_matches(self, matches_add):
+ for x in range(0, matches_add):
+ self.pop_match()
- logging.debug("%s1ORM HAS. Adding (%s) to star match (%d)", tabs_str, word, len(matched_stars))
- matched_stars.append([])
- matched_stars[len(matched_stars) - 1].append(word)
+ def set_template(self, template):
+ self._template_node = template
- if root.underline is not None:
- if self.match_children(match_context, root.underline, sentence, num_word + 1, matched_path,
- matched_stars, depth + 1) is True:
- return True
- if root.star is not None:
- if self.match_children(match_context, root.star, sentence, num_word + 1, matched_path,
- matched_stars, depth + 1) is True:
- return True
- else:
- raise Exception("Unknown one or ore wild card")
+ @property
+ def matched_nodes(self):
+ return self._matched_nodes
- if len(matched_stars) > 0:
- matched_stars.pop()
+ def template_node(self):
+ return self._template_node
+ def matched(self):
+ if self._template_node is not None:
+ return True
else:
- for child in root.children:
- if child.matches(match_context.bot, match_context.clientid, word):
-
- if child.is_set() or child.is_bot():
- matched_stars.append([])
- logging.debug("%sAdding new star match", tabs_str)
- matched_stars[len(matched_stars) - 1].append(word)
-
- logging.debug("%s1 or more matched child [%s] -> word [%s]", tabs_str, child.to_string(), word)
- if self.match_children(match_context, child, sentence, num_word + 1, matched_path, matched_stars,
- depth + 1) is True:
- return True
-
- logging.debug("%s1ORM Adding (%s) to star match (%d)", tabs_str, word, len(matched_stars))
- matched_stars[len(matched_stars) - 1].append(word)
+ return False
- if self.match_children(match_context, root, sentence, num_word + 1, matched_path, matched_stars,
- depth + 1) is True:
- return True
+ def _get_indexed_match_by_type(self, index, type):
+ count = 1
+ for match in self._matched_nodes:
+ if match._match_type == type and \
+ ( match._matched_node.is_wildcard() or
+ match._matched_node.is_set() or
+ match._matched_node.is_bot()):
+ if count == index:
+ return match.joined_words()
+ count += 1
+ return None
- if len(matched_stars) > 0:
- matched_stars.pop()
+ def star(self, index):
+ return self._get_indexed_match_by_type(index, Match.WORD)
- return False
+ def topicstar(self, index):
+ return self._get_indexed_match_by_type(index, Match.TOPIC)
- def match_children(self, match_context: MatchContext, root: PatternNode, sentence: Sentence, num_word: int,
- matched_path: list, matched_stars: list, depth: int):
+ def thatstar(self, index):
+ return self._get_indexed_match_by_type(index, Match.THAT)
- tabs_str = self._get_tabs(depth)
+ def list_matches(self, output_func=logging.debug):
+ output_func("Matches...")
+ count = 1
+ for match in self._matched_nodes:
+ output_func("\t%d - %s"%(count, match.to_string()))
+ count += 1
+ if self.matched() is True:
+ output_func("\tT - %s"%(self._template_node.to_string()))
+ else:
+ output_func("\tT - None")
- if depth > self._max_match_depth:
- logging.debug("%sMax recursive depth reached [%d]", tabs_str, self._max_match_depth)
- return False
- if num_word >= sentence.num_words():
- return self.end_of_sentence(match_context, root, sentence, num_word, matched_path, matched_stars, depth)
-
- if root.is_zero_or_more():
- result = self.is_zero_or_more(match_context, root, sentence, num_word, matched_path, matched_stars, depth)
- if result is True:
- return True
-
- if root.is_one_or_more():
- result = self.is_one_or_more(match_context, root, sentence, num_word, matched_path, matched_stars, depth)
- if result is True:
- return True
-
- #########################################################################################################
- # Order = $ # _ word ^ *
-
- word = sentence.word(num_word)
-
- if root.has_priority_words():
- logging.debug("%sRoot has priority", tabs_str)
- for child in root.priority_words:
- if child.matches(match_context.bot, match_context.clientid, word):
-
- if child.is_set() or child.is_bot():
- matched_stars.append([])
- logging.debug("%sAdding new star match", tabs_str)
- matched_stars[len(matched_stars) - 1].append(word)
-
- logging.debug("%sPriority matched child [%s] -> word [%s]", tabs_str, child.to_string(), word)
- if self.match_children(match_context, child, sentence, num_word+1, matched_path, matched_stars,
- depth+1) is True:
- return True
-
- if root.has_zero_or_more():
- if num_word <= sentence.num_words():
-
- if root.hash is not None:
- logging.debug("%sRoot is 0 or more", tabs_str)
- matched_stars.append([])
-
- logging.debug("%sMatching child [#] -> word [%s]", tabs_str, word)
- if self.match_children(match_context, root.hash, sentence, num_word, matched_path, matched_stars,
- depth+1) is True:
- return True
-
- if len(matched_stars) > 0:
- matched_stars.pop()
-
- if root.has_one_or_more():
- if num_word < sentence.num_words():
- if root.underline is not None:
- logging.debug("%sRoot has 1 or more", tabs_str)
-
- logging.debug("%sHAS 1ORM Adding (%s) to star match (%d)", tabs_str, word, len(matched_stars))
- matched_stars.append([])
- matched_stars[len(matched_stars) - 1].append(word)
-
- logging.debug("%sMatching child [_] -> word [%s]", tabs_str, word)
- if self.match_children(match_context, root.underline, sentence, num_word+1, matched_path,
- matched_stars, depth+1) is True:
- return True
-
- if len(matched_stars) > 0:
- matched_stars.pop()
-
- if root.has_children():
- logging.debug("%sRoot has children (%d)", tabs_str, depth)
- for child in root.children:
- if child.matches(match_context.bot, match_context.clientid, word):
-
- if child.is_set() or child.is_bot():
- matched_stars.append([])
- logging.debug("%sAdding new star match", tabs_str)
- matched_stars[len(matched_stars) - 1].append(word)
-
- logging.debug("%sMatched child [%s] -> word [%s]", tabs_str, child.to_string(), word)
- if self.match_children(match_context, child, sentence, num_word+1, matched_path, matched_stars,
- depth+1) is True:
- return True
-
- if root.has_zero_or_more():
- if num_word <= sentence.num_words():
- if root.arrow is not None:
- logging.debug("%sRoot is 0 or more", tabs_str)
- matched_stars.append([])
-
- logging.debug("%sMatching child [^] -> word [%s]", word, tabs_str)
- if self.match_children(match_context, root.arrow, sentence, num_word, matched_path, matched_stars,
- depth+1) is True:
- return True
-
- if len(matched_stars) > 0:
- matched_stars.pop()
-
- if root.has_one_or_more():
- if num_word < sentence.num_words():
- if root.star is not None:
- logging.debug("%sRoot has 1 or more", tabs_str)
- logging.debug("%sHAS 1ORM Adding (%s) to star match (%d)", tabs_str, word, len(matched_stars))
- matched_stars.append([])
- matched_stars[len(matched_stars) - 1].append(word)
-
- logging.debug("%sMatching child [*] -> word [%s]", tabs_str, word)
- if self.match_children(match_context, root.star, sentence, num_word+1, matched_path,
- matched_stars, depth+1) is True:
- return True
-
- if len(matched_stars) > 0:
- matched_stars.pop()
-
- logging.debug("%sNo match", tabs_str)
- matched_stars.clear()
- matched_stars.append([])
- return False
diff --git a/src/programy/parser/pattern/nodes.py b/src/programy/parser/pattern/nodes.py
index 1101d6f27..74051a91d 100644
--- a/src/programy/parser/pattern/nodes.py
+++ b/src/programy/parser/pattern/nodes.py
@@ -16,27 +16,47 @@
import logging
from programy.parser.exceptions import ParserException
-
+from programy.utils.text.text import TextUtils
+from programy.parser.pattern.matcher import Match
#######################################################################################################################
#
class PatternNode(object):
def __init__(self):
+
+ # Child Nodes
self._priority_words = []
- self._0ormore_arrow = None
self._0ormore_hash = None
- self._children = []
self._1ormore_underline = None
+ self._children = []
+ self._0ormore_arrow = None
self._1ormore_star = None
+
+ # Topic, That and Template Nodes
self._topic = None
self._that = None
self._template = None
+ ########################################################################
+ #
+ def is_root(self):
+ return False
+
+ ########################################################################
+ #
@property
def priority_words(self):
return self._priority_words
+ def has_priority_words(self):
+ return True if len(self._priority_words) > 0 else False
+
+ def is_priority(self):
+ return False
+
+ ########################################################################
+ #
@property
def arrow(self):
return self._0ormore_arrow
@@ -45,13 +65,6 @@ def arrow(self):
def hash(self):
return self._0ormore_hash
- @property
- def children(self):
- return self._children
-
- def child(self, num):
- return self._children[num]
-
@property
def underline(self):
return self._1ormore_underline
@@ -60,23 +73,34 @@ def underline(self):
def star(self):
return self._1ormore_star
- @property
- def topic(self):
- return self._topic
+ def has_wildcard(self):
+ if self.has_zero_or_more() is True or self.has_one_or_more():
+ return True
+ return False
- @property
- def template(self):
- return self._template
+ def has_zero_or_more(self):
+ if self._0ormore_arrow is not None or self._0ormore_hash is not None:
+ return True
+ else:
+ return False
- @property
- def that(self):
- return self._that
+ def has_0ormore_arrow(self):
+ return bool(self._0ormore_arrow is not None)
- def is_root(self):
- return False
+ def has_0ormore_hash(self):
+ return bool(self._0ormore_hash is not None)
- def is_priority(self):
- return False
+ def has_one_or_more(self):
+ if self._1ormore_star is not None or self._1ormore_underline is not None:
+ return True
+ else:
+ return False
+
+ def has_1ormore_star(self):
+ return bool(self._1ormore_star is not None)
+
+ def has_1ormore_underline(self):
+ return bool(self._1ormore_underline is not None)
def is_wildcard(self):
return False
@@ -87,34 +111,41 @@ def is_zero_or_more(self):
def is_one_or_more(self):
return False
- def is_set(self):
- return False
+ ########################################################################
+ #
+ @property
+ def children(self):
+ return self._children
- def is_bot(self):
- return False
+ def child(self, num):
+ return self._children[num]
- def is_template(self):
- return False
+ def has_children(self):
+ if len(self._children) > 0:
+ return True
- def has_priority_words(self):
- return True if len(self._priority_words) > 0 else False
+ return False
- def has_wildcard(self):
- if self.has_zero_or_more() is True or self.has_one_or_more():
+ def has_nodes(self):
+ if len(self._children) > 0:
return True
- return False
- def has_zero_or_more(self):
- if self._0ormore_arrow is not None or self._0ormore_hash is not None:
+ if self.has_priority_words():
return True
- else:
- return False
- def has_one_or_more(self):
- if self._1ormore_star is not None or self._1ormore_underline is not None:
+ if self.has_wildcard():
return True
- else:
- return False
+
+ return False
+
+ ########################################################################
+ #
+ @property
+ def topic(self):
+ return self._topic
+
+ def is_topic(self):
+ return False
def has_topic(self):
return bool(self.topic is not None)
@@ -124,14 +155,32 @@ def add_topic(self, topic):
self._topic = topic
return self._topic
+ ########################################################################
+ #
+ @property
+ def that(self):
+ return self._that
+
def add_that(self, that):
if self.has_that() is False:
self._that = that
return self._that
+ def is_that(self):
+ return False
+
def has_that(self):
return bool(self.that is not None)
+ ########################################################################
+ #
+ @property
+ def template(self):
+ return self._template
+
+ def is_template(self):
+ return False
+
def has_template(self):
return bool(self.template is not None)
@@ -140,27 +189,26 @@ def add_template(self, template):
self._template = template
return self._template
- def has_children(self):
- if len(self._children) > 0:
- return True
-
- if self.has_priority_words():
- return True
-
- if self.has_wildcard():
- return True
+ ########################################################################
+ #
+ def is_set(self):
+ return False
+ ########################################################################
+ #
+ def is_bot(self):
return False
+ ########################################################################
+ #
def equivalent(self, other):
return False
def equals(self, bot, clientid, word):
return False
- def matches(self, bot, clientid, word):
- return False
-
+ ########################################################################
+ #
def can_add(self, new_node):
pass
@@ -168,7 +216,7 @@ def _node_exists(self, new_node):
for priority in self._priority_words:
if priority.equivalent(new_node):
- # Equivalent node already exists, use this one insead
+ # Equivalent node already exists, use this one instead
return priority
if self._0ormore_arrow is not None:
@@ -250,7 +298,10 @@ def _child_count(self, verbose=True):
return ""
def to_string(self, verbose=True):
- return "NODE [%s]" % self._child_count(verbose)
+ if verbose is True:
+ return "NODE [%s]" % self._child_count(verbose)
+ else:
+ return "NODE"
def dump(self, tabs, output_func=logging.debug, verbose=True):
@@ -275,6 +326,94 @@ def dump(self, tabs, output_func=logging.debug, verbose=True):
for child in self.children:
child.dump(tabs+"\t", output_func, verbose)
+ def consume(self, bot, clientid, context, words, word_no, type):
+
+ if word_no >= words.num_words():
+ if self._template is not None:
+ logging.debug("%sFound a template, success!" % (TextUtils.get_tabs(word_no)))
+ return self._template
+ else:
+ logging.debug("%sNo more words and no template, no match found!" % (TextUtils.get_tabs(word_no)))
+ #context.pop_match()
+ return None
+
+ if self._topic is not None:
+ match = self._topic.consume(bot, clientid, context, words, word_no, Match.TOPIC)
+ if match is not None:
+ return match
+ if words.word(word_no) == '__TOPIC__':
+ logging.debug("%sLooking for a __TOPIC__, none give, no match found!" % (TextUtils.get_tabs(word_no)))
+ #context.pop_match()
+ return None
+
+ if self._that is not None:
+ match = self._that.consume(bot, clientid, context, words, word_no, Match.THAT)
+ if match is not None:
+ return match
+ if words.word(word_no) == '__THAT__':
+ logging.debug("%sLooking for a __THAT__, none give, no match found!" % (TextUtils.get_tabs(word_no)))
+ #context.pop_match()
+ return None
+
+ for child in self._priority_words:
+ if child.equals(bot, clientid, words.word(word_no)):
+ logging.debug("%sPriority %s matched %s" % (TextUtils.get_tabs(word_no), child._word, words.word(word_no)))
+
+ logging.debug("%sMATCH -> %s" % (TextUtils.get_tabs(word_no), words.word(word_no)))
+ match_node = Match(type, child, words.word(word_no))
+ context.add_match(match_node)
+
+ match = child.consume(bot, clientid, context, words, word_no + 1, type)
+ if match is not None:
+ return match
+ else:
+ context.pop_match ()
+
+ if self._0ormore_hash is not None:
+ match = self._0ormore_hash.consume(bot, clientid, context, words, word_no, type)
+ if match is not None:
+ return match
+ #else:
+ # context.pop_match ()
+
+ if self._1ormore_underline is not None:
+ match = self._1ormore_underline.consume(bot, clientid, context, words, word_no, type)
+ if match is not None:
+ return match
+ #else:
+ # context.pop_match ()
+
+ for child in self._children:
+ if child.equals(bot, clientid, words.word(word_no)):
+ logging.debug("%sChild %s matched %s" % (TextUtils.get_tabs(word_no), child._word, words.word(word_no)))
+
+ logging.debug("%sMATCH -> %s" % (TextUtils.get_tabs(word_no), words.word(word_no)))
+ match_node = Match(type, child, words.word(word_no))
+ context.add_match(match_node)
+
+ match = child.consume(bot, clientid, context, words, word_no + 1, type)
+ if match is not None:
+ return match
+ else:
+ context.pop_match ()
+
+ if self._0ormore_arrow is not None:
+ match = self._0ormore_arrow.consume(bot, clientid, context, words, word_no, type)
+ if match is not None:
+ return match
+ #else:
+ # context.pop_match ()
+
+ if self._1ormore_star is not None:
+ match = self._1ormore_star.consume(bot, clientid, context, words, word_no, type)
+ if match is not None:
+ return match
+ #else:
+ # context.pop_match ()
+
+ logging.debug("%sNo match for %s, trying another path" % (TextUtils.get_tabs(word_no), words.word(word_no)))
+ return None
+
#######################################################################################################################
#
@@ -302,13 +441,20 @@ def equivalent(self, other: PatternNode)->bool:
return False
def to_string(self, verbose: bool=True)->str:
- return "ROOT [%s]" % self._child_count(verbose)
+ if verbose is True:
+ return "ROOT [%s]" % self._child_count(verbose)
+ else:
+ return "ROOT "
+ def match(self, bot, clientid, context, words):
+ return self.consume(bot, clientid, context, words, 0, Match.WORD)
#######################################################################################################################
#
class PatternTopicNode(PatternNode):
+ TOPIC = "__TOPIC__"
+
def __init__(self):
PatternNode.__init__(self)
@@ -320,19 +466,34 @@ def can_add(self, new_node):
if isinstance(new_node, PatternThatNode):
raise ParserException("Cannot add that node to topic node")
+ def is_topic(self):
+ return True
+
def equivalent(self, other):
if isinstance(other, PatternTopicNode):
return True
return False
def to_string(self, verbose=True):
- return "TOPIC [%s]" % self._child_count(verbose)
+ if verbose is True:
+ return "TOPIC [%s]" % self._child_count(verbose)
+ else:
+ return "TOPIC"
+ def consume(self, bot, clientid, context, words, word_no, type):
+ if words.word(word_no) == '__TOPIC__':
+ logging.debug("%sTopic matched %s" % (TextUtils.get_tabs(word_no), words.word(word_no)))
+ return super(PatternTopicNode, self).consume(bot, clientid, context, words, word_no+1, type)
+
+ logging.debug("%sTopic NOT matched %s" % (TextUtils.get_tabs(word_no), words.word(word_no)))
+ return None
#######################################################################################################################
#
class PatternThatNode(PatternNode):
+ THAT = "__THAT__"
+
def __init__(self):
PatternNode.__init__(self)
@@ -344,14 +505,27 @@ def can_add(self, new_node):
if isinstance(new_node, PatternThatNode):
raise ParserException("Cannot add that node to that node")
+ def is_that(self):
+ return True
+
def equivalent(self, other):
if isinstance(other, PatternThatNode):
return True
return False
def to_string(self, verbose=True):
- return "THAT [%s]" % self._child_count(verbose)
+ if verbose is True:
+ return "THAT [%s]" % self._child_count(verbose)
+ else:
+ return "THAT"
+
+ def consume(self, bot, clientid, context, words, word_no, type):
+ if words.word(word_no) == '__THAT__':
+ logging.debug("%sThat matched %s" % (TextUtils.get_tabs(word_no), words.word(word_no)))
+ return super(PatternThatNode, self).consume(bot, clientid, context, words, word_no + 1, type)
+ logging.debug("%sTHAT NOT matched %s" % (TextUtils.get_tabs(word_no), words.word(word_no)))
+ return None
#######################################################################################################################
#
@@ -384,8 +558,10 @@ def equivalent(self, other):
return False
def to_string(self, verbose=True):
- return "PTEMPLATE [%s] " % (self._child_count(verbose))
-
+ if verbose is True:
+ return "PTEMPLATE [%s] " % (self._child_count(verbose))
+ else:
+ return "PTEMPLATE"
#######################################################################################################################
#
@@ -403,11 +579,6 @@ def can_add(self, new_node):
if isinstance(new_node, PatternRootNode):
raise ParserException("Cannot add root node to child node")
- def matches(self, bot, clientid, word):
- if self._word == word:
- return True
- return False
-
def equivalent(self, other):
if isinstance(other, PatternWordNode):
if self._word == other.word:
@@ -420,8 +591,10 @@ def equals(self, bot, clientid, word):
return False
def to_string(self, verbose=True):
- return "WORD [%s] word=[%s]" % (self._child_count(verbose), self.word)
-
+ if verbose is True:
+ return "WORD [%s] word=[%s]" % (self._child_count(verbose), self.word)
+ else:
+ return "WORD [%s]" % (self.word)
#######################################################################################################################
#
@@ -444,13 +617,11 @@ def equals(self, bot, clientid, word):
return True
return False
- def matches(self, bot, clientid, word):
- if self._word == word:
- return True
- return False
-
def to_string(self, verbose=True):
- return "PWORD [%s] word=[%s]" % (self._child_count(verbose), self.word)
+ if verbose is True:
+ return "PWORD [%s] word=[%s]" % (self._child_count(verbose), self.word)
+ else:
+ return "PWORD [%s]" % (self.word)
#######################################################################################################################
@@ -480,15 +651,15 @@ def equals(self, bot, client, word):
logging.debug("Looking for [%s] in set [%s]", word, self.set_name)
set_words = bot.brain.sets.set(self.set_name)
if word in set_words:
- logging.debug("Found a word [%s] in set [%s]", word, self.set_name)
+ logging.debug("Found word [%s] in set [%s]"%(word, self.set_name))
return True
return False
- def matches(self, bot, clientid, word):
- return self.equals(bot, clientid, word)
-
def to_string(self, verbose=True):
- return "SET [%s] name=[%s]" % (self._child_count(verbose), self.word)
+ if verbose is True:
+ return "SET [%s] name=[%s]" % (self._child_count(verbose), self.word)
+ else:
+ return "SET name=[%s]" % (self.word)
#######################################################################################################################
@@ -510,14 +681,15 @@ def equivalent(self, other):
def equals(self, bot, clientid, word):
if bot.brain.properties.has_property(self.word):
if word == bot.brain.properties.property(self.word):
+ logging.debug("Found word [%s] as bot property"%(word))
return True
return False
- def matches(self, bot, clientid, word):
- return self.equals(bot, clientid, word)
-
def to_string(self, verbose=True):
- return "BOT [%s] property=[%s]" % (self._child_count(verbose), self.word)
+ if verbose is True:
+ return "BOT [%s] property=[%s]" % (self._child_count(verbose), self.word)
+ else:
+ return "BOT property=[%s]" % (self.word)
#######################################################################################################################
@@ -537,30 +709,6 @@ def can_add(self, new_node):
if isinstance(new_node, PatternRootNode):
raise ParserException("Cannot add root node to child node")
- def has_child_match(self, bot, clientid, next_word):
-
- for priority in self._priority_words:
- if priority.equals(bot, clientid, next_word):
- return priority
-
- if self._0ormore_arrow is not None:
- return self._0ormore_arrow
-
- if self._0ormore_hash is not None:
- return self._0ormore_hash
-
- for child in self.children:
- if child.equals(bot, clientid, next_word):
- return child
-
- if self._1ormore_underline is not None:
- return self._1ormore_underline
-
- if self._1ormore_star is not None:
- return self._1ormore_star
-
- return None
-
@property
def wildcard(self):
return self._wildcard
@@ -595,8 +743,107 @@ def equivalent(self, other):
return False
def to_string(self, verbose=True):
- return "ZEROORMORE [%s] wildcard=[%s]" % (self._child_count(verbose), self.wildcard)
+ if verbose is True:
+ return "ZEROORMORE [%s] wildcard=[%s]" % (self._child_count(verbose), self.wildcard)
+ else:
+ return "ZEROORMORE [%s]" % (self.wildcard)
+
+ def consume(self, bot, clientid, context, words, word_no, type):
+
+ context_match = Match(type, self, None)
+ context.add_match(context_match)
+ matches_added = 1
+
+ if self._0ormore_hash is not None:
+ logging.debug("%sWildcard is next node, moving on!"%(TextUtils.get_tabs(word_no)))
+ match = self._0ormore_hash.consume(bot, clientid, context, words, word_no+1, type)
+ if match is not None:
+ return match
+
+ if self._1ormore_underline is not None:
+ logging.debug("%sWildcard is next node, moving on!"%(TextUtils.get_tabs(word_no)))
+ match = self._1ormore_underline.consume(bot, clientid, context, words, word_no+1, type)
+ if match is not None:
+ return match
+
+ if self._0ormore_arrow is not None:
+ logging.debug("%sWildcard is next node, moving on!"%(TextUtils.get_tabs(word_no)))
+ match = self._0ormore_arrow.consume(bot, clientid, context, words, word_no+1, type)
+ if match is not None:
+ return match
+
+ if self._1ormore_star is not None:
+ logging.debug("%sWildcard is next node, moving on!"%(TextUtils.get_tabs(word_no)))
+ match = self._1ormore_star.consume(bot, clientid, context, words, word_no+1, type)
+ if match is not None:
+ return match
+
+ # TODO Add priority words first
+
+ word = words.word(word_no)
+
+ if len(self._children) > 0:
+ for child in self._children:
+ if child.equals(bot, clientid, word):
+ logging.debug ("%sWildcard child %s matched %s"%(TextUtils.get_tabs(word_no), child._word, word))
+
+ logging.debug("%s*MATCH -> %s" % (TextUtils.get_tabs(word_no), word))
+ context_match2 = Match(Match.WORD, child, word)
+ context.add_match(context_match2)
+ matches_added += 1
+
+ match = child.consume(bot, clientid, context, words, word_no+1, type)
+ if match is not None:
+ return match
+
+ logging.debug("%sWildcard %s consumed %s" % (TextUtils.get_tabs(word_no), self._wildcard, word))
+
+ logging.debug("%s*MATCH -> %s" % (TextUtils.get_tabs(word_no), word))
+ context_match.add_word(word)
+
+ match = super(PatternZeroOrMoreWildCardNode, self).consume(bot, clientid, context, words, word_no + 1, type)
+ if match is not None:
+ return match
+
+ word_no += 1
+ word = words.word(word_no)
+
+ logging.debug("%sWildcard %s consumed %s" % (TextUtils.get_tabs(word_no), self._wildcard, word))
+ logging.debug("%s*MATCH -> %s" % (TextUtils.get_tabs(word_no), word))
+ context_match.add_word(word)
+ match = super(PatternZeroOrMoreWildCardNode, self).consume(bot, clientid, context, words, word_no + 1, type)
+ if match is not None:
+ return match
+
+ word_no += 1
+ if word_no >= words.num_words():
+ context.pop_matches(matches_added)
+ return None
+ word = words.word(word_no)
+
+ logging.debug("%sNo children, consume words until next break point" % (TextUtils.get_tabs(word_no)))
+ while word_no < words.num_words() - 1:
+ match = super(PatternZeroOrMoreWildCardNode, self).consume(bot, clientid, context, words, word_no, type)
+ if match is not None:
+ return match
+
+ logging.debug("%s*MATCH -> %s" % (TextUtils.get_tabs(word_no), word))
+ context_match.add_word(word)
+
+ word_no += 1
+ word = words.word(word_no)
+ logging.debug("%sWildcard %s consumed %s" % (TextUtils.get_tabs(word_no), self._wildcard, word))
+
+ logging.debug("%sWildcard %s consumed %s" % (TextUtils.get_tabs(word_no), self._wildcard, word))
+
+ match = super(PatternZeroOrMoreWildCardNode, self).consume(bot, clientid, context, words, word_no, type)
+
+ if match is not None:
+ return match
+ else:
+ context.pop_matches(matches_added)
+ return None
#######################################################################################################################
#
@@ -624,4 +871,105 @@ def equivalent(self, other):
return False
def to_string(self, verbose=True):
- return "ONEORMORE [%s] wildcard=[%s]" % (self._child_count(verbose), self.wildcard)
+ if verbose is True:
+ return "ONEORMORE [%s] wildcard=[%s]" % (self._child_count(verbose), self.wildcard)
+ else:
+ return "ONEORMORE [%s]" % (self.wildcard)
+
+ def consume(self, bot, clientid, context, words, word_no, type):
+
+ if word_no >= words.num_words():
+ return None
+ word = words.word(word_no)
+ logging.debug("%sWildcard %s consumed %s" % (TextUtils.get_tabs(word_no), self._wildcard, word))
+
+ logging.debug("%s*MATCH -> %s" % (TextUtils.get_tabs(word_no), word))
+ context_match = Match(type, self, word)
+ context.add_match(context_match)
+ matches_add = 1
+
+ if self._0ormore_hash is not None:
+ logging.debug("%sWildcard is next node, moving on!"%(TextUtils.get_tabs(word_no)))
+ match = self._0ormore_hash.consume(bot, clientid, context, words, word_no+1, type)
+ if match is not None:
+ return match
+
+ if self._1ormore_underline is not None:
+ logging.debug("%sWildcard is next node, moving on!"%(TextUtils.get_tabs(word_no)))
+ match = self._1ormore_underline.consume(bot, clientid, context, words, word_no+1, type)
+ if match is not None:
+ return match
+
+ if self._0ormore_arrow is not None:
+ logging.debug("%sWildcard is next node, moving on!"%(TextUtils.get_tabs(word_no)))
+ match = self._0ormore_arrow.consume(bot, clientid, context, words, word_no+1, type)
+ if match is not None:
+ return match
+
+ if self._1ormore_star is not None:
+ logging.debug("%sWildcard is next node, moving on!"%(TextUtils.get_tabs(word_no)))
+ match = self._1ormore_star.consume(bot, clientid, context, words, word_no+1, type)
+ if match is not None:
+ return match
+
+ # TODO Add priority words first
+
+ word_no += 1
+ if word_no >= words.num_words():
+ logging.debug("%sNo more words" % (TextUtils.get_tabs(word_no)))
+ return super(PatternOneOrMoreWildCardNode, self).consume(bot, clientid, context, words, word_no, type)
+ word = words.word(word_no)
+
+ if len(self._children) > 0:
+ for child in self._children:
+ if child.equals(bot, clientid, word):
+ logging.debug ("%sWildcard child %s matched %s"%(TextUtils.get_tabs(word_no), child._word, word))
+
+ logging.debug("%sMATCH -> %s" % (TextUtils.get_tabs(word_no), word))
+ context_match2 = Match(Match.WORD, child, word)
+ context.add_match(context_match2)
+ matches_add += 1
+ match = child.consume(bot, clientid, context, words, word_no+1, type)
+ if match is not None:
+ return match
+
+ logging.debug ("%sWildcard %s consumed %s"%(TextUtils.get_tabs(word_no), self._wildcard, word))
+
+ logging.debug("%s*MATCH -> %s" % (TextUtils.get_tabs(word_no), word))
+ context_match.add_word(word)
+
+ word_no += 1
+ if word_no >= words.num_words():
+ context.pop_matches(matches_add)
+ return None
+ word = words.word(word_no)
+
+ logging.debug("%sNo children, consume words until next break point"%(TextUtils.get_tabs(word_no)))
+ while word_no < words.num_words()-1:
+ match = super(PatternOneOrMoreWildCardNode, self).consume(bot, clientid, context, words, word_no, type)
+ if match is not None:
+ return match
+
+ logging.debug("%sWildcard %s consumed %s" % (TextUtils.get_tabs(word_no), self._wildcard, word))
+
+ logging.debug("%s*MATCH -> %s" % (TextUtils.get_tabs(word_no), word))
+ context_match.add_word(word)
+
+ word_no += 1
+ word = words.word(word_no)
+
+ logging.debug("%sWildcard %s consumed %s" % (TextUtils.get_tabs(word_no), self._wildcard, word))
+ logging.debug("%s*MATCH -> %s" % (TextUtils.get_tabs(word_no), word))
+ context_match.add_word(word)
+
+ if word_no == words.num_words()-1:
+ match = super(PatternOneOrMoreWildCardNode, self).consume(bot, clientid, context, words, word_no+1, type)
+ else:
+ match = super(PatternOneOrMoreWildCardNode, self).consume(bot, clientid, context, words, word_no, type)
+
+ if match is not None:
+ return match
+ else:
+ context.pop_matches(matches_add)
+ return None
+
diff --git a/src/programy/parser/template/graph.py b/src/programy/parser/template/graph.py
index 25a82e439..c7c93ee46 100644
--- a/src/programy/parser/template/graph.py
+++ b/src/programy/parser/template/graph.py
@@ -207,6 +207,13 @@ def parse_tag_expression(self, expression, branch):
elif expression.tag == 'rest':
self.parse_rest_expression(expression, branch)
+ # Tags found in Program-A reference implementastion, but not documented in the spec !!! ffs
+ # addtriple
+ # deletetriple
+ # select
+ # uniq
+ # resetlearnf
+ # resetlearn
# This is tag not AIML 2.0 compliant
elif expression.tag == 'extension':
diff --git a/src/programy/parser/template/maps/__init__.py b/src/programy/parser/template/maps/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/src/programy/parser/template/maps/map.py b/src/programy/parser/template/maps/map.py
new file mode 100644
index 000000000..d14c66657
--- /dev/null
+++ b/src/programy/parser/template/maps/map.py
@@ -0,0 +1,18 @@
+
+from abc import ABCMeta, abstractmethod
+
+class TemplateMap(object):
+ __metaclass__ = ABCMeta
+
+ @abstractmethod
+ def get_name(self):
+ """
+ Never Implemented
+ """
+
+ @abstractmethod
+ def map(self, value):
+ """
+ Never Implemented
+ """
+
diff --git a/src/programy/parser/template/maps/plural.py b/src/programy/parser/template/maps/plural.py
new file mode 100644
index 000000000..1db93a705
--- /dev/null
+++ b/src/programy/parser/template/maps/plural.py
@@ -0,0 +1,32 @@
+import logging
+
+from programy.parser.template.maps.map import TemplateMap
+
+
+class PluralMap(TemplateMap):
+
+ NAME = "plural"
+ STATICS = {"MOUSE": "MICE"
+ }
+
+ def __init__(self):
+ TemplateMap.__init__(self)
+
+ def get_name(self):
+ return PluralMap.NAME
+
+ def static_map(self, value):
+ if value in PluralMap.STATICS:
+ return PluralMap.STATICS[value]
+ return None
+
+ def map(self, value):
+ plural_value = self.static_map(value)
+ if plural_value is not None:
+ return plural_value
+
+ if value.endswith('Y'):
+ return value[:-1] + 'IES'
+
+ return value + 'S'
+
diff --git a/src/programy/parser/template/maps/predecessor.py b/src/programy/parser/template/maps/predecessor.py
new file mode 100644
index 000000000..3dd478f1f
--- /dev/null
+++ b/src/programy/parser/template/maps/predecessor.py
@@ -0,0 +1,18 @@
+import logging
+
+from programy.parser.template.maps.map import TemplateMap
+
+class PredecessorMap(TemplateMap):
+
+ NAME = "predecessor"
+
+ def __init__(self):
+ TemplateMap.__init__(self)
+
+ def get_name(self):
+ return PredecessorMap.NAME
+
+ def map(self, value):
+ int_value = int(value)
+ str_value = str(int_value - 1)
+ return str_value
diff --git a/src/programy/parser/template/maps/singular.py b/src/programy/parser/template/maps/singular.py
new file mode 100644
index 000000000..d6b75c253
--- /dev/null
+++ b/src/programy/parser/template/maps/singular.py
@@ -0,0 +1,32 @@
+import logging
+
+from programy.parser.template.maps.map import TemplateMap
+
+class SingularMap(TemplateMap):
+
+ NAME = "singular"
+ STATICS = {"MICE": "MOUSE"
+ }
+
+ def __init__(self):
+ TemplateMap.__init__(self)
+
+ def get_name(self):
+ return SingularMap.NAME
+
+ def static_map(self, value):
+ if value in SingularMap.STATICS:
+ return SingularMap.STATICS[value]
+ return None
+
+ def map(self, value):
+ plural_value = self.static_map(value)
+ if plural_value is not None:
+ return plural_value
+
+ if value.endswith('IES'):
+ return value[:-3] + "Y"
+ elif value.endswith('S'):
+ return value[:-1]
+ else:
+ return value
diff --git a/src/programy/parser/template/maps/successor.py b/src/programy/parser/template/maps/successor.py
new file mode 100644
index 000000000..8b730bfbc
--- /dev/null
+++ b/src/programy/parser/template/maps/successor.py
@@ -0,0 +1,20 @@
+import logging
+
+from programy.parser.template.maps.map import TemplateMap
+
+class SuccessorMap(TemplateMap):
+
+ NAME = "successor"
+
+ def __init__(self):
+ TemplateMap.__init__(self)
+
+ def get_name(self):
+ return SuccessorMap.NAME
+
+ def map(self, value):
+ int_value = int(value)
+ str_value = str(int_value + 1)
+ return str_value
+
+
diff --git a/src/programy/parser/template/nodes.py b/src/programy/parser/template/nodes.py
index b2ff27b01..ea842ca9d 100644
--- a/src/programy/parser/template/nodes.py
+++ b/src/programy/parser/template/nodes.py
@@ -25,6 +25,11 @@
from programy.parser.exceptions import ParserException
from programy.utils.classes.loader import ClassLoader
from programy.utils.services.service import ServiceFactory
+from programy.utils.text.text import TextUtils
+from programy.parser.template.maps.plural import PluralMap
+from programy.parser.template.maps.singular import SingularMap
+from programy.parser.template.maps.predecessor import PredecessorMap
+from programy.parser.template.maps.successor import SuccessorMap
# TODO wrap every resolve method in try/catch and return "" if error
# TODO rename resolve to evaluate
@@ -143,6 +148,8 @@ def __init__(self):
def resolve(self, bot, clientid):
srai_text = self.resolve_children_to_string(bot, clientid)
+ logging.debug("[%s] SRAI Text [%s]"%(self.to_string(), srai_text))
+
resolved = bot.ask_question(clientid, srai_text, srai=True)
logging.debug("[%s] resolved to [%s]", self.to_string(), resolved)
return resolved
@@ -167,8 +174,10 @@ def __init__(self):
def resolve(self, bot, clientid):
sentence = bot.get_conversation(clientid).current_question().current_sentence()
- if len(sentence.stars) > 0:
- resolved = bot.ask_question(clientid, sentence.stars[0], srai=True)
+ star = sentence.matched_context.star(1)
+
+ if star is not None:
+ resolved = bot.ask_question(clientid, star, srai=True)
else:
logging.error("Sr node has no stars available")
resolved = ""
@@ -257,13 +266,17 @@ def __init__(self, position=1, index=1):
TemplateIndexedNode.__init__(self, position, index)
def resolve(self, bot, clientid):
- sentence = bot.get_conversation(clientid).current_question().current_sentence()
+ conversation = bot.get_conversation(clientid)
+ current_question = conversation.current_question()
+ current_sentence = current_question.current_sentence()
+ matched_context = current_sentence.matched_context
- if self.index <= len(sentence.stars):
- resolved = sentence.stars[self.index -1]
- else:
- logging.error("Star index not in range [%d] -> [%d]", self.index, len(sentence.stars))
+ resolved = matched_context.star(self.index)
+
+ if resolved is None:
+ logging.error("Star index not in range [%d]"%(self.index))
resolved = ""
+
logging.debug("[%s] resolved to [%s]", self.to_string(), resolved)
return resolved
@@ -433,6 +446,7 @@ class TemplateMapNode(TemplateNode):
def __init__(self):
TemplateNode.__init__(self)
self._name = None
+ self._internal_maps = [PluralMap(), SingularMap(), PredecessorMap(), SuccessorMap()]
@property
def name(self):
@@ -450,31 +464,15 @@ def resolve_children(self, bot, clientid):
def resolve(self, bot, clientid):
name = self.name.resolve(bot, clientid)
- #name = name.upper ()
var = self.resolve_children(bot, clientid)
- #var = var.upper()
-
- if name == 'successor':
- val = int(var)
- value = str(val + 1)
- elif name == 'predecessor':
- val = int(var)
- value = str(val - 1)
- elif name == 'singular':
- if name.endswith('IES'):
- value = var[:-3]
- elif name.endswith('ES'):
- value = var[:-2]
- elif name.endswith('S'):
- value = var[:-1]
- else:
- value = var
- elif name == 'plural':
- if name.endswith('Y'):
- value = var[:-1] + 'IES'
- else:
- value = var + 'S'
- else:
+
+ internal = False
+ for map in self._internal_maps:
+ if map.get_name() == name:
+ value = map.map(var)
+ internal = True
+
+ if internal is False:
the_map = bot.brain.maps.map(name)
if the_map is None:
logging.error("No map defined for [%s], using default-map" % name)
@@ -493,7 +491,6 @@ def resolve(self, bot, clientid):
value = ""
logging.debug("MAP [%s] resolved to [%s] = [%s]", self.to_string(), name, value)
- #return value.upper()
return value
def to_string(self):
@@ -1498,19 +1495,15 @@ def __init__(self, position=1, index=1):
TemplateIndexedNode.__init__(self, position, index)
def resolve(self, bot, clientid):
- try:
- sentence = bot.get_conversation(clientid).current_question().current_sentence()
+ sentence = bot.get_conversation(clientid).current_question().current_sentence()
- if self.index > 0:
- if self.index <= len(sentence.topicstars):
- return sentence.topicstars[self.index - 1]
- else:
- logging.error("Topic Star index not in range [%d] -> [%d]", self.index, len(sentence.topicstars))
+ resolved = sentence.matched_context.topicstar(self.index)
- except Exception:
- logging.error("Topic Star index is not an integer value [%d]", self.index)
+ if resolved is None:
+ logging.error("That Star index not in range [%d]" % (self.index))
+ resolved = ""
- return ""
+ return resolved
def to_string(self):
return "TOPICSTAR Index=%s" % (self.index)
@@ -1534,21 +1527,17 @@ def __init__(self, position=1, index=1):
TemplateIndexedNode.__init__(self, position, index)
def resolve(self, bot, clientid):
- try:
- question = bot.get_conversation(clientid).nth_question(1)
+ question = bot.get_conversation(clientid).nth_question(1)
- sentence = question.current_sentence()
+ sentence = question.current_sentence()
- if self.index > 0:
- if self.index <= len(sentence.thatstars):
- return sentence.thatstars[self.index - 1]
- else:
- logging.error("That Star index not in range [%d] -> [%d]", self.index, len(sentence.thatstars))
+ resolved = sentence.matched_context.thatstar(self.index)
- except Exception:
- logging.error("That Star index is not an integer value [%d]", self.index)
+ if resolved is None:
+ logging.error("That Star index not in range [%d]" % (self.index))
+ resolved = ""
- return ""
+ return resolved
def to_string(self):
return "THATSTAR Index=%s" % (self.index)
@@ -1764,21 +1753,25 @@ def resolve_element_evals(self, bot, clientid, element):
new_element = ET.Element(element.tag)
- new_element.text = element.text
+ new_element.text = TextUtils.strip_whitespace(element.text)
for child in element:
if child.tag == 'eval':
eval_str = ET.tostring(child, 'utf-8').decode('ascii')
+ eval_str = TextUtils.strip_whitespace(eval_str)
template = ET.fromstring("%s" % eval_str)
ast = bot.brain.aiml_parser.template_parser.parse_template_expression(template)
resolved = ast.resolve(bot, clientid)
- new_element.text += resolved
+
+ new_element.text += " " + resolved
else:
new_element.append(child)
+ new_element.text = new_element.text.upper ()
+
if element.tail is not None:
- new_element.tail = element.tail.strip()
+ new_element.tail = TextUtils.strip_whitespace(element.tail)
return new_element
@@ -1813,6 +1806,7 @@ def to_xml(self, bot, clientid):
xml += ""
xml += ""
+ xml += ""
return xml
diff --git a/src/programy/utils/text/__init__.py b/src/programy/utils/text/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/src/programy/parser/template/evaluator.py b/src/programy/utils/text/text.py
similarity index 62%
rename from src/programy/parser/template/evaluator.py
rename to src/programy/utils/text/text.py
index 98da46d44..586653c1d 100644
--- a/src/programy/parser/template/evaluator.py
+++ b/src/programy/utils/text/text.py
@@ -14,14 +14,29 @@
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
"""
-import logging
-from programy.parser.template.nodes import TemplateNode
-from programy.bot import Bot
+import re
-class TemplateEvaluator(object):
+class TextUtils:
+
+ DEFAULT_TAB_SPACE = " "
+
+ STRIP_ALL_WHITESPACE = '[\s+]'
+ STRIP_WHITESPACE = '[\n\t\r+]'
+
+ @staticmethod
+ def get_tabs(depth: int, tabs=DEFAULT_TAB_SPACE):
+ string = ""
+ for i in range(depth):
+ string += tabs
+ return string
+
+ @staticmethod
+ def strip_whitespace(string):
+ first_pass = re.sub(TextUtils.STRIP_WHITESPACE, ' ', string)
+ return ' '.join(first_pass.split())
+
+ @staticmethod
+ def strip_all_whitespace(string):
+ first_pass = re.sub(TextUtils.STRIP_ALL_WHITESPACE, '', string)
+ return ' '.join(first_pass.split())
- # TODO wrap every resolve method in try/catch and return "" if error
- def evaluate(self, bot: Bot, clientid: str, template_node: TemplateNode):
- logging.debug("Evaluating node [%s]", template_node.to_string())
- template_node.output()
- return template_node.resolve(bot, clientid)
diff --git a/src/test/.DS_Store b/src/test/.DS_Store
new file mode 100644
index 000000000..fbd193ffd
Binary files /dev/null and b/src/test/.DS_Store differ
diff --git a/src/test/aiml_tests/.DS_Store b/src/test/aiml_tests/.DS_Store
new file mode 100644
index 000000000..698cd1b11
Binary files /dev/null and b/src/test/aiml_tests/.DS_Store differ
diff --git a/src/test/aiml_tests/arrow_tests/__init__.py b/src/test/aiml_tests/arrow_tests/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/src/test/aiml_tests/test_files/arrow/arrow.aiml b/src/test/aiml_tests/arrow_tests/arrow.aiml
similarity index 100%
rename from src/test/aiml_tests/test_files/arrow/arrow.aiml
rename to src/test/aiml_tests/arrow_tests/arrow.aiml
diff --git a/src/test/aiml_tests/test_arrow_aiml.py b/src/test/aiml_tests/arrow_tests/test_arrow_aiml.py
similarity index 96%
rename from src/test/aiml_tests/test_arrow_aiml.py
rename to src/test/aiml_tests/arrow_tests/test_arrow_aiml.py
index a66a89d97..af20b5860 100644
--- a/src/test/aiml_tests/test_arrow_aiml.py
+++ b/src/test/aiml_tests/arrow_tests/test_arrow_aiml.py
@@ -10,7 +10,7 @@ def __init__(self):
def load_configuration(self, arguments):
super(BasicTestClient, self).load_configuration(arguments)
- self.configuration.brain_configuration._aiml_files = BrainFileConfiguration(os.path.dirname(__file__)+"/../aiml_tests/test_files/arrow", ".aiml", False)
+ self.configuration.brain_configuration._aiml_files = BrainFileConfiguration(os.path.dirname(__file__), ".aiml", False)
class ArrowAIMLTests(unittest.TestCase):
diff --git a/src/test/aiml_tests/basics_tests/__init__.py b/src/test/aiml_tests/basics_tests/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/src/test/aiml_tests/test_files/basics/basic.aiml b/src/test/aiml_tests/basics_tests/basic.aiml
similarity index 100%
rename from src/test/aiml_tests/test_files/basics/basic.aiml
rename to src/test/aiml_tests/basics_tests/basic.aiml
diff --git a/src/test/aiml_tests/test_basic_aiml.py b/src/test/aiml_tests/basics_tests/test_basic_aiml.py
similarity index 97%
rename from src/test/aiml_tests/test_basic_aiml.py
rename to src/test/aiml_tests/basics_tests/test_basic_aiml.py
index 8aa199fc7..96c5d3b65 100644
--- a/src/test/aiml_tests/test_basic_aiml.py
+++ b/src/test/aiml_tests/basics_tests/test_basic_aiml.py
@@ -1,5 +1,6 @@
import unittest
import os
+import logging
from test.aiml_tests.client import TestClient
from programy.config import BrainFileConfiguration
@@ -7,11 +8,11 @@
class BasicTestClient(TestClient):
def __init__(self):
- TestClient.__init__(self)
+ TestClient.__init__(self, debug=True)
def load_configuration(self, arguments):
super(BasicTestClient, self).load_configuration(arguments)
- self.configuration.brain_configuration._aiml_files = BrainFileConfiguration(os.path.dirname(__file__)+"/../aiml_tests/test_files/basics", ".aiml", False)
+ self.configuration.brain_configuration._aiml_files = BrainFileConfiguration(os.path.dirname(__file__), ".aiml", False)
class BasicAIMLTests(unittest.TestCase):
@@ -23,6 +24,7 @@ def test_basic_no_response(self):
self.assertEqual(response, '')
def test_basic_one_word(self):
+ BasicAIMLTests.test_client.dump_bot_brain_tree()
response = BasicAIMLTests.test_client.bot.ask_question("test", "HELLO")
self.assertEqual(response, "HELLO, WORLD")
diff --git a/src/test/aiml_tests/bot_tests/__init__.py b/src/test/aiml_tests/bot_tests/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/src/test/aiml_tests/test_files/bot/bot.aiml b/src/test/aiml_tests/bot_tests/bot.aiml
similarity index 100%
rename from src/test/aiml_tests/test_files/bot/bot.aiml
rename to src/test/aiml_tests/bot_tests/bot.aiml
diff --git a/src/test/aiml_tests/test_bot_aiml.py b/src/test/aiml_tests/bot_tests/test_bot_aiml.py
similarity index 98%
rename from src/test/aiml_tests/test_bot_aiml.py
rename to src/test/aiml_tests/bot_tests/test_bot_aiml.py
index 21a48f774..25f5a3939 100644
--- a/src/test/aiml_tests/test_bot_aiml.py
+++ b/src/test/aiml_tests/bot_tests/test_bot_aiml.py
@@ -10,7 +10,7 @@ def __init__(self):
def load_configuration(self, arguments):
super(BasicTestClient, self).load_configuration(arguments)
- self.configuration.brain_configuration._aiml_files = BrainFileConfiguration(os.path.dirname(__file__)+"/../aiml_tests/test_files/bot", ".aiml", False)
+ self.configuration.brain_configuration._aiml_files = BrainFileConfiguration(os.path.dirname(__file__), ".aiml", False)
class BotAIMLTests(unittest.TestCase):
diff --git a/src/test/aiml_tests/condition_tests/__init__.py b/src/test/aiml_tests/condition_tests/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/src/test/aiml_tests/test_files/condition/condition.aiml b/src/test/aiml_tests/condition_tests/condition.aiml
similarity index 100%
rename from src/test/aiml_tests/test_files/condition/condition.aiml
rename to src/test/aiml_tests/condition_tests/condition.aiml
diff --git a/src/test/aiml_tests/test_condition_aiml.py b/src/test/aiml_tests/condition_tests/test_condition_aiml.py
similarity index 97%
rename from src/test/aiml_tests/test_condition_aiml.py
rename to src/test/aiml_tests/condition_tests/test_condition_aiml.py
index 17659cefd..85725edd1 100644
--- a/src/test/aiml_tests/test_condition_aiml.py
+++ b/src/test/aiml_tests/condition_tests/test_condition_aiml.py
@@ -10,7 +10,7 @@ def __init__(self):
def load_configuration(self, arguments):
super(BasicTestClient, self).load_configuration(arguments)
- self.configuration.brain_configuration._aiml_files = BrainFileConfiguration(os.path.dirname(__file__)+"/../aiml_tests/test_files/condition", ".aiml", False)
+ self.configuration.brain_configuration._aiml_files = BrainFileConfiguration(os.path.dirname(__file__), ".aiml", False)
class ConditionAIMLTests(unittest.TestCase):
diff --git a/src/test/aiml_tests/conversations_tests/__init__.py b/src/test/aiml_tests/conversations_tests/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/src/test/aiml_tests/test_files/conversations/conversations.aiml b/src/test/aiml_tests/conversations_tests/conversations.aiml
similarity index 100%
rename from src/test/aiml_tests/test_files/conversations/conversations.aiml
rename to src/test/aiml_tests/conversations_tests/conversations.aiml
diff --git a/src/test/aiml_tests/test_conversational_aiml.py b/src/test/aiml_tests/conversations_tests/test_conversational_aiml.py
similarity index 89%
rename from src/test/aiml_tests/test_conversational_aiml.py
rename to src/test/aiml_tests/conversations_tests/test_conversational_aiml.py
index 0748ed5e9..c03198070 100644
--- a/src/test/aiml_tests/test_conversational_aiml.py
+++ b/src/test/aiml_tests/conversations_tests/test_conversational_aiml.py
@@ -11,7 +11,7 @@ def __init__(self):
def load_configuration(self, arguments):
super(ConversationalTestClient, self).load_configuration(arguments)
- self.configuration.brain_configuration._aiml_files = BrainFileConfiguration(os.path.dirname(__file__)+"/../aiml_tests/test_files/conversations", ".aiml", False)
+ self.configuration.brain_configuration._aiml_files = BrainFileConfiguration(os.path.dirname(__file__), ".aiml", False)
class ConversationalAIMLTests(unittest.TestCase):
diff --git a/src/test/aiml_tests/datetime_tests/__init__.py b/src/test/aiml_tests/datetime_tests/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/src/test/aiml_tests/test_files/datetime/datetime.aiml b/src/test/aiml_tests/datetime_tests/datetime.aiml
similarity index 100%
rename from src/test/aiml_tests/test_files/datetime/datetime.aiml
rename to src/test/aiml_tests/datetime_tests/datetime.aiml
diff --git a/src/test/aiml_tests/test_files/datetime/maps/successor.txt b/src/test/aiml_tests/datetime_tests/maps/successor.txt
similarity index 100%
rename from src/test/aiml_tests/test_files/datetime/maps/successor.txt
rename to src/test/aiml_tests/datetime_tests/maps/successor.txt
diff --git a/src/test/aiml_tests/test_files/datetime/maps/tomorrow.txt b/src/test/aiml_tests/datetime_tests/maps/tomorrow.txt
similarity index 100%
rename from src/test/aiml_tests/test_files/datetime/maps/tomorrow.txt
rename to src/test/aiml_tests/datetime_tests/maps/tomorrow.txt
diff --git a/src/test/aiml_tests/test_files/datetime/sets/weekday.txt b/src/test/aiml_tests/datetime_tests/sets/weekday.txt
similarity index 100%
rename from src/test/aiml_tests/test_files/datetime/sets/weekday.txt
rename to src/test/aiml_tests/datetime_tests/sets/weekday.txt
diff --git a/src/test/aiml_tests/test_datetime_aiml.py b/src/test/aiml_tests/datetime_tests/test_datetime_aiml.py
similarity index 87%
rename from src/test/aiml_tests/test_datetime_aiml.py
rename to src/test/aiml_tests/datetime_tests/test_datetime_aiml.py
index db445ee18..73b0791e7 100644
--- a/src/test/aiml_tests/test_datetime_aiml.py
+++ b/src/test/aiml_tests/datetime_tests/test_datetime_aiml.py
@@ -12,9 +12,9 @@ def __init__(self):
def load_configuration(self, arguments):
super(BasicTestClient, self).load_configuration(arguments)
- self.configuration.brain_configuration._aiml_files = BrainFileConfiguration(os.path.dirname(__file__)+"/../aiml_tests/test_files/datetime", ".aiml", False)
- self.configuration.brain_configuration._set_files = BrainFileConfiguration(os.path.dirname(__file__)+"/../aiml_tests/test_files/datetime/sets", ".txt", False)
- self.configuration.brain_configuration._map_files = BrainFileConfiguration(os.path.dirname(__file__)+"/../aiml_tests/test_files/datetime/maps", ".txt", False)
+ self.configuration.brain_configuration._aiml_files = BrainFileConfiguration(os.path.dirname(__file__), ".aiml", False)
+ self.configuration.brain_configuration._set_files = BrainFileConfiguration(os.path.dirname(__file__)+"/sets", ".txt", False)
+ self.configuration.brain_configuration._map_files = BrainFileConfiguration(os.path.dirname(__file__)+"/maps", ".txt", False)
class DateTimeAIMLTests(unittest.TestCase):
diff --git a/src/test/aiml_tests/denormalize_tests/__init__.py b/src/test/aiml_tests/denormalize_tests/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/src/test/aiml_tests/test_files/denormalize/denormal.txt b/src/test/aiml_tests/denormalize_tests/denormal.txt
similarity index 100%
rename from src/test/aiml_tests/test_files/denormalize/denormal.txt
rename to src/test/aiml_tests/denormalize_tests/denormal.txt
diff --git a/src/test/aiml_tests/test_files/denormalize/denormalize.aiml b/src/test/aiml_tests/denormalize_tests/denormalize.aiml
similarity index 100%
rename from src/test/aiml_tests/test_files/denormalize/denormalize.aiml
rename to src/test/aiml_tests/denormalize_tests/denormalize.aiml
diff --git a/src/test/aiml_tests/test_denormalize_aiml.py b/src/test/aiml_tests/denormalize_tests/test_denormalize_aiml.py
similarity index 85%
rename from src/test/aiml_tests/test_denormalize_aiml.py
rename to src/test/aiml_tests/denormalize_tests/test_denormalize_aiml.py
index db2413130..586c47710 100644
--- a/src/test/aiml_tests/test_denormalize_aiml.py
+++ b/src/test/aiml_tests/denormalize_tests/test_denormalize_aiml.py
@@ -10,8 +10,8 @@ def __init__(self):
def load_configuration(self, arguments):
super(BasicTestClient, self).load_configuration(arguments)
- self.configuration.brain_configuration._aiml_files = BrainFileConfiguration(os.path.dirname(__file__)+"/../aiml_tests/test_files/denormalize", ".aiml", False)
- self.configuration.brain_configuration._denormal = os.path.dirname(__file__)+"/../aiml_tests/test_files/denormalize/denormal.txt"
+ self.configuration.brain_configuration._aiml_files = BrainFileConfiguration(os.path.dirname(__file__), ".aiml", False)
+ self.configuration.brain_configuration._denormal = os.path.dirname(__file__)+"/denormal.txt"
class DenormalizeAIMLTests(unittest.TestCase):
diff --git a/src/test/aiml_tests/gender_tests/__init__.py b/src/test/aiml_tests/gender_tests/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/src/test/aiml_tests/test_files/gender/gender.aiml b/src/test/aiml_tests/gender_tests/gender.aiml
similarity index 100%
rename from src/test/aiml_tests/test_files/gender/gender.aiml
rename to src/test/aiml_tests/gender_tests/gender.aiml
diff --git a/src/test/aiml_tests/test_files/gender/gender.txt b/src/test/aiml_tests/gender_tests/gender.txt
similarity index 100%
rename from src/test/aiml_tests/test_files/gender/gender.txt
rename to src/test/aiml_tests/gender_tests/gender.txt
diff --git a/src/test/aiml_tests/test_gender_aiml.py b/src/test/aiml_tests/gender_tests/test_gender_aiml.py
similarity index 83%
rename from src/test/aiml_tests/test_gender_aiml.py
rename to src/test/aiml_tests/gender_tests/test_gender_aiml.py
index c9ead9af4..d3503d4ea 100644
--- a/src/test/aiml_tests/test_gender_aiml.py
+++ b/src/test/aiml_tests/gender_tests/test_gender_aiml.py
@@ -10,8 +10,8 @@ def __init__(self):
def load_configuration(self, arguments):
super(BasicTestClient, self).load_configuration(arguments)
- self.configuration.brain_configuration._aiml_files = BrainFileConfiguration(os.path.dirname(__file__)+"/../aiml_tests/test_files/gender", ".aiml", False)
- self.configuration.brain_configuration._gender = os.path.dirname(__file__)+"/../aiml_tests/test_files/gender/gender.txt"
+ self.configuration.brain_configuration._aiml_files = BrainFileConfiguration(os.path.dirname(__file__), ".aiml", False)
+ self.configuration.brain_configuration._gender = os.path.dirname(__file__)+"/gender.txt"
class GenderAIMLTests(unittest.TestCase):
diff --git a/src/test/aiml_tests/get_tests/__init__.py b/src/test/aiml_tests/get_tests/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/src/test/aiml_tests/test_files/get/get.aiml b/src/test/aiml_tests/get_tests/get.aiml
similarity index 100%
rename from src/test/aiml_tests/test_files/get/get.aiml
rename to src/test/aiml_tests/get_tests/get.aiml
diff --git a/src/test/aiml_tests/test_get_aiml.py b/src/test/aiml_tests/get_tests/test_get_aiml.py
similarity index 96%
rename from src/test/aiml_tests/test_get_aiml.py
rename to src/test/aiml_tests/get_tests/test_get_aiml.py
index 15b84c8df..f4d5ca749 100644
--- a/src/test/aiml_tests/test_get_aiml.py
+++ b/src/test/aiml_tests/get_tests/test_get_aiml.py
@@ -10,7 +10,7 @@ def __init__(self):
def load_configuration(self, arguments):
super(BasicTestClient, self).load_configuration(arguments)
- self.configuration.brain_configuration._aiml_files = BrainFileConfiguration(os.path.dirname(__file__)+"/../aiml_tests/test_files/get", ".aiml", False)
+ self.configuration.brain_configuration._aiml_files = BrainFileConfiguration(os.path.dirname(__file__), ".aiml", False)
class GetAIMLTests(unittest.TestCase):
diff --git a/src/test/aiml_tests/hash_tests/__init__.py b/src/test/aiml_tests/hash_tests/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/src/test/aiml_tests/test_files/hash/hash.aiml b/src/test/aiml_tests/hash_tests/hash.aiml
similarity index 100%
rename from src/test/aiml_tests/test_files/hash/hash.aiml
rename to src/test/aiml_tests/hash_tests/hash.aiml
diff --git a/src/test/aiml_tests/test_hash_aiml.py b/src/test/aiml_tests/hash_tests/test_hash_aiml.py
similarity index 93%
rename from src/test/aiml_tests/test_hash_aiml.py
rename to src/test/aiml_tests/hash_tests/test_hash_aiml.py
index 9fc512f3b..5b6736a4e 100644
--- a/src/test/aiml_tests/test_hash_aiml.py
+++ b/src/test/aiml_tests/hash_tests/test_hash_aiml.py
@@ -6,16 +6,15 @@
class BasicTestClient(TestClient):
def __init__(self):
- TestClient.__init__(self)
+ TestClient.__init__(self, debug=True)
def load_configuration(self, arguments):
super(BasicTestClient, self).load_configuration(arguments)
- self.configuration.brain_configuration._aiml_files = BrainFileConfiguration(os.path.dirname(__file__)+"/../aiml_tests/test_files/hash", ".aiml", False)
+ self.configuration.brain_configuration._aiml_files = BrainFileConfiguration(os.path.dirname(__file__), ".aiml", False)
class HashAIMLTests(unittest.TestCase):
- @classmethod
- def setUpClass(cls):
+ def setUp(cls):
HashAIMLTests.test_client = BasicTestClient()
def test_hash_first_word(self):
diff --git a/src/test/aiml_tests/info_tests/__init__.py b/src/test/aiml_tests/info_tests/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/src/test/aiml_tests/test_files/info/info.aiml b/src/test/aiml_tests/info_tests/info.aiml
similarity index 100%
rename from src/test/aiml_tests/test_files/info/info.aiml
rename to src/test/aiml_tests/info_tests/info.aiml
diff --git a/src/test/aiml_tests/test_info_aiml.py b/src/test/aiml_tests/info_tests/test_info_aiml.py
similarity index 92%
rename from src/test/aiml_tests/test_info_aiml.py
rename to src/test/aiml_tests/info_tests/test_info_aiml.py
index fff4897c2..03091a2e1 100644
--- a/src/test/aiml_tests/test_info_aiml.py
+++ b/src/test/aiml_tests/info_tests/test_info_aiml.py
@@ -10,7 +10,7 @@ def __init__(self):
def load_configuration(self, arguments):
super(BasicTestClient, self).load_configuration(arguments)
- self.configuration.brain_configuration._aiml_files = BrainFileConfiguration(os.path.dirname(__file__)+"/../aiml_tests/test_files/info", ".aiml", False)
+ self.configuration.brain_configuration._aiml_files = BrainFileConfiguration(os.path.dirname(__file__), ".aiml", False)
class InfoAIMLTests(unittest.TestCase):
diff --git a/src/test/aiml_tests/learn_tests/__init__.py b/src/test/aiml_tests/learn_tests/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/src/test/aiml_tests/test_files/learn/learn.aiml b/src/test/aiml_tests/learn_tests/learn.aiml
similarity index 100%
rename from src/test/aiml_tests/test_files/learn/learn.aiml
rename to src/test/aiml_tests/learn_tests/learn.aiml
diff --git a/src/test/aiml_tests/test_learn_aiml.py b/src/test/aiml_tests/learn_tests/test_learn_aiml.py
similarity index 90%
rename from src/test/aiml_tests/test_learn_aiml.py
rename to src/test/aiml_tests/learn_tests/test_learn_aiml.py
index 41a9fba18..e15a75904 100644
--- a/src/test/aiml_tests/test_learn_aiml.py
+++ b/src/test/aiml_tests/learn_tests/test_learn_aiml.py
@@ -10,7 +10,7 @@ def __init__(self):
def load_configuration(self, arguments):
super(LearnTestClient, self).load_configuration(arguments)
- self.configuration.brain_configuration._aiml_files = BrainFileConfiguration(os.path.dirname(__file__)+"/../aiml_tests/test_files/learn", ".aiml", False)
+ self.configuration.brain_configuration._aiml_files = BrainFileConfiguration(os.path.dirname(__file__), ".aiml", False)
class LearnAIMLTests(unittest.TestCase):
diff --git a/src/test/aiml_tests/learnf_tests/__init__.py b/src/test/aiml_tests/learnf_tests/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/src/test/aiml_tests/test_files/learnf/learn.aiml b/src/test/aiml_tests/learnf_tests/learn.aiml
similarity index 100%
rename from src/test/aiml_tests/test_files/learnf/learn.aiml
rename to src/test/aiml_tests/learnf_tests/learn.aiml
diff --git a/src/test/aiml_tests/test_learnf_aiml.py b/src/test/aiml_tests/learnf_tests/test_learnf_aiml.py
similarity index 91%
rename from src/test/aiml_tests/test_learnf_aiml.py
rename to src/test/aiml_tests/learnf_tests/test_learnf_aiml.py
index a10aa7b1d..6529e0684 100644
--- a/src/test/aiml_tests/test_learnf_aiml.py
+++ b/src/test/aiml_tests/learnf_tests/test_learnf_aiml.py
@@ -10,7 +10,7 @@ def __init__(self):
def load_configuration(self, arguments):
super(LearnfTestClient, self).load_configuration(arguments)
- self.configuration.brain_configuration._aiml_files = BrainFileConfiguration(os.path.dirname(__file__)+"/../aiml_tests/test_files/learnf", ".aiml", False)
+ self.configuration.brain_configuration._aiml_files = BrainFileConfiguration(os.path.dirname(__file__), ".aiml", False)
class LearnfAIMLTests(unittest.TestCase):
diff --git a/src/test/aiml_tests/loop_tests/__init__.py b/src/test/aiml_tests/loop_tests/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/src/test/aiml_tests/test_files/loop/loop.aiml b/src/test/aiml_tests/loop_tests/loop.aiml
similarity index 100%
rename from src/test/aiml_tests/test_files/loop/loop.aiml
rename to src/test/aiml_tests/loop_tests/loop.aiml
diff --git a/src/test/aiml_tests/test_loop_aiml.py b/src/test/aiml_tests/loop_tests/test_loop_aiml.py
similarity index 91%
rename from src/test/aiml_tests/test_loop_aiml.py
rename to src/test/aiml_tests/loop_tests/test_loop_aiml.py
index d365db594..1fc5e117d 100644
--- a/src/test/aiml_tests/test_loop_aiml.py
+++ b/src/test/aiml_tests/loop_tests/test_loop_aiml.py
@@ -10,7 +10,7 @@ def __init__(self):
def load_configuration(self, arguments):
super(BasicTestClient, self).load_configuration(arguments)
- self.configuration.brain_configuration._aiml_files = BrainFileConfiguration(os.path.dirname(__file__)+"/../aiml_tests/test_files/loop", ".aiml", False)
+ self.configuration.brain_configuration._aiml_files = BrainFileConfiguration(os.path.dirname(__file__), ".aiml", False)
class ConditionLoopAIMLTests(unittest.TestCase):
diff --git a/src/test/aiml_tests/multiples_tests/__init__.py b/src/test/aiml_tests/multiples_tests/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/src/test/aiml_tests/test_files/multiples/multiples.aiml b/src/test/aiml_tests/multiples_tests/multiples.aiml
similarity index 100%
rename from src/test/aiml_tests/test_files/multiples/multiples.aiml
rename to src/test/aiml_tests/multiples_tests/multiples.aiml
diff --git a/src/test/aiml_tests/test_multiples_aiml.py b/src/test/aiml_tests/multiples_tests/test_multiples_aiml.py
similarity index 89%
rename from src/test/aiml_tests/test_multiples_aiml.py
rename to src/test/aiml_tests/multiples_tests/test_multiples_aiml.py
index 17fdf3b23..129a40537 100644
--- a/src/test/aiml_tests/test_multiples_aiml.py
+++ b/src/test/aiml_tests/multiples_tests/test_multiples_aiml.py
@@ -10,7 +10,7 @@ def __init__(self):
def load_configuration(self, arguments):
super(MultiplesTestClient, self).load_configuration(arguments)
- self.configuration.brain_configuration._aiml_files = BrainFileConfiguration(os.path.dirname(__file__)+"/../aiml_tests/test_files/multiples", ".aiml", False)
+ self.configuration.brain_configuration._aiml_files = BrainFileConfiguration(os.path.dirname(__file__), ".aiml", False)
class MultiplesAIMLTests(unittest.TestCase):
diff --git a/src/test/aiml_tests/normalize_tests/__init__.py b/src/test/aiml_tests/normalize_tests/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/src/test/aiml_tests/test_files/normalize/normal.txt b/src/test/aiml_tests/normalize_tests/normal.txt
similarity index 100%
rename from src/test/aiml_tests/test_files/normalize/normal.txt
rename to src/test/aiml_tests/normalize_tests/normal.txt
diff --git a/src/test/aiml_tests/test_files/normalize/normalize.aiml b/src/test/aiml_tests/normalize_tests/normalize.aiml
similarity index 100%
rename from src/test/aiml_tests/test_files/normalize/normalize.aiml
rename to src/test/aiml_tests/normalize_tests/normalize.aiml
diff --git a/src/test/aiml_tests/test_normalize_aiml.py b/src/test/aiml_tests/normalize_tests/test_normalize_aiml.py
similarity index 83%
rename from src/test/aiml_tests/test_normalize_aiml.py
rename to src/test/aiml_tests/normalize_tests/test_normalize_aiml.py
index fa968e283..c0d3ea59b 100644
--- a/src/test/aiml_tests/test_normalize_aiml.py
+++ b/src/test/aiml_tests/normalize_tests/test_normalize_aiml.py
@@ -10,8 +10,8 @@ def __init__(self):
def load_configuration(self, arguments):
super(BasicTestClient, self).load_configuration(arguments)
- self.configuration.brain_configuration._aiml_files = BrainFileConfiguration(os.path.dirname(__file__)+"/../aiml_tests/test_files/normalize", ".aiml", False)
- self.configuration.brain_configuration._normal = os.path.dirname(__file__)+"/../aiml_tests/test_files/normalize/normal.txt"
+ self.configuration.brain_configuration._aiml_files = BrainFileConfiguration(os.path.dirname(__file__), ".aiml", False)
+ self.configuration.brain_configuration._normal = os.path.dirname(__file__)+"/normal.txt"
class NormalizeAIMLTests(unittest.TestCase):
diff --git a/src/test/aiml_tests/pattern_bot_tests/__init__.py b/src/test/aiml_tests/pattern_bot_tests/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/src/test/aiml_tests/test_files/pattern_bot/bot.aiml b/src/test/aiml_tests/pattern_bot_tests/bot.aiml
similarity index 100%
rename from src/test/aiml_tests/test_files/pattern_bot/bot.aiml
rename to src/test/aiml_tests/pattern_bot_tests/bot.aiml
diff --git a/src/test/aiml_tests/test_pattern_bot_aiml.py b/src/test/aiml_tests/pattern_bot_tests/test_pattern_bot_aiml.py
similarity index 90%
rename from src/test/aiml_tests/test_pattern_bot_aiml.py
rename to src/test/aiml_tests/pattern_bot_tests/test_pattern_bot_aiml.py
index 5fca514a4..0858f81cb 100644
--- a/src/test/aiml_tests/test_pattern_bot_aiml.py
+++ b/src/test/aiml_tests/pattern_bot_tests/test_pattern_bot_aiml.py
@@ -10,7 +10,7 @@ def __init__(self):
def load_configuration(self, arguments):
super(BasicTestClient, self).load_configuration(arguments)
- self.configuration.brain_configuration._aiml_files = BrainFileConfiguration(os.path.dirname(__file__)+"/../aiml_tests/test_files/pattern_bot", ".aiml", False)
+ self.configuration.brain_configuration._aiml_files = BrainFileConfiguration(os.path.dirname(__file__), ".aiml", False)
class PatternBotAIMLTests(unittest.TestCase):
diff --git a/src/test/aiml_tests/pattern_ordering_tests/__init__.py b/src/test/aiml_tests/pattern_ordering_tests/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/src/test/aiml_tests/test_files/pattern_ordering/animals.aiml b/src/test/aiml_tests/pattern_ordering_tests/animals.aiml
similarity index 100%
rename from src/test/aiml_tests/test_files/pattern_ordering/animals.aiml
rename to src/test/aiml_tests/pattern_ordering_tests/animals.aiml
diff --git a/src/test/aiml_tests/test_files/pattern_ordering/colours.aiml b/src/test/aiml_tests/pattern_ordering_tests/colours.aiml
similarity index 100%
rename from src/test/aiml_tests/test_files/pattern_ordering/colours.aiml
rename to src/test/aiml_tests/pattern_ordering_tests/colours.aiml
diff --git a/src/test/aiml_tests/test_pattern_ordering_aiml.py b/src/test/aiml_tests/pattern_ordering_tests/test_pattern_ordering_aiml.py
similarity index 94%
rename from src/test/aiml_tests/test_pattern_ordering_aiml.py
rename to src/test/aiml_tests/pattern_ordering_tests/test_pattern_ordering_aiml.py
index d49e7b1e8..6d3187c6a 100644
--- a/src/test/aiml_tests/test_pattern_ordering_aiml.py
+++ b/src/test/aiml_tests/pattern_ordering_tests/test_pattern_ordering_aiml.py
@@ -11,7 +11,7 @@ def __init__(self):
def load_configuration(self, arguments):
super(OrderingTestClient, self).load_configuration(arguments)
- self.configuration.brain_configuration._aiml_files = BrainFileConfiguration(os.path.dirname(__file__)+"/../aiml_tests/test_files/pattern_ordering", ".aiml", False)
+ self.configuration.brain_configuration._aiml_files = BrainFileConfiguration(os.path.dirname(__file__), ".aiml", False)
class OrderingAIMLTests(unittest.TestCase):
diff --git a/src/test/aiml_tests/pattern_set_tests/__init__.py b/src/test/aiml_tests/pattern_set_tests/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/src/test/aiml_tests/test_files/pattern_set/set.aiml b/src/test/aiml_tests/pattern_set_tests/set.aiml
similarity index 100%
rename from src/test/aiml_tests/test_files/pattern_set/set.aiml
rename to src/test/aiml_tests/pattern_set_tests/set.aiml
diff --git a/src/test/aiml_tests/test_files/pattern_set/sets/color.txt b/src/test/aiml_tests/pattern_set_tests/sets/color.txt
similarity index 100%
rename from src/test/aiml_tests/test_files/pattern_set/sets/color.txt
rename to src/test/aiml_tests/pattern_set_tests/sets/color.txt
diff --git a/src/test/aiml_tests/test_pattern_set_aiml.py b/src/test/aiml_tests/pattern_set_tests/test_pattern_set_aiml.py
similarity index 79%
rename from src/test/aiml_tests/test_pattern_set_aiml.py
rename to src/test/aiml_tests/pattern_set_tests/test_pattern_set_aiml.py
index f414af991..896e1251f 100644
--- a/src/test/aiml_tests/test_pattern_set_aiml.py
+++ b/src/test/aiml_tests/pattern_set_tests/test_pattern_set_aiml.py
@@ -10,8 +10,8 @@ def __init__(self):
def load_configuration(self, arguments):
super(BasicTestClient, self).load_configuration(arguments)
- self.configuration.brain_configuration._aiml_files = BrainFileConfiguration(os.path.dirname(__file__)+"/../aiml_tests/test_files/pattern_set", ".aiml", False)
- self.configuration.brain_configuration._set_files = BrainFileConfiguration(os.path.dirname(__file__)+"/../aiml_tests/test_files/pattern_set/sets", ".txt", False)
+ self.configuration.brain_configuration._aiml_files = BrainFileConfiguration(os.path.dirname(__file__), ".aiml", False)
+ self.configuration.brain_configuration._set_files = BrainFileConfiguration(os.path.dirname(__file__)+"/sets", ".txt", False)
class PatternsetAIMLTests(unittest.TestCase):
diff --git a/src/test/aiml_tests/patterns_tests/__init__.py b/src/test/aiml_tests/patterns_tests/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/src/test/aiml_tests/test_files/patterns/basic_patterns.aiml b/src/test/aiml_tests/patterns_tests/basic_patterns.aiml
similarity index 100%
rename from src/test/aiml_tests/test_files/patterns/basic_patterns.aiml
rename to src/test/aiml_tests/patterns_tests/basic_patterns.aiml
diff --git a/src/test/aiml_tests/test_patterns_aiml.py b/src/test/aiml_tests/patterns_tests/test_patterns_aiml.py
similarity index 98%
rename from src/test/aiml_tests/test_patterns_aiml.py
rename to src/test/aiml_tests/patterns_tests/test_patterns_aiml.py
index 27b02dd5b..8d396952d 100644
--- a/src/test/aiml_tests/test_patterns_aiml.py
+++ b/src/test/aiml_tests/patterns_tests/test_patterns_aiml.py
@@ -6,11 +6,11 @@
class PatternsTestClient(TestClient):
def __init__(self):
- TestClient.__init__(self)
+ TestClient.__init__(self, debug=True)
def load_configuration(self, arguments):
super(PatternsTestClient, self).load_configuration(arguments)
- self.configuration.brain_configuration._aiml_files = BrainFileConfiguration(os.path.dirname(__file__)+"/../aiml_tests/test_files/patterns", ".aiml", False)
+ self.configuration.brain_configuration._aiml_files = BrainFileConfiguration(os.path.dirname(__file__), ".aiml", False)
class PatternsAIMLTests(unittest.TestCase):
diff --git a/src/test/aiml_tests/person2_tests/__init__.py b/src/test/aiml_tests/person2_tests/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/src/test/aiml_tests/test_files/person2/person2.aiml b/src/test/aiml_tests/person2_tests/person2.aiml
similarity index 100%
rename from src/test/aiml_tests/test_files/person2/person2.aiml
rename to src/test/aiml_tests/person2_tests/person2.aiml
diff --git a/src/test/aiml_tests/test_files/person2/person2.txt b/src/test/aiml_tests/person2_tests/person2.txt
similarity index 100%
rename from src/test/aiml_tests/test_files/person2/person2.txt
rename to src/test/aiml_tests/person2_tests/person2.txt
diff --git a/src/test/aiml_tests/test_person2_aiml.py b/src/test/aiml_tests/person2_tests/test_person2_aiml.py
similarity index 82%
rename from src/test/aiml_tests/test_person2_aiml.py
rename to src/test/aiml_tests/person2_tests/test_person2_aiml.py
index 6cb29a899..071ade860 100644
--- a/src/test/aiml_tests/test_person2_aiml.py
+++ b/src/test/aiml_tests/person2_tests/test_person2_aiml.py
@@ -10,8 +10,8 @@ def __init__(self):
def load_configuration(self, arguments):
super(BasicTestClient, self).load_configuration(arguments)
- self.configuration.brain_configuration._aiml_files = BrainFileConfiguration(os.path.dirname(__file__)+"/../aiml_tests/test_files/person2", ".aiml", False)
- self.configuration.brain_configuration._person2 = os.path.dirname(__file__)+ "/../aiml_tests/test_files/person2/person2.txt"
+ self.configuration.brain_configuration._aiml_files = BrainFileConfiguration(os.path.dirname(__file__), ".aiml", False)
+ self.configuration.brain_configuration._person2 = os.path.dirname(__file__)+ "/person2.txt"
class Person2AIMLTests(unittest.TestCase):
diff --git a/src/test/aiml_tests/person_tests/__init__.py b/src/test/aiml_tests/person_tests/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/src/test/aiml_tests/test_files/person/person.aiml b/src/test/aiml_tests/person_tests/person.aiml
similarity index 100%
rename from src/test/aiml_tests/test_files/person/person.aiml
rename to src/test/aiml_tests/person_tests/person.aiml
diff --git a/src/test/aiml_tests/test_files/person/person.txt b/src/test/aiml_tests/person_tests/person.txt
similarity index 100%
rename from src/test/aiml_tests/test_files/person/person.txt
rename to src/test/aiml_tests/person_tests/person.txt
diff --git a/src/test/aiml_tests/test_person_aiml.py b/src/test/aiml_tests/person_tests/test_person_aiml.py
similarity index 83%
rename from src/test/aiml_tests/test_person_aiml.py
rename to src/test/aiml_tests/person_tests/test_person_aiml.py
index 86b563cb0..00f67e906 100644
--- a/src/test/aiml_tests/test_person_aiml.py
+++ b/src/test/aiml_tests/person_tests/test_person_aiml.py
@@ -10,8 +10,8 @@ def __init__(self):
def load_configuration(self, arguments):
super(BasicTestClient, self).load_configuration(arguments)
- self.configuration.brain_configuration._aiml_files = BrainFileConfiguration(os.path.dirname(__file__)+"/../aiml_tests/test_files/person", ".aiml", False)
- self.configuration.brain_configuration._person = os.path.dirname(__file__)+"/../aiml_tests/test_files/person/person.txt"
+ self.configuration.brain_configuration._aiml_files = BrainFileConfiguration(os.path.dirname(__file__), ".aiml", False)
+ self.configuration.brain_configuration._person = os.path.dirname(__file__)+"/person.txt"
class PersonAIMLTests(unittest.TestCase):
diff --git a/src/test/aiml_tests/priority_tests/__init__.py b/src/test/aiml_tests/priority_tests/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/src/test/aiml_tests/test_files/priority/priority.aiml b/src/test/aiml_tests/priority_tests/priority.aiml
similarity index 100%
rename from src/test/aiml_tests/test_files/priority/priority.aiml
rename to src/test/aiml_tests/priority_tests/priority.aiml
diff --git a/src/test/aiml_tests/test_priority_aiml.py b/src/test/aiml_tests/priority_tests/test_priority_aiml.py
similarity index 96%
rename from src/test/aiml_tests/test_priority_aiml.py
rename to src/test/aiml_tests/priority_tests/test_priority_aiml.py
index 40eeaf532..075805b54 100644
--- a/src/test/aiml_tests/test_priority_aiml.py
+++ b/src/test/aiml_tests/priority_tests/test_priority_aiml.py
@@ -10,7 +10,7 @@ def __init__(self):
def load_configuration(self, arguments):
super(BasicTestClient, self).load_configuration(arguments)
- self.configuration.brain_configuration._aiml_files = BrainFileConfiguration(os.path.dirname(__file__)+"/../aiml_tests/test_files/priority", ".aiml", False)
+ self.configuration.brain_configuration._aiml_files = BrainFileConfiguration(os.path.dirname(__file__), ".aiml", False)
class PriorityAIMLTests(unittest.TestCase):
diff --git a/src/test/aiml_tests/random_tests/__init__.py b/src/test/aiml_tests/random_tests/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/src/test/aiml_tests/test_files/random/random.aiml b/src/test/aiml_tests/random_tests/random.aiml
similarity index 100%
rename from src/test/aiml_tests/test_files/random/random.aiml
rename to src/test/aiml_tests/random_tests/random.aiml
diff --git a/src/test/aiml_tests/test_random_aiml.py b/src/test/aiml_tests/random_tests/test_random_aiml.py
similarity index 88%
rename from src/test/aiml_tests/test_random_aiml.py
rename to src/test/aiml_tests/random_tests/test_random_aiml.py
index 1f1e877b2..c1b9ecdbc 100644
--- a/src/test/aiml_tests/test_random_aiml.py
+++ b/src/test/aiml_tests/random_tests/test_random_aiml.py
@@ -10,7 +10,7 @@ def __init__(self):
def load_configuration(self, arguments):
super(BasicTestClient, self).load_configuration(arguments)
- self.configuration.brain_configuration._aiml_files = BrainFileConfiguration(os.path.dirname(__file__)+"/../aiml_tests/test_files/random", ".aiml", False)
+ self.configuration.brain_configuration._aiml_files = BrainFileConfiguration(os.path.dirname(__file__), ".aiml", False)
class RandomAIMLTests(unittest.TestCase):
diff --git a/src/test/aiml_tests/sr_tests/__init__.py b/src/test/aiml_tests/sr_tests/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/src/test/aiml_tests/test_files/sr/sr.aiml b/src/test/aiml_tests/sr_tests/sr.aiml
similarity index 100%
rename from src/test/aiml_tests/test_files/sr/sr.aiml
rename to src/test/aiml_tests/sr_tests/sr.aiml
diff --git a/src/test/aiml_tests/test_sr_aiml.py b/src/test/aiml_tests/sr_tests/test_sr_aiml.py
similarity index 92%
rename from src/test/aiml_tests/test_sr_aiml.py
rename to src/test/aiml_tests/sr_tests/test_sr_aiml.py
index 783ac3e02..080d8feb0 100644
--- a/src/test/aiml_tests/test_sr_aiml.py
+++ b/src/test/aiml_tests/sr_tests/test_sr_aiml.py
@@ -10,7 +10,7 @@ def __init__(self):
def load_configuration(self, arguments):
super(SrTestClient, self).load_configuration(arguments)
- self.configuration.brain_configuration._aiml_files = BrainFileConfiguration(os.path.dirname(__file__)+"/../aiml_tests/test_files/sr", ".aiml", False)
+ self.configuration.brain_configuration._aiml_files = BrainFileConfiguration(os.path.dirname(__file__), ".aiml", False)
class SrAIMLTests(unittest.TestCase):
diff --git a/src/test/aiml_tests/srai_tests/__init__.py b/src/test/aiml_tests/srai_tests/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/src/test/aiml_tests/test_files/srai/length.aiml b/src/test/aiml_tests/srai_tests/length.aiml
similarity index 100%
rename from src/test/aiml_tests/test_files/srai/length.aiml
rename to src/test/aiml_tests/srai_tests/length.aiml
diff --git a/src/test/aiml_tests/test_files/srai/srai.aiml b/src/test/aiml_tests/srai_tests/srai.aiml
similarity index 100%
rename from src/test/aiml_tests/test_files/srai/srai.aiml
rename to src/test/aiml_tests/srai_tests/srai.aiml
diff --git a/src/test/aiml_tests/test_files/srai/srai_star.aiml b/src/test/aiml_tests/srai_tests/srai_star.aiml
similarity index 100%
rename from src/test/aiml_tests/test_files/srai/srai_star.aiml
rename to src/test/aiml_tests/srai_tests/srai_star.aiml
diff --git a/src/test/aiml_tests/test_srai_aiml.py b/src/test/aiml_tests/srai_tests/test_srai_aiml.py
similarity index 96%
rename from src/test/aiml_tests/test_srai_aiml.py
rename to src/test/aiml_tests/srai_tests/test_srai_aiml.py
index 82eeebb8b..bc0b19c3b 100644
--- a/src/test/aiml_tests/test_srai_aiml.py
+++ b/src/test/aiml_tests/srai_tests/test_srai_aiml.py
@@ -11,7 +11,7 @@ def __init__(self):
def load_configuration(self, arguments):
super(SraiTestClient, self).load_configuration(arguments)
- self.configuration.brain_configuration._aiml_files = BrainFileConfiguration(os.path.dirname(__file__)+"/../aiml_tests/test_files/srai", ".aiml", False)
+ self.configuration.brain_configuration._aiml_files = BrainFileConfiguration(os.path.dirname(__file__), ".aiml", False)
class SraiAIMLTests(unittest.TestCase):
@@ -64,9 +64,14 @@ def test_xlength_xadd_1_1(self):
self.assertIsNotNone(response)
self.assertEqual('2', response)
+ def test_length_no_string(self):
+ response = SraiAIMLTests.test_client.bot.ask_question("test", "XLENGTH")
+ self.assertIsNotNone(response)
+ self.assertEqual('0', response)
+
def test_xxlength_1char_string(self):
SraiAIMLTests.test_client.dump_bot_brain_tree()
- response = SraiAIMLTests.test_client.bot.ask_question("test", "XXLENGTH XYZ XS 0")
+ response = SraiAIMLTests.test_client.bot.ask_question("test", "XXLENGTH X XS 0")
self.assertIsNotNone(response)
self.assertEqual('1', response)
@@ -75,7 +80,3 @@ def test_xxlength_3char_string(self):
self.assertIsNotNone(response)
self.assertEqual('3', response)
- def test_length_no_string(self):
- response = SraiAIMLTests.test_client.bot.ask_question("test", "XLENGTH")
- self.assertIsNotNone(response)
- self.assertEqual('0', response)
diff --git a/src/test/aiml_tests/sraix_tests/__init__.py b/src/test/aiml_tests/sraix_tests/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/src/test/aiml_tests/test_files/sraix/sraix.aiml b/src/test/aiml_tests/sraix_tests/sraix.aiml
similarity index 100%
rename from src/test/aiml_tests/test_files/sraix/sraix.aiml
rename to src/test/aiml_tests/sraix_tests/sraix.aiml
diff --git a/src/test/aiml_tests/test_sraix_aiml.py b/src/test/aiml_tests/sraix_tests/test_sraix_aiml.py
similarity index 84%
rename from src/test/aiml_tests/test_sraix_aiml.py
rename to src/test/aiml_tests/sraix_tests/test_sraix_aiml.py
index 488642690..181e04787 100644
--- a/src/test/aiml_tests/test_sraix_aiml.py
+++ b/src/test/aiml_tests/sraix_tests/test_sraix_aiml.py
@@ -10,7 +10,7 @@ def __init__(self):
def load_configuration(self, arguments):
super(SraixTestClient, self).load_configuration(arguments)
- self.configuration.brain_configuration._aiml_files = BrainFileConfiguration(os.path.dirname(__file__)+"/../aiml_tests/test_files/sraix", ".aiml", False)
+ self.configuration.brain_configuration._aiml_files = BrainFileConfiguration(os.path.dirname(__file__), ".aiml", False)
class SraixAIMLTests(unittest.TestCase):
diff --git a/src/test/aiml_tests/star_tests/__init__.py b/src/test/aiml_tests/star_tests/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/src/test/aiml_tests/test_files/star/recursive.aiml b/src/test/aiml_tests/star_tests/recursive.aiml
similarity index 100%
rename from src/test/aiml_tests/test_files/star/recursive.aiml
rename to src/test/aiml_tests/star_tests/recursive.aiml
diff --git a/src/test/aiml_tests/test_files/star/star.aiml b/src/test/aiml_tests/star_tests/star.aiml
similarity index 100%
rename from src/test/aiml_tests/test_files/star/star.aiml
rename to src/test/aiml_tests/star_tests/star.aiml
diff --git a/src/test/aiml_tests/test_star_aiml.py b/src/test/aiml_tests/star_tests/test_star_aiml.py
similarity index 97%
rename from src/test/aiml_tests/test_star_aiml.py
rename to src/test/aiml_tests/star_tests/test_star_aiml.py
index 65caac38d..6cde4f32d 100644
--- a/src/test/aiml_tests/test_star_aiml.py
+++ b/src/test/aiml_tests/star_tests/test_star_aiml.py
@@ -6,11 +6,11 @@
class BasicTestClient(TestClient):
def __init__(self):
- TestClient.__init__(self)
+ TestClient.__init__(self, debug=True)
def load_configuration(self, arguments):
super(BasicTestClient, self).load_configuration(arguments)
- self.configuration.brain_configuration._aiml_files = BrainFileConfiguration(os.path.dirname(__file__)+"/../aiml_tests/test_files/star", ".aiml", False)
+ self.configuration.brain_configuration._aiml_files = BrainFileConfiguration(os.path.dirname(__file__), ".aiml", False)
class StarAIMLTests(unittest.TestCase):
diff --git a/src/test/aiml_tests/template_map_tests/__init__.py b/src/test/aiml_tests/template_map_tests/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/src/test/aiml_tests/test_files/template_map/map.aiml b/src/test/aiml_tests/template_map_tests/map.aiml
similarity index 100%
rename from src/test/aiml_tests/test_files/template_map/map.aiml
rename to src/test/aiml_tests/template_map_tests/map.aiml
diff --git a/src/test/aiml_tests/test_files/template_map/maps/map1.txt b/src/test/aiml_tests/template_map_tests/maps/map1.txt
similarity index 100%
rename from src/test/aiml_tests/test_files/template_map/maps/map1.txt
rename to src/test/aiml_tests/template_map_tests/maps/map1.txt
diff --git a/src/test/aiml_tests/test_template_map_aiml.py b/src/test/aiml_tests/template_map_tests/test_template_map_aiml.py
similarity index 83%
rename from src/test/aiml_tests/test_template_map_aiml.py
rename to src/test/aiml_tests/template_map_tests/test_template_map_aiml.py
index 4e7deee91..dec89518c 100644
--- a/src/test/aiml_tests/test_template_map_aiml.py
+++ b/src/test/aiml_tests/template_map_tests/test_template_map_aiml.py
@@ -10,8 +10,8 @@ def __init__(self):
def load_configuration(self, arguments):
super(BasicTestClient, self).load_configuration(arguments)
- self.configuration.brain_configuration._aiml_files = BrainFileConfiguration(os.path.dirname(__file__)+"/../aiml_tests/test_files/template_map", ".aiml", False)
- self.configuration.brain_configuration._map_files = BrainFileConfiguration(os.path.dirname(__file__)+"/../aiml_tests/test_files/template_map/maps", ".txt", False)
+ self.configuration.brain_configuration._aiml_files = BrainFileConfiguration(os.path.dirname(__file__), ".aiml", False)
+ self.configuration.brain_configuration._map_files = BrainFileConfiguration(os.path.dirname(__file__)+"/maps", ".txt", False)
class TemplateMapAIMLTests(unittest.TestCase):
diff --git a/src/test/aiml_tests/template_set_tests/__init__.py b/src/test/aiml_tests/template_set_tests/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/src/test/aiml_tests/test_files/template_set/set.aiml b/src/test/aiml_tests/template_set_tests/set.aiml
similarity index 100%
rename from src/test/aiml_tests/test_files/template_set/set.aiml
rename to src/test/aiml_tests/template_set_tests/set.aiml
diff --git a/src/test/aiml_tests/test_template_set_aiml.py b/src/test/aiml_tests/template_set_tests/test_template_set_aiml.py
similarity index 96%
rename from src/test/aiml_tests/test_template_set_aiml.py
rename to src/test/aiml_tests/template_set_tests/test_template_set_aiml.py
index 09cf3ec8d..a189ad935 100644
--- a/src/test/aiml_tests/test_template_set_aiml.py
+++ b/src/test/aiml_tests/template_set_tests/test_template_set_aiml.py
@@ -10,7 +10,7 @@ def __init__(self):
def load_configuration(self, arguments):
super(BasicTestClient, self).load_configuration(arguments)
- self.configuration.brain_configuration._aiml_files = BrainFileConfiguration(os.path.dirname(__file__)+"/../aiml_tests/test_files/template_set", ".aiml", False)
+ self.configuration.brain_configuration._aiml_files = BrainFileConfiguration(os.path.dirname(__file__), ".aiml", False)
class TemplateSetAIMLTests(unittest.TestCase):
diff --git a/src/test/aiml_tests/text_tests/__init__.py b/src/test/aiml_tests/text_tests/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/src/test/aiml_tests/test_text_aiml.py b/src/test/aiml_tests/text_tests/test_text_aiml.py
similarity index 93%
rename from src/test/aiml_tests/test_text_aiml.py
rename to src/test/aiml_tests/text_tests/test_text_aiml.py
index f1bbccb09..a4ca861e3 100644
--- a/src/test/aiml_tests/test_text_aiml.py
+++ b/src/test/aiml_tests/text_tests/test_text_aiml.py
@@ -10,7 +10,7 @@ def __init__(self):
def load_configuration(self, arguments):
super(BasicTestClient, self).load_configuration(arguments)
- self.configuration.brain_configuration._aiml_files = BrainFileConfiguration(os.path.dirname(__file__)+"/../aiml_tests/test_files/text", ".aiml", False)
+ self.configuration.brain_configuration._aiml_files = BrainFileConfiguration(os.path.dirname(__file__), ".aiml", False)
class TextAIMLTests(unittest.TestCase):
diff --git a/src/test/aiml_tests/test_files/text/text.aiml b/src/test/aiml_tests/text_tests/text.aiml
similarity index 100%
rename from src/test/aiml_tests/test_files/text/text.aiml
rename to src/test/aiml_tests/text_tests/text.aiml
diff --git a/src/test/aiml_tests/that_tests/__init__.py b/src/test/aiml_tests/that_tests/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/src/test/aiml_tests/test_files/that/coffee.aiml b/src/test/aiml_tests/that_tests/coffee.aiml
similarity index 100%
rename from src/test/aiml_tests/test_files/that/coffee.aiml
rename to src/test/aiml_tests/that_tests/coffee.aiml
diff --git a/src/test/aiml_tests/test_that_aiml.py b/src/test/aiml_tests/that_tests/test_that_aiml.py
similarity index 95%
rename from src/test/aiml_tests/test_that_aiml.py
rename to src/test/aiml_tests/that_tests/test_that_aiml.py
index 051d0f68e..9841fbf9e 100644
--- a/src/test/aiml_tests/test_that_aiml.py
+++ b/src/test/aiml_tests/that_tests/test_that_aiml.py
@@ -12,7 +12,7 @@ def __init__(self):
def load_configuration(self, arguments):
super(ThatTestClient, self).load_configuration(arguments)
- self.configuration.brain_configuration._aiml_files = BrainFileConfiguration(os.path.dirname(__file__)+"/../aiml_tests/test_files/that", ".aiml", False)
+ self.configuration.brain_configuration._aiml_files = BrainFileConfiguration(os.path.dirname(__file__), ".aiml", False)
class ThatAIMLTests(unittest.TestCase):
diff --git a/src/test/aiml_tests/test_files/that/that.aiml b/src/test/aiml_tests/that_tests/that.aiml
similarity index 100%
rename from src/test/aiml_tests/test_files/that/that.aiml
rename to src/test/aiml_tests/that_tests/that.aiml
diff --git a/src/test/aiml_tests/thatstar_tests/__init__.py b/src/test/aiml_tests/thatstar_tests/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/src/test/aiml_tests/test_thatstar_aiml.py b/src/test/aiml_tests/thatstar_tests/test_thatstar_aiml.py
similarity index 76%
rename from src/test/aiml_tests/test_thatstar_aiml.py
rename to src/test/aiml_tests/thatstar_tests/test_thatstar_aiml.py
index 2b17d404b..cd99900e2 100644
--- a/src/test/aiml_tests/test_thatstar_aiml.py
+++ b/src/test/aiml_tests/thatstar_tests/test_thatstar_aiml.py
@@ -9,18 +9,21 @@
class ThatStarTestClient(TestClient):
def __init__(self):
- TestClient.__init__(self)
+ TestClient.__init__(self, debug=True)
def load_configuration(self, arguments):
super(ThatStarTestClient, self).load_configuration(arguments)
- self.configuration.brain_configuration._aiml_files = BrainFileConfiguration(os.path.dirname(__file__)+"/../aiml_tests/test_files/thatstar", ".aiml", False)
+ self.configuration.brain_configuration._aiml_files = BrainFileConfiguration(os.path.dirname(__file__), ".aiml", False)
class ThatStarAIMLTests(unittest.TestCase):
def setUp(self):
ThatStarAIMLTests.test_client = ThatStarTestClient()
- def test_single_thatstar_word(self):
+ def test_single_thatstar_word_default(self):
+ # We need to ask 2 questions, first we get a response which is stored in the clause, we then return it
+ # on the second question
+
response = ThatStarAIMLTests.test_client.bot.ask_question("test", "HELLO THERE")
self.assertIsNotNone(response)
self.assertEqual(response, 'HI THERE')
diff --git a/src/test/aiml_tests/test_files/thatstar/thatstar.aiml b/src/test/aiml_tests/thatstar_tests/thatstar.aiml
similarity index 97%
rename from src/test/aiml_tests/test_files/thatstar/thatstar.aiml
rename to src/test/aiml_tests/thatstar_tests/thatstar.aiml
index 9bec3579e..3120fef89 100644
--- a/src/test/aiml_tests/test_files/thatstar/thatstar.aiml
+++ b/src/test/aiml_tests/thatstar_tests/thatstar.aiml
@@ -28,7 +28,6 @@ For more information see [url]
I SAID HI THERE
- *
HEARD YOU SAY
diff --git a/src/test/aiml_tests/think_tests/__init__.py b/src/test/aiml_tests/think_tests/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/src/test/aiml_tests/test_think_aiml.py b/src/test/aiml_tests/think_tests/test_think_aiml.py
similarity index 91%
rename from src/test/aiml_tests/test_think_aiml.py
rename to src/test/aiml_tests/think_tests/test_think_aiml.py
index f23e35e71..77859fc9f 100644
--- a/src/test/aiml_tests/test_think_aiml.py
+++ b/src/test/aiml_tests/think_tests/test_think_aiml.py
@@ -10,7 +10,7 @@ def __init__(self):
def load_configuration(self, arguments):
super(BasicTestClient, self).load_configuration(arguments)
- self.configuration.brain_configuration._aiml_files = BrainFileConfiguration(os.path.dirname(__file__)+"/../aiml_tests/test_files/think", ".aiml", False)
+ self.configuration.brain_configuration._aiml_files = BrainFileConfiguration(os.path.dirname(__file__), ".aiml", False)
class ThinkAIMLTests(unittest.TestCase):
diff --git a/src/test/aiml_tests/test_files/think/think.aiml b/src/test/aiml_tests/think_tests/think.aiml
similarity index 100%
rename from src/test/aiml_tests/test_files/think/think.aiml
rename to src/test/aiml_tests/think_tests/think.aiml
diff --git a/src/test/aiml_tests/topic_tests/__init__.py b/src/test/aiml_tests/topic_tests/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/src/test/aiml_tests/test_topic_aiml.py b/src/test/aiml_tests/topic_tests/test_topic_aiml.py
similarity index 93%
rename from src/test/aiml_tests/test_topic_aiml.py
rename to src/test/aiml_tests/topic_tests/test_topic_aiml.py
index 01166618e..04356ad62 100644
--- a/src/test/aiml_tests/test_topic_aiml.py
+++ b/src/test/aiml_tests/topic_tests/test_topic_aiml.py
@@ -12,7 +12,7 @@ def __init__(self):
def load_configuration(self, arguments):
super(TopicTestClient, self).load_configuration(arguments)
- self.configuration.brain_configuration._aiml_files = BrainFileConfiguration(os.path.dirname(__file__)+"/../aiml_tests/test_files/topic", ".aiml", False)
+ self.configuration.brain_configuration._aiml_files = BrainFileConfiguration(os.path.dirname(__file__), ".aiml", False)
class TopicAIMLTests(unittest.TestCase):
diff --git a/src/test/aiml_tests/test_files/topic/topic.aiml b/src/test/aiml_tests/topic_tests/topic.aiml
similarity index 100%
rename from src/test/aiml_tests/test_files/topic/topic.aiml
rename to src/test/aiml_tests/topic_tests/topic.aiml
diff --git a/src/test/aiml_tests/topicstar_tests/__init__.py b/src/test/aiml_tests/topicstar_tests/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/src/test/aiml_tests/test_topicstar_aiml.py b/src/test/aiml_tests/topicstar_tests/test_topicstar_aiml.py
similarity index 89%
rename from src/test/aiml_tests/test_topicstar_aiml.py
rename to src/test/aiml_tests/topicstar_tests/test_topicstar_aiml.py
index eba25a9ab..bdb40755b 100644
--- a/src/test/aiml_tests/test_topicstar_aiml.py
+++ b/src/test/aiml_tests/topicstar_tests/test_topicstar_aiml.py
@@ -13,7 +13,7 @@ def __init__(self):
def load_configuration(self, arguments):
super(TopicStarTestClient, self).load_configuration(arguments)
- self.configuration.brain_configuration._aiml_files = BrainFileConfiguration(os.path.dirname(__file__)+"/../aiml_tests/test_files/topicstar", ".aiml", False)
+ self.configuration.brain_configuration._aiml_files = BrainFileConfiguration(os.path.dirname(__file__), ".aiml", False)
class TopicStarAIMLTests(unittest.TestCase):
diff --git a/src/test/aiml_tests/test_files/topicstar/topicstar.aiml b/src/test/aiml_tests/topicstar_tests/topicstar.aiml
similarity index 100%
rename from src/test/aiml_tests/test_files/topicstar/topicstar.aiml
rename to src/test/aiml_tests/topicstar_tests/topicstar.aiml
diff --git a/src/test/aiml_tests/train_tests/__init__.py b/src/test/aiml_tests/train_tests/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/src/test/aiml_tests/test_files/train/likesto.aiml b/src/test/aiml_tests/train_tests/likesto.aiml
similarity index 99%
rename from src/test/aiml_tests/test_files/train/likesto.aiml
rename to src/test/aiml_tests/train_tests/likesto.aiml
index 776c39b70..8f20a2267 100644
--- a/src/test/aiml_tests/test_files/train/likesto.aiml
+++ b/src/test/aiml_tests/train_tests/likesto.aiml
@@ -195,4 +195,4 @@
-
\ No newline at end of file
+
diff --git a/src/test/aiml_tests/train_tests/nowaskme.aiml b/src/test/aiml_tests/train_tests/nowaskme.aiml
new file mode 100644
index 000000000..2bf1eaccd
--- /dev/null
+++ b/src/test/aiml_tests/train_tests/nowaskme.aiml
@@ -0,0 +1,90 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ familiarname
+ is *
+
+
+
+ Who
+
+
+
+
+
+ ?
+ Your
+
+
+ .
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Now you can ask me: ""?
+
+ What does my
+
+
+
+ ?
+
+
+
+
+
+ .
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ and ""?
+
+
+
+
\ No newline at end of file
diff --git a/src/test/aiml_tests/train_tests/test_now_ask_me.py b/src/test/aiml_tests/train_tests/test_now_ask_me.py
new file mode 100644
index 000000000..ceda0e52e
--- /dev/null
+++ b/src/test/aiml_tests/train_tests/test_now_ask_me.py
@@ -0,0 +1,26 @@
+import unittest
+import os
+from test.aiml_tests.client import TestClient
+from programy.config import ConfigurationFactory
+from programy.config import ClientConfiguration
+
+class NowAskMeTrainTestClient(TestClient):
+
+ def __init__(self):
+ TestClient.__init__(self, debug=True)
+
+ def load_configuration(self, arguments):
+ self.configuration = ClientConfiguration()
+ ConfigurationFactory.load_configuration_from_file(self.configuration, os.path.dirname(__file__)+"/testconfig.yaml")
+
+class TrainAIMLTests(unittest.TestCase):
+
+ def setUp(cls):
+ TrainAIMLTests.test_client = NowAskMeTrainTestClient()
+
+ def test_now_ask_me(self):
+ TrainAIMLTests.test_client.bot.brain.dump_tree()
+ response = TrainAIMLTests.test_client.bot.ask_question("test", "daddy is great")
+ self.assertIsNotNone(response)
+ #TODO Sort out space in questions
+ self.assertEqual("Now you can ask me: \" Who IS GREAT \"? and \" What does my DADDY BE \"?", response)
diff --git a/src/test/aiml_tests/test_train_aiml.py b/src/test/aiml_tests/train_tests/test_train_aiml.py
similarity index 78%
rename from src/test/aiml_tests/test_train_aiml.py
rename to src/test/aiml_tests/train_tests/test_train_aiml.py
index fd0cb0a22..2eb741e81 100644
--- a/src/test/aiml_tests/test_train_aiml.py
+++ b/src/test/aiml_tests/train_tests/test_train_aiml.py
@@ -7,11 +7,11 @@
class TrainTestClient(TestClient):
def __init__(self):
- TestClient.__init__(self)
+ TestClient.__init__(self, debug=True)
def load_configuration(self, arguments):
self.configuration = ClientConfiguration()
- ConfigurationFactory.load_configuration_from_file(self.configuration, os.path.dirname(__file__)+"/test_files/train/testconfig.yaml")
+ ConfigurationFactory.load_configuration_from_file(self.configuration, os.path.dirname(__file__)+"/testconfig.yaml")
class TrainAIMLTests(unittest.TestCase):
@@ -19,38 +19,44 @@ def setUp(cls):
TrainAIMLTests.test_client = TrainTestClient()
def test_train_noun(self):
+
TrainAIMLTests.test_client.bot.brain.dump_tree()
+
response = TrainAIMLTests.test_client.bot.ask_question("test", "jessica likes to smoke cigars")
self.assertIsNotNone(response)
self.assertEqual("Do you smoke cigars too?", response)
- TrainAIMLTests.test_client.bot.brain.dump_tree()
response = TrainAIMLTests.test_client.bot.ask_question("test", "who likes to smoke cigars")
self.assertIsNotNone(response)
self.assertEqual("Jessica likes to smoke cigars", response)
- TrainAIMLTests.test_client.bot.brain.dump_tree()
+ response = TrainAIMLTests.test_client.bot.ask_question("test", "who likes to smoke cigars")
+ self.assertIsNotNone(response)
+ self.assertEqual("Jessica likes to smoke cigars", response)
+
response = TrainAIMLTests.test_client.bot.ask_question("test", "what does jessica like")
self.assertIsNotNone(response)
self.assertEqual("Jessica likes to smoke cigars", response)
- TrainAIMLTests.test_client.bot.brain.dump_tree()
response = TrainAIMLTests.test_client.bot.ask_question("test", "what does jessica smoke")
self.assertIsNotNone(response)
self.assertEqual("Jessica likes to smoke cigars", response)
- TrainAIMLTests.test_client.bot.brain.dump_tree()
response = TrainAIMLTests.test_client.bot.ask_question("test", "who smokes")
self.assertIsNotNone(response)
self.assertEqual("Jessica likes to smoke cigars", response)
def test_train_pronoun(self):
+
TrainAIMLTests.test_client.bot.brain.dump_tree()
+
response = TrainAIMLTests.test_client.bot.ask_question("test", "mommy likes to smoke cigars")
self.assertIsNotNone(response)
- self.assertEqual("Do you smoke cigars too?", response)
- TrainAIMLTests.test_client.bot.brain.dump_tree()
+ #TODO Fix the spacing in quotes
+ self.assertEqual("Now you can ask me: \" Who LIKES TO SMOKE CIGARS \"? and \" What does my MOMMY LIKE \"?", response)
+
response = TrainAIMLTests.test_client.bot.ask_question("test", "who likes to smoke cigars")
self.assertIsNotNone(response)
- self.assertEqual("Mommy likes to smoke cigars", response)
\ No newline at end of file
+ self.assertEqual("Your MOMMY", response)
+
diff --git a/src/test/aiml_tests/test_files/train/testconfig.yaml b/src/test/aiml_tests/train_tests/testconfig.yaml
similarity index 97%
rename from src/test/aiml_tests/test_files/train/testconfig.yaml
rename to src/test/aiml_tests/train_tests/testconfig.yaml
index 0a51a84be..a936316a5 100644
--- a/src/test/aiml_tests/test_files/train/testconfig.yaml
+++ b/src/test/aiml_tests/train_tests/testconfig.yaml
@@ -9,7 +9,7 @@ brain:
files:
aiml:
- files: /Users/keithsterling/Documents/Development/Python/Projects/AIML/program-y/src/test/aiml_tests/test_files/train
+ files: /Users/keithsterling/Documents/Development/Python/Projects/AIML/program-y/src/test/aiml_tests/train_tests
extension: .aiml
directories: false
sets:
diff --git a/src/test/aiml_tests/underline_star_tests/__init__.py b/src/test/aiml_tests/underline_star_tests/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/src/test/aiml_tests/test_underline_star_aiml.py b/src/test/aiml_tests/underline_star_tests/test_underline_star_aiml.py
similarity index 89%
rename from src/test/aiml_tests/test_underline_star_aiml.py
rename to src/test/aiml_tests/underline_star_tests/test_underline_star_aiml.py
index e1c21c707..66d5830f2 100644
--- a/src/test/aiml_tests/test_underline_star_aiml.py
+++ b/src/test/aiml_tests/underline_star_tests/test_underline_star_aiml.py
@@ -6,11 +6,11 @@
class BasicTestClient(TestClient):
def __init__(self):
- TestClient.__init__(self)
+ TestClient.__init__(self, debug=True)
def load_configuration(self, arguments):
super(BasicTestClient, self).load_configuration(arguments)
- self.configuration.brain_configuration._aiml_files = BrainFileConfiguration(os.path.dirname(__file__)+"/../aiml_tests/test_files/underline_star", ".aiml", False)
+ self.configuration.brain_configuration._aiml_files = BrainFileConfiguration(os.path.dirname(__file__), ".aiml", False)
class UnderlineStarAIMLTests(unittest.TestCase):
diff --git a/src/test/aiml_tests/test_files/underline_star/underline_star.aiml b/src/test/aiml_tests/underline_star_tests/underline_star.aiml
similarity index 100%
rename from src/test/aiml_tests/test_files/underline_star/underline_star.aiml
rename to src/test/aiml_tests/underline_star_tests/underline_star.aiml
diff --git a/src/test/aiml_tests/underline_tests/__init__.py b/src/test/aiml_tests/underline_tests/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/src/test/aiml_tests/test_underline_aiml.py b/src/test/aiml_tests/underline_tests/test_underline_aiml.py
similarity index 92%
rename from src/test/aiml_tests/test_underline_aiml.py
rename to src/test/aiml_tests/underline_tests/test_underline_aiml.py
index 8f4d383c0..23bbc332d 100644
--- a/src/test/aiml_tests/test_underline_aiml.py
+++ b/src/test/aiml_tests/underline_tests/test_underline_aiml.py
@@ -6,16 +6,15 @@
class BasicTestClient(TestClient):
def __init__(self):
- TestClient.__init__(self)
+ TestClient.__init__(self, debug=True)
def load_configuration(self, arguments):
super(BasicTestClient, self).load_configuration(arguments)
- self.configuration.brain_configuration._aiml_files = BrainFileConfiguration(os.path.dirname(__file__)+"/../aiml_tests/test_files/underline", ".aiml", False)
+ self.configuration.brain_configuration._aiml_files = BrainFileConfiguration(os.path.dirname(__file__), ".aiml", False)
class UnderlineAIMLTests(unittest.TestCase):
- @classmethod
- def setUpClass(cls):
+ def setUp(cls):
UnderlineAIMLTests.test_client = BasicTestClient()
def test_underline_first(self):
diff --git a/src/test/aiml_tests/test_files/underline/star.aiml b/src/test/aiml_tests/underline_tests/underline.aiml
similarity index 100%
rename from src/test/aiml_tests/test_files/underline/star.aiml
rename to src/test/aiml_tests/underline_tests/underline.aiml
diff --git a/src/test/aiml_tests/util_tests/__init__.py b/src/test/aiml_tests/util_tests/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/src/test/aiml_tests/test_util.py b/src/test/aiml_tests/util_tests/test_util.py
similarity index 54%
rename from src/test/aiml_tests/test_util.py
rename to src/test/aiml_tests/util_tests/test_util.py
index ee8f8b0e8..295bff24a 100644
--- a/src/test/aiml_tests/test_util.py
+++ b/src/test/aiml_tests/util_tests/test_util.py
@@ -4,21 +4,21 @@
from test.aiml_tests.client import TestClient
from programy.config import BrainFileConfiguration
-class UtiltiyTestClient(TestClient):
+class UtiltyTestClient(TestClient):
def __init__(self):
TestClient.__init__(self, debug=True)
def load_configuration(self, arguments):
- super(UtiltiyTestClient, self).load_configuration(arguments)
- self.configuration.brain_configuration._aiml_files = BrainFileConfiguration(os.path.dirname(__file__)+"/../aiml_tests/test_files/util", ".aiml", False)
+ super(UtiltyTestClient, self).load_configuration(arguments)
+ self.configuration.brain_configuration._aiml_files = BrainFileConfiguration(os.path.dirname(__file__), ".aiml", False)
-class UtiltiyAIMLTests(unittest.TestCase):
+class UtiltyAIMLTests(unittest.TestCase):
def setUp(self):
- UtiltiyAIMLTests.test_client = UtiltiyTestClient()
+ UtiltyAIMLTests.test_client = UtiltyTestClient()
def test_util_function(self):
- response = UtiltiyAIMLTests.test_client.bot.ask_question("test", "KEITH IS A PROGRAMMER")
+ response = UtiltyAIMLTests.test_client.bot.ask_question("test", "KEITH IS A PROGRAMMER")
self.assertIsNotNone(response)
self.assertEqual(response, 'Ok, I will remember KEITH is a PROGRAMMER .')
diff --git a/src/test/aiml_tests/test_files/util/util.aiml b/src/test/aiml_tests/util_tests/util.aiml
similarity index 91%
rename from src/test/aiml_tests/test_files/util/util.aiml
rename to src/test/aiml_tests/util_tests/util.aiml
index 9516ac31c..e8fd42987 100644
--- a/src/test/aiml_tests/test_files/util/util.aiml
+++ b/src/test/aiml_tests/util_tests/util.aiml
@@ -84,4 +84,16 @@ For more information see [url]
+
+ ISANAME
+ name
+
+ true
+
+
+
+ ISANAME *
+ false
+
+
\ No newline at end of file
diff --git a/src/test/aiml_tests/vocab_tests/__init__.py b/src/test/aiml_tests/vocab_tests/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/src/test/aiml_tests/test_files/vocab/info.aiml b/src/test/aiml_tests/vocab_tests/info.aiml
similarity index 100%
rename from src/test/aiml_tests/test_files/vocab/info.aiml
rename to src/test/aiml_tests/vocab_tests/info.aiml
diff --git a/src/test/aiml_tests/test_vocab_aiml.py b/src/test/aiml_tests/vocab_tests/test_vocab_aiml.py
similarity index 91%
rename from src/test/aiml_tests/test_vocab_aiml.py
rename to src/test/aiml_tests/vocab_tests/test_vocab_aiml.py
index 43cec1148..ee8d27950 100644
--- a/src/test/aiml_tests/test_vocab_aiml.py
+++ b/src/test/aiml_tests/vocab_tests/test_vocab_aiml.py
@@ -10,7 +10,7 @@ def __init__(self):
def load_configuration(self, arguments):
super(BasicTestClient, self).load_configuration(arguments)
- self.configuration.brain_configuration._aiml_files = BrainFileConfiguration(os.path.dirname(__file__)+"/../aiml_tests/test_files/vocab", ".aiml", False)
+ self.configuration.brain_configuration._aiml_files = BrainFileConfiguration(os.path.dirname(__file__), ".aiml", False)
class VocabularyAIMLTests(unittest.TestCase):
diff --git a/src/test/aiml_tests/xplode_tests/__init__.py b/src/test/aiml_tests/xplode_tests/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/src/test/aiml_tests/test_xplode_aiml.py b/src/test/aiml_tests/xplode_tests/test_xplode_aiml.py
similarity index 93%
rename from src/test/aiml_tests/test_xplode_aiml.py
rename to src/test/aiml_tests/xplode_tests/test_xplode_aiml.py
index 9ffeaee84..3b49948d0 100644
--- a/src/test/aiml_tests/test_xplode_aiml.py
+++ b/src/test/aiml_tests/xplode_tests/test_xplode_aiml.py
@@ -10,7 +10,7 @@ def __init__(self):
def load_configuration(self, arguments):
super(BasicTestClient, self).load_configuration(arguments)
- self.configuration.brain_configuration._aiml_files = BrainFileConfiguration(os.path.dirname(__file__)+"/../aiml_tests/test_files/xplode", ".aiml", False)
+ self.configuration.brain_configuration._aiml_files = BrainFileConfiguration(os.path.dirname(__file__), ".aiml", False)
class XPlodeAIMLTests(unittest.TestCase):
diff --git a/src/test/aiml_tests/test_files/xplode/xplode.aiml b/src/test/aiml_tests/xplode_tests/xplode.aiml
similarity index 100%
rename from src/test/aiml_tests/test_files/xplode/xplode.aiml
rename to src/test/aiml_tests/xplode_tests/xplode.aiml
diff --git a/src/test/config_tests/__init__.py b/src/test/config_tests/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/src/test/test_config.py b/src/test/config_tests/test_config_data.py
similarity index 60%
rename from src/test/test_config.py
rename to src/test/config_tests/test_config_data.py
index 3ea14c8d1..8588511f6 100644
--- a/src/test/test_config.py
+++ b/src/test/config_tests/test_config_data.py
@@ -15,315 +15,6 @@
from programy.config import RestClientConfiguration
-class ConfigurationFactoryTests(unittest.TestCase):
-
- def test_guess_format_from_filename(self):
- config_format = ConfigurationFactory.guess_format_from_filename("file.yaml")
- self.assertEqual(config_format, "yaml")
- config_format = ConfigurationFactory.guess_format_from_filename("file.json")
- self.assertEqual(config_format, "json")
- config_format = ConfigurationFactory.guess_format_from_filename("file.xml")
- self.assertEqual(config_format, "xml")
-
- def test_guess_format_no_extension(self):
- with self.assertRaises(Exception):
- ConfigurationFactory.guess_format_from_filename("file_yaml")
-
- def test_get_config_by_name(self):
- client_config = ClientConfiguration()
- config_type = ConfigurationFactory.get_config_by_name(client_config, "yaml")
- self.assertIsNotNone(config_type)
- config_type = ConfigurationFactory.get_config_by_name(client_config, "json")
- self.assertIsNotNone(config_type)
- config_type = ConfigurationFactory.get_config_by_name(client_config, "xml")
- self.assertIsNotNone(config_type)
-
- def test_get_config_by_name_wrong_extension(self):
- with self.assertRaises(Exception):
- ConfigurationFactory.get_config_by_name("other")
- with self.assertRaises(Exception):
- ConfigurationFactory.get_config_by_name("")
- with self.assertRaises(Exception):
- ConfigurationFactory.get_config_by_name(None)
-
-
-class YamlConfigurationFileTests(unittest.TestCase):
-
- def test_load_from_file(self):
- client_config = ClientConfiguration()
- yaml = YamlConfigurationFile(client_config)
- self.assertIsNotNone(yaml)
- yaml.load_from_file(os.path.dirname(__file__)+"/test_yaml.yaml", ",")
- self.assertIsNotNone(yaml.yaml_data)
- brain = yaml.get_section("brain")
- self.assertIsNotNone(brain)
- files = yaml.get_section("files", brain)
- self.assertIsNotNone(files)
- aiml = yaml.get_section("aiml", files)
- self.assertIsNotNone(aiml)
-
- files = yaml.get_section("files", aiml)
- self.assertIsNotNone(files)
- self.assertEqual(files, "/aiml")
- extension = yaml.get_section("extension", aiml)
- self.assertIsNotNone(extension)
- self.assertEqual(extension, ".aiml")
- directories = yaml.get_section("directories", aiml)
- self.assertIsNotNone(directories)
- self.assertEqual(directories, True)
-
- def test_load_from_text(self):
- client_config = ClientConfiguration()
- yaml = YamlConfigurationFile(client_config)
- self.assertIsNotNone(yaml)
- yaml.load_from_text("""
- brain:
- supress_warnings: true
- allow_system_aiml: true
- allow_learn_aiml: true
- allow_learnf_aiml: true
-
- files:
- aiml:
- files: /aiml
- extension: .aiml
- directories: true
- sets:
- files: /sets
- extension: .txt
- directories: false
- maps:
- files: /maps
- extension: .txt
- directories: true
- denormal: denormal.txt
- normal: normal.txt
- gender: gender.txt
- person: person.txt
- person2: person2.txt
- predicates: predicates.txt
- pronouns: pronouns.txt
- properties: properties.txt
- triples: triples.txt
- preprocessors: preprocessors.txt
- postprocessors: postprocessors.txt
-
- services:
- REST:
- path: programy.utils.services.rest.GenericRESTService
- Pannous:
- path: programy.utils.services.pannous.PannousService
- Pandora:
- path: programy.utils.services.pandora.PandoraService
- Wikipedia:
- path: programy.utils.services.wikipedia.WikipediaService
-
- bot:
- prompt: ">>>"
- default_response: Sorry, I don't have an answer for that!
- exit_response: So long, and thanks for the fish!
- initial_question: Hi, how can I help you?
- """, ".")
-
- self.assertIsNotNone(yaml.yaml_data)
- brain = yaml.get_section("brain")
- self.assertIsNotNone(brain)
- files = yaml.get_section("files", brain)
- self.assertIsNotNone(files)
- aiml = yaml.get_section("aiml", files)
- self.assertIsNotNone(aiml)
-
- files = yaml.get_section("files", aiml)
- self.assertIsNotNone(files)
- self.assertEqual(files, "/aiml")
- extension = yaml.get_section("extension", aiml)
- self.assertIsNotNone(extension)
- self.assertEqual(extension, ".aiml")
- directories = yaml.get_section("directories", aiml)
- self.assertIsNotNone(directories)
- self.assertEqual(directories, True)
-
-
-class JsonConfigurationFileTests(unittest.TestCase):
-
- def test_load_from_file(self):
- client_config = ClientConfiguration()
- json = JSONConfigurationFile(client_config)
- self.assertIsNotNone(json)
- json.load_from_file(os.path.dirname(__file__)+"/test_json.json", ",")
- self.assertIsNotNone(json.json_data)
- brain = json.get_section("brain")
- self.assertIsNotNone(brain)
- files = json.get_section("files", brain)
- self.assertIsNotNone(files)
- aiml = json.get_section("aiml", files)
- self.assertIsNotNone(aiml)
-
- files = json.get_section("files", aiml)
- self.assertIsNotNone(files)
- self.assertEqual(files, "/aiml")
- extension = json.get_section("extension", aiml)
- self.assertIsNotNone(extension)
- self.assertEqual(extension, ".aiml")
- directories = json.get_section("directories", aiml)
- self.assertIsNotNone(directories)
- self.assertEqual(directories, True)
-
- def test_load_from_text(self):
- client_config = ClientConfiguration()
- json = JSONConfigurationFile(client_config)
- self.assertIsNotNone(json)
- json.load_from_text("""
-{
- "brain": {
- "supress_warnings": false,
- "allow_system_aiml": true,
- "allow_learn_aiml": true,
- "allow_learnf_aiml": true,
-
- "files": {
- "aiml": {
- "files": "/aiml",
- "extension": ".aiml",
- "directories": true
- },
- "sets": {
- "files": "/sets",
- "extension": ".txt",
- "directories": false
- },
- "maps": {
- "files": "/maps",
- "extension": ".txt",
- "directories": true
- },
- "denormal": "denormal.txt",
- "normal": "normal.txt",
- "gender": "gender.txt",
- "person": "person.txt",
- "person2": "person2.txt",
- "predicates": "predicates.txt",
- "pronouns": "pronouns.txt",
- "properties": "properties.txt",
- "triples": "triples.txt",
- "preprocessors": "preprocessors.txt",
- "postprocessors": "postprocessors.txt"
- },
-
- "services": {
- "REST": {
- "path": "programy.utils.services.rest.GenericRESTService"
- },
- "Pannous": {
- "path": "programy.utils.services.pannous.PannousService"
- },
- "Pandora": {
- "path": "programy.utils.services.pandora.PandoraService"
- },
- "Wikipedia": {
- "path": "programy.utils.services.wikipedia.WikipediaService"
- }
- }
- },
- "bot": {
- "prompt": ">>>",
- "default_response": "Sorry, I don't have an answer for that!",
- "exit_response": "So long, and thanks for the fish!",
- "initial_question": "Hi, how can I help you>"
- }
-}""", ",")
-
-
-class XMLConfigurationFileTests(unittest.TestCase):
-
- def test_load_from_file(self):
- client_config = ClientConfiguration()
- xml = XMLConfigurationFile(client_config)
- self.assertIsNotNone(xml)
- xml.load_from_file(os.path.dirname(__file__)+"/test_xml.xml", ",")
- self.assertIsNotNone(xml.xml_data)
- brain = xml.get_section("brain")
- self.assertIsNotNone(brain)
- files = xml.get_section("files", brain)
- self.assertIsNotNone(files)
- aiml = xml.get_section("aiml", files)
- self.assertIsNotNone(aiml)
-
- files = xml.get_section("files", aiml)
- self.assertIsNotNone(files)
- self.assertEqual(files.text, "/aiml")
- extension = xml.get_section("extension", aiml)
- self.assertIsNotNone(extension)
- self.assertEqual(extension.text, ".aiml")
- directories = xml.get_section("directories", aiml)
- self.assertIsNotNone(directories)
- self.assertEqual(directories.text, "True")
-
- def test_load_from_text(self):
- client_config = ClientConfiguration()
- xml = XMLConfigurationFile(client_config)
- self.assertIsNotNone(xml)
- xml.load_from_text("""
-
-
- True
- True
- True
- True
-
-
-
- /aiml
- .aiml
- True
-
-
- /sets
- .txt
- False
-
-
- /maps
- .txt
- True
-
- denormal.txt
- normal.txt
- gender.txt
- person.txt
- person2.txt
- predicates.txt
- pronouns.txt
- properties.txt
- triples.txt
- preprocessors.txt
- postprocessors.txt
-
-
-
- programy.utils.services.rest.GenericRESTService
-
-
- programy.utils.services.pannous.PannousService
-
-
- programy.utils.services.pandora.PandoraService
-
-
- programy.utils.services.wikipedia.WikipediaService
-
-
-
-
- >>>
- Sorry, I don't have an answer for that!
- So long, and thanks for the fish!
- Hi, how can I help you?
-
-
-""", ",")
-
-
class LoadConfigurationDataTests(unittest.TestCase):
def test_load_config_data_yaml(self):
diff --git a/src/test/config_tests/test_factory.py b/src/test/config_tests/test_factory.py
new file mode 100644
index 000000000..3ec0bd763
--- /dev/null
+++ b/src/test/config_tests/test_factory.py
@@ -0,0 +1,36 @@
+import unittest
+
+from programy.config import ConfigurationFactory
+from programy.config import ClientConfiguration
+
+
+class ConfigurationFactoryTests(unittest.TestCase):
+
+ def test_guess_format_from_filename(self):
+ config_format = ConfigurationFactory.guess_format_from_filename("file.yaml")
+ self.assertEqual(config_format, "yaml")
+ config_format = ConfigurationFactory.guess_format_from_filename("file.json")
+ self.assertEqual(config_format, "json")
+ config_format = ConfigurationFactory.guess_format_from_filename("file.xml")
+ self.assertEqual(config_format, "xml")
+
+ def test_guess_format_no_extension(self):
+ with self.assertRaises(Exception):
+ ConfigurationFactory.guess_format_from_filename("file_yaml")
+
+ def test_get_config_by_name(self):
+ client_config = ClientConfiguration()
+ config_type = ConfigurationFactory.get_config_by_name(client_config, "yaml")
+ self.assertIsNotNone(config_type)
+ config_type = ConfigurationFactory.get_config_by_name(client_config, "json")
+ self.assertIsNotNone(config_type)
+ config_type = ConfigurationFactory.get_config_by_name(client_config, "xml")
+ self.assertIsNotNone(config_type)
+
+ def test_get_config_by_name_wrong_extension(self):
+ with self.assertRaises(Exception):
+ ConfigurationFactory.get_config_by_name("other")
+ with self.assertRaises(Exception):
+ ConfigurationFactory.get_config_by_name("")
+ with self.assertRaises(Exception):
+ ConfigurationFactory.get_config_by_name(None)
diff --git a/src/test/test_json.json b/src/test/config_tests/test_json.json
similarity index 100%
rename from src/test/test_json.json
rename to src/test/config_tests/test_json.json
diff --git a/src/test/config_tests/test_json.py b/src/test/config_tests/test_json.py
new file mode 100644
index 000000000..b756f823f
--- /dev/null
+++ b/src/test/config_tests/test_json.py
@@ -0,0 +1,96 @@
+import unittest
+import os
+
+from programy.config import JSONConfigurationFile
+from programy.config import ClientConfiguration
+
+
+class JsonConfigurationFileTests(unittest.TestCase):
+
+ def test_load_from_file(self):
+ client_config = ClientConfiguration()
+ json = JSONConfigurationFile(client_config)
+ self.assertIsNotNone(json)
+ json.load_from_file(os.path.dirname(__file__)+"/test_json.json", ",")
+ self.assertIsNotNone(json.json_data)
+ brain = json.get_section("brain")
+ self.assertIsNotNone(brain)
+ files = json.get_section("files", brain)
+ self.assertIsNotNone(files)
+ aiml = json.get_section("aiml", files)
+ self.assertIsNotNone(aiml)
+
+ files = json.get_section("files", aiml)
+ self.assertIsNotNone(files)
+ self.assertEqual(files, "/aiml")
+ extension = json.get_section("extension", aiml)
+ self.assertIsNotNone(extension)
+ self.assertEqual(extension, ".aiml")
+ directories = json.get_section("directories", aiml)
+ self.assertIsNotNone(directories)
+ self.assertEqual(directories, True)
+
+ def test_load_from_text(self):
+ client_config = ClientConfiguration()
+ json = JSONConfigurationFile(client_config)
+ self.assertIsNotNone(json)
+ json.load_from_text("""
+{
+ "brain": {
+ "supress_warnings": false,
+ "allow_system_aiml": true,
+ "allow_learn_aiml": true,
+ "allow_learnf_aiml": true,
+
+ "files": {
+ "aiml": {
+ "files": "/aiml",
+ "extension": ".aiml",
+ "directories": true
+ },
+ "sets": {
+ "files": "/sets",
+ "extension": ".txt",
+ "directories": false
+ },
+ "maps": {
+ "files": "/maps",
+ "extension": ".txt",
+ "directories": true
+ },
+ "denormal": "denormal.txt",
+ "normal": "normal.txt",
+ "gender": "gender.txt",
+ "person": "person.txt",
+ "person2": "person2.txt",
+ "predicates": "predicates.txt",
+ "pronouns": "pronouns.txt",
+ "properties": "properties.txt",
+ "triples": "triples.txt",
+ "preprocessors": "preprocessors.txt",
+ "postprocessors": "postprocessors.txt"
+ },
+
+ "services": {
+ "REST": {
+ "path": "programy.utils.services.rest.GenericRESTService"
+ },
+ "Pannous": {
+ "path": "programy.utils.services.pannous.PannousService"
+ },
+ "Pandora": {
+ "path": "programy.utils.services.pandora.PandoraService"
+ },
+ "Wikipedia": {
+ "path": "programy.utils.services.wikipedia.WikipediaService"
+ }
+ }
+ },
+ "bot": {
+ "prompt": ">>>",
+ "default_response": "Sorry, I don't have an answer for that!",
+ "exit_response": "So long, and thanks for the fish!",
+ "initial_question": "Hi, how can I help you>"
+ }
+}""", ",")
+
diff --git a/src/test/config_tests/test_xml.py b/src/test/config_tests/test_xml.py
new file mode 100644
index 000000000..4457c97dc
--- /dev/null
+++ b/src/test/config_tests/test_xml.py
@@ -0,0 +1,96 @@
+import unittest
+import os
+
+from programy.config import XMLConfigurationFile
+from programy.config import ClientConfiguration
+
+
+class XMLConfigurationFileTests(unittest.TestCase):
+
+ def test_load_from_file(self):
+ client_config = ClientConfiguration()
+ xml = XMLConfigurationFile(client_config)
+ self.assertIsNotNone(xml)
+ xml.load_from_file(os.path.dirname(__file__)+"/test_xml.xml", ",")
+ self.assertIsNotNone(xml.xml_data)
+ brain = xml.get_section("brain")
+ self.assertIsNotNone(brain)
+ files = xml.get_section("files", brain)
+ self.assertIsNotNone(files)
+ aiml = xml.get_section("aiml", files)
+ self.assertIsNotNone(aiml)
+
+ files = xml.get_section("files", aiml)
+ self.assertIsNotNone(files)
+ self.assertEqual(files.text, "/aiml")
+ extension = xml.get_section("extension", aiml)
+ self.assertIsNotNone(extension)
+ self.assertEqual(extension.text, ".aiml")
+ directories = xml.get_section("directories", aiml)
+ self.assertIsNotNone(directories)
+ self.assertEqual(directories.text, "True")
+
+ def test_load_from_text(self):
+ client_config = ClientConfiguration()
+ xml = XMLConfigurationFile(client_config)
+ self.assertIsNotNone(xml)
+ xml.load_from_text("""
+
+
+ True
+ True
+ True
+ True
+
+
+
+ /aiml
+ .aiml
+ True
+
+
+ /sets
+ .txt
+ False
+
+
+ /maps
+ .txt
+ True
+
+ denormal.txt
+ normal.txt
+ gender.txt
+ person.txt
+ person2.txt
+ predicates.txt
+ pronouns.txt
+ properties.txt
+ triples.txt
+ preprocessors.txt
+ postprocessors.txt
+
+
+
+ programy.utils.services.rest.GenericRESTService
+
+
+ programy.utils.services.pannous.PannousService
+
+
+ programy.utils.services.pandora.PandoraService
+
+
+ programy.utils.services.wikipedia.WikipediaService
+
+
+
+
+ >>>
+ Sorry, I don't have an answer for that!
+ So long, and thanks for the fish!
+ Hi, how can I help you?
+
+
+""", ",")
+
diff --git a/src/test/test_xml.xml b/src/test/config_tests/test_xml.xml
similarity index 100%
rename from src/test/test_xml.xml
rename to src/test/config_tests/test_xml.xml
diff --git a/src/test/config_tests/test_yaml.py b/src/test/config_tests/test_yaml.py
new file mode 100644
index 000000000..c2e324d32
--- /dev/null
+++ b/src/test/config_tests/test_yaml.py
@@ -0,0 +1,103 @@
+import unittest
+import os
+
+from programy.config import YamlConfigurationFile
+from programy.config import ClientConfiguration
+
+
+class YamlConfigurationFileTests(unittest.TestCase):
+
+ def test_load_from_file(self):
+ client_config = ClientConfiguration()
+ yaml = YamlConfigurationFile(client_config)
+ self.assertIsNotNone(yaml)
+ yaml.load_from_file(os.path.dirname(__file__)+"/test_yaml.yaml", ",")
+ self.assertIsNotNone(yaml.yaml_data)
+ brain = yaml.get_section("brain")
+ self.assertIsNotNone(brain)
+ files = yaml.get_section("files", brain)
+ self.assertIsNotNone(files)
+ aiml = yaml.get_section("aiml", files)
+ self.assertIsNotNone(aiml)
+
+ files = yaml.get_section("files", aiml)
+ self.assertIsNotNone(files)
+ self.assertEqual(files, "/aiml")
+ extension = yaml.get_section("extension", aiml)
+ self.assertIsNotNone(extension)
+ self.assertEqual(extension, ".aiml")
+ directories = yaml.get_section("directories", aiml)
+ self.assertIsNotNone(directories)
+ self.assertEqual(directories, True)
+
+ def test_load_from_text(self):
+ client_config = ClientConfiguration()
+ yaml = YamlConfigurationFile(client_config)
+ self.assertIsNotNone(yaml)
+ yaml.load_from_text("""
+ brain:
+ supress_warnings: true
+ allow_system_aiml: true
+ allow_learn_aiml: true
+ allow_learnf_aiml: true
+
+ files:
+ aiml:
+ files: /aiml
+ extension: .aiml
+ directories: true
+ sets:
+ files: /sets
+ extension: .txt
+ directories: false
+ maps:
+ files: /maps
+ extension: .txt
+ directories: true
+ denormal: denormal.txt
+ normal: normal.txt
+ gender: gender.txt
+ person: person.txt
+ person2: person2.txt
+ predicates: predicates.txt
+ pronouns: pronouns.txt
+ properties: properties.txt
+ triples: triples.txt
+ preprocessors: preprocessors.txt
+ postprocessors: postprocessors.txt
+
+ services:
+ REST:
+ path: programy.utils.services.rest.GenericRESTService
+ Pannous:
+ path: programy.utils.services.pannous.PannousService
+ Pandora:
+ path: programy.utils.services.pandora.PandoraService
+ Wikipedia:
+ path: programy.utils.services.wikipedia.WikipediaService
+
+ bot:
+ prompt: ">>>"
+ default_response: Sorry, I don't have an answer for that!
+ exit_response: So long, and thanks for the fish!
+ initial_question: Hi, how can I help you?
+ """, ".")
+
+ self.assertIsNotNone(yaml.yaml_data)
+ brain = yaml.get_section("brain")
+ self.assertIsNotNone(brain)
+ files = yaml.get_section("files", brain)
+ self.assertIsNotNone(files)
+ aiml = yaml.get_section("aiml", files)
+ self.assertIsNotNone(aiml)
+
+ files = yaml.get_section("files", aiml)
+ self.assertIsNotNone(files)
+ self.assertEqual(files, "/aiml")
+ extension = yaml.get_section("extension", aiml)
+ self.assertIsNotNone(extension)
+ self.assertEqual(extension, ".aiml")
+ directories = yaml.get_section("directories", aiml)
+ self.assertIsNotNone(directories)
+ self.assertEqual(directories, True)
+
diff --git a/src/test/test_yaml.yaml b/src/test/config_tests/test_yaml.yaml
similarity index 100%
rename from src/test/test_yaml.yaml
rename to src/test/config_tests/test_yaml.yaml
diff --git a/src/test/parser/pattern/test_graph.py b/src/test/parser/pattern/test_graph.py
index d00e9c83d..7b8e855be 100644
--- a/src/test/parser/pattern/test_graph.py
+++ b/src/test/parser/pattern/test_graph.py
@@ -1,12 +1,9 @@
-import xml.etree.ElementTree as ET
-
+from test.parser.pattern.test_nodes.base import PatternTestBaseClass
+from programy.dialog import Sentence
from programy.parser.pattern.graph import PatternGraph
-from programy.parser.pattern.matcher import PatternMatcher
from programy.parser.pattern.nodes import *
from programy.parser.template.nodes import *
-from programy.dialog import Sentence
-from test.parser.pattern.base import PatternTestBaseClass
-from programy.parser.aiml_parser import AIMLParser
+
class PatternGraphTests(PatternTestBaseClass):
@@ -15,6 +12,41 @@ def test_init_graph(self):
self.assertIsNotNone(graph)
self.assertIsNotNone(graph.root)
+ def test_add_pattern_with_whitepsace(self):
+ graph = PatternGraph()
+ topic_element = ET.fromstring('*')
+ that_element = ET.fromstring('*')
+ template_graph_root = None
+
+ element = ET.fromstring("\nthis\n that\n the other")
+ graph.add_pattern_to_graph(element, topic_element, that_element, template_graph_root)
+
+ root = graph.root
+ self.assertIsNotNone(root)
+ self.assertIsNotNone(root.children)
+ self.assertEqual(len(root.children), 1)
+ self.assertIsInstance(root.children[0], PatternWordNode)
+
+ this = root.children[0]
+ self.assertIsNotNone(this)
+ self.assertEqual(this.word, "this")
+ self.assertEqual(len(this.children), 1)
+
+ that = this.children[0]
+ self.assertIsNotNone(that)
+ self.assertEqual(that.word, "that")
+ self.assertEqual(len(that.children), 1)
+
+ the = that.children[0]
+ self.assertIsNotNone(the)
+ self.assertEqual(the.word, "the")
+ self.assertEqual(len(the.children), 1)
+
+ other = the.children[0]
+ self.assertIsNotNone(other)
+ self.assertEqual(other.word, "other")
+ self.assertEqual(len(other.children), 0)
+
def test_add_pattern_to_graph_basic(self):
graph = PatternGraph()
topic_element = ET.fromstring('*')
@@ -41,12 +73,6 @@ def test_add_pattern_to_graph_basic(self):
self.assertIsInstance(graph.root.children[0], PatternWordNode)
self.assertEqual(graph.root.children[1].word, "test2")
- matcher = PatternMatcher(graph)
- self.assertIsNotNone(matcher.match(self.bot, self.clientid, Sentence("test1"), [], Sentence("*"), [], Sentence("*"), []))
- self.assertIsNotNone(matcher.match(self.bot, self.clientid, Sentence("test2"), [], Sentence("*"), [], Sentence("*"), []))
- self.assertIsNone(matcher.match(self.bot, self.clientid, Sentence("test1 test2"), [], Sentence("*"), [], Sentence("*"), []))
- self.assertIsNone(matcher.match(self.bot, self.clientid, Sentence("test2 test1"), [], Sentence("*"), [], Sentence("*"), []))
-
def test_add_pattern_to_graph_multi_word(self):
graph = PatternGraph()
topic_element = ET.fromstring('*')
@@ -85,12 +111,6 @@ def test_add_pattern_to_graph_multi_word(self):
self.assertIsInstance(graph.root.children[0].children[1].children[0], PatternWordNode)
self.assertEqual(graph.root.children[0].children[1].children[0].word, "test4")
- matcher = PatternMatcher(graph)
- self.assertIsNone(matcher.match(self.bot, self.clientid, Sentence("test1"), [], Sentence("*"), [], Sentence("*"), []))
- self.assertIsNotNone(matcher.match(self.bot, self.clientid, Sentence("test1 test2"), [], Sentence("*"), [], Sentence("*"), []))
- self.assertIsNone(matcher.match(self.bot, self.clientid, Sentence("test1 test3"), [], Sentence("*"), [], Sentence("*"), []))
- self.assertIsNotNone(matcher.match(self.bot, self.clientid, Sentence("test1 test3 test4"), [], Sentence("*"), [], Sentence("*"), []))
-
def test_add_pattern_to_graph_basic_set_text(self):
graph = PatternGraph()
topic_element = ET.fromstring('*')
@@ -108,12 +128,6 @@ def test_add_pattern_to_graph_basic_set_text(self):
self.assertIsInstance(graph.root.children[0], PatternSetNode)
self.assertEqual(graph.root.children[0].word, "SET1")
- matcher = PatternMatcher(graph)
- self.assertIsNotNone(matcher.match(self.bot, self.clientid, Sentence("VAL1 IS A VALUE"), [], Sentence("*"), [], Sentence("*"), []))
- self.assertIsNotNone(matcher.match(self.bot, self.clientid, Sentence("VAL2 IS A VALUE"), [], Sentence("*"), [], Sentence("*"), []))
- self.assertIsNotNone(matcher.match(self.bot, self.clientid, Sentence("VAL3 IS A VALUE"), [], Sentence("*"), [], Sentence("*"), []))
- self.assertIsNone(matcher.match(self.bot, self.clientid, Sentence("VAL4 IS A VALUE"), [], Sentence("*"), [], Sentence("*"), []))
-
def test_add_pattern_to_graph_basic_set_name_attrib(self):
graph = PatternGraph()
topic_element = ET.fromstring('*')
@@ -131,12 +145,6 @@ def test_add_pattern_to_graph_basic_set_name_attrib(self):
self.assertIsInstance(graph.root.children[0], PatternSetNode)
self.assertEqual(graph.root.children[0].word, "SET1")
- matcher = PatternMatcher(graph)
- self.assertIsNotNone(matcher.match(self.bot, self.clientid, Sentence("val1"), [], Sentence("*"), [], Sentence("*"), []))
- self.assertIsNotNone(matcher.match(self.bot, self.clientid, Sentence("val2"), [], Sentence("*"), [], Sentence("*"), []))
- self.assertIsNotNone(matcher.match(self.bot, self.clientid, Sentence("val3"), [], Sentence("*"), [], Sentence("*"), []))
- self.assertIsNone(matcher.match(self.bot, self.clientid, Sentence("val4"), [], Sentence("*"), [], Sentence("*"), []))
-
def test_add_pattern_to_graph_basic_bot_text(self):
graph = PatternGraph()
topic_element = ET.fromstring('*')
@@ -154,10 +162,6 @@ def test_add_pattern_to_graph_basic_bot_text(self):
self.assertIsInstance(graph.root.children[0], PatternBotNode)
self.assertEqual(graph.root.children[0].word, "bot1")
- matcher = PatternMatcher(graph)
- self.assertIsNotNone(matcher.match(self.bot, self.clientid, Sentence("val1"), [], Sentence("*"), [], Sentence("*"), []))
- self.assertIsNone(matcher.match(self.bot, self.clientid, Sentence("val2"), [], Sentence("*"), [], Sentence("*"), []))
-
def test_add_pattern_to_graph_basic_bot_name_attrib(self):
graph = PatternGraph()
topic_element = ET.fromstring('*')
@@ -175,10 +179,6 @@ def test_add_pattern_to_graph_basic_bot_name_attrib(self):
self.assertIsInstance(graph.root.children[0], PatternBotNode)
self.assertEqual(graph.root.children[0].word, "bot1")
- matcher = PatternMatcher(graph)
- self.assertIsNotNone(matcher.match(self.bot, self.clientid, Sentence("val1"), [], Sentence("*"), [], Sentence("*"), []))
- self.assertIsNone(matcher.match(self.bot, self.clientid, Sentence("val2"), [], Sentence("*"), [], Sentence("*"), []))
-
def test_add_pattern_to_graph_word_set_bot(self):
graph = PatternGraph()
topic_element = ET.fromstring('*')
@@ -225,10 +225,6 @@ def test_add_pattern_to_graph_word_set_bot(self):
self.assertEqual(graph.root.children[0].children[0].children[0].children[0].children[0].children[0].word,
"test6")
- matcher = PatternMatcher(graph)
- self.assertIsNotNone(matcher.match(self.bot, self.clientid, Sentence("test1 test2 val1 test4 val1 test6"), [],
- Sentence("*"), [], Sentence("*"), []))
-
def test_add_pattern_to_graph_basic_zero_or_more(self):
graph = PatternGraph()
topic_element = ET.fromstring('*')
@@ -238,12 +234,6 @@ def test_add_pattern_to_graph_basic_zero_or_more(self):
element = ET.fromstring('#')
graph.add_pattern_to_graph(element, topic_element, that_element, template_graph_root)
- matcher = PatternMatcher(graph)
- self.assertIsNotNone(matcher.match(self.bot, self.clientid, Sentence(""), [], Sentence("*"), [], Sentence("*"), []))
- self.assertIsNotNone(matcher.match(self.bot, self.clientid, Sentence("test1"), [], Sentence("*"), [], Sentence("*"), []))
- self.assertIsNotNone(matcher.match(self.bot, self.clientid, Sentence("test1 test2"), [], Sentence("*"), [], Sentence("*"), []))
- self.assertIsNotNone(matcher.match(self.bot, self.clientid, Sentence("test1 test2 test3"), [], Sentence("*"), [], Sentence("*"), []))
-
def test_add_pattern_to_graph_zero_or_more_front(self):
graph = PatternGraph()
topic_element = ET.fromstring('*')
@@ -253,10 +243,6 @@ def test_add_pattern_to_graph_zero_or_more_front(self):
element = ET.fromstring('# XXX')
graph.add_pattern_to_graph(element, topic_element, that_element, template_graph_root)
- matcher = PatternMatcher(graph)
- self.assertIsNone(matcher.match(self.bot, self.clientid, Sentence(""), [], Sentence("*"), [], Sentence("*"), []))
- self.assertIsNotNone(matcher.match(self.bot, self.clientid, Sentence("Hello XXX"), [], Sentence("*"), [], Sentence("*"), []))
-
def test_add_pattern_to_graph_zero_or_more_middle(self):
graph = PatternGraph()
topic_element = ET.fromstring('*')
@@ -266,10 +252,6 @@ def test_add_pattern_to_graph_zero_or_more_middle(self):
element = ET.fromstring('XXX # YYY')
graph.add_pattern_to_graph(element, topic_element, that_element, template_graph_root)
- matcher = PatternMatcher(graph)
- self.assertIsNone(matcher.match(self.bot, self.clientid, Sentence(""), [], Sentence("*"), [], Sentence("*"), []))
- self.assertIsNotNone(matcher.match(self.bot, self.clientid, Sentence("XXX Hello YYY"), [], Sentence("*"), [], Sentence("*"), []))
-
def test_add_pattern_to_graph_zero_or_more_last(self):
graph = PatternGraph()
topic_element = ET.fromstring('*')
@@ -279,10 +261,6 @@ def test_add_pattern_to_graph_zero_or_more_last(self):
element = ET.fromstring('XXX #')
graph.add_pattern_to_graph(element, topic_element, that_element, template_graph_root)
- matcher = PatternMatcher(graph)
- self.assertIsNone(matcher.match(self.bot, self.clientid, Sentence(""), [], Sentence("*"), [], Sentence("*"), []))
- self.assertIsNotNone(matcher.match(self.bot, self.clientid, Sentence("XXX Hello"), [], Sentence("*"), [], Sentence("*"), []))
-
def test_add_pattern_to_graph_zero_or_more_multiple(self):
graph = PatternGraph()
topic_element = ET.fromstring('*')
@@ -292,10 +270,6 @@ def test_add_pattern_to_graph_zero_or_more_multiple(self):
element = ET.fromstring('XXX # YYY # ZZZ')
graph.add_pattern_to_graph(element, topic_element, that_element, template_graph_root)
- matcher = PatternMatcher(graph)
- self.assertIsNone(matcher.match(self.bot, self.clientid, Sentence(""), [], Sentence("*"), [], Sentence("*"), []))
- self.assertIsNotNone(matcher.match(self.bot, self.clientid, Sentence("XXX Hello YYY There ZZZ"), [], Sentence("*"), [], Sentence("*"), []))
-
def test_add_pattern_to_graph_basic_zero_or_more_with_patterns(self):
graph = PatternGraph()
topic_element = ET.fromstring('*')
@@ -309,20 +283,6 @@ def test_add_pattern_to_graph_basic_zero_or_more_with_patterns(self):
template_graph_root = TemplateWordNode("RESPONSE2")
graph.add_pattern_to_graph(element, topic_element, that_element, template_graph_root)
- matcher = PatternMatcher(graph)
-
- self.assertIsNone(matcher.match(self.bot, self.clientid, Sentence(""), [], Sentence("*"), [], Sentence("*"), []))
-
- template = matcher.match(self.bot, self.clientid, Sentence("HELLO"), [], Sentence("*"), [], Sentence("*"), [])
- self.assertIsNotNone(template)
- self.assertIsInstance(template, PatternTemplateNode)
- self.assertEqual(template.template.resolve(None, None), "RESPONSE1")
-
- template = matcher.match(self.bot, self.clientid, Sentence("WELL HI THERE"), [], Sentence("*"), [], Sentence("*"), [])
- self.assertIsNotNone(template)
- self.assertIsInstance(template, PatternTemplateNode)
- self.assertEqual(template.template.resolve(None, None), "RESPONSE2")
-
def test_add_pattern_to_graph_basic_one_or_more(self):
graph = PatternGraph()
topic_element = ET.fromstring('*')
@@ -342,12 +302,6 @@ def test_add_pattern_to_graph_basic_one_or_more(self):
self.assertIsNone(graph.root._0ormore_hash)
self.assertIsNone(graph.root._1ormore_underline)
- matcher = PatternMatcher(graph)
- self.assertIsNone(matcher.match(self.bot, self.clientid, Sentence(""), [], Sentence("*"), [], Sentence("*"), []))
- self.assertIsNotNone(matcher.match(self.bot, self.clientid, Sentence("test1"), [], Sentence("*"), [], Sentence("*"), []))
- self.assertIsNotNone(matcher.match(self.bot, self.clientid, Sentence("test1 test2"), [], Sentence("*"), [], Sentence("*"), []))
- self.assertIsNotNone(matcher.match(self.bot, self.clientid, Sentence("test1 test2 test3"), [], Sentence("*"), [], Sentence("*"), []))
-
def test_add_pattern_to_graph_one_or_more_front(self):
graph = PatternGraph()
topic_element = ET.fromstring('*')
@@ -357,11 +311,6 @@ def test_add_pattern_to_graph_one_or_more_front(self):
element = ET.fromstring('* XXX')
graph.add_pattern_to_graph(element, topic_element, that_element, template_graph_root)
- matcher = PatternMatcher(graph)
- self.assertIsNone(matcher.match(self.bot, self.clientid, Sentence(""), [], Sentence("*"), [], Sentence("*"), []))
- self.assertIsNotNone(matcher.match(self.bot, self.clientid, Sentence("HELLO XXX"), [], Sentence("*"), [], Sentence("*"), []))
- self.assertIsNotNone(matcher.match(self.bot, self.clientid, Sentence("HELLO THERE XXX"), [], Sentence("*"), [], Sentence("*"), []))
-
def test_add_pattern_to_graph_one_or_more_middle(self):
graph = PatternGraph()
topic_element = ET.fromstring('*')
@@ -371,10 +320,6 @@ def test_add_pattern_to_graph_one_or_more_middle(self):
element = ET.fromstring('XXX * YYY')
graph.add_pattern_to_graph(element, topic_element, that_element, template_graph_root)
- matcher = PatternMatcher(graph)
- self.assertIsNone(matcher.match(self.bot, self.clientid, Sentence(""), [], Sentence("*"), [], Sentence("*"), []))
- self.assertIsNotNone(matcher.match(self.bot, self.clientid, Sentence("XXX HELLO THERE YYY"), [], Sentence("*"), [], Sentence("*"), []))
-
def test_add_pattern_to_graph_one_or_more_last(self):
graph = PatternGraph()
topic_element = ET.fromstring('*')
@@ -384,10 +329,6 @@ def test_add_pattern_to_graph_one_or_more_last(self):
element = ET.fromstring('XXX *')
graph.add_pattern_to_graph(element, topic_element, that_element, template_graph_root)
- matcher = PatternMatcher(graph)
- self.assertIsNone(matcher.match(self.bot, self.clientid, Sentence(""), [], Sentence("*"), [], Sentence("*"), []))
- self.assertIsNotNone(matcher.match(self.bot, self.clientid, Sentence("XXX HELLO THERE YYY"), [], Sentence("*"), [], Sentence("*"), []))
-
##################################################################################################################
#
@@ -405,7 +346,7 @@ def test_add_topic_to_node_star(self):
self.assertIsNotNone(base_node.topic)
self.assertIsInstance(base_node.topic, PatternTopicNode)
- self.assertTrue(base_node.topic.has_children())
+ self.assertFalse(base_node.topic.has_children())
self.assertTrue(base_node.topic.has_wildcard())
self.assertIsNotNone(base_node.topic.star)
self.assertEqual(base_node.topic.star.wildcard, "*")
@@ -475,7 +416,7 @@ def test_add_that_to_node_star(self):
self.assertIsNotNone(base_node.that)
self.assertIsInstance(base_node.that, PatternThatNode)
- self.assertTrue(base_node.that.has_children())
+ self.assertFalse(base_node.that.has_children())
self.assertTrue(base_node.that.has_wildcard())
self.assertIsNotNone(base_node.that.star)
self.assertEqual(base_node.that.star.wildcard, "*")
diff --git a/src/test/parser/pattern/test_matcher.py b/src/test/parser/pattern/test_matcher.py
deleted file mode 100644
index c8e0bc73d..000000000
--- a/src/test/parser/pattern/test_matcher.py
+++ /dev/null
@@ -1,840 +0,0 @@
-import logging
-import xml.etree.ElementTree as ET
-
-from programy.dialog import Sentence
-from programy.parser.pattern.nodes import *
-from programy.parser.pattern.graph import PatternGraph
-from programy.parser.pattern.matcher import PatternMatcher
-from programy.parser.template.nodes import TemplateNode
-
-from test.parser.pattern.base import PatternTestBaseClass
-
-
-class PatternMatcherTests(PatternTestBaseClass):
-
- @classmethod
- def setUpClass(cls):
- PatternMatcherTests.bot = None
- PatternMatcherTests.clientid = "testid"
-
- def test_simple_sequence(self):
-
- graph = PatternGraph()
-
- pattern_element = ET.fromstring("A B C")
- topic_element = ET.fromstring("*")
- that_element = ET.fromstring("*")
- template_node = TemplateNode ()
-
- graph.add_pattern_to_graph(pattern_element, topic_element, that_element, template_node)
-
- matcher = PatternMatcher(graph)
-
- pattern_stars = []
- topic_stars = []
- that_stars = []
- result = matcher.match(PatternMatcherTests.bot, PatternMatcherTests.clientid,
- Sentence("A B"), pattern_stars,
- Sentence("*"), topic_stars,
- Sentence("*"), that_stars)
- self.assertIsNone(result)
- self.assertEqual(len(pattern_stars), 0)
- self.assertEqual(len(topic_stars), 0)
- self.assertEqual(len(that_stars), 0)
-
- pattern_stars = []
- topic_stars = []
- that_stars = []
- result = matcher.match(PatternMatcherTests.bot, PatternMatcherTests.clientid,
- Sentence("A B C D"), pattern_stars,
- Sentence("*"), topic_stars,
- Sentence("*"), that_stars)
- self.assertIsNone(result)
- self.assertEqual(len(pattern_stars), 0)
- self.assertEqual(len(topic_stars), 0)
- self.assertEqual(len(that_stars), 0)
-
- pattern_stars = []
- topic_stars = []
- that_stars = []
- result = matcher.match(PatternMatcherTests.bot, PatternMatcherTests.clientid,
- Sentence("A B C"), pattern_stars,
- Sentence("*"), topic_stars,
- Sentence("*"), that_stars)
- self.assertIsNotNone(result)
- self.assertIsInstance(result, PatternTemplateNode)
- self.assertEqual(len(pattern_stars), 0)
- self.assertEqual(len(topic_stars), 0)
- self.assertEqual(len(that_stars), 0)
-
- pattern_stars = []
- topic_stars = []
- that_stars = []
- result = matcher.match(PatternMatcherTests.bot, PatternMatcherTests.clientid,
- Sentence("A B C"), pattern_stars,
- Sentence("X X"), topic_stars,
- Sentence("*"), that_stars)
- self.assertIsNotNone(result)
- self.assertIsInstance(result, PatternTemplateNode)
- self.assertEqual(len(pattern_stars), 0)
- self.assertEqual(len(topic_stars), 1)
- self.assertEqual(topic_stars[0], "X X")
- self.assertEqual(len(that_stars), 0)
-
- pattern_stars = []
- topic_stars = []
- that_stars = []
- result = matcher.match(PatternMatcherTests.bot, PatternMatcherTests.clientid,
- Sentence("A B C"), pattern_stars,
- Sentence("*"), topic_stars,
- Sentence("Y Y"), that_stars)
- self.assertIsNotNone(result)
- self.assertIsInstance(result, PatternTemplateNode)
- self.assertEqual(len(pattern_stars), 0)
- self.assertEqual(len(topic_stars), 0)
- self.assertEqual(len(that_stars), 1)
- self.assertEqual(that_stars[0], "Y Y")
-
- pattern_stars = []
- topic_stars = []
- that_stars = []
- result = matcher.match(PatternMatcherTests.bot, PatternMatcherTests.clientid,
- Sentence("A B C"), pattern_stars,
- Sentence("X X"), topic_stars,
- Sentence("Y Y"), that_stars)
- self.assertIsNotNone(result)
- self.assertIsInstance(result, PatternTemplateNode)
- self.assertEqual(len(pattern_stars), 0)
- self.assertEqual(len(topic_stars), 1)
- self.assertEqual(topic_stars[0], "X X")
- self.assertEqual(len(that_stars), 1)
- self.assertEqual(that_stars[0], "Y Y")
-
- def test_simple_star(self):
- graph = PatternGraph()
-
- pattern_element = ET.fromstring("A * C")
- topic_element = ET.fromstring("*")
- that_element = ET.fromstring("*")
- template_node = TemplateNode()
-
- graph.add_pattern_to_graph(pattern_element, topic_element, that_element, template_node)
-
- matcher = PatternMatcher(graph)
-
- pattern_stars = []
- topic_stars = []
- that_stars = []
- result = matcher.match(PatternMatcherTests.bot, PatternMatcherTests.clientid,
- Sentence("A B B B C"), pattern_stars,
- Sentence("*"), topic_stars,
- Sentence("*"), that_stars)
- self.assertIsNotNone(result)
- self.assertIsInstance(result, PatternTemplateNode)
- self.assertEqual(len(pattern_stars), 1)
- self.assertEqual(pattern_stars[0], "B B B")
- self.assertEqual(len(topic_stars), 0)
- self.assertEqual(len(that_stars), 0)
-
- pattern_stars = []
- topic_stars = []
- that_stars = []
- result = matcher.match(PatternMatcherTests.bot, PatternMatcherTests.clientid,
- Sentence("A C"), pattern_stars,
- Sentence("*"), topic_stars,
- Sentence("*"), that_stars)
- self.assertIsNone(result)
- self.assertEqual(len(pattern_stars), 0)
- self.assertEqual(len(topic_stars), 0)
- self.assertEqual(len(that_stars), 0)
-
- def test_simple_star_at_front(self):
- graph = PatternGraph()
-
- pattern_element = ET.fromstring("* B C")
- topic_element = ET.fromstring("*")
- that_element = ET.fromstring("*")
- template_node = TemplateNode()
-
- graph.add_pattern_to_graph(pattern_element, topic_element, that_element, template_node)
-
- matcher = PatternMatcher(graph)
-
- pattern_stars = []
- topic_stars = []
- that_stars = []
- result = matcher.match(PatternMatcherTests.bot, PatternMatcherTests.clientid,
- Sentence("A B C"), pattern_stars,
- Sentence("*"), topic_stars,
- Sentence("*"), that_stars)
- self.assertIsNotNone(result)
- self.assertIsInstance(result, PatternTemplateNode)
- self.assertEqual(len(pattern_stars), 1)
- self.assertEqual('A', pattern_stars[0])
- self.assertEqual(len(topic_stars), 0)
- self.assertEqual(len(that_stars), 0)
-
- def test_simple_star_at_end(self):
- graph = PatternGraph()
-
- pattern_element = ET.fromstring("A B *")
- topic_element = ET.fromstring("*")
- that_element = ET.fromstring("*")
- template_node = TemplateNode()
-
- graph.add_pattern_to_graph(pattern_element, topic_element, that_element, template_node)
-
- matcher = PatternMatcher(graph)
-
- pattern_stars = []
- topic_stars = []
- that_stars = []
- result = matcher.match(PatternMatcherTests.bot, PatternMatcherTests.clientid,
- Sentence("A B C"), pattern_stars,
- Sentence("*"), topic_stars,
- Sentence("*"), that_stars)
- self.assertIsNotNone(result)
- self.assertIsInstance(result, PatternTemplateNode)
- self.assertEqual(len(pattern_stars), 1)
- self.assertEqual('C', pattern_stars[0])
- self.assertEqual(len(topic_stars), 0)
- self.assertEqual(len(that_stars), 0)
-
- def test_simple_multiple_stars(self):
- graph = PatternGraph()
-
- pattern_element = ET.fromstring("A * * D")
- topic_element = ET.fromstring("*")
- that_element = ET.fromstring("*")
- template_node = TemplateNode()
-
- graph.add_pattern_to_graph(pattern_element, topic_element, that_element, template_node)
-
- matcher = PatternMatcher(graph)
-
- pattern_stars = []
- topic_stars = []
- that_stars = []
- result = matcher.match(PatternMatcherTests.bot, PatternMatcherTests.clientid,
- Sentence("A B C C2 D"), pattern_stars,
- Sentence("*"), topic_stars,
- Sentence("*"), that_stars)
- self.assertIsNotNone(result)
- self.assertIsInstance(result, PatternTemplateNode)
- self.assertEqual(len(pattern_stars), 2)
- self.assertEqual('B', pattern_stars[0])
- self.assertEqual('C C2', pattern_stars[1])
- self.assertEqual(len(topic_stars), 0)
- self.assertEqual(len(that_stars), 0)
-
- pattern_stars = []
- topic_stars = []
- that_stars = []
- result = matcher.match(PatternMatcherTests.bot, PatternMatcherTests.clientid,
- Sentence("A B D"), pattern_stars,
- Sentence("*"), topic_stars,
- Sentence("*"), that_stars)
- self.assertIsNone(result)
- self.assertEqual(len(pattern_stars), 0)
- self.assertEqual(len(topic_stars), 0)
- self.assertEqual(len(that_stars), 0)
-
- def test_multiple_stars_with_topic_and_that(self):
- graph = PatternGraph()
-
- pattern_element = ET.fromstring("A * * D")
- topic_element = ET.fromstring("THIS")
- that_element = ET.fromstring("OTHER")
- template_node = TemplateNode()
-
- graph.add_pattern_to_graph(pattern_element, topic_element, that_element, template_node)
-
- matcher = PatternMatcher(graph)
-
- pattern_stars = []
- topic_stars = []
- that_stars = []
- result = matcher.match(PatternMatcherTests.bot, PatternMatcherTests.clientid,
- Sentence("A B C C2 D"), pattern_stars,
- Sentence("THIS"), topic_stars,
- Sentence("OTHER"), that_stars)
- self.assertIsNotNone(result)
- self.assertIsInstance(result, PatternTemplateNode)
- self.assertEqual(len(pattern_stars), 2)
- self.assertEqual('B', pattern_stars[0])
- self.assertEqual('C C2', pattern_stars[1])
- self.assertEqual(len(topic_stars), 0)
- self.assertEqual(len(that_stars), 0)
-
- def test_multiple_hashes_with_topic_and_that(self):
- graph = PatternGraph()
-
- pattern_element = ET.fromstring("A # # D")
- topic_element = ET.fromstring("THIS")
- that_element = ET.fromstring("OTHER")
- template_node = TemplateNode()
-
- graph.add_pattern_to_graph(pattern_element, topic_element, that_element, template_node)
-
- matcher = PatternMatcher(graph)
-
- pattern_stars = []
- topic_stars = []
- that_stars = []
- result = matcher.match(PatternMatcherTests.bot, PatternMatcherTests.clientid,
- Sentence("A B C C2 D"), pattern_stars,
- Sentence("THIS"), topic_stars,
- Sentence("OTHER"), that_stars)
- self.assertIsNotNone(result)
- self.assertIsInstance(result, PatternTemplateNode)
- self.assertEqual(len(pattern_stars), 2)
- self.assertEqual('B', pattern_stars[0])
- self.assertEqual('C C2', pattern_stars[1])
- self.assertEqual(len(topic_stars), 0)
- self.assertEqual(len(that_stars), 0)
-
- def test_multiple_hashes_with_topic_and_star(self):
- graph = PatternGraph()
-
- pattern_element = ET.fromstring("A # # D")
- topic_element = ET.fromstring("THIS")
- that_element = ET.fromstring("*")
- template_node = TemplateNode()
-
- graph.add_pattern_to_graph(pattern_element, topic_element, that_element, template_node)
-
- matcher = PatternMatcher(graph)
-
- pattern_stars = []
- topic_stars = []
- that_stars = []
- result = matcher.match(PatternMatcherTests.bot, PatternMatcherTests.clientid,
- Sentence("A B C C2 D"), pattern_stars,
- Sentence("THIS"), topic_stars,
- Sentence("THAT"), that_stars)
- self.assertIsNotNone(result)
- self.assertIsInstance(result, PatternTemplateNode)
- self.assertEqual(len(pattern_stars), 2)
- self.assertEqual('B', pattern_stars[0])
- self.assertEqual('C C2', pattern_stars[1])
- self.assertEqual(len(topic_stars), 0)
- self.assertEqual(len(that_stars), 1)
- self.assertEqual("THAT", that_stars[0])
-
- def test_multiple_hashes_with_star_and_that(self):
- graph = PatternGraph()
-
- pattern_element = ET.fromstring("A # # D")
- topic_element = ET.fromstring("*")
- that_element = ET.fromstring("THAT")
- template_node = TemplateNode()
-
- graph.add_pattern_to_graph(pattern_element, topic_element, that_element, template_node)
-
- matcher = PatternMatcher(graph)
-
- pattern_stars = []
- topic_stars = []
- that_stars = []
- result = matcher.match(PatternMatcherTests.bot, PatternMatcherTests.clientid,
- Sentence("A B C C2 D"), pattern_stars,
- Sentence("THIS"), topic_stars,
- Sentence("THAT"), that_stars)
- self.assertIsNotNone(result)
- self.assertIsInstance(result, PatternTemplateNode)
- self.assertEqual(len(pattern_stars), 2)
- self.assertEqual('B', pattern_stars[0])
- self.assertEqual('C C2', pattern_stars[1])
- self.assertEqual(len(topic_stars), 1)
- self.assertEqual("THIS", topic_stars[0])
- self.assertEqual(len(that_stars), 0)
-
- def test_simple_priorty(self):
- graph = PatternGraph()
-
- pattern_element = ET.fromstring("$A B C")
- topic_element = ET.fromstring("*")
- that_element = ET.fromstring("*")
- template_node = TemplateNode()
-
- graph.add_pattern_to_graph(pattern_element, topic_element, that_element, template_node)
-
- matcher = PatternMatcher(graph)
-
- pattern_stars = []
- topic_stars = []
- that_stars = []
- result = matcher.match(PatternMatcherTests.bot, PatternMatcherTests.clientid,
- Sentence("A B C"), pattern_stars,
- Sentence("*"), topic_stars,
- Sentence("*"), that_stars)
- self.assertIsNotNone(result)
- self.assertIsInstance(result, PatternTemplateNode)
- self.assertEqual(len(pattern_stars), 0)
- self.assertEqual(len(topic_stars), 0)
- self.assertEqual(len(that_stars), 0)
-
- def test_mixed_priorty_and_star(self):
- graph = PatternGraph()
-
- pattern_element1 = ET.fromstring("A $B C")
- pattern_element2 = ET.fromstring("A * C")
- pattern_element3 = ET.fromstring("A D C")
- topic_element = ET.fromstring("*")
- that_element = ET.fromstring("*")
- template_node1 = TemplateNode()
- template_node2 = TemplateNode()
- template_node3 = TemplateNode()
-
- graph.add_pattern_to_graph(pattern_element1, topic_element, that_element, template_node1)
- graph.add_pattern_to_graph(pattern_element2, topic_element, that_element, template_node2)
- graph.add_pattern_to_graph(pattern_element3, topic_element, that_element, template_node3)
-
- matcher = PatternMatcher(graph)
-
- pattern_stars = []
- topic_stars = []
- that_stars = []
- result = matcher.match(PatternMatcherTests.bot, PatternMatcherTests.clientid,
- Sentence("A B C"), pattern_stars,
- Sentence("*"), topic_stars,
- Sentence("*"), that_stars)
- self.assertIsNotNone(result)
- self.assertIsInstance(result, PatternTemplateNode)
- self.assertEqual(result.template, template_node1)
- self.assertEqual(len(pattern_stars), 0)
- self.assertEqual(len(topic_stars), 0)
- self.assertEqual(len(that_stars), 0)
-
- pattern_stars = []
- topic_stars = []
- that_stars = []
- result = matcher.match(PatternMatcherTests.bot, PatternMatcherTests.clientid,
- Sentence("A F C"), pattern_stars,
- Sentence("*"), topic_stars,
- Sentence("*"), that_stars)
- self.assertIsNotNone(result)
- self.assertIsInstance(result, PatternTemplateNode)
- self.assertEqual(result.template, template_node2)
- self.assertEqual(len(pattern_stars), 1)
- self.assertEqual("F", pattern_stars[0])
- self.assertEqual(len(topic_stars), 0)
- self.assertEqual(len(that_stars), 0)
-
- pattern_stars = []
- topic_stars = []
- that_stars = []
- result = matcher.match(PatternMatcherTests.bot, PatternMatcherTests.clientid,
- Sentence("A D C"), pattern_stars,
- Sentence("*"), topic_stars,
- Sentence("*"), that_stars)
- self.assertIsNotNone(result)
- self.assertIsInstance(result, PatternTemplateNode)
- self.assertEqual(result.template, template_node3)
- self.assertEqual(len(pattern_stars), 0)
- self.assertEqual(len(topic_stars), 0)
- self.assertEqual(len(that_stars), 0)
-
- def test_simple_hash(self):
- graph = PatternGraph()
-
- pattern_element = ET.fromstring("A # C")
- topic_element = ET.fromstring("*")
- that_element = ET.fromstring("*")
- template_node = TemplateNode()
-
- graph.add_pattern_to_graph(pattern_element, topic_element, that_element, template_node)
-
- matcher = PatternMatcher(graph)
-
- pattern_stars = []
- topic_stars = []
- that_stars = []
- result = matcher.match(PatternMatcherTests.bot, PatternMatcherTests.clientid,
- Sentence("A B C"), pattern_stars,
- Sentence("*"), topic_stars,
- Sentence("*"), that_stars)
- self.assertIsNotNone(result)
- self.assertIsInstance(result, PatternTemplateNode)
- self.assertEqual(len(pattern_stars), 1)
- self.assertEqual("B", pattern_stars[0])
- self.assertEqual(len(topic_stars), 0)
- self.assertEqual(len(that_stars), 0)
-
- pattern_stars = []
- topic_stars = []
- that_stars = []
- result = matcher.match(PatternMatcherTests.bot, PatternMatcherTests.clientid,
- Sentence("A C"), pattern_stars,
- Sentence("*"), topic_stars,
- Sentence("*"), that_stars)
- self.assertIsNotNone(result)
- self.assertIsInstance(result, PatternTemplateNode)
- self.assertEqual(len(pattern_stars), 0)
- self.assertEqual(len(topic_stars), 0)
- self.assertEqual(len(topic_stars), 0)
-
- def test_simple_hash_at_front(self):
- graph = PatternGraph()
-
- pattern_element = ET.fromstring("# B C")
- topic_element = ET.fromstring("*")
- that_element = ET.fromstring("*")
- template_node = TemplateNode()
-
- graph.add_pattern_to_graph(pattern_element, topic_element, that_element, template_node)
-
- matcher = PatternMatcher(graph)
-
- pattern_stars = []
- topic_stars = []
- that_stars = []
- result = matcher.match(PatternMatcherTests.bot, PatternMatcherTests.clientid,
- Sentence("A B C"), pattern_stars,
- Sentence("*"), topic_stars,
- Sentence("*"), that_stars)
- self.assertIsNotNone(result)
- self.assertIsInstance(result, PatternTemplateNode)
- self.assertEqual(len(pattern_stars), 1)
- self.assertEqual('A', pattern_stars[0])
- self.assertEqual(len(topic_stars), 0)
- self.assertEqual(len(that_stars), 0)
-
- pattern_stars = []
- topic_stars = []
- that_stars = []
- result = matcher.match(PatternMatcherTests.bot, PatternMatcherTests.clientid,
- Sentence("B C"), pattern_stars,
- Sentence("*"), topic_stars,
- Sentence("*"), that_stars)
- self.assertIsNotNone(result)
- self.assertIsInstance(result, PatternTemplateNode)
- self.assertEqual(len(pattern_stars), 0)
- self.assertEqual(len(topic_stars), 0)
- self.assertEqual(len(that_stars), 0)
-
- def test_simple_hash_at_end(self):
- graph = PatternGraph()
-
- pattern_element = ET.fromstring("A B #")
- topic_element = ET.fromstring("*")
- that_element = ET.fromstring("*")
- template_node = TemplateNode()
-
- graph.add_pattern_to_graph(pattern_element, topic_element, that_element, template_node)
-
- matcher = PatternMatcher(graph)
-
- pattern_stars = []
- topic_stars = []
- that_stars = []
- result = matcher.match(PatternMatcherTests.bot, PatternMatcherTests.clientid,
- Sentence("A B C"), pattern_stars,
- Sentence("*"), topic_stars,
- Sentence("*"), that_stars)
- self.assertIsNotNone(result)
- self.assertIsInstance(result, PatternTemplateNode)
- self.assertEqual(len(pattern_stars), 1)
- self.assertEqual('C', pattern_stars[0])
- self.assertEqual(len(topic_stars), 0)
- self.assertEqual(len(that_stars), 0)
-
- pattern_stars = []
- topic_stars = []
- that_stars = []
- result = matcher.match(PatternMatcherTests.bot, PatternMatcherTests.clientid,
- Sentence("A B"), pattern_stars,
- Sentence("*"), topic_stars,
- Sentence("*"), that_stars)
- self.assertIsNotNone(result)
- self.assertIsInstance(result, PatternTemplateNode)
- self.assertEqual(len(pattern_stars), 0)
- self.assertEqual(len(topic_stars), 0)
- self.assertEqual(len(that_stars), 0)
-
- def test_simple_multiple_hashes(self):
- graph = PatternGraph()
-
- pattern_element = ET.fromstring("A # # D")
- topic_element = ET.fromstring("*")
- that_element = ET.fromstring("*")
- template_node = TemplateNode()
-
- graph.add_pattern_to_graph(pattern_element, topic_element, that_element, template_node)
-
- matcher = PatternMatcher(graph)
-
- pattern_stars = []
- topic_stars = []
- that_stars = []
- result = matcher.match(PatternMatcherTests.bot, PatternMatcherTests.clientid,
- Sentence("A B C D"), pattern_stars,
- Sentence("*"), topic_stars,
- Sentence("*"), that_stars)
- self.assertIsNotNone(result)
- self.assertIsInstance(result, PatternTemplateNode)
- self.assertEqual(len(pattern_stars), 2)
- self.assertEqual('B', pattern_stars[0])
- self.assertEqual('C', pattern_stars[1])
- self.assertEqual(len(topic_stars), 0)
- self.assertEqual(len(that_stars), 0)
-
- pattern_stars = []
- topic_stars = []
- that_stars = []
- result = matcher.match(PatternMatcherTests.bot, PatternMatcherTests.clientid,
- Sentence("A B D"), pattern_stars,
- Sentence("*"), topic_stars,
- Sentence("*"), that_stars)
- self.assertIsNotNone(result)
- self.assertIsInstance(result, PatternTemplateNode)
- self.assertEqual(len(pattern_stars), 1)
- self.assertEqual('B', pattern_stars[0])
- self.assertEqual(len(topic_stars), 0)
- self.assertEqual(len(that_stars), 0)
-
- def test_simple_topic_and_that(self):
- graph = PatternGraph()
-
- pattern_element = ET.fromstring("A # D")
- topic_element = ET.fromstring("TOPIC1")
- that_element = ET.fromstring("THAT2")
- template_node = TemplateNode()
-
- graph.add_pattern_to_graph(pattern_element, topic_element, that_element, template_node)
-
- matcher = PatternMatcher(graph)
-
- pattern_stars = []
- topic_stars = []
- that_stars = []
- result = matcher.match(PatternMatcherTests.bot, PatternMatcherTests.clientid,
- Sentence("A B C D"), pattern_stars,
- Sentence("TOPIC1"), topic_stars,
- Sentence("THAT2"), that_stars)
- self.assertIsNotNone(result)
- self.assertIsInstance(result, PatternTemplateNode)
- self.assertEqual(len(pattern_stars), 1)
- self.assertEqual('B C', pattern_stars[0])
- self.assertEqual(len(topic_stars), 0)
- self.assertEqual(len(that_stars), 0)
-
- def test_simple_star_and_that(self):
- graph = PatternGraph()
-
- pattern_element = ET.fromstring("A * D")
- topic_element = ET.fromstring("*")
- that_element = ET.fromstring("THAT1")
- template_node = TemplateNode()
-
- graph.add_pattern_to_graph(pattern_element, topic_element, that_element, template_node)
-
- matcher = PatternMatcher(graph)
-
- pattern_stars = []
- topic_stars = []
- that_stars = []
- result = matcher.match(PatternMatcherTests.bot, PatternMatcherTests.clientid,
- Sentence("A B C D"), pattern_stars,
- Sentence("TOPIC1"), topic_stars,
- Sentence("THAT1"), that_stars)
- self.assertIsNotNone(result)
- self.assertEqual(len(pattern_stars), 1)
- self.assertEqual('B C', pattern_stars[0])
- self.assertEqual(len(topic_stars), 1)
- self.assertEqual('TOPIC1', topic_stars[0])
- self.assertEqual(len(that_stars), 0)
-
- def test_simple_topic_and_star(self):
- graph = PatternGraph()
-
- pattern_element = ET.fromstring("A * D")
- topic_element = ET.fromstring("TOPIC1")
- that_element = ET.fromstring("*")
- template_node = TemplateNode()
-
- graph.add_pattern_to_graph(pattern_element, topic_element, that_element, template_node)
-
- matcher = PatternMatcher(graph)
-
- pattern_stars = []
- topic_stars = []
- that_stars = []
- result = matcher.match(PatternMatcherTests.bot, PatternMatcherTests.clientid,
- Sentence("A B C D"), pattern_stars,
- Sentence("TOPIC1"), topic_stars,
- Sentence("THAT1"), that_stars)
- self.assertIsNotNone(result)
- self.assertEqual(len(pattern_stars), 1)
- self.assertEqual('B C', pattern_stars[0])
- self.assertEqual(len(topic_stars), 0)
- self.assertEqual(len(that_stars), 1)
- self.assertEqual('THAT1', that_stars[0])
-
- def test_simple_multi_branch_star(self):
- graph = PatternGraph()
-
- pattern_element1 = ET.fromstring("A * B C")
- pattern_element2 = ET.fromstring("A * C D")
- topic_element = ET.fromstring("*")
- that_element = ET.fromstring("*")
- template_node = TemplateNode()
-
- pattern_stars = []
- topic_stars = []
- that_stars = []
-
- graph.add_pattern_to_graph(pattern_element1, topic_element, that_element, template_node)
- graph.add_pattern_to_graph(pattern_element2, topic_element, that_element, template_node)
-
- matcher = PatternMatcher(graph)
-
- result = matcher.match(PatternMatcherTests.bot, PatternMatcherTests.clientid,
- Sentence("A X Y B C"), pattern_stars,
- Sentence("*"), topic_stars,
- Sentence("*"), that_stars)
- self.assertIsNotNone(result)
- self.assertIsInstance(result, PatternTemplateNode)
- self.assertEqual(1, len(pattern_stars))
- self.assertEqual('X Y', pattern_stars[0])
- self.assertEqual(len(topic_stars), 0)
- self.assertEqual(len(that_stars), 0)
-
- def test_multi_star_multi_branch_star(self):
- graph = PatternGraph()
-
- pattern_element1 = ET.fromstring("A * B * C")
- pattern_element2 = ET.fromstring("A * C * D")
- topic_element = ET.fromstring("*")
- that_element = ET.fromstring("*")
- template_node = TemplateNode()
-
- graph.add_pattern_to_graph(pattern_element1, topic_element, that_element, template_node)
- graph.add_pattern_to_graph(pattern_element2, topic_element, that_element, template_node)
-
- matcher = PatternMatcher(graph)
-
- pattern_stars = []
- topic_stars = []
- that_stars = []
- result = matcher.match(PatternMatcherTests.bot, PatternMatcherTests.clientid,
- Sentence("A X B Y C"), pattern_stars,
- Sentence("*"), topic_stars,
- Sentence("*"), that_stars)
- self.assertIsNotNone(result)
- self.assertIsInstance(result, PatternTemplateNode)
- self.assertEqual(2, len(pattern_stars))
- self.assertEqual('X', pattern_stars[0])
- self.assertEqual('Y', pattern_stars[1])
- self.assertEqual(len(topic_stars), 0)
- self.assertEqual(len(that_stars), 0)
-
- def test_simple_arrow(self):
- graph = PatternGraph()
-
- pattern_element = ET.fromstring("A ^ C")
- topic_element = ET.fromstring("*")
- that_element = ET.fromstring("*")
- template_node = TemplateNode()
-
- graph.add_pattern_to_graph(pattern_element, topic_element, that_element, template_node)
-
- matcher = PatternMatcher(graph)
-
- pattern_stars = []
- topic_stars = []
- that_stars = []
- result = matcher.match(PatternMatcherTests.bot, PatternMatcherTests.clientid,
- Sentence("A B B B C"), pattern_stars,
- Sentence("*"), topic_stars,
- Sentence("*"), that_stars)
- self.assertIsNotNone(result)
- self.assertIsInstance(result, PatternTemplateNode)
- self.assertEqual(1, len(pattern_stars))
- self.assertEqual('B B B', pattern_stars[0])
- self.assertEqual(len(topic_stars), 0)
- self.assertEqual(len(that_stars), 0)
-
- pattern_stars = []
- topic_stars = []
- that_stars = []
- result = matcher.match(PatternMatcherTests.bot, PatternMatcherTests.clientid,
- Sentence("A C"), pattern_stars,
- Sentence("*"), topic_stars,
- Sentence("*"), that_stars)
- self.assertIsNotNone(result)
- self.assertIsInstance(result, PatternTemplateNode)
- self.assertEqual(len(pattern_stars), 0)
- self.assertEqual(len(topic_stars), 0)
- self.assertEqual(len(that_stars), 0)
-
- def test_simple_arrow_at_end(self):
- graph = PatternGraph()
-
- pattern_element = ET.fromstring("A B ^")
- topic_element = ET.fromstring("*")
- that_element = ET.fromstring("*")
- template_node = TemplateNode()
-
- graph.add_pattern_to_graph(pattern_element, topic_element, that_element, template_node)
-
- matcher = PatternMatcher(graph)
-
- pattern_stars = []
- topic_stars = []
- that_stars = []
- result = matcher.match(PatternMatcherTests.bot, PatternMatcherTests.clientid,
- Sentence("A B C"), pattern_stars,
- Sentence("*"), topic_stars,
- Sentence("*"), that_stars)
- self.assertIsNotNone(result)
- self.assertIsInstance(result, PatternTemplateNode)
- self.assertEqual(1, len(pattern_stars))
- self.assertEqual('C', pattern_stars[0])
- self.assertEqual(len(topic_stars), 0)
- self.assertEqual(len(that_stars), 0)
-
- pattern_stars = []
- topic_stars = []
- that_stars = []
- result = matcher.match(PatternMatcherTests.bot, PatternMatcherTests.clientid,
- Sentence("A B"), pattern_stars,
- Sentence("*"), topic_stars,
- Sentence("*"), that_stars)
- self.assertIsNotNone(result)
- self.assertIsInstance(result, PatternTemplateNode)
- self.assertEqual(len(pattern_stars), 0)
- self.assertEqual(len(topic_stars), 0)
- self.assertEqual(len(that_stars), 0)
-
- def test_simple_arrow_and_hash_at_end(self):
- graph = PatternGraph()
-
- pattern_element1 = ET.fromstring("A ^")
- pattern_element2 = ET.fromstring("A #")
- topic_element = ET.fromstring("*")
- that_element = ET.fromstring("*")
- template_node1 = TemplateNode()
- template_node2 = TemplateNode()
-
- graph.add_pattern_to_graph(pattern_element1, topic_element, that_element, template_node1)
- graph.add_pattern_to_graph(pattern_element2, topic_element, that_element, template_node2)
-
- matcher = PatternMatcher(graph)
-
- pattern_stars = []
- topic_stars = []
- that_stars = []
- result = matcher.match(PatternMatcherTests.bot, PatternMatcherTests.clientid,
- Sentence("A C"), pattern_stars,
- Sentence("*"), topic_stars,
- Sentence("*"), that_stars)
- self.assertIsNotNone(result)
- self.assertIsInstance(result, PatternTemplateNode)
- self.assertEqual(result.template, template_node2)
- self.assertEqual(1, len(pattern_stars))
- self.assertEqual('C', pattern_stars[0])
- self.assertEqual(len(topic_stars), 0)
- self.assertEqual(len(that_stars), 0)
-
-
diff --git a/src/test/parser/pattern/test_matching/__init__.py b/src/test/parser/pattern/test_matching/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/src/test/parser/pattern/test_matching/base.py b/src/test/parser/pattern/test_matching/base.py
new file mode 100644
index 000000000..edc126378
--- /dev/null
+++ b/src/test/parser/pattern/test_matching/base.py
@@ -0,0 +1,42 @@
+import logging
+import xml.etree.ElementTree as ET
+
+from test.parser.pattern.test_nodes.base import PatternTestBaseClass, TestBot
+from programy.dialog import Sentence
+from programy.parser.pattern.graph import PatternGraph
+from programy.parser.template.nodes import TemplateWordNode
+from programy.parser.aiml_parser import AIMLParser
+
+class PatternMatcherBaseClass(PatternTestBaseClass):
+
+ @classmethod
+ def setUpClass(cls):
+ logging.getLogger().setLevel(logging.DEBUG)
+ PatternMatcherBaseClass.bot = TestBot()
+ PatternMatcherBaseClass.clientid = "matcher_test"
+
+ def setUp(self):
+ self._dump_graph = True
+ self.graph = PatternGraph()
+ self.matcher = AIMLParser()
+
+ def dump_graph(self):
+ if self._dump_graph is True:
+ self.graph.dump()
+
+ def add_pattern_to_graph(self, pattern, topic="*", that="*", template="test"):
+
+ pattern_element = ET.fromstring("%s"%(pattern))
+ topic_element = ET.fromstring("%s"%(topic))
+ that_element = ET.fromstring("%s"%(that))
+ template_node = TemplateWordNode(template)
+
+ self.matcher.pattern_parser.add_pattern_to_graph(pattern_element, topic_element, that_element, template_node)
+
+ def match_sentence(self, sentence, topic="*", that="*"):
+
+ return self.matcher.match_sentence( PatternMatcherBaseClass.bot,
+ PatternMatcherBaseClass.clientid,
+ Sentence(sentence),
+ topic,
+ that)
\ No newline at end of file
diff --git a/src/test/parser/pattern/test_matching/test_arrow.py b/src/test/parser/pattern/test_matching/test_arrow.py
new file mode 100644
index 000000000..62224dddf
--- /dev/null
+++ b/src/test/parser/pattern/test_matching/test_arrow.py
@@ -0,0 +1,120 @@
+
+from test.parser.pattern.test_matching.base import PatternMatcherBaseClass
+
+class PatternMatcherTests(PatternMatcherBaseClass):
+
+ def test_arrow_tree_matching_empty(self):
+
+ self.add_pattern_to_graph(pattern="^", topic="X", that="Y", template="1")
+
+ self.dump_graph()
+
+ context = self.match_sentence("A", topic="X", that="Y")
+ self.assertIsNotNone(context)
+ self.assertIsNotNone(context.template_node())
+ self.assertEqual("1", context.template_node().template.word)
+
+ self.assertEqual("A", context.star(1))
+
+ def test_arrow_tree_matching_single(self):
+
+ self.add_pattern_to_graph(pattern="^ A", topic="X", that="Y", template="1")
+
+ self.dump_graph()
+
+ context = self.match_sentence("B A", topic="X", that="Y")
+ self.assertIsNotNone(context)
+ self.assertIsNotNone(context.template_node())
+ self.assertEqual("1", context.template_node().template.word)
+
+ self.assertEqual("B", context.star(1))
+
+ def test_arrow_tree_matching_front(self):
+
+ self.add_pattern_to_graph(pattern="^ C D", topic="X", that="Y", template="1")
+
+ self.dump_graph()
+
+ context = self.match_sentence("A B C D", topic="X", that="Y")
+ self.assertIsNotNone(context)
+ self.assertIsNotNone(context.template_node())
+ self.assertEqual("1", context.template_node().template.word)
+
+ self.assertEqual("A B", context.star(1))
+
+ context = self.match_sentence("C D", topic="X", that="Y")
+ self.assertIsNotNone(context)
+ self.assertIsNotNone(context.template_node())
+ self.assertEqual("1", context.template_node().template.word)
+
+ self.assertEqual("", context.star(1))
+
+ def test_arrow_tree_matching_middle(self):
+
+ self.add_pattern_to_graph(pattern="A ^ D", topic="X", that="Y", template="1")
+
+ self.dump_graph()
+
+ context = self.match_sentence("A B C D", topic="X", that="Y")
+ self.assertIsNotNone(context)
+ self.assertIsNotNone(context.template_node())
+ self.assertEqual("1", context.template_node().template.word)
+
+ self.assertEqual("B C", context.star(1))
+
+ context = self.match_sentence("A D", topic="X", that="Y")
+ self.assertIsNotNone(context)
+ self.assertIsNotNone(context.template_node())
+ self.assertEqual("1", context.template_node().template.word)
+
+ self.assertEqual("", context.star(1))
+
+ def test_arrow_tree_matching_end(self):
+
+ self.add_pattern_to_graph(pattern="A B ^", topic="X", that="Y", template="1")
+
+ self.dump_graph()
+
+ context = self.match_sentence("A B C D", topic="X", that="Y")
+ self.assertIsNotNone(context)
+ self.assertIsNotNone(context.template_node())
+ self.assertEqual("1", context.template_node().template.word)
+
+ self.assertEqual("C D", context.star(1))
+
+ context = self.match_sentence("A B", topic="X", that="Y")
+ self.assertIsNotNone(context)
+ self.assertIsNotNone(context.template_node())
+ self.assertEqual("1", context.template_node().template.word)
+
+ self.assertEqual("", context.star(1))
+
+ def test_arrow_front_and_back(self):
+
+ self.add_pattern_to_graph(pattern="^ F G", topic="*", that="*", template="2")
+ self.add_pattern_to_graph(pattern="^ A B ^", topic="*", that="*", template="1")
+
+ self.dump_graph()
+
+ context = self.match_sentence("F A B G", topic="X", that="Y")
+ self.assertIsNotNone(context)
+ self.assertIsNotNone(context.template_node())
+ self.assertEqual("1", context.template_node().template.word)
+
+ self.assertEqual("F", context.star(1))
+ self.assertEqual("G", context.star(2))
+
+ def test_arrow_deep_tree_matching(self):
+
+ self.add_pattern_to_graph(pattern="A ^ B ^ C", topic="X", that="Z", template="1")
+ self.add_pattern_to_graph(pattern="A ^ B ^ C", topic="X", that="Y", template="1")
+
+ self.dump_graph()
+
+ context = self.match_sentence("A X1 X2 X3 X4 B Y1 Y2 Y3 Y4 C", topic="X", that="Y")
+ self.assertIsNotNone(context)
+ self.assertIsNotNone(context.template_node())
+ self.assertEqual("1", context.template_node().template.word)
+
+ self.assertEqual("X1 X2 X3 X4", context.star(1))
+ self.assertEqual("Y1 Y2 Y3 Y4", context.star(2))
\ No newline at end of file
diff --git a/src/test/parser/pattern/test_matching/test_basic_branches.py b/src/test/parser/pattern/test_matching/test_basic_branches.py
new file mode 100644
index 000000000..27bac2e2d
--- /dev/null
+++ b/src/test/parser/pattern/test_matching/test_basic_branches.py
@@ -0,0 +1,37 @@
+
+from test.parser.pattern.test_matching.base import PatternMatcherBaseClass
+
+class PatternMatcherTests(PatternMatcherBaseClass):
+
+ def test_basic_tree_matching_no_wildcards(self):
+
+ self.add_pattern_to_graph(pattern="A B D E F", topic="X", that="Y", template="1")
+ self.add_pattern_to_graph(pattern="A B D E F", topic="X", that="Z", template="2")
+ self.add_pattern_to_graph(pattern="A B D G", topic="X", that="Z", template="3")
+
+ self.dump_graph()
+
+ context = self.match_sentence("A B D E F", topic="X", that="Z")
+ self.assertIsNotNone(context)
+ self.assertIsNotNone(context.template_node())
+ self.assertEqual("2", context.template_node().template.word)
+
+ def test_basic_multi_tree_matching_no_wildcards(self):
+
+ self.add_pattern_to_graph(pattern="A B D", topic="X", that="Y", template="1")
+ self.add_pattern_to_graph(pattern="A B D", topic="X", that="Z", template="2")
+ self.add_pattern_to_graph(pattern="A B D", topic="X", that="X", template="3")
+
+ self.dump_graph()
+
+ context = self.match_sentence("A B D", topic="X", that="Y")
+ self.assertIsNotNone(context)
+ self.assertIsNotNone(context.template_node())
+ self.assertEqual("1", context.template_node().template.word)
+
+ context = self.match_sentence("A B D", topic="X", that="Z")
+ self.assertIsNotNone(context)
+ self.assertIsNotNone(context.template_node())
+ self.assertEqual("2", context.template_node().template.word)
+
+
diff --git a/src/test/parser/pattern/test_matching/test_basics.py b/src/test/parser/pattern/test_matching/test_basics.py
new file mode 100644
index 000000000..e9f8bfb23
--- /dev/null
+++ b/src/test/parser/pattern/test_matching/test_basics.py
@@ -0,0 +1,30 @@
+import logging
+from test.parser.pattern.test_matching.base import PatternMatcherBaseClass
+
+class PatternMatcherBasicTests(PatternMatcherBaseClass):
+
+ def test_single_word_match(self):
+ self.add_pattern_to_graph(pattern="A", topic="X", that="Y", template="1")
+
+ self.dump_graph()
+
+ context = self.match_sentence("A", topic="X", that="Y")
+ self.assertIsNotNone(context)
+ self.assertIsNotNone(context.template_node())
+ self.assertEqual("1", context.template_node().template.word)
+
+ def test_single_word_no_match(self):
+ self.add_pattern_to_graph(pattern="A", topic="X", that="Y", template="1")
+
+ self.dump_graph()
+
+ context = self.match_sentence("B", topic="X", that="Y")
+ self.assertIsNone(context)
+
+
+
+
+
+
+
+
diff --git a/src/test/parser/pattern/test_matching/test_bot.py b/src/test/parser/pattern/test_matching/test_bot.py
new file mode 100644
index 000000000..780758bdd
--- /dev/null
+++ b/src/test/parser/pattern/test_matching/test_bot.py
@@ -0,0 +1,19 @@
+
+from test.parser.pattern.test_matching.base import PatternMatcherBaseClass
+
+class PatternMatcherBotTests(PatternMatcherBaseClass):
+
+ def test_basic_bot_match(self):
+
+ PatternMatcherBaseClass.bot.brain.properties._properties['firstname'] = 'testbot'
+
+ self.add_pattern_to_graph(pattern="firstname", topic="X", that="Y", template="1")
+
+ self.dump_graph()
+
+ context = self.match_sentence("testbot", topic="X", that="Y")
+ self.assertIsNotNone(context)
+ self.assertIsNotNone(context.template_node())
+ self.assertEqual("1", context.template_node().template.word)
+
+ self.assertEqual("testbot", context.star(1))
diff --git a/src/test/parser/pattern/test_matching/test_hash.py b/src/test/parser/pattern/test_matching/test_hash.py
new file mode 100644
index 000000000..9bcc6bac1
--- /dev/null
+++ b/src/test/parser/pattern/test_matching/test_hash.py
@@ -0,0 +1,128 @@
+
+from test.parser.pattern.test_matching.base import PatternMatcherBaseClass
+
+class PatternMatcherTests(PatternMatcherBaseClass):
+
+ def test_hash_tree_matching_empty(self):
+
+ self.add_pattern_to_graph(pattern="#", topic="X", that="Y", template="1")
+
+ self.dump_graph()
+
+ context = self.match_sentence("A", topic="X", that="Y")
+ self.assertIsNotNone(context)
+ self.assertIsNotNone(context.template_node())
+ self.assertEqual("1", context.template_node().template.word)
+
+ self.assertEqual("A", context.star(1))
+
+ def test_hash_tree_matching_single(self):
+
+ self.add_pattern_to_graph(pattern="# A", topic="X", that="Y", template="1")
+
+ self.dump_graph()
+
+ context = self.match_sentence("B A", topic="X", that="Y")
+ self.assertIsNotNone(context)
+ self.assertIsNotNone(context.template_node())
+ self.assertEqual("1", context.template_node().template.word)
+
+ self.assertEqual("B", context.star(1))
+
+ context = self.match_sentence("A", topic="X", that="Y")
+ self.assertIsNotNone(context)
+ self.assertIsNotNone(context.template_node())
+ self.assertEqual("1", context.template_node().template.word)
+
+ self.assertEqual("", context.star(1))
+
+ def test_hash_tree_matching_front(self):
+
+ self.add_pattern_to_graph(pattern="# C D", topic="X", that="Y", template="1")
+
+ self.dump_graph()
+
+ context = self.match_sentence("A B C D", topic="X", that="Y")
+ self.assertIsNotNone(context)
+ self.assertIsNotNone(context.template_node())
+ self.assertEqual("1", context.template_node().template.word)
+
+ self.assertEqual("A B", context.star(1))
+
+ context = self.match_sentence("C D", topic="X", that="Y")
+ self.assertIsNotNone(context)
+ self.assertIsNotNone(context.template_node())
+ self.assertEqual("1", context.template_node().template.word)
+
+ self.assertEqual("", context.star(1))
+
+ def test_hash_tree_matching_middle(self):
+
+ self.add_pattern_to_graph(pattern="A # D", topic="X", that="Y", template="1")
+
+ self.dump_graph()
+
+ context = self.match_sentence("A B C D", topic="X", that="Y")
+ self.assertIsNotNone(context)
+ self.assertIsNotNone(context.template_node())
+ self.assertEqual("1", context.template_node().template.word)
+
+ self.assertEqual("B C", context.star(1))
+
+ context = self.match_sentence("A D", topic="X", that="Y")
+ self.assertIsNotNone(context)
+ self.assertIsNotNone(context.template_node())
+ self.assertEqual("1", context.template_node().template.word)
+
+ self.assertEqual("", context.star(1))
+
+ def test_hash_tree_matching_end(self):
+
+ self.add_pattern_to_graph(pattern="A B #", topic="X", that="Y", template="1")
+
+ self.dump_graph()
+
+ context = self.match_sentence("A B C D", topic="X", that="Y")
+ self.assertIsNotNone(context)
+ self.assertIsNotNone(context.template_node())
+ self.assertEqual("1", context.template_node().template.word)
+
+ self.assertEqual("C D", context.star(1))
+
+ context = self.match_sentence("A B", topic="X", that="Y")
+ self.assertIsNotNone(context)
+ self.assertIsNotNone(context.template_node())
+ self.assertEqual("1", context.template_node().template.word)
+
+ self.assertEqual("", context.star(1))
+
+ def test_hash_front_and_back(self):
+
+ self.add_pattern_to_graph(pattern="# F G", topic="*", that="*", template="2")
+ self.add_pattern_to_graph(pattern="# A B #", topic="*", that="*", template="1")
+
+ self.dump_graph()
+
+ context = self.match_sentence("F A B G", topic="X", that="Y")
+ self.assertIsNotNone(context)
+ self.assertIsNotNone(context.template_node())
+
+ self.assertEqual("1", context.template_node().template.word)
+ self.assertEqual("F", context.star(1))
+ self.assertEqual("G", context.star(2))
+
+ def test_arrow_deep_tree_matching(self):
+
+ self.add_pattern_to_graph(pattern="A # B # C", topic="X", that="Z", template="1")
+ self.add_pattern_to_graph(pattern="A # B # C", topic="X", that="Y", template="1")
+
+ self.dump_graph()
+
+ context = self.match_sentence("A X1 X2 X3 X4 B Y1 Y2 Y3 Y4 C", topic="X", that="Y")
+
+ self.assertIsNotNone(context)
+ self.assertIsNotNone(context.template_node())
+ self.assertEqual("1", context.template_node().template.word)
+
+ self.assertEqual("X1 X2 X3 X4", context.star(1))
+ self.assertEqual("Y1 Y2 Y3 Y4", context.star(2))
\ No newline at end of file
diff --git a/src/test/parser/pattern/test_matching/test_priority.py b/src/test/parser/pattern/test_matching/test_priority.py
new file mode 100644
index 000000000..03ca2ec0f
--- /dev/null
+++ b/src/test/parser/pattern/test_matching/test_priority.py
@@ -0,0 +1,18 @@
+
+from test.parser.pattern.test_matching.base import PatternMatcherBaseClass
+
+class PatternMatcherTests(PatternMatcherBaseClass):
+
+ def test_priority_tree_matching_no_wildcards(self):
+
+ self.add_pattern_to_graph(pattern="$A B D", topic="X", that="Y", template="1")
+ self.add_pattern_to_graph(pattern="A B D", topic="X", that="Y", template="2")
+
+ self.dump_graph()
+
+ context = self.match_sentence("A B D", topic="X", that="Y")
+ self.assertIsNotNone(context)
+ self.assertIsNotNone(context.template_node())
+ self.assertEqual("1", context.template_node().template.word)
+
+
diff --git a/src/test/parser/pattern/test_matching/test_set.py b/src/test/parser/pattern/test_matching/test_set.py
new file mode 100644
index 000000000..017126619
--- /dev/null
+++ b/src/test/parser/pattern/test_matching/test_set.py
@@ -0,0 +1,17 @@
+
+from test.parser.pattern.test_matching.base import PatternMatcherBaseClass
+
+class PatternMatcherSetTests(PatternMatcherBaseClass):
+
+ def test_basic_set_match(self):
+
+ self.add_pattern_to_graph(pattern="I AM number YEARS OLD", topic="X", that="Y", template="1")
+
+ self.dump_graph()
+
+ context = self.match_sentence("I AM 49 YEARS OLD", topic="X", that="Y")
+ self.assertIsNotNone(context)
+ self.assertIsNotNone(context.template_node())
+ self.assertEqual("1", context.template_node().template.word)
+
+ self.assertEqual("49", context.star(1))
diff --git a/src/test/parser/pattern/test_matching/test_star.py b/src/test/parser/pattern/test_matching/test_star.py
new file mode 100644
index 000000000..02f0b4fb7
--- /dev/null
+++ b/src/test/parser/pattern/test_matching/test_star.py
@@ -0,0 +1,135 @@
+
+from test.parser.pattern.test_matching.base import PatternMatcherBaseClass
+
+class PatternMatcherTests(PatternMatcherBaseClass):
+
+ def test_star_tree_matching_single(self):
+
+ self.add_pattern_to_graph(pattern="*", topic="X", that="Y", template="1")
+
+ self.dump_graph()
+
+ context = self.match_sentence("A B D", topic="X", that="Y")
+ self.assertIsNotNone(context)
+ self.assertIsNotNone(context.template_node())
+ self.assertEqual("1", context.template_node().template.word)
+
+ self.assertEqual("A B D", context.star(1))
+
+ def test_star_tree_matching_front(self):
+
+ self.add_pattern_to_graph(pattern="* C D", topic="X", that="Y", template="1")
+
+ self.dump_graph()
+
+ context = self.match_sentence("A B C D", topic="X", that="Y")
+ self.assertIsNotNone(context)
+ self.assertIsNotNone(context.template_node())
+ self.assertEqual("1", context.template_node().template.word)
+
+ self.assertEqual("A B", context.star(1))
+
+ def test_star_tree_matching_middle(self):
+
+ self.add_pattern_to_graph(pattern="A * D", topic="X", that="Y", template="1")
+
+ self.dump_graph()
+
+ context = self.match_sentence("A B C D", topic="X", that="Y")
+ self.assertIsNotNone(context)
+ self.assertIsNotNone(context.template_node())
+ self.assertEqual("1", context.template_node().template.word)
+
+ self.assertEqual("B C", context.star(1))
+
+ def test_star_tree_matching_end(self):
+
+ self.add_pattern_to_graph(pattern="A B *", topic="X", that="Y", template="1")
+
+ self.dump_graph()
+
+ context = self.match_sentence("A B C D", topic="X", that="Y")
+ self.assertIsNotNone(context)
+ self.assertIsNotNone(context.template_node())
+ self.assertEqual("1", context.template_node().template.word)
+
+ self.assertEqual("C D", context.star(1))
+
+ def test_star_tree_matching_multiple(self):
+
+ self.add_pattern_to_graph(pattern="A * * D", topic="X", that="Y", template="1")
+
+ self.dump_graph()
+
+ context = self.match_sentence("A B C D", topic="X", that="Y")
+ self.assertIsNotNone(context)
+ self.assertIsNotNone(context.template_node())
+ self.assertEqual("1", context.template_node().template.word)
+
+ self.assertEqual("B", context.star(1))
+ self.assertEqual("C", context.star(2))
+
+ def test_star_tree_matching_all(self):
+
+ self.add_pattern_to_graph(pattern="A * D", topic="*", that="*", template="1")
+
+ self.dump_graph()
+
+ context = self.match_sentence("A B C D", topic="X Y", that="Z1 Z2")
+ self.assertIsNotNone(context)
+ self.assertIsNotNone(context.template_node())
+ self.assertEqual("1", context.template_node().template.word)
+
+ self.assertEqual("B C", context.star(1))
+ self.assertEqual("X Y", context.topicstar(1))
+ self.assertEqual("Z1 Z2", context.thatstar(1))
+
+ def test_stars_front_and_back(self):
+
+ self.add_pattern_to_graph(pattern="* F G", topic="*", that="*", template="2")
+ self.add_pattern_to_graph(pattern="* A B *", topic="*", that="*", template="1")
+
+ self.dump_graph()
+
+ context = self.match_sentence("F A B G", topic="X", that="Y")
+ self.assertIsNotNone(context)
+ self.assertIsNotNone(context.template_node())
+ self.assertEqual("1", context.template_node().template.word)
+
+ self.assertEqual("F", context.star(1))
+ self.assertEqual("G", context.star(2))
+ self.assertEqual("X", context.topicstar(1))
+ self.assertEqual("Y", context.thatstar(1))
+
+ def test_star_deep_tree_matching(self):
+
+ self.add_pattern_to_graph(pattern="A * B * C", topic="X", that="Z", template="1")
+ self.add_pattern_to_graph(pattern="A * B * C", topic="X", that="Y", template="1")
+
+ self.dump_graph()
+
+ context = self.match_sentence("A X1 X2 X3 X4 B Y1 Y2 Y3 Y4 C", topic="X", that="Y")
+ self.assertIsNotNone(context)
+ self.assertIsNotNone(context.template_node())
+ self.assertEqual("1", context.template_node().template.word)
+
+ self.assertEqual("X1 X2 X3 X4", context.star(1))
+ self.assertEqual("Y1 Y2 Y3 Y4", context.star(2))
+
+ def test_star_with_set_matching(self):
+
+ self.add_pattern_to_graph(pattern="XXLENGTH * XS number", topic="*", that="*", template="1")
+ self.add_pattern_to_graph(pattern="XXLENGTH * * XS number", topic="*", that="*", template="2")
+
+ self.dump_graph()
+
+ context = self.match_sentence("XXLENGTH X Y XS 1", topic="*", that="*")
+ self.assertIsNotNone(context)
+ self.assertIsNotNone(context.template_node())
+ self.assertEqual("2", context.template_node().template.word)
+
+ context = self.match_sentence("XXLENGTH X XS 1", topic="*", that="XXLENGTH X Y XS 2")
+ self.assertIsNotNone(context)
+ self.assertIsNotNone(context.template_node())
+ self.assertEqual("1", context.template_node().template.word)
+
diff --git a/src/test/parser/pattern/test_matching/test_underline.py b/src/test/parser/pattern/test_matching/test_underline.py
new file mode 100644
index 000000000..16db91fe9
--- /dev/null
+++ b/src/test/parser/pattern/test_matching/test_underline.py
@@ -0,0 +1,97 @@
+
+from test.parser.pattern.test_matching.base import PatternMatcherBaseClass
+
+class PatternMatcherTests(PatternMatcherBaseClass):
+
+ def test_underline_tree_matching_single(self):
+
+ self.add_pattern_to_graph(pattern="_", topic="X", that="Y", template="1")
+
+ self.dump_graph()
+
+ context = self.match_sentence("A B D", topic="X", that="Y")
+ self.assertIsNotNone(context)
+ self.assertIsNotNone(context.template_node())
+ self.assertEqual("1", context.template_node().template.word)
+
+ def test_underline_tree_matching_front(self):
+
+ self.add_pattern_to_graph(pattern="_ C D", topic="X", that="Y", template="1")
+
+ self.dump_graph()
+
+ context = self.match_sentence("A B C D", topic="X", that="Y")
+ self.assertIsNotNone(context)
+ self.assertIsNotNone(context.template_node())
+ self.assertEqual("1", context.template_node().template.word)
+
+ def test_underline_tree_matching_middle(self):
+
+ self.add_pattern_to_graph(pattern="A _ D", topic="X", that="Y", template="1")
+
+ self.dump_graph()
+
+ context = self.match_sentence("A B C D", topic="X", that="Y")
+ self.assertIsNotNone(context)
+ self.assertIsNotNone(context.template_node())
+ self.assertEqual("1", context.template_node().template.word)
+
+ def test_underline_tree_matching_end(self):
+
+ self.add_pattern_to_graph(pattern="A B _", topic="X", that="Y", template="1")
+
+ self.dump_graph()
+
+ context = self.match_sentence("A B C D", topic="X", that="Y")
+ self.assertIsNotNone(context)
+ self.assertIsNotNone(context.template_node())
+ self.assertEqual("1", context.template_node().template.word)
+
+ def test_underline_tree_matching_multiple(self):
+
+ self.add_pattern_to_graph(pattern="A _ _ D", topic="X", that="Y", template="1")
+
+ self.dump_graph()
+
+ context = self.match_sentence("A B C D", topic="X", that="Y")
+ self.assertIsNotNone(context)
+ self.assertIsNotNone(context.template_node())
+ self.assertEqual("1", context.template_node().template.word)
+
+ def test_underline_tree_matching_all(self):
+
+ self.add_pattern_to_graph(pattern="A _ D", topic="_", that="_", template="1")
+
+ self.dump_graph()
+
+ context = self.match_sentence("A B C D", topic="X Y", that="Z")
+ self.assertIsNotNone(context)
+ self.assertIsNotNone(context.template_node())
+ self.assertEqual("1", context.template_node().template.word)
+
+ def test_underline_front_and_back(self):
+
+ self.add_pattern_to_graph(pattern="_ F G", topic="*", that="*", template="2")
+ self.add_pattern_to_graph(pattern="_ A B _", topic="*", that="*", template="1")
+
+ self.dump_graph()
+
+ context = self.match_sentence("F A B G", topic="X", that="Y")
+ self.assertIsNotNone(context)
+ self.assertIsNotNone(context.template_node())
+ self.assertEqual("1", context.template_node().template.word)
+
+ def test_underline_deep_tree_matching(self):
+
+ self.add_pattern_to_graph(pattern="A _ B _ C", topic="X", that="Z", template="1")
+ self.add_pattern_to_graph(pattern="A _ B _ C", topic="X", that="Y", template="1")
+
+ self.dump_graph()
+
+ context = self.match_sentence("A X1 X2 X3 X4 B Y1 Y2 Y3 Y4 C", topic="X", that="Y")
+ self.assertIsNotNone(context)
+ self.assertIsNotNone(context.template_node())
+ self.assertEqual("1", context.template_node().template.word)
+
+ self.assertEqual("X1 X2 X3 X4", context.star(1))
+ self.assertEqual("Y1 Y2 Y3 Y4", context.star(2))
diff --git a/src/test/parser/pattern/test_matching/test_wildcard_branches.py b/src/test/parser/pattern/test_matching/test_wildcard_branches.py
new file mode 100644
index 000000000..66bb1ee72
--- /dev/null
+++ b/src/test/parser/pattern/test_matching/test_wildcard_branches.py
@@ -0,0 +1,5 @@
+
+from test.parser.pattern.test_matching.base import PatternMatcherBaseClass
+
+class PatternMatcherWildcardBranchesTests(PatternMatcherBaseClass):
+ pass
diff --git a/src/test/parser/pattern/test_nodes.py b/src/test/parser/pattern/test_nodes.py
deleted file mode 100644
index c62356076..000000000
--- a/src/test/parser/pattern/test_nodes.py
+++ /dev/null
@@ -1,350 +0,0 @@
-from programy.dialog import Sentence
-from programy.parser.pattern.nodes import *
-from programy.parser.template.nodes import TemplateNode
-
-from test.parser.pattern.base import PatternTestBaseClass
-
-class PatternNodeTests(PatternTestBaseClass):
-
- def test_init(self):
- node = PatternNode()
- self.assertIsNotNone(node)
- self.assertFalse(node.is_root())
- self.assertFalse(node.is_priority())
- self.assertFalse(node.is_wildcard())
- self.assertFalse(node.is_zero_or_more())
- self.assertFalse(node.is_one_or_more())
- self.assertFalse(node.has_children())
- self.assertIsNotNone(node.children)
-
- self.assertFalse(node.equivalent(PatternNode()))
- self.assertEqual(node.to_string(), "NODE [P(0)^(0)#(0)C(0)_(0)*(0)To(0)Th(0)Te(0)]")
-
- node.add_child(PatternNode())
- self.assertEqual(len(node.children), 1)
- self.assertEqual(node.to_string(), "NODE [P(0)^(0)#(0)C(1)_(0)*(0)To(0)Th(0)Te(0)]")
-
- def test_add_child(self):
-
- node = PatternNode()
-
- priority_word1 = PatternPriorityWordNode("pword")
- priority_word2 = PatternPriorityWordNode("pword")
- node.add_child(priority_word1)
- new_node = node.add_child(priority_word2)
- self.assertEqual(new_node, priority_word1)
-
- arrow_node1 = PatternZeroOrMoreWildCardNode("^")
- arrow_node2 = PatternZeroOrMoreWildCardNode("^")
- node.add_child(arrow_node1)
- new_node = node.add_child(arrow_node2)
- self.assertEqual(new_node, arrow_node1)
-
-
-class PatternRootNodeTests(PatternTestBaseClass):
-
- def test_init(self):
- node = PatternRootNode()
- self.assertIsNotNone(node)
-
- self.assertTrue(node.is_root())
- self.assertFalse(node.is_priority())
- self.assertFalse(node.is_wildcard())
- self.assertFalse(node.is_zero_or_more())
- self.assertFalse(node.is_one_or_more())
- self.assertIsNotNone(node.children)
- self.assertFalse(node.has_children())
-
- self.assertTrue(node.equivalent(PatternRootNode()))
- self.assertEqual(node.to_string(), "ROOT [P(0)^(0)#(0)C(0)_(0)*(0)To(0)Th(0)Te(0)]")
-
- node.add_child(PatternNode())
- self.assertEqual(len(node.children), 1)
- self.assertEqual(node.to_string(), "ROOT [P(0)^(0)#(0)C(1)_(0)*(0)To(0)Th(0)Te(0)]")
-
- def test_multiple_roots(self):
- node1 = PatternRootNode()
- node2 = PatternRootNode()
-
- with self.assertRaises(ParserException) as raised:
- node1.can_add(node2)
- self.assertTrue(str(raised.exception).startswith("Cannot add root node to existing root node"))
-
- def test_root_added_to_child(self):
- node1 = PatternWordNode("test")
- node2 = PatternRootNode()
-
- with self.assertRaises(ParserException) as raised:
- node1.can_add(node2)
- self.assertTrue(str(raised.exception).startswith("Cannot add root node to child node"))
-
-
-class PatternTopicNodeTests(PatternTestBaseClass):
-
- def test_init(self):
- node = PatternTopicNode()
- self.assertIsNotNone(node)
-
- self.assertFalse(node.is_root())
- self.assertFalse(node.is_priority())
- self.assertFalse(node.is_wildcard())
- self.assertFalse(node.is_zero_or_more())
- self.assertFalse(node.is_one_or_more())
- self.assertIsNotNone(node.children)
- self.assertFalse(node.has_children())
-
- self.assertTrue(node.equivalent(PatternTopicNode()))
- self.assertEqual(node.to_string(), "TOPIC [P(0)^(0)#(0)C(0)_(0)*(0)To(0)Th(0)Te(0)]")
-
- def test_topic_to_root(self):
- node1 = PatternRootNode()
- node2 = PatternTopicNode()
-
- with self.assertRaises(ParserException) as raised:
- node1.can_add(node2)
- self.assertEqual(str(raised.exception), "Cannot add topic node to root node")
-
- def test_multiple_topics(self):
- node1 = PatternTopicNode()
- node2 = PatternTopicNode()
-
- with self.assertRaises(ParserException) as raised:
- node1.can_add(node2)
- self.assertEqual(str(raised.exception), "Cannot add topic node to topic node")
-
-
-class PatternThatNodeTests(PatternTestBaseClass):
-
- def test_init(self):
- node = PatternThatNode()
- self.assertIsNotNone(node)
-
- self.assertFalse(node.is_root())
- self.assertFalse(node.is_priority())
- self.assertFalse(node.is_wildcard())
- self.assertFalse(node.is_zero_or_more())
- self.assertFalse(node.is_one_or_more())
- self.assertIsNotNone(node.children)
- self.assertFalse(node.has_children())
-
- self.assertTrue(node.equivalent(PatternThatNode()))
- self.assertEqual(node.to_string(), "THAT [P(0)^(0)#(0)C(0)_(0)*(0)To(0)Th(0)Te(0)]")
-
- def test_that_to_root(self):
- node1 = PatternRootNode()
- node2 = PatternThatNode()
-
- with self.assertRaises(ParserException) as raised:
- node1.can_add(node2)
- self.assertEqual(str(raised.exception), "Cannot add that node to root node")
-
- def test_multiple_thats(self):
- node1 = PatternThatNode()
- node2 = PatternThatNode()
-
- with self.assertRaises(ParserException) as raised:
- node1.can_add(node2)
- self.assertEqual(str(raised.exception), "Cannot add that node to that node")
-
-
-class PatternTemplateNodeTests(PatternTestBaseClass):
-
- def test_init(self):
-
- node = PatternTemplateNode(TemplateNode())
- self.assertIsNotNone(node)
-
- self.assertFalse(node.is_root())
- self.assertFalse(node.is_priority())
- self.assertFalse(node.is_wildcard())
- self.assertFalse(node.is_zero_or_more())
- self.assertFalse(node.is_one_or_more())
- self.assertIsNotNone(node.children)
- self.assertFalse(node.has_children())
-
- self.assertTrue(node.equivalent(PatternTemplateNode(TemplateNode())))
- self.assertEqual(node.to_string(), "PTEMPLATE [P(0)^(0)#(0)C(0)_(0)*(0)To(0)Th(0)Te(1)] ")
-
- def test_template_to_root(self):
- node1 = PatternRootNode()
- node2 = PatternTemplateNode(TemplateNode())
-
- with self.assertRaises(ParserException) as raised:
- node1.can_add(node2)
- self.assertEqual(str(raised.exception), "Cannot add template node to root node")
-
- def test_multiple_templates(self):
- node1 = PatternTemplateNode(TemplateNode())
- node2 = PatternTemplateNode(TemplateNode())
-
- with self.assertRaises(ParserException) as raised:
- node1.can_add(node2)
- self.assertEqual(str(raised.exception), "Cannot add template node to template node")
-
-
-class PatternWordNodeTests(PatternTestBaseClass):
-
- def test_init(self):
- node = PatternWordNode("test1")
-
- self.assertFalse(node.is_root())
- self.assertFalse(node.is_priority())
- self.assertFalse(node.is_wildcard())
- self.assertFalse(node.is_zero_or_more())
- self.assertFalse(node.is_one_or_more())
- self.assertIsNotNone(node.children)
- self.assertFalse(node.has_children())
-
- self.assertTrue(node.equivalent(PatternWordNode("test1")))
- self.assertFalse(node.is_root())
- self.assertEqual(node.to_string(), "WORD [P(0)^(0)#(0)C(0)_(0)*(0)To(0)Th(0)Te(0)] word=[test1]")
-
- self.assertTrue(node.matches(self.bot, self.clientid, "test1"))
-
- node.add_child(PatternWordNode("test2"))
- self.assertEqual(len(node.children), 1)
- self.assertEqual(node.to_string(), "WORD [P(0)^(0)#(0)C(1)_(0)*(0)To(0)Th(0)Te(0)] word=[test1]")
-
- self.assertIsNotNone(node.matches(self.bot, self.clientid, Sentence("test1")))
-
-class PatternPriorityWordNodeTests(PatternTestBaseClass):
-
- def test_init(self):
- node = PatternPriorityWordNode("test1")
- self.assertIsNotNone(node)
-
- self.assertFalse(node.is_root())
- self.assertTrue(node.is_priority())
- self.assertFalse(node.is_wildcard())
- self.assertFalse(node.is_zero_or_more())
- self.assertFalse(node.is_one_or_more())
- self.assertIsNotNone(node.children)
- self.assertFalse(node.has_children())
-
- self.assertTrue(node.equivalent(PatternPriorityWordNode("test1")))
- self.assertFalse(node.is_root())
- self.assertEqual(node.to_string(), "PWORD [P(0)^(0)#(0)C(0)_(0)*(0)To(0)Th(0)Te(0)] word=[test1]")
-
- self.assertTrue(node.matches(self.bot, self.clientid, "test1"))
-
- node.add_child(PatternWordNode("test2"))
- self.assertEqual(len(node.children), 1)
- self.assertEqual(node.to_string(), "PWORD [P(0)^(0)#(0)C(1)_(0)*(0)To(0)Th(0)Te(0)] word=[test1]")
-
- self.assertTrue(node.matches(self.bot, self.clientid, "test1"))
-
-class PatternSetNodeTests(PatternTestBaseClass):
-
- def test_init(self):
- node = PatternSetNode("test1")
- self.assertIsNotNone(node)
-
- self.assertFalse(node.is_root())
- self.assertFalse(node.is_priority())
- self.assertFalse(node.is_wildcard())
- self.assertFalse(node.is_zero_or_more())
- self.assertFalse(node.is_one_or_more())
- self.assertIsNotNone(node.children)
- self.assertFalse(node.has_children())
-
- self.assertTrue(node.equivalent(PatternSetNode("test1")))
- self.assertFalse(node.is_root())
- self.assertEqual(node.to_string(), "SET [P(0)^(0)#(0)C(0)_(0)*(0)To(0)Th(0)Te(0)] name=[TEST1]")
-
- self.bot.brain.sets._sets["TEST1"] = ["val1", "val2", "val3"]
-
- self.assertTrue(node.matches(self.bot, self.clientid, "val1"))
- self.assertTrue(node.matches(self.bot, self.clientid, "val2"))
- self.assertFalse(node.matches(self.bot, self.clientid, "val4"))
-
-class PatternBotNodeTests(PatternTestBaseClass):
-
- def test_init(self):
- node = PatternBotNode("test1")
- self.assertIsNotNone(node)
-
- self.assertFalse(node.is_root())
- self.assertFalse(node.is_priority())
- self.assertFalse(node.is_wildcard())
- self.assertFalse(node.is_zero_or_more())
- self.assertFalse(node.is_one_or_more())
- self.assertIsNotNone(node.children)
- self.assertFalse(node.has_children())
-
- self.assertTrue(node.equivalent(PatternBotNode("test1")))
- self.assertFalse(node.is_root())
- self.assertEqual(node.to_string(), "BOT [P(0)^(0)#(0)C(0)_(0)*(0)To(0)Th(0)Te(0)] property=[test1]")
-
- self.bot.brain.properties._properties["test1"] = "val1"
-
- self.assertTrue(node.matches(self.bot, self.clientid, "val1"))
- self.assertFalse(node.matches(self.bot, self.clientid, "val4"))
-
-class PatternZeroOrMoreWildCardNodeTests(PatternTestBaseClass):
-
- def test_invalid_wildcard(self):
- with self.assertRaises(ParserException) as raised:
- node = PatternZeroOrMoreWildCardNode("X")
- self.assertIsNone(node)
-
- def test_init(self):
- node = PatternZeroOrMoreWildCardNode("#")
-
- self.assertFalse(node.is_root())
- self.assertFalse(node.is_priority())
- self.assertTrue(node.is_wildcard())
- self.assertTrue(node.is_zero_or_more())
- self.assertFalse(node.is_one_or_more())
- self.assertIsNotNone(node.children)
- self.assertFalse(node.has_children())
-
- self.assertEqual(node.wildcard, "#")
-
- self.assertTrue(node.equivalent(PatternZeroOrMoreWildCardNode("#")))
- self.assertFalse(node.is_root())
- self.assertEqual(node.to_string(), "ZEROORMORE [P(0)^(0)#(0)C(0)_(0)*(0)To(0)Th(0)Te(0)] wildcard=[#]")
-
- node = PatternZeroOrMoreWildCardNode("^")
- self.assertIsNotNone(node)
-
- self.assertEqual(node.wildcard, "^")
-
- self.assertTrue(node.equivalent(PatternZeroOrMoreWildCardNode("^")))
- self.assertFalse(node.is_root())
- self.assertEqual(node.to_string(), "ZEROORMORE [P(0)^(0)#(0)C(0)_(0)*(0)To(0)Th(0)Te(0)] wildcard=[^]")
-
-class PatternOneOrMoreWildCardNodeTests(PatternTestBaseClass):
-
- def test_invalid_wildcard(self):
- with self.assertRaises(ParserException) as raised:
- node = PatternOneOrMoreWildCardNode("X")
- self.assertIsNone(node)
-
- def test_init(self):
- node = PatternOneOrMoreWildCardNode("*")
- self.assertIsNotNone(node)
-
- self.assertFalse(node.is_root())
- self.assertFalse(node.is_priority())
- self.assertTrue(node.is_wildcard())
- self.assertFalse(node.is_zero_or_more())
- self.assertTrue(node.is_one_or_more())
-
- self.assertIsNotNone(node.children)
- self.assertFalse(node.has_children())
-
- self.assertEqual(node.wildcard, "*")
-
- self.assertTrue(node.equivalent(PatternOneOrMoreWildCardNode("*")))
- self.assertFalse(node.is_root())
- self.assertEqual(node.to_string(), "ONEORMORE [P(0)^(0)#(0)C(0)_(0)*(0)To(0)Th(0)Te(0)] wildcard=[*]")
-
- node = PatternOneOrMoreWildCardNode("_")
- self.assertIsNotNone(node)
-
- self.assertEqual(node.wildcard, "_")
-
- self.assertTrue(node.equivalent(PatternOneOrMoreWildCardNode("_")))
- self.assertFalse(node.is_root())
- self.assertEqual(node.to_string(), "ONEORMORE [P(0)^(0)#(0)C(0)_(0)*(0)To(0)Th(0)Te(0)] wildcard=[_]")
-
diff --git a/src/test/parser/pattern/test_nodes/__init__.py b/src/test/parser/pattern/test_nodes/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/src/test/parser/pattern/base.py b/src/test/parser/pattern/test_nodes/base.py
similarity index 100%
rename from src/test/parser/pattern/base.py
rename to src/test/parser/pattern/test_nodes/base.py
diff --git a/src/test/parser/pattern/test_nodes/test_bot.py b/src/test/parser/pattern/test_nodes/test_bot.py
new file mode 100644
index 000000000..01b6c548a
--- /dev/null
+++ b/src/test/parser/pattern/test_nodes/test_bot.py
@@ -0,0 +1,21 @@
+from test.parser.pattern.test_nodes.base import PatternTestBaseClass
+from programy.parser.pattern.nodes import *
+
+class PatternBotNodeTests(PatternTestBaseClass):
+
+ def test_init(self):
+ node = PatternBotNode("test1")
+ self.assertIsNotNone(node)
+
+ self.assertFalse(node.is_root())
+ self.assertFalse(node.is_priority())
+ self.assertFalse(node.is_wildcard())
+ self.assertFalse(node.is_zero_or_more())
+ self.assertFalse(node.is_one_or_more())
+ self.assertIsNotNone(node.children)
+ self.assertFalse(node.has_children())
+
+ self.assertTrue(node.equivalent(PatternBotNode("test1")))
+ self.assertFalse(node.is_root())
+ self.assertEqual(node.to_string(), "BOT [P(0)^(0)#(0)C(0)_(0)*(0)To(0)Th(0)Te(0)] property=[test1]")
+
diff --git a/src/test/parser/pattern/test_nodes/test_node.py b/src/test/parser/pattern/test_nodes/test_node.py
new file mode 100644
index 000000000..b2564ad99
--- /dev/null
+++ b/src/test/parser/pattern/test_nodes/test_node.py
@@ -0,0 +1,40 @@
+from test.parser.pattern.test_nodes.base import PatternTestBaseClass
+from programy.parser.pattern.nodes import *
+
+class PatternNodeTests(PatternTestBaseClass):
+
+ def test_init(self):
+ node = PatternNode()
+ self.assertIsNotNone(node)
+ self.assertFalse(node.is_root())
+ self.assertFalse(node.is_priority())
+ self.assertFalse(node.is_wildcard())
+ self.assertFalse(node.is_zero_or_more())
+ self.assertFalse(node.is_one_or_more())
+ self.assertFalse(node.has_children())
+ self.assertIsNotNone(node.children)
+
+ self.assertFalse(node.equivalent(PatternNode()))
+ self.assertEqual(node.to_string(), "NODE [P(0)^(0)#(0)C(0)_(0)*(0)To(0)Th(0)Te(0)]")
+
+ node.add_child(PatternNode())
+ self.assertEqual(len(node.children), 1)
+ self.assertEqual(node.to_string(), "NODE [P(0)^(0)#(0)C(1)_(0)*(0)To(0)Th(0)Te(0)]")
+
+ def test_add_child(self):
+
+ node = PatternNode()
+
+ priority_word1 = PatternPriorityWordNode("pword")
+ priority_word2 = PatternPriorityWordNode("pword")
+ node.add_child(priority_word1)
+ new_node = node.add_child(priority_word2)
+ self.assertEqual(new_node, priority_word1)
+
+ arrow_node1 = PatternZeroOrMoreWildCardNode("^")
+ arrow_node2 = PatternZeroOrMoreWildCardNode("^")
+ node.add_child(arrow_node1)
+ new_node = node.add_child(arrow_node2)
+ self.assertEqual(new_node, arrow_node1)
+
+
diff --git a/src/test/parser/pattern/test_nodes/test_one_or_more.py b/src/test/parser/pattern/test_nodes/test_one_or_more.py
new file mode 100644
index 000000000..018fb3494
--- /dev/null
+++ b/src/test/parser/pattern/test_nodes/test_one_or_more.py
@@ -0,0 +1,38 @@
+from test.parser.pattern.test_nodes.base import PatternTestBaseClass
+from programy.parser.pattern.nodes import *
+
+class PatternOneOrMoreWildCardNodeTests(PatternTestBaseClass):
+
+ def test_invalid_wildcard(self):
+ with self.assertRaises(ParserException) as raised:
+ node = PatternOneOrMoreWildCardNode("X")
+ self.assertIsNone(node)
+
+ def test_init(self):
+ node = PatternOneOrMoreWildCardNode("*")
+ self.assertIsNotNone(node)
+
+ self.assertFalse(node.is_root())
+ self.assertFalse(node.is_priority())
+ self.assertTrue(node.is_wildcard())
+ self.assertFalse(node.is_zero_or_more())
+ self.assertTrue(node.is_one_or_more())
+
+ self.assertIsNotNone(node.children)
+ self.assertFalse(node.has_children())
+
+ self.assertEqual(node.wildcard, "*")
+
+ self.assertTrue(node.equivalent(PatternOneOrMoreWildCardNode("*")))
+ self.assertFalse(node.is_root())
+ self.assertEqual(node.to_string(), "ONEORMORE [P(0)^(0)#(0)C(0)_(0)*(0)To(0)Th(0)Te(0)] wildcard=[*]")
+
+ node = PatternOneOrMoreWildCardNode("_")
+ self.assertIsNotNone(node)
+
+ self.assertEqual(node.wildcard, "_")
+
+ self.assertTrue(node.equivalent(PatternOneOrMoreWildCardNode("_")))
+ self.assertFalse(node.is_root())
+ self.assertEqual(node.to_string(), "ONEORMORE [P(0)^(0)#(0)C(0)_(0)*(0)To(0)Th(0)Te(0)] wildcard=[_]")
+
diff --git a/src/test/parser/pattern/test_nodes/test_priority.py b/src/test/parser/pattern/test_nodes/test_priority.py
new file mode 100644
index 000000000..e48165ecf
--- /dev/null
+++ b/src/test/parser/pattern/test_nodes/test_priority.py
@@ -0,0 +1,25 @@
+from test.parser.pattern.test_nodes.base import PatternTestBaseClass
+from programy.parser.pattern.nodes import *
+
+
+class PatternPriorityWordNodeTests(PatternTestBaseClass):
+
+ def test_init(self):
+ node = PatternPriorityWordNode("test1")
+ self.assertIsNotNone(node)
+
+ self.assertFalse(node.is_root())
+ self.assertTrue(node.is_priority())
+ self.assertFalse(node.is_wildcard())
+ self.assertFalse(node.is_zero_or_more())
+ self.assertFalse(node.is_one_or_more())
+ self.assertIsNotNone(node.children)
+ self.assertFalse(node.has_children())
+
+ self.assertTrue(node.equivalent(PatternPriorityWordNode("test1")))
+ self.assertFalse(node.is_root())
+ self.assertEqual(node.to_string(), "PWORD [P(0)^(0)#(0)C(0)_(0)*(0)To(0)Th(0)Te(0)] word=[test1]")
+
+ node.add_child(PatternWordNode("test2"))
+ self.assertEqual(len(node.children), 1)
+ self.assertEqual(node.to_string(), "PWORD [P(0)^(0)#(0)C(1)_(0)*(0)To(0)Th(0)Te(0)] word=[test1]")
diff --git a/src/test/parser/pattern/test_nodes/test_root.py b/src/test/parser/pattern/test_nodes/test_root.py
new file mode 100644
index 000000000..364514011
--- /dev/null
+++ b/src/test/parser/pattern/test_nodes/test_root.py
@@ -0,0 +1,41 @@
+from test.parser.pattern.test_nodes.base import PatternTestBaseClass
+from programy.parser.pattern.nodes import *
+
+class PatternRootNodeTests(PatternTestBaseClass):
+
+ def test_init(self):
+ node = PatternRootNode()
+ self.assertIsNotNone(node)
+
+ self.assertTrue(node.is_root())
+ self.assertFalse(node.is_priority())
+ self.assertFalse(node.is_wildcard())
+ self.assertFalse(node.is_zero_or_more())
+ self.assertFalse(node.is_one_or_more())
+ self.assertIsNotNone(node.children)
+ self.assertFalse(node.has_children())
+
+ self.assertTrue(node.equivalent(PatternRootNode()))
+ self.assertEqual(node.to_string(), "ROOT [P(0)^(0)#(0)C(0)_(0)*(0)To(0)Th(0)Te(0)]")
+
+ node.add_child(PatternNode())
+ self.assertEqual(len(node.children), 1)
+ self.assertEqual(node.to_string(), "ROOT [P(0)^(0)#(0)C(1)_(0)*(0)To(0)Th(0)Te(0)]")
+
+ def test_multiple_roots(self):
+ node1 = PatternRootNode()
+ node2 = PatternRootNode()
+
+ with self.assertRaises(ParserException) as raised:
+ node1.can_add(node2)
+ self.assertTrue(str(raised.exception).startswith("Cannot add root node to existing root node"))
+
+ def test_root_added_to_child(self):
+ node1 = PatternWordNode("test")
+ node2 = PatternRootNode()
+
+ with self.assertRaises(ParserException) as raised:
+ node1.can_add(node2)
+ self.assertTrue(str(raised.exception).startswith("Cannot add root node to child node"))
+
+
diff --git a/src/test/parser/pattern/test_nodes/test_set.py b/src/test/parser/pattern/test_nodes/test_set.py
new file mode 100644
index 000000000..2d2ff7b1b
--- /dev/null
+++ b/src/test/parser/pattern/test_nodes/test_set.py
@@ -0,0 +1,21 @@
+from test.parser.pattern.test_nodes.base import PatternTestBaseClass
+from programy.parser.pattern.nodes import *
+
+class PatternSetNodeTests(PatternTestBaseClass):
+
+ def test_init(self):
+ node = PatternSetNode("test1")
+ self.assertIsNotNone(node)
+
+ self.assertFalse(node.is_root())
+ self.assertFalse(node.is_priority())
+ self.assertFalse(node.is_wildcard())
+ self.assertFalse(node.is_zero_or_more())
+ self.assertFalse(node.is_one_or_more())
+ self.assertIsNotNone(node.children)
+ self.assertFalse(node.has_children())
+
+ self.assertTrue(node.equivalent(PatternSetNode("test1")))
+ self.assertFalse(node.is_root())
+ self.assertEqual(node.to_string(), "SET [P(0)^(0)#(0)C(0)_(0)*(0)To(0)Th(0)Te(0)] name=[TEST1]")
+
diff --git a/src/test/parser/pattern/test_nodes/test_template.py b/src/test/parser/pattern/test_nodes/test_template.py
new file mode 100644
index 000000000..ff299811a
--- /dev/null
+++ b/src/test/parser/pattern/test_nodes/test_template.py
@@ -0,0 +1,40 @@
+from test.parser.pattern.test_nodes.base import PatternTestBaseClass
+from programy.parser.pattern.nodes import *
+from programy.parser.template.nodes import TemplateNode
+
+
+class PatternTemplateNodeTests(PatternTestBaseClass):
+
+ def test_init(self):
+
+ node = PatternTemplateNode(TemplateNode())
+ self.assertIsNotNone(node)
+
+ self.assertFalse(node.is_root())
+ self.assertFalse(node.is_priority())
+ self.assertFalse(node.is_wildcard())
+ self.assertFalse(node.is_zero_or_more())
+ self.assertFalse(node.is_one_or_more())
+ self.assertIsNotNone(node.children)
+ self.assertFalse(node.has_children())
+
+ self.assertTrue(node.equivalent(PatternTemplateNode(TemplateNode())))
+ self.assertEqual(node.to_string(), "PTEMPLATE [P(0)^(0)#(0)C(0)_(0)*(0)To(0)Th(0)Te(1)] ")
+
+ def test_template_to_root(self):
+ node1 = PatternRootNode()
+ node2 = PatternTemplateNode(TemplateNode())
+
+ with self.assertRaises(ParserException) as raised:
+ node1.can_add(node2)
+ self.assertEqual(str(raised.exception), "Cannot add template node to root node")
+
+ def test_multiple_templates(self):
+ node1 = PatternTemplateNode(TemplateNode())
+ node2 = PatternTemplateNode(TemplateNode())
+
+ with self.assertRaises(ParserException) as raised:
+ node1.can_add(node2)
+ self.assertEqual(str(raised.exception), "Cannot add template node to template node")
+
+
diff --git a/src/test/parser/pattern/test_nodes/test_that.py b/src/test/parser/pattern/test_nodes/test_that.py
new file mode 100644
index 000000000..905190d2e
--- /dev/null
+++ b/src/test/parser/pattern/test_nodes/test_that.py
@@ -0,0 +1,36 @@
+from test.parser.pattern.test_nodes.base import PatternTestBaseClass
+from programy.parser.pattern.nodes import *
+
+
+class PatternThatNodeTests(PatternTestBaseClass):
+
+ def test_init(self):
+ node = PatternThatNode()
+ self.assertIsNotNone(node)
+
+ self.assertFalse(node.is_root())
+ self.assertFalse(node.is_priority())
+ self.assertFalse(node.is_wildcard())
+ self.assertFalse(node.is_zero_or_more())
+ self.assertFalse(node.is_one_or_more())
+ self.assertIsNotNone(node.children)
+ self.assertFalse(node.has_children())
+
+ self.assertTrue(node.equivalent(PatternThatNode()))
+ self.assertEqual(node.to_string(), "THAT [P(0)^(0)#(0)C(0)_(0)*(0)To(0)Th(0)Te(0)]")
+
+ def test_that_to_root(self):
+ node1 = PatternRootNode()
+ node2 = PatternThatNode()
+
+ with self.assertRaises(ParserException) as raised:
+ node1.can_add(node2)
+ self.assertEqual(str(raised.exception), "Cannot add that node to root node")
+
+ def test_multiple_thats(self):
+ node1 = PatternThatNode()
+ node2 = PatternThatNode()
+
+ with self.assertRaises(ParserException) as raised:
+ node1.can_add(node2)
+ self.assertEqual(str(raised.exception), "Cannot add that node to that node")
diff --git a/src/test/parser/pattern/test_nodes/test_topic.py b/src/test/parser/pattern/test_nodes/test_topic.py
new file mode 100644
index 000000000..0306460ac
--- /dev/null
+++ b/src/test/parser/pattern/test_nodes/test_topic.py
@@ -0,0 +1,34 @@
+from test.parser.pattern.test_nodes.base import PatternTestBaseClass
+from programy.parser.pattern.nodes import *
+
+class PatternTopicNodeTests(PatternTestBaseClass):
+ def test_init(self):
+ node = PatternTopicNode()
+ self.assertIsNotNone(node)
+
+ self.assertFalse(node.is_root())
+ self.assertFalse(node.is_priority())
+ self.assertFalse(node.is_wildcard())
+ self.assertFalse(node.is_zero_or_more())
+ self.assertFalse(node.is_one_or_more())
+ self.assertIsNotNone(node.children)
+ self.assertFalse(node.has_children())
+
+ self.assertTrue(node.equivalent(PatternTopicNode()))
+ self.assertEqual(node.to_string(), "TOPIC [P(0)^(0)#(0)C(0)_(0)*(0)To(0)Th(0)Te(0)]")
+
+ def test_topic_to_root(self):
+ node1 = PatternRootNode()
+ node2 = PatternTopicNode()
+
+ with self.assertRaises(ParserException) as raised:
+ node1.can_add(node2)
+ self.assertEqual(str(raised.exception), "Cannot add topic node to root node")
+
+ def test_multiple_topics(self):
+ node1 = PatternTopicNode()
+ node2 = PatternTopicNode()
+
+ with self.assertRaises(ParserException) as raised:
+ node1.can_add(node2)
+ self.assertEqual(str(raised.exception), "Cannot add topic node to topic node")
diff --git a/src/test/parser/pattern/test_nodes/test_word.py b/src/test/parser/pattern/test_nodes/test_word.py
new file mode 100644
index 000000000..01d4c498b
--- /dev/null
+++ b/src/test/parser/pattern/test_nodes/test_word.py
@@ -0,0 +1,25 @@
+from test.parser.pattern.test_nodes.base import PatternTestBaseClass
+from programy.dialog import Sentence
+from programy.parser.pattern.nodes import *
+
+
+class PatternWordNodeTests(PatternTestBaseClass):
+
+ def test_init(self):
+ node = PatternWordNode("test1")
+
+ self.assertFalse(node.is_root())
+ self.assertFalse(node.is_priority())
+ self.assertFalse(node.is_wildcard())
+ self.assertFalse(node.is_zero_or_more())
+ self.assertFalse(node.is_one_or_more())
+ self.assertIsNotNone(node.children)
+ self.assertFalse(node.has_children())
+
+ self.assertTrue(node.equivalent(PatternWordNode("test1")))
+ self.assertFalse(node.is_root())
+ self.assertEqual(node.to_string(), "WORD [P(0)^(0)#(0)C(0)_(0)*(0)To(0)Th(0)Te(0)] word=[test1]")
+
+ node.add_child(PatternWordNode("test2"))
+ self.assertEqual(len(node.children), 1)
+ self.assertEqual(node.to_string(), "WORD [P(0)^(0)#(0)C(1)_(0)*(0)To(0)Th(0)Te(0)] word=[test1]")
diff --git a/src/test/parser/pattern/test_nodes/test_zero_or_more.py b/src/test/parser/pattern/test_nodes/test_zero_or_more.py
new file mode 100644
index 000000000..5fd721516
--- /dev/null
+++ b/src/test/parser/pattern/test_nodes/test_zero_or_more.py
@@ -0,0 +1,37 @@
+from test.parser.pattern.test_nodes.base import PatternTestBaseClass
+from programy.parser.pattern.nodes import *
+
+
+class PatternZeroOrMoreWildCardNodeTests(PatternTestBaseClass):
+
+ def test_invalid_wildcard(self):
+ with self.assertRaises(ParserException) as raised:
+ node = PatternZeroOrMoreWildCardNode("X")
+ self.assertIsNone(node)
+
+ def test_init(self):
+ node = PatternZeroOrMoreWildCardNode("#")
+
+ self.assertFalse(node.is_root())
+ self.assertFalse(node.is_priority())
+ self.assertTrue(node.is_wildcard())
+ self.assertTrue(node.is_zero_or_more())
+ self.assertFalse(node.is_one_or_more())
+ self.assertIsNotNone(node.children)
+ self.assertFalse(node.has_children())
+
+ self.assertEqual(node.wildcard, "#")
+
+ self.assertTrue(node.equivalent(PatternZeroOrMoreWildCardNode("#")))
+ self.assertFalse(node.is_root())
+ self.assertEqual(node.to_string(), "ZEROORMORE [P(0)^(0)#(0)C(0)_(0)*(0)To(0)Th(0)Te(0)] wildcard=[#]")
+
+ node = PatternZeroOrMoreWildCardNode("^")
+ self.assertIsNotNone(node)
+
+ self.assertEqual(node.wildcard, "^")
+
+ self.assertTrue(node.equivalent(PatternZeroOrMoreWildCardNode("^")))
+ self.assertFalse(node.is_root())
+ self.assertEqual(node.to_string(), "ZEROORMORE [P(0)^(0)#(0)C(0)_(0)*(0)To(0)Th(0)Te(0)] wildcard=[^]")
+
diff --git a/src/test/parser/template/graph/test_basics.py b/src/test/parser/template/graph/test_basics.py
index f728d2d5b..2d7a2c4e3 100644
--- a/src/test/parser/template/graph/test_basics.py
+++ b/src/test/parser/template/graph/test_basics.py
@@ -1,34 +1,10 @@
import unittest
import xml.etree.ElementTree as ET
-from programy.bot import Bot
-from programy.brain import Brain
-from programy.config import ClientConfiguration, BrainConfiguration
-from programy.dialog import Question, Sentence
-from programy.parser.template.graph import TemplateGraph
from programy.parser.template.nodes import *
+from test.parser.template.graph.test_graph_client import TemplateGraphTestClient
-
-class TemplateGraphBasicTests(unittest.TestCase):
-
- def setUp(self):
- self.parser = TemplateGraph()
- self.assertIsNotNone(self.parser)
-
- self.test_brain = None
- self.test_sentence = Sentence("test sentence")
- self.test_sentence._stars = ['one', 'two', 'three', 'four', 'five', 'six']
- self.test_sentence._thatstars = ["*"]
- self.test_sentence._topicstars = ["*"]
-
- test_config = ClientConfiguration()
-
- self.test_bot = Bot(Brain(BrainConfiguration()), config=test_config.bot_configuration)
- self.test_clientid = "testid"
-
- conversation = self.test_bot.get_conversation(self.test_clientid)
- question = Question.create_from_sentence(self.test_sentence)
- conversation._questions.append(question)
+class TemplateGraphBasicTests(TemplateGraphTestClient):
def test_template_no_content(self):
template = ET.fromstring("""
diff --git a/src/test/parser/template/graph/test_bot.py b/src/test/parser/template/graph/test_bot.py
index 6c83a44e7..7f34bef3d 100644
--- a/src/test/parser/template/graph/test_bot.py
+++ b/src/test/parser/template/graph/test_bot.py
@@ -1,34 +1,9 @@
import unittest
-import xml.etree.ElementTree as ET
-
-from programy.bot import Bot
-from programy.brain import Brain
-from programy.config import ClientConfiguration, BrainConfiguration
-from programy.dialog import Question, Sentence
-from programy.parser.template.graph import TemplateGraph
from programy.parser.template.nodes import *
+from test.parser.template.graph.test_graph_client import TemplateGraphTestClient
-class TemplateGraphBotTests(unittest.TestCase):
-
- def setUp(self):
- self.parser = TemplateGraph()
- self.assertIsNotNone(self.parser)
-
- self.test_brain = None
- self.test_sentence = Sentence("test sentence")
- self.test_sentence._stars = ['one', 'two', 'three', 'four', 'five', 'six']
- self.test_sentence._thatstars = ["*"]
- self.test_sentence._topicstars = ["*"]
-
- test_config = ClientConfiguration()
-
- self.test_bot = Bot(Brain(BrainConfiguration()), config=test_config.bot_configuration)
- self.test_clientid = "testid"
-
- conversation = self.test_bot.get_conversation(self.test_clientid)
- question = Question.create_from_sentence(self.test_sentence)
- conversation._questions.append(question)
+class TemplateGraphBotTests(TemplateGraphTestClient):
def test_bot_name_as_attrib(self):
template = ET.fromstring("""
diff --git a/src/test/parser/template/graph/test_condition.py b/src/test/parser/template/graph/test_condition.py
index c3975af33..083785dbf 100644
--- a/src/test/parser/template/graph/test_condition.py
+++ b/src/test/parser/template/graph/test_condition.py
@@ -1,34 +1,10 @@
import unittest
-import xml.etree.ElementTree as ET
-from programy.bot import Bot
-from programy.brain import Brain
-from programy.config import ClientConfiguration, BrainConfiguration
-from programy.dialog import Question, Sentence
-from programy.parser.template.graph import TemplateGraph
from programy.parser.template.nodes import *
+from test.parser.template.graph.test_graph_client import TemplateGraphTestClient
-class TemplateGraphConditionTests(unittest.TestCase):
-
- def setUp(self):
- self.parser = TemplateGraph()
- self.assertIsNotNone(self.parser)
-
- self.test_brain = None
- self.test_sentence = Sentence("test sentence")
- self.test_sentence._stars = ['one', 'two', 'three', 'four', 'five', 'six']
- self.test_sentence._thatstars = ["*"]
- self.test_sentence._topicstars = ["*"]
-
- test_config = ClientConfiguration()
-
- self.test_bot = Bot(Brain(BrainConfiguration()), config=test_config.bot_configuration)
- self.test_clientid = "testid"
-
- conversation = self.test_bot.get_conversation(self.test_clientid)
- question = Question.create_from_sentence(self.test_sentence)
- conversation._questions.append(question)
+class TemplateGraphConditionTests(TemplateGraphTestClient):
def test_condition_template_no_attribs(self):
template = ET.fromstring("""
diff --git a/src/test/parser/template/graph/test_datetime.py b/src/test/parser/template/graph/test_datetime.py
index 33636f682..e29702a86 100644
--- a/src/test/parser/template/graph/test_datetime.py
+++ b/src/test/parser/template/graph/test_datetime.py
@@ -1,34 +1,9 @@
import unittest
-import xml.etree.ElementTree as ET
-
-from programy.bot import Bot
-from programy.brain import Brain
-from programy.config import ClientConfiguration, BrainConfiguration
-from programy.dialog import Question, Sentence
-from programy.parser.template.graph import TemplateGraph
from programy.parser.template.nodes import *
+from test.parser.template.graph.test_graph_client import TemplateGraphTestClient
-class TemplateGraphDateTimeTests(unittest.TestCase):
-
- def setUp(self):
- self.parser = TemplateGraph()
- self.assertIsNotNone(self.parser)
-
- self.test_brain = None
- self.test_sentence = Sentence("test sentence")
- self.test_sentence._stars = ['one', 'two', 'three', 'four', 'five', 'six']
- self.test_sentence._thatstars = ["*"]
- self.test_sentence._topicstars = ["*"]
-
- test_config = ClientConfiguration()
-
- self.test_bot = Bot(Brain(BrainConfiguration()), config=test_config.bot_configuration)
- self.test_clientid = "testid"
-
- conversation = self.test_bot.get_conversation(self.test_clientid)
- question = Question.create_from_sentence(self.test_sentence)
- conversation._questions.append(question)
+class TemplateGraphDateTimeTests(TemplateGraphTestClient):
def test_date_format_as_attrib(self):
template = ET.fromstring("""
diff --git a/src/test/parser/template/graph/test_extension.py b/src/test/parser/template/graph/test_extension.py
index 57e8c0a37..ddf20a228 100644
--- a/src/test/parser/template/graph/test_extension.py
+++ b/src/test/parser/template/graph/test_extension.py
@@ -1,12 +1,7 @@
import unittest
-import xml.etree.ElementTree as ET
-
-from programy.bot import Bot
-from programy.brain import Brain
-from programy.config import ClientConfiguration, BrainConfiguration
-from programy.dialog import Question, Sentence
-from programy.parser.template.graph import TemplateGraph
from programy.parser.template.nodes import *
+from test.parser.template.graph.test_graph_client import TemplateGraphTestClient
+
class TestExtension(object):
@@ -14,26 +9,8 @@ def execute(self, data):
print(data)
return "executed"
-class TemplateGraphBotTests(unittest.TestCase):
-
- def setUp(self):
- self.parser = TemplateGraph()
- self.assertIsNotNone(self.parser)
-
- self.test_brain = None
- self.test_sentence = Sentence("test sentence")
- self.test_sentence._stars = ['one', 'two', 'three', 'four', 'five', 'six']
- self.test_sentence._thatstars = ["*"]
- self.test_sentence._topicstars = ["*"]
-
- test_config = ClientConfiguration()
-
- self.test_bot = Bot(Brain(BrainConfiguration()), config=test_config.bot_configuration)
- self.test_clientid = "testid"
- conversation = self.test_bot.get_conversation(self.test_clientid)
- question = Question.create_from_sentence(self.test_sentence)
- conversation._questions.append(question)
+class TemplateGraphBotTests(TemplateGraphTestClient):
def test_extension_as_attrib(self):
template = ET.fromstring("""
diff --git a/src/test/parser/template/graph/test_get.py b/src/test/parser/template/graph/test_get.py
index 63401237b..a0925b593 100644
--- a/src/test/parser/template/graph/test_get.py
+++ b/src/test/parser/template/graph/test_get.py
@@ -1,34 +1,9 @@
import unittest
-import xml.etree.ElementTree as ET
-
-from programy.bot import Bot
-from programy.brain import Brain
-from programy.config import ClientConfiguration, BrainConfiguration
-from programy.dialog import Question, Sentence
-from programy.parser.template.graph import TemplateGraph
from programy.parser.template.nodes import *
+from test.parser.template.graph.test_graph_client import TemplateGraphTestClient
-class TemplateGraphGetTests(unittest.TestCase):
-
- def setUp(self):
- self.parser = TemplateGraph()
- self.assertIsNotNone(self.parser)
-
- self.test_brain = None
- self.test_sentence = Sentence("test sentence")
- self.test_sentence._stars = ['one', 'two', 'three', 'four', 'five', 'six']
- self.test_sentence._thatstars = ["*"]
- self.test_sentence._topicstars = ["*"]
-
- test_config = ClientConfiguration()
-
- self.test_bot = Bot(Brain(BrainConfiguration()), config=test_config.bot_configuration)
- self.test_clientid = "testid"
-
- conversation = self.test_bot.get_conversation(self.test_clientid)
- question = Question.create_from_sentence(self.test_sentence)
- conversation._questions.append(question)
+class TemplateGraphGetTests(TemplateGraphTestClient):
def test_get_template_predicate_as_attrib(self):
template = ET.fromstring("""
diff --git a/src/test/parser/template/graph/test_graph_client.py b/src/test/parser/template/graph/test_graph_client.py
new file mode 100644
index 000000000..9787edbea
--- /dev/null
+++ b/src/test/parser/template/graph/test_graph_client.py
@@ -0,0 +1,41 @@
+import unittest
+import xml.etree.ElementTree as ET
+
+from programy.bot import Bot
+from programy.brain import Brain
+from programy.config import ClientConfiguration, BrainConfiguration
+from programy.dialog import Question, Sentence
+from programy.parser.template.graph import TemplateGraph
+from programy.parser.pattern.matcher import MatchContext, Match
+from programy.parser.pattern.nodes import PatternOneOrMoreWildCardNode
+from programy.parser.aiml_parser import AIMLParser
+
+class TemplateGraphTestClient(unittest.TestCase):
+
+ def setUp(self):
+ self.parser = TemplateGraph(AIMLParser())
+ self.assertIsNotNone(self.parser)
+
+ self.test_brain = None
+ self.test_sentence = Sentence("test sentence")
+
+ test_node = PatternOneOrMoreWildCardNode("*")
+
+ self.test_sentence._matched_context = MatchContext()
+ self.test_sentence._matched_context._matched_nodes = [Match(Match.WORD, test_node, 'one'),
+ Match(Match.WORD, test_node, 'two'),
+ Match(Match.WORD, test_node, 'three'),
+ Match(Match.WORD, test_node, 'four'),
+ Match(Match.WORD, test_node, 'five'),
+ Match(Match.WORD, test_node, 'six'),
+ Match(Match.TOPIC, test_node, '*'),
+ Match(Match.THAT, test_node, '*')]
+
+ test_config = ClientConfiguration()
+
+ self.test_bot = Bot(Brain(BrainConfiguration()), config=test_config.bot_configuration)
+ self.test_clientid = "testid"
+
+ conversation = self.test_bot.get_conversation(self.test_clientid)
+ question = Question.create_from_sentence(self.test_sentence)
+ conversation._questions.append(question)
diff --git a/src/test/parser/template/graph/test_learn.py b/src/test/parser/template/graph/test_learn.py
index 3dbbec835..357a5f193 100644
--- a/src/test/parser/template/graph/test_learn.py
+++ b/src/test/parser/template/graph/test_learn.py
@@ -1,37 +1,13 @@
import unittest
-import xml.etree.ElementTree as ET
-from programy.bot import Bot
-from programy.brain import Brain
-from programy.config import ClientConfiguration, BrainConfiguration
-from programy.dialog import Question, Sentence
-from programy.parser.template.graph import TemplateGraph
from programy.parser.template.nodes import *
-from programy.parser.aiml_parser import AIMLParser
from programy.config import BrainFileConfiguration
+from test.parser.template.graph.test_graph_client import TemplateGraphTestClient
-class TemplateGraphLearnTests(unittest.TestCase):
- def setUp(self):
- self.parser = TemplateGraph(AIMLParser())
- self.assertIsNotNone(self.parser)
+class TemplateGraphLearnTests(TemplateGraphTestClient):
- self.test_brain = None
- self.test_sentence = Sentence("test sentence")
- self.test_sentence._stars = ['one', 'two', 'three', 'four', 'five', 'six']
- self.test_sentence._thatstars = ["*"]
- self.test_sentence._topicstars = ["*"]
-
- test_config = ClientConfiguration()
-
- self.test_bot = Bot(Brain(BrainConfiguration()), config=test_config.bot_configuration)
- self.test_clientid = "testid"
-
- conversation = self.test_bot.get_conversation(self.test_clientid)
- question = Question.create_from_sentence(self.test_sentence)
- conversation._questions.append(question)
-
- def test_eval_simple(self):
+ def test_eval_simple(self):
template = ET.fromstring("""
sometext
@@ -54,7 +30,8 @@ def test_eval_simple(self):
self.assertEqual(eval_node.resolve(self.test_bot, self.test_clientid), "sometext")
- def test_learn_simple(self):
+ def test_learn_simple(self):
+
template = ET.fromstring("""
@@ -90,7 +67,7 @@ def test_learn_simple(self):
response = self.test_bot.ask_question(self.test_clientid, "HELLO WORLD THERE")
self.assertEqual("HIYA", response)
- def test_learnf_simple(self):
+ def test_learnf_simple(self):
template = ET.fromstring("""
diff --git a/src/test/parser/template/graph/test_lists.py b/src/test/parser/template/graph/test_lists.py
index 9d9176753..2089b957a 100644
--- a/src/test/parser/template/graph/test_lists.py
+++ b/src/test/parser/template/graph/test_lists.py
@@ -1,25 +1,9 @@
import unittest
-import xml.etree.ElementTree as ET
-
-from programy.bot import Bot
-from programy.brain import Brain
-from programy.config import ClientConfiguration, BrainConfiguration
-from programy.dialog import Question, Sentence
-from programy.parser.template.graph import TemplateGraph
from programy.parser.template.nodes import *
+from test.parser.template.graph.test_graph_client import TemplateGraphTestClient
-class TemplateGraphListProcessingTests(unittest.TestCase):
-
- def setUp(self):
- self.parser = TemplateGraph()
- self.assertIsNotNone(self.parser)
-
- self.test_brain = None
- test_config = ClientConfiguration()
- self.test_bot = Bot(Brain(BrainConfiguration()), config=test_config.bot_configuration)
- self.test_clientid = "testid"
-
+class TemplateGraphListProcessingTests(TemplateGraphTestClient):
def test_first(self):
template = ET.fromstring("""
diff --git a/src/test/parser/template/graph/test_map.py b/src/test/parser/template/graph/test_map.py
index 0060c2b5c..b18029192 100644
--- a/src/test/parser/template/graph/test_map.py
+++ b/src/test/parser/template/graph/test_map.py
@@ -1,35 +1,9 @@
import unittest
-import xml.etree.ElementTree as ET
-
-from programy.bot import Bot
-from programy.brain import Brain
-from programy.config import ClientConfiguration, BrainConfiguration
-from programy.dialog import Question, Sentence
-from programy.parser.template.graph import TemplateGraph
from programy.parser.template.nodes import *
+from test.parser.template.graph.test_graph_client import TemplateGraphTestClient
-class TemplateGraphMapTests(unittest.TestCase):
-
- def setUp(self):
- self.parser = TemplateGraph()
- self.assertIsNotNone(self.parser)
-
- self.test_brain = None
- self.test_sentence = Sentence("test sentence")
- self.test_sentence._stars = ['one', 'two', 'three', 'four', 'five', 'six']
- self.test_sentence._thatstars = ["*"]
- self.test_sentence._topicstars = ["*"]
-
- test_config = ClientConfiguration()
-
- self.test_bot = Bot(Brain(BrainConfiguration()), config=test_config.bot_configuration)
- self.test_clientid = "testid"
-
- conversation = self.test_bot.get_conversation(self.test_clientid)
- question = Question.create_from_sentence(self.test_sentence)
- conversation._questions.append(question)
-
+class TemplateGraphMapTests(TemplateGraphTestClient):
def test_map_name_as_attrib(self):
template = ET.fromstring("""
diff --git a/src/test/parser/template/graph/test_random.py b/src/test/parser/template/graph/test_random.py
index 5f3e2ff7e..964944db7 100644
--- a/src/test/parser/template/graph/test_random.py
+++ b/src/test/parser/template/graph/test_random.py
@@ -1,34 +1,10 @@
import unittest
-import xml.etree.ElementTree as ET
-
-from programy.bot import Bot
-from programy.brain import Brain
-from programy.config import ClientConfiguration, BrainConfiguration
-from programy.dialog import Question, Sentence
-from programy.parser.template.graph import TemplateGraph
from programy.parser.template.nodes import *
+from test.parser.template.graph.test_graph_client import TemplateGraphTestClient
-class TemplateGraphRandomTests(unittest.TestCase):
-
- def setUp(self):
- self.parser = TemplateGraph()
- self.assertIsNotNone(self.parser)
-
- self.test_brain = None
- self.test_sentence = Sentence("test sentence")
- self.test_sentence._stars = ['one', 'two', 'three', 'four', 'five', 'six']
- self.test_sentence._thatstars = ["*"]
- self.test_sentence._topicstars = ["*"]
-
- test_config = ClientConfiguration()
-
- self.test_bot = Bot(Brain(BrainConfiguration()), config=test_config.bot_configuration)
- self.test_clientid = "testid"
+class TemplateGraphRandomTests(TemplateGraphTestClient):
- conversation = self.test_bot.get_conversation(self.test_clientid)
- question = Question.create_from_sentence(self.test_sentence)
- conversation._questions.append(question)
def test_random_template_no_li(self):
template = ET.fromstring("""
diff --git a/src/test/parser/template/graph/test_req_resp.py b/src/test/parser/template/graph/test_req_resp.py
index dd52b7ed6..bb75c5732 100644
--- a/src/test/parser/template/graph/test_req_resp.py
+++ b/src/test/parser/template/graph/test_req_resp.py
@@ -1,34 +1,11 @@
import unittest
import xml.etree.ElementTree as ET
-from programy.bot import Bot
-from programy.brain import Brain
-from programy.config import ClientConfiguration, BrainConfiguration
-from programy.dialog import Question, Sentence
-from programy.parser.template.graph import TemplateGraph
from programy.parser.template.nodes import *
+from test.parser.template.graph.test_graph_client import TemplateGraphTestClient
-class TemplateGraphBasicRequestResponseTests(unittest.TestCase):
-
- def setUp(self):
- self.parser = TemplateGraph()
- self.assertIsNotNone(self.parser)
-
- self.test_brain = None
- self.test_sentence = Sentence("test sentence")
- self.test_sentence._stars = ['one', 'two', 'three', 'four', 'five', 'six']
- self.test_sentence._thatstars = ["*"]
- self.test_sentence._topicstars = ["*"]
-
- test_config = ClientConfiguration()
-
- self.test_bot = Bot(Brain(BrainConfiguration()), config=test_config.bot_configuration)
- self.test_clientid = "testid"
-
- conversation = self.test_bot.get_conversation(self.test_clientid)
- question = Question.create_from_sentence(self.test_sentence)
- conversation._questions.append(question)
+class TemplateGraphBasicRequestResponseTests(TemplateGraphTestClient):
def test_response_index_as_attrib_full(self):
template = ET.fromstring("""
diff --git a/src/test/parser/template/graph/test_set.py b/src/test/parser/template/graph/test_set.py
index 5bdc0f3f3..00de5c8e4 100644
--- a/src/test/parser/template/graph/test_set.py
+++ b/src/test/parser/template/graph/test_set.py
@@ -1,34 +1,11 @@
import unittest
import xml.etree.ElementTree as ET
-from programy.bot import Bot
-from programy.brain import Brain
-from programy.config import ClientConfiguration, BrainConfiguration
-from programy.dialog import Question, Sentence
-from programy.parser.template.graph import TemplateGraph
from programy.parser.template.nodes import *
+from test.parser.template.graph.test_graph_client import TemplateGraphTestClient
-class TemplateGraphSetTests(unittest.TestCase):
-
- def setUp(self):
- self.parser = TemplateGraph()
- self.assertIsNotNone(self.parser)
-
- self.test_brain = None
- self.test_sentence = Sentence("test sentence")
- self.test_sentence._stars = ['one', 'two', 'three', 'four', 'five', 'six']
- self.test_sentence._thatstars = ["*"]
- self.test_sentence._topicstars = ["*"]
-
- test_config = ClientConfiguration()
-
- self.test_bot = Bot(Brain(BrainConfiguration()), config=test_config.bot_configuration)
- self.test_clientid = "testid"
-
- conversation = self.test_bot.get_conversation(self.test_clientid)
- question = Question.create_from_sentence(self.test_sentence)
- conversation._questions.append(question)
+class TemplateGraphSetTests(TemplateGraphTestClient):
def test_set_template_predicate_as_attrib(self):
template = ET.fromstring("""
diff --git a/src/test/parser/template/graph/test_srai.py b/src/test/parser/template/graph/test_srai.py
index 911c6442b..b2fb71264 100644
--- a/src/test/parser/template/graph/test_srai.py
+++ b/src/test/parser/template/graph/test_srai.py
@@ -1,34 +1,10 @@
import unittest
-import xml.etree.ElementTree as ET
-from programy.bot import Bot
-from programy.brain import Brain
-from programy.config import ClientConfiguration, BrainConfiguration
-from programy.dialog import Question, Sentence
-from programy.parser.template.graph import TemplateGraph
from programy.parser.template.nodes import *
+from test.parser.template.graph.test_graph_client import TemplateGraphTestClient
-class TemplateGraphSraiTests(unittest.TestCase):
-
- def setUp(self):
- self.parser = TemplateGraph()
- self.assertIsNotNone(self.parser)
-
- self.test_brain = None
- self.test_sentence = Sentence("test sentence")
- self.test_sentence._stars = ['one', 'two', 'three', 'four', 'five', 'six']
- self.test_sentence._thatstars = ["*"]
- self.test_sentence._topicstars = ["*"]
-
- test_config = ClientConfiguration()
-
- self.test_bot = Bot(Brain(BrainConfiguration()), config=test_config.bot_configuration)
- self.test_clientid = "testid"
-
- conversation = self.test_bot.get_conversation(self.test_clientid)
- question = Question.create_from_sentence(self.test_sentence)
- conversation._questions.append(question)
+class TemplateGraphSraiTests(TemplateGraphTestClient):
def test_srai_template_simple(self):
template = ET.fromstring("""
diff --git a/src/test/parser/template/graph/test_sraix.py b/src/test/parser/template/graph/test_sraix.py
index 8a5f05640..ac5cd1b61 100644
--- a/src/test/parser/template/graph/test_sraix.py
+++ b/src/test/parser/template/graph/test_sraix.py
@@ -1,34 +1,9 @@
import unittest
-import xml.etree.ElementTree as ET
-
-from programy.bot import Bot
-from programy.brain import Brain
-from programy.config import ClientConfiguration, BrainConfiguration
-from programy.dialog import Question, Sentence
-from programy.parser.template.graph import TemplateGraph
from programy.parser.template.nodes import *
+from test.parser.template.graph.test_graph_client import TemplateGraphTestClient
-class TemplateGraphSraixTests(unittest.TestCase):
-
- def setUp(self):
- self.parser = TemplateGraph()
- self.assertIsNotNone(self.parser)
-
- self.test_brain = None
- self.test_sentence = Sentence("test sentence")
- self.test_sentence._stars = ['one', 'two', 'three', 'four', 'five', 'six']
- self.test_sentence._thatstars = ["*"]
- self.test_sentence._topicstars = ["*"]
-
- test_config = ClientConfiguration()
-
- self.test_bot = Bot(Brain(BrainConfiguration()), config=test_config.bot_configuration)
- self.test_clientid = "testid"
-
- conversation = self.test_bot.get_conversation(self.test_clientid)
- question = Question.create_from_sentence(self.test_sentence)
- conversation._questions.append(question)
+class TemplateGraphSraixTests(TemplateGraphTestClient):
def test_sraix_template_params_as_attribs(self):
template = ET.fromstring("""
diff --git a/src/test/parser/template/graph/test_star.py b/src/test/parser/template/graph/test_star.py
index ec87203ed..aabf689dd 100644
--- a/src/test/parser/template/graph/test_star.py
+++ b/src/test/parser/template/graph/test_star.py
@@ -1,34 +1,8 @@
import unittest
-import xml.etree.ElementTree as ET
-
-from programy.bot import Bot
-from programy.brain import Brain
-from programy.config import ClientConfiguration, BrainConfiguration
-from programy.dialog import Question, Sentence
-from programy.parser.template.graph import TemplateGraph
from programy.parser.template.nodes import *
+from test.parser.template.graph.test_graph_client import TemplateGraphTestClient
-
-class TemplateGraphStarTests(unittest.TestCase):
-
- def setUp(self):
- self.parser = TemplateGraph()
- self.assertIsNotNone(self.parser)
-
- self.test_brain = None
- self.test_sentence = Sentence("test sentence")
- self.test_sentence._stars = ['one', 'two', 'three', 'four', 'five', 'six']
- self.test_sentence._thatstars = ["*"]
- self.test_sentence._topicstars = ["*"]
-
- test_config = ClientConfiguration()
-
- self.test_bot = Bot(Brain(BrainConfiguration()), config=test_config.bot_configuration)
- self.test_clientid = "testid"
-
- conversation = self.test_bot.get_conversation(self.test_clientid)
- question = Question.create_from_sentence(self.test_sentence)
- conversation._questions.append(question)
+class TemplateGraphStarTests(TemplateGraphTestClient):
def test_star_no_index_full(self):
template = ET.fromstring("""
diff --git a/src/test/parser/template/graph/test_system.py b/src/test/parser/template/graph/test_system.py
index 18ab726dd..73aaea5f1 100644
--- a/src/test/parser/template/graph/test_system.py
+++ b/src/test/parser/template/graph/test_system.py
@@ -1,34 +1,9 @@
import unittest
-import xml.etree.ElementTree as ET
-
-from programy.bot import Bot
-from programy.brain import Brain
-from programy.config import ClientConfiguration, BrainConfiguration
-from programy.dialog import Question, Sentence
-from programy.parser.template.graph import TemplateGraph
from programy.parser.template.nodes import *
+from test.parser.template.graph.test_graph_client import TemplateGraphTestClient
-class TemplateGraphSystemTests(unittest.TestCase):
-
- def setUp(self):
- self.parser = TemplateGraph()
- self.assertIsNotNone(self.parser)
-
- self.test_brain = None
- self.test_sentence = Sentence("test sentence")
- self.test_sentence._stars = ['one', 'two', 'three', 'four', 'five', 'six']
- self.test_sentence._thatstars = ["*"]
- self.test_sentence._topicstars = ["*"]
-
- test_config = ClientConfiguration()
-
- self.test_bot = Bot(Brain(BrainConfiguration()), config=test_config.bot_configuration)
- self.test_clientid = "testid"
-
- conversation = self.test_bot.get_conversation(self.test_clientid)
- question = Question.create_from_sentence(self.test_sentence)
- conversation._questions.append(question)
+class TemplateGraphSystemTests(TemplateGraphTestClient):
def test_system_timeout_as_attrib_full(self):
template = ET.fromstring("""
diff --git a/src/test/parser/template/graph/test_that.py b/src/test/parser/template/graph/test_that.py
index 349065d74..1240cd649 100644
--- a/src/test/parser/template/graph/test_that.py
+++ b/src/test/parser/template/graph/test_that.py
@@ -1,34 +1,9 @@
import unittest
-import xml.etree.ElementTree as ET
-
-from programy.bot import Bot
-from programy.brain import Brain
-from programy.config import ClientConfiguration, BrainConfiguration
-from programy.dialog import Question, Sentence
-from programy.parser.template.graph import TemplateGraph
from programy.parser.template.nodes import *
+from test.parser.template.graph.test_graph_client import TemplateGraphTestClient
-class TemplateGraphThatTests(unittest.TestCase):
-
- def setUp(self):
- self.parser = TemplateGraph()
- self.assertIsNotNone(self.parser)
-
- self.test_brain = None
- self.test_sentence = Sentence("test sentence")
- self.test_sentence._stars = ['one', 'two', 'three', 'four', 'five', 'six']
- self.test_sentence._thatstars = ["*"]
- self.test_sentence._topicstars = ["*"]
-
- test_config = ClientConfiguration()
-
- self.test_bot = Bot(Brain(BrainConfiguration()), config=test_config.bot_configuration)
- self.test_clientid = "testid"
-
- conversation = self.test_bot.get_conversation(self.test_clientid)
- question = Question.create_from_sentence(self.test_sentence)
- conversation._questions.append(question)
+class TemplateGraphThatTests(TemplateGraphTestClient):
def test_that_index_as_attrib_full(self):
template = ET.fromstring("""
diff --git a/src/test/parser/template/graph/test_think.py b/src/test/parser/template/graph/test_think.py
index 82ac15147..4ab9ef84d 100644
--- a/src/test/parser/template/graph/test_think.py
+++ b/src/test/parser/template/graph/test_think.py
@@ -1,34 +1,9 @@
import unittest
-import xml.etree.ElementTree as ET
-
-from programy.bot import Bot
-from programy.brain import Brain
-from programy.config import ClientConfiguration, BrainConfiguration
-from programy.dialog import Question, Sentence
-from programy.parser.template.graph import TemplateGraph
from programy.parser.template.nodes import *
+from test.parser.template.graph.test_graph_client import TemplateGraphTestClient
-class TemplateGraphThinkTests(unittest.TestCase):
-
- def setUp(self):
- self.parser = TemplateGraph()
- self.assertIsNotNone(self.parser)
-
- self.test_brain = None
- self.test_sentence = Sentence("test sentence")
- self.test_sentence._stars = ['one', 'two', 'three', 'four', 'five', 'six']
- self.test_sentence._thatstars = ["*"]
- self.test_sentence._topicstars = ["*"]
-
- test_config = ClientConfiguration()
-
- self.test_bot = Bot(Brain(BrainConfiguration()), config=test_config.bot_configuration)
- self.test_clientid = "testid"
-
- conversation = self.test_bot.get_conversation(self.test_clientid)
- question = Question.create_from_sentence(self.test_sentence)
- conversation._questions.append(question)
+class TemplateGraphThinkTests(TemplateGraphTestClient):
def test_think(self):
template = ET.fromstring("""
diff --git a/src/test/parser/template/graph/test_topic.py b/src/test/parser/template/graph/test_topic.py
index 4cb670491..394ad23eb 100644
--- a/src/test/parser/template/graph/test_topic.py
+++ b/src/test/parser/template/graph/test_topic.py
@@ -1,34 +1,10 @@
import unittest
-import xml.etree.ElementTree as ET
-
-from programy.bot import Bot
-from programy.brain import Brain
-from programy.config import ClientConfiguration, BrainConfiguration
-from programy.dialog import Question, Sentence
-from programy.parser.template.graph import TemplateGraph
from programy.parser.template.nodes import *
+from test.parser.template.graph.test_graph_client import TemplateGraphTestClient
-class TemplateGraphTopicTests(unittest.TestCase):
-
- def setUp(self):
- self.parser = TemplateGraph()
- self.assertIsNotNone(self.parser)
-
- self.test_brain = None
- self.test_sentence = Sentence("test sentence")
- self.test_sentence._stars = ['one', 'two', 'three', 'four', 'five', 'six']
- self.test_sentence._thatstars = ["*"]
- self.test_sentence._topicstars = ["*"]
-
- test_config = ClientConfiguration()
-
- self.test_bot = Bot(Brain(BrainConfiguration()), config=test_config.bot_configuration)
- self.test_clientid = "testid"
+class TemplateGraphTopicTests(TemplateGraphTestClient):
- conversation = self.test_bot.get_conversation(self.test_clientid)
- question = Question.create_from_sentence(self.test_sentence)
- conversation._questions.append(question)
def test_topicstar_index_as_attrib_full(self):
template = ET.fromstring("""
diff --git a/src/test/parser/template/graph/test_transforms.py b/src/test/parser/template/graph/test_transforms.py
index 57d7c2eab..f77a2db54 100644
--- a/src/test/parser/template/graph/test_transforms.py
+++ b/src/test/parser/template/graph/test_transforms.py
@@ -1,34 +1,9 @@
import unittest
-import xml.etree.ElementTree as ET
-
-from programy.bot import Bot
-from programy.brain import Brain
-from programy.config import ClientConfiguration, BrainConfiguration
-from programy.dialog import Question, Sentence
-from programy.parser.template.graph import TemplateGraph
from programy.parser.template.nodes import *
+from test.parser.template.graph.test_graph_client import TemplateGraphTestClient
-class TemplateGraphTransformsTests(unittest.TestCase):
-
- def setUp(self):
- self.parser = TemplateGraph()
- self.assertIsNotNone(self.parser)
-
- self.test_brain = None
- self.test_sentence = Sentence("test sentence")
- self.test_sentence._stars = ['one', 'two', 'three', 'four', 'five', 'six']
- self.test_sentence._thatstars = ["*"]
- self.test_sentence._topicstars = ["*"]
-
- test_config = ClientConfiguration()
-
- self.test_bot = Bot(Brain(BrainConfiguration()), config=test_config.bot_configuration)
- self.test_clientid = "testid"
-
- conversation = self.test_bot.get_conversation(self.test_clientid)
- question = Question.create_from_sentence(self.test_sentence)
- conversation._questions.append(question)
+class TemplateGraphTransformsTests(TemplateGraphTestClient):
def test_lowercase(self):
template = ET.fromstring("""
diff --git a/src/test/parser/template/maps/__init__.py b/src/test/parser/template/maps/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/src/test/parser/template/maps/test_pluralmap.py b/src/test/parser/template/maps/test_pluralmap.py
new file mode 100644
index 000000000..2483a3f3a
--- /dev/null
+++ b/src/test/parser/template/maps/test_pluralmap.py
@@ -0,0 +1,17 @@
+import unittest
+
+from programy.parser.template.maps.plural import PluralMap
+
+class TestPluralMaps(unittest.TestCase):
+
+ def test_static_map(self):
+ map = PluralMap()
+ self.assertEqual("MICE", map.map("MOUSE"))
+
+ def test_singular_y_to_plural(self):
+ map = PluralMap()
+ self.assertEqual("HOLLIES", map.map("HOLLY"))
+
+ def test_singular_s_to_plural(self):
+ map = PluralMap()
+ self.assertEqual("COWS", map.map("COW"))
diff --git a/src/test/parser/template/maps/test_predecessormap.py b/src/test/parser/template/maps/test_predecessormap.py
new file mode 100644
index 000000000..7caffb519
--- /dev/null
+++ b/src/test/parser/template/maps/test_predecessormap.py
@@ -0,0 +1,11 @@
+import unittest
+
+from programy.parser.template.maps.predecessor import PredecessorMap
+
+class TestSingularMaps(unittest.TestCase):
+
+ def test_successor(self):
+ map = PredecessorMap()
+ self.assertEqual("1", map.map("2"))
+
+
diff --git a/src/test/parser/template/maps/test_singularmap.py b/src/test/parser/template/maps/test_singularmap.py
new file mode 100644
index 000000000..aae5241d4
--- /dev/null
+++ b/src/test/parser/template/maps/test_singularmap.py
@@ -0,0 +1,18 @@
+import unittest
+
+from programy.parser.template.maps.singular import SingularMap
+
+class TestSingularMaps(unittest.TestCase):
+
+ def test_static_map(self):
+ map = SingularMap()
+ self.assertEqual("MOUSE", map.map("MICE"))
+
+ def test_plural_ies_to_singular(self):
+ map = SingularMap()
+ self.assertEqual("HOLLY", map.map("HOLLIES"))
+
+ def test_plural_s_to_singular(self):
+ map = SingularMap()
+ self.assertEqual("CURL", map.map("CURLS"))
+
diff --git a/src/test/parser/template/maps/test_successormap.py b/src/test/parser/template/maps/test_successormap.py
new file mode 100644
index 000000000..3be3805dd
--- /dev/null
+++ b/src/test/parser/template/maps/test_successormap.py
@@ -0,0 +1,11 @@
+import unittest
+
+from programy.parser.template.maps.successor import SuccessorMap
+
+class TestSingularMaps(unittest.TestCase):
+
+ def test_successor(self):
+ map = SuccessorMap()
+ self.assertEqual("2", map.map("1"))
+
+
diff --git a/src/test/parser/template/test_nodes.py b/src/test/parser/template/test_nodes.py
index 7c1f48192..2a709a75d 100644
--- a/src/test/parser/template/test_nodes.py
+++ b/src/test/parser/template/test_nodes.py
@@ -4,9 +4,9 @@
from programy.bot import Bot
from programy.brain import Brain
from programy.dialog import Conversation, Question
+from programy.config import BrainConfiguration, BotConfiguration, BrainFileConfiguration
from test.parser.template.base import TemplateTestsBaseClass
-from programy.config import BrainConfiguration, BotConfiguration, BrainFileConfiguration
######################################################################################################################
#
diff --git a/src/test/parser/test_aiml_parser.py b/src/test/parser/test_aiml_parser.py
index e8542d8b3..d7e0807d7 100644
--- a/src/test/parser/test_aiml_parser.py
+++ b/src/test/parser/test_aiml_parser.py
@@ -3,8 +3,10 @@
from programy.parser.aiml_parser import AIMLParser
from programy.parser.pattern.nodes import *
+from programy.dialog import Sentence
class AIMLParserTests(unittest.TestCase):
+
def setUp(self):
self.parser = AIMLParser(supress_warnings=True, stop_on_invalid=True)
self.assertIsNotNone(self.parser)
@@ -677,6 +679,23 @@ def test_base_aiml_multiple_categories_in_and_out_of_topic(self):
self.assertIsInstance(that.star, PatternOneOrMoreWildCardNode)
self.assertEquals(that.star.wildcard, "*")
+ def test_match_sentence(self):
+
+ self.parser.parse_from_text(
+ """
+
+
+ HELLO
+ Hiya
+
+
+ """)
+
+ self.parser.pattern_parser.dump()
+
+ context = self.parser.match_sentence(None, "test", Sentence("HELLO"), "*", "*")
+ self.assertIsNotNone(context)
+ self.assertEqual("Hiya", context.template_node().template.resolve(None, None))
if __name__ == '__main__':
unittest.main()
diff --git a/src/test/utils/classes/test_loader.py b/src/test/utils/classes/test_loader.py
index 7b269b662..748c91b42 100644
--- a/src/test/utils/classes/test_loader.py
+++ b/src/test/utils/classes/test_loader.py
@@ -11,7 +11,7 @@ def test_instantiate_module_class(self):
loader = ClassLoader()
self.assertIsNotNone(loader)
- meta_class = loader.instantiate_class("test.testclass.TestClass")
+ meta_class = loader.instantiate_class("test.utils.classes.testclass.TestClass")
self.assertIsNotNone(meta_class)
new_class = meta_class()
self.assertIsNotNone(new_class)
diff --git a/src/test/testclass.py b/src/test/utils/classes/testclass.py
similarity index 100%
rename from src/test/testclass.py
rename to src/test/utils/classes/testclass.py
diff --git a/src/test/utils/text/__init__.py b/src/test/utils/text/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/src/test/utils/text/test_text.py b/src/test/utils/text/test_text.py
new file mode 100644
index 000000000..c8e8b9398
--- /dev/null
+++ b/src/test/utils/text/test_text.py
@@ -0,0 +1,41 @@
+import unittest
+from programy.utils.text.text import TextUtils
+
+#############################################################################
+#
+
+class TextUtilsTests(unittest.TestCase):
+
+ def test_get_tabs(self):
+ tabs = TextUtils.get_tabs(0)
+ self.assertEqual(tabs, "")
+
+ tabs = TextUtils.get_tabs(1, tabs="\t")
+ self.assertEqual(tabs, "\t")
+
+ tabs = TextUtils.get_tabs(5, tabs="\t")
+ self.assertEqual(tabs, "\t\t\t\t\t")
+
+ def test_strip_whitespace(self):
+ self.assertEquals("", TextUtils.strip_whitespace(""))
+ self.assertEquals("", TextUtils.strip_whitespace(" "))
+ self.assertEquals("", TextUtils.strip_whitespace("\t"))
+ self.assertEquals("", TextUtils.strip_whitespace("\n"))
+ self.assertEquals("", TextUtils.strip_whitespace("\r"))
+ self.assertEquals("", TextUtils.strip_whitespace("\r\t\n"))
+ self.assertEquals("test", TextUtils.strip_whitespace("\r\t\ntest\r\t\n"))
+ self.assertEquals("test test", TextUtils.strip_whitespace("\r\t\ntest test\r\t\n"))
+ self.assertEquals("test test", TextUtils.strip_whitespace("\r\t\ntest\n\r\ttest\r\t\n"))
+
+ def test_strip_all_whitespace(self):
+ self.assertEquals("", TextUtils.strip_all_whitespace(""))
+ self.assertEquals("", TextUtils.strip_all_whitespace(" "))
+ self.assertEquals("", TextUtils.strip_all_whitespace("\t"))
+ self.assertEquals("", TextUtils.strip_all_whitespace("\n"))
+ self.assertEquals("", TextUtils.strip_all_whitespace("\r"))
+ self.assertEquals("", TextUtils.strip_all_whitespace("\r\t\n"))
+ self.assertEquals("test", TextUtils.strip_all_whitespace("\r\t\ntest\r\t\n"))
+ self.assertEquals("testtest", TextUtils.strip_all_whitespace("\r\t\ntest test\r\t\n"))
+ self.assertEquals("testtest", TextUtils.strip_all_whitespace("\r\t\ntest\n\r\ttest\r\t\n"))
+
+