def test_assignment_within_disjunction():
    vars = {}
    natex = NatexNLU('{$A=hello, $A=hi}')
    assert natex.match('hello', vars=vars)
    assert vars['A'] == 'hello'
    vars = {}
    assert natex.match('hi', vars=vars, debugging=False)
    assert vars['A'] == 'hi'
Exemple #2
0
def test_assignment_within_disjunction():
    vars = {}
    natex = NatexNLU("{$A=hello, $A=hi}")
    assert natex.match("hello", vars=vars)
    assert vars["A"] == "hello"
    vars = {}
    assert natex.match("hi", vars=vars, debugging=False)
    assert vars["A"] == "hi"
 def __init__(self, macro_dependencies=None):
     if macro_dependencies is None: macro_dependencies = {}
     self.natex = NatexNLU(natex_string,
                           macros={
                               **mc.macros_common_dict,
                               **macro_dependencies
                           })
     self.natex.precache()
 def __init__(self, macro_dependencies=None):
     if macro_dependencies is None: macro_dependencies = {}
     self.natex = NatexNLU(natex_string,
                           macros={
                               **mc.macros_common_dict,
                               **macro_dependencies
                           })
     self.natex.compile()
     self.natex._regex = self.natex.regex().replace("_END_", "").strip()
Exemple #5
0
    class _CommonNatex(Macro):
        def __init__(self, macro_dependencies=None):
            if macro_dependencies is None:
                macro_dependencies = {}
            self.natex = NatexNLU(natex_string, macros={**macro_dependencies})
            self.natex.compile()
            self.natex._regex = self.natex.regex().replace("_END_", "").strip()

        def run(self, ngrams: Ngrams, vars: Dict[str, Any], args: List[Any]):
            return self.natex.regex()
Exemple #6
0
    class _CommonNatex(Macro):
        def __init__(self, macro_dependencies=None):
            if macro_dependencies is None:
                macro_dependencies = {}
            self.natex = NatexNLU(natex_string, macros={**macro_dependencies})
            self.natex.precache()

        def run(self, ngrams: Ngrams, vars: Dict[str, Any], args: List[Any]):
            match = self.natex.match(ngrams.text(), vars=vars)
            return bool(match)
Exemple #7
0
 def run(self, ngrams: Ngrams, vars: Dict[str, Any], args: List[Any]):
     if len(args) > 1:
         score = float(args[1])
     else:
         score = 0.5
     if len(args) > 2:
         natex = NatexNLU(args[2], macros=self.dialogue_flow._macros)
     else:
         natex = NatexNLU("/.*/", macros=self.dialogue_flow._macros)
     target = args[0]
     vars["__converged__"] = "True"
     self.dialogue_flow.dynamic_transitions().append(
         (natex, (self.dialogue_flow.state(), target, self.dialogue_flow.speaker()), score)
     )
def test_assignment():
    v = {'A': 'apple'}
    natex = NatexNLU('[!i ate a $A={orange, raddish} today]')
    assert natex.match('i ate a orange today', vars=v, debugging=True)
    assert v['A'] == 'orange'
    assert natex.match('i ate a raddish today', vars=v)
    assert v['A'] == 'raddish'
    assert natex.match('i ate a raddish today')
    assert not natex.match('i ate a carrot today', vars=v)
    natex = NatexNLU('[!i ate a $B={orange, raddish} today]')
    assert natex.match('i ate a raddish today', vars=v)
    assert v['B'] == 'raddish'
Exemple #9
0
def test_assignment():
    v = {"A": "apple"}
    natex = NatexNLU("[!i ate a $A={orange, raddish} today]")
    assert natex.match("i ate a orange today", vars=v, debugging=True)
    assert v["A"] == "orange"
    assert natex.match("i ate a raddish today", vars=v)
    assert v["A"] == "raddish"
    assert natex.match("i ate a raddish today")
    assert not natex.match("i ate a carrot today", vars=v)
    natex = NatexNLU("[!i ate a $B={orange, raddish} today]")
    assert natex.match("i ate a raddish today", vars=v)
    assert v["B"] == "raddish"
Exemple #10
0
def test_simple_macro():
    natex = NatexNLU("[!i #SIMPLE]", macros=macros)
    assert natex.match("i foo")
    assert natex.match("i bar")
    assert not natex.match("i err")
    natex = NatexNLU("[!i #SIMPLE()]", macros=macros)
    assert natex.match("i foo")
    assert natex.match("i bar")
    assert not natex.match("i err")
def test_simple_macro():
    natex = NatexNLU('[!i #SIMPLE]', macros=macros)
    assert natex.match('i foo')
    assert natex.match('i bar')
    assert not natex.match('i err')
    natex = NatexNLU('[!i #SIMPLE()]', macros=macros)
    assert natex.match('i foo')
    assert natex.match('i bar')
    assert not natex.match('i err')
Exemple #12
0
class UpdateRule:
    def __init__(self, precondition, postcondition='', vars=None, macros=None):
        self.precondition = None
        self.precondition_score = 1.0
        self.postcondition = None
        self.postcondition_score = None
        self.is_repeating = len(precondition) > 0 and precondition[0] == '*'
        if self.is_repeating:
            precondition = precondition[1:]
        if macros is None:
            macros = {}
        if vars is None:
            vars = {}
        self.vars = vars
        self.macros = macros
        self.set_precondition(precondition)
        if postcondition:
            self.set_postcondition(postcondition)

    def set_precondition(self, natex_string):
        natex, score = self._natex_string_score(natex_string)
        self.precondition = NatexNLU(natex, macros=self.macros)
        if score:
            self.precondition_score = score

    def set_postcondition(self, natex_string):
        natex, score = self._natex_string_score(natex_string)
        self.postcondition = NatexNLG(natex, macros=self.macros)
        self.postcondition_score = score

    def _natex_string_score(self, natex_string):
        i = natex_string.rfind(' (')
        if i != -1:
            for c in natex_string[i + len(' ('):-1]:
                if c not in set('0123456789.'):
                    return natex_string, None
            return natex_string[:i], float(natex_string[i + len(' ('):-1])
        return natex_string, None

    def satisfied(self, user_input, vars, debugging=False):
        return self.precondition.match(user_input,
                                       vars=vars,
                                       debugging=debugging)

    def apply(self, vars, debugging=False):
        if self.postcondition is not None:
            return self.postcondition.generate(vars=vars, debugging=debugging)
        else:
            return ''

    def set_vars(self, vars):
        self.vars = vars

    def __str__(self):
        return '{} ==> {}'.format(self.precondition, self.postcondition)

    def __repr__(self):
        return str(self)
 def set_transition_natex(self, source, target, speaker, natex):
     source, target = module_source_target(source, target)
     source = State(source)
     target = State(target)
     if isinstance(natex, str):
         if speaker == Speaker.USER:
             natex = NatexNLU(natex, macros=self._macros)
         else:
             natex = NatexNLG(natex, macros=self._macros)
     self._graph.arc_data(source, target, speaker)['natex'] = natex
def test_backreference():
    natex = NatexNLU('[!$A good eat $A={apple, banana}]')
    v = {'A': 'apple'}
    assert natex.match('apple good eat banana', vars=v, debugging=False)
    assert v['A'] == 'banana'
    natex = NatexNLU('[!$A={apple, banana} good eat $A]')
    v = {'A': 'apple'}
    assert natex.match('banana good eat banana', vars=v, debugging=False)
    assert v['A'] == 'banana'
    assert not natex.match('apple good eat banana', debugging=False)
    assert v['A'] != 'apple'
Exemple #15
0
def test_backreference():
    natex = NatexNLU("[!$A good eat $A={apple, banana}]")
    v = {"A": "apple"}
    assert natex.match("apple good eat banana", vars=v, debugging=False)
    assert v["A"] == "banana"
    natex = NatexNLU("[!$A={apple, banana} good eat $A]")
    v = {"A": "apple"}
    assert natex.match("banana good eat banana", vars=v, debugging=False)
    assert v["A"] == "banana"
    assert not natex.match("apple good eat banana", debugging=False)
    assert v["A"] != "apple"
def test_reference():
    v1 = {'A': 'apple', 'B': 'brown', 'C': 'charlie'}
    v2 = {'C': 'candice'}
    natex = NatexNLU('[!i saw $C today]')
    assert natex.match('i saw charlie today', vars=v1, debugging=False)
    assert natex.match('i saw charlie today', debugging=False) is None
    assert not natex.match('i saw candice today', vars=v1)
    assert natex.match('i saw candice today', vars=v2)
Exemple #17
0
def test_reference():
    v1 = {"A": "apple", "B": "brown", "C": "charlie"}
    v2 = {"C": "candice"}
    natex = NatexNLU("[!i saw $C today]")
    assert natex.match("i saw charlie today", vars=v1, debugging=False)
    assert natex.match("i saw charlie today", debugging=False) is None
    assert not natex.match("i saw candice today", vars=v1)
    assert natex.match("i saw candice today", vars=v2)
Exemple #18
0
class Unexpected(Macro):
    def __init__(self):
        self.question_natex = NatexNLU(question)

    def run(self, ngrams: Ngrams, vars: Dict[str, Any], args: List[Any]):
        statement_only = 's' in args or 'state' in args or 'statement' in args
        vars['__score__'] = 0.0
        if '__previous_unx_response__' not in vars:
            vars['__previous_unx_response__'] = 'Gotcha.'
        if '__previous_unx_answer__' not in vars:
            vars['__previous_unx_answer__'] = 'None'

        is_question = self.question_natex.match(ngrams.text())
        if is_question and statement_only:
            return False
        elif is_question:
            if '_explained_stupidity_' in vars and vars[
                    '_explained_stupidity_'] == 'True':
                options = {
                    'I\'m not sure.', 'I don\'t know.',
                    'I\'m not sure about that.', ''
                } - {vars['__previous_unx_response__']}
                question_response = random.choice(list(options))
                vars['__previous_unx_answer__'] = question_response
                vars['__response_prefix__'] = question_response
            else:
                vars['_explained_stupidity_'] = 'True'
                vars['__response_prefix__'] = 'I\'m not sure.'
        elif len(ngrams.text().split()) < 3 and len(args) == 0:
            vars['__response_prefix__'] = ''
            return True
        else:
            options = {'Yeah.', 'For sure.', 'Right.', 'Uh-huh.'
                       } - {vars['__previous_unx_response__']}
            statement_response = random.choice(list(options))
            if len(args) > 0:
                statement_response = ', '.join([
                    arg
                    for arg in args if arg not in {'s', 'state', 'statement'}
                ]) + ', '
                if args[0] == 'None':
                    statement_response = ''
            vars['__previous_unx_response__'] = statement_response
            vars['__response_prefix__'] = statement_response
        return True
Exemple #19
0
class Unexpected(Macro):
    def __init__(self):
        self.question_natex = NatexNLU(question)

    def run(self, ngrams: Ngrams, vars: Dict[str, Any], args: List[Any]):
        statement_only = "s" in args or "state" in args or "statement" in args
        vars["__score__"] = 0.0
        if "__previous_unx_response__" not in vars:
            vars["__previous_unx_response__"] = "Gotcha."
        if "__previous_unx_answer__" not in vars:
            vars["__previous_unx_answer__"] = "None"

        is_question = self.question_natex.match(ngrams.text())
        if is_question and statement_only:
            return False
        elif is_question:
            if "_explained_stupidity_" in vars and vars[
                    "_explained_stupidity_"] == "True":
                options = {
                    "I'm not sure.", "I don't know.",
                    "I'm not sure about that.", ""
                } - {vars["__previous_unx_response__"]}
                question_response = random.choice(list(options))
                vars["__previous_unx_answer__"] = question_response
                vars["__response_prefix__"] = question_response
            else:
                vars["_explained_stupidity_"] = "True"
                vars["__response_prefix__"] = "I'm not sure."
        elif len(ngrams.text().split()) < 3 and len(args) == 0:
            vars["__response_prefix__"] = ""
            return True
        else:
            options = {"Yeah.", "For sure.", "Right.", "Uh-huh."
                       } - {vars["__previous_unx_response__"]}
            statement_response = random.choice(list(options))
            if len(args) > 0:
                statement_response = ", ".join([
                    arg
                    for arg in args if arg not in {"s", "state", "statement"}
                ]) + ", "
                if args[0] == "None":
                    statement_response = ""
            vars["__previous_unx_response__"] = statement_response
            vars["__response_prefix__"] = statement_response
        return True
 def add_user_transition(self, source: Union[Enum, str, tuple], target: Union[Enum, str, tuple],
                         natex_nlu: Union[str, NatexNLU, List[str]], **settings):
     source, target = module_source_target(source, target)
     source = State(source)
     target = State(target)
     if self.has_transition(source, target, Speaker.USER):
         raise ValueError('user transition {} -> {} already exists'.format(source, target))
     natex_nlu = NatexNLU(natex_nlu, macros=self._macros)
     if not self.has_state(source):
         self.add_state(source)
     if not self.has_state(target):
         self.add_state(target)
     self._graph.add_arc(source, target, Speaker.USER)
     self.set_transition_natex(source, target, Speaker.USER, natex_nlu)
     transition_settings = Settings(score=1.0)
     transition_settings.update(**settings)
     if self._all_multi_hop:
         self.update_state_settings(source, user_multi_hop=True)
     self.set_transition_settings(source, target, Speaker.USER, transition_settings)
     if target in self._prepends:
         prepend = self._prepends[target]
         natex = self.transition_natex(source, target, Speaker.USER)
         self.set_transition_natex(source, target, Speaker.USER, prepend + natex)
Exemple #21
0
            if len(args) > 0:
                statement_response = ', '.join([
                    arg
                    for arg in args if arg not in {'s', 'state', 'statement'}
                ]) + ', '
                if args[0] == 'None':
                    statement_response = ''
            vars['__previous_unx_response__'] = statement_response
            vars['__response_prefix__'] = statement_response
        return True


natex_macros_common = {
    'AGREE': Agree(),
    'DISAGREE': Disagree(),
    'QUESTION': Question(),
    'NEGATION': Negation(),
    'IDK': DontKnow(),
    'MAYBE': Maybe(),
    'CONFIRM': Confirm(),
    'UNINTERESTED': Uninterested(),
    'NOTINTERESTED': NotInterested(),
    'INTERESTED': Interested(),
    'UNX': Unexpected(),
    'PRIVATE': DeclineShare(),
}

if __name__ == '__main__':
    from emora_stdm.state_transition_dialogue_manager.natex_nlu import NatexNLU
    print(NatexNLU(question).match("i don't know"))
Exemple #22
0
def test_kleene_plus():
    natex = NatexNLU("[!i, really+, love, sports]")
    assert natex.match("i really love sports")
    assert natex.match("i really really really love sports")
    assert not natex.match("i love sports")
Exemple #23
0
def test_conjunction():
    natex = NatexNLU("<quick, fox, brown, dog>")
    assert natex.match("the quick fox and the brown dog", debugging=False)
    assert natex.match("the brown fox and the quick dog")
    assert not natex.match("the fox and the quick dog")
Exemple #24
0
 def set_precondition(self, natex_string):
     natex, score = self._natex_string_score(natex_string)
     self.precondition = NatexNLU(natex, macros=self.macros)
     if score:
         self.precondition_score = score
Exemple #25
0
def test_optional():
    natex = NatexNLU("[!i, really?, love sports]")
    assert natex.match("i really love sports", debugging=False)
    assert natex.match("i love sports")
    assert not natex.match("i sports")
Exemple #26
0
def test_negation():
    natex = NatexNLU("-[{bad, horrible, not}]")
    assert natex.match("i am good")
    assert natex.match("good")
    assert not natex.match("i am not good")
    assert not natex.match("i am horrible")
    assert not natex.match("bad")
    natex = NatexNLU("[!-bad [good]]")
    assert natex.match("good")
    assert not natex.match("bad but good", debugging=False)
    assert not natex.match("good but bad")
    assert natex.match("im good sort of")
    assert not natex.match("im good sort of but bad")
    assert not natex.match("im bad but also good")
Exemple #27
0
 def __init__(self):
     self.question_natex = NatexNLU(question)
Exemple #28
0
def test_integration_opening_component():

    kb = KnowledgeBase()
    kb.load_json_file("opening_database.json")

    receive_how_are_you = ("{"
                           "[how are you],"
                           "[how you doing],"
                           "[what about you],"
                           "[whats up with you],"
                           "[how you are],"
                           "[how about you]"
                           "}")

    feelings_pos_and_not_received_how_are_you = (
        "{"
        "[!#ONT_NEG(ont_negation), -%s, [#ONT(ont_feelings_positive)]],"
        "[! -%s, [#ONT(ont_negation)], [#ONT(ont_feelings_negative)]],"
        "#IsPositiveSentiment"
        "}" % (receive_how_are_you, receive_how_are_you))

    nlu = NatexNLU(
        feelings_pos_and_not_received_how_are_you,
        macros={
            "ONT": ONTE(kb),
            "ONT_NEG": ONT_NEG(kb)
        },
    )

    m = nlu.match("im not too bad", debugging=False)
    assert m
    m = nlu.match("great i guess", debugging=False)
    assert m
    m = nlu.match("great", debugging=False)
    assert m
    m = nlu.match("i seem to be pretty great thanks", debugging=False)
    assert m
    m = nlu.match("not bad", debugging=False)
    assert m
    m = nlu.match("thanks im not bad dude", debugging=False)
    assert m
    m = nlu.match("well how are you", debugging=False)
    assert not m
    m = nlu.match("pretty well how are you", debugging=False)
    assert not m
    m = nlu.match("not well how are you", debugging=False)
    assert not m
    m = nlu.match("how are you im not well", debugging=False)
    assert not m
    m = nlu.match("im bad", debugging=False)
    assert not m
    m = nlu.match("bad", debugging=False)
    assert not m
    m = nlu.match("im doing ok", debugging=False)
    assert not m
    feelings_neg_and_not_received_how_are_you = (
        "{"
        "[!#ONT_NEG(ont_negation), -%s, [#ONT(ont_feelings_negative)]],"
        "[! -%s, [#ONT(ont_negation)], [{#ONT(ont_feelings_positive),#ONT(ont_feelings_neutral)}]],"
        "#IsNegativeSentiment"
        "}" % (receive_how_are_you, receive_how_are_you))
    nlu = NatexNLU(
        feelings_neg_and_not_received_how_are_you,
        macros={
            "ONT": ONTE(kb),
            "ONT_NEG": ONT_NEG(kb)
        },
    )
    m = nlu.match("bad i guess", debugging=False)
    assert m
    m = nlu.match("bad", debugging=False)
    assert m
    m = nlu.match("i seem to be pretty bad thanks", debugging=False)
    assert m
    m = nlu.match("not good", debugging=False)
    assert m
    m = nlu.match("thanks im not ok dude", debugging=False)
    assert m
    m = nlu.match("great i guess", debugging=False)
    assert not m
    m = nlu.match("great", debugging=False)
    assert not m
    m = nlu.match("i seem to be pretty great thanks", debugging=False)
    assert not m
    m = nlu.match("not bad", debugging=False)
    assert not m
    m = nlu.match("thanks im not bad dude", debugging=False)
    assert not m
    m = nlu.match("ok how are you", debugging=False)
    assert not m
    m = nlu.match("pretty well how are you", debugging=False)
    assert not m
    m = nlu.match("not well how are you", debugging=False)
    assert not m
    m = nlu.match("how are you im not well", debugging=False)
    assert not m
    feelings_neutral_and_not_received_how_are_you = (
        "[!#ONT_NEG(ont_negation), -%s, [#ONT(ont_feelings_neutral)]]" %
        (receive_how_are_you))
    nlu = NatexNLU(
        feelings_neutral_and_not_received_how_are_you,
        macros={
            "ONT": ONTE(kb),
            "ONT_NEG": ONT_NEG(kb)
        },
    )
    m = nlu.match("ok i guess", debugging=False)
    assert m
    m = nlu.match("ok", debugging=False)
    assert m
    m = nlu.match("i seem to be ok thanks", debugging=False)
    assert m
    m = nlu.match("great i guess", debugging=False)
    assert not m
    m = nlu.match("great", debugging=False)
    assert not m
    m = nlu.match("i seem to be pretty great thanks", debugging=False)
    assert not m
    m = nlu.match("not bad", debugging=False)
    assert not m
    m = nlu.match("thanks im not bad dude", debugging=False)
    assert not m
    m = nlu.match("ok how are you", debugging=False)
    assert not m
    m = nlu.match("pretty well how are you", debugging=False)
    assert not m
    m = nlu.match("not well how are you", debugging=False)
    assert not m
    m = nlu.match("how are you im not well", debugging=False)
    assert not m
    m = nlu.match("bad i guess", debugging=False)
    assert not m
    m = nlu.match("bad", debugging=False)
    assert not m
    m = nlu.match("i seem to be pretty bad thanks", debugging=False)
    assert not m
    m = nlu.match("not good", debugging=False)
    assert not m
    m = nlu.match("thanks im not ok dude", debugging=False)
    assert not m
    feelings_pos_and_received_how_are_you = (
        "{"
        "[!#ONT_NEG(ont_negation), [#ONT(ont_feelings_positive)], [%s]],"
        "[#ONT(ont_negation), #ONT(ont_feelings_negative), %s],"
        "<#IsPositiveSentiment, %s>"
        "}" % (receive_how_are_you, receive_how_are_you, receive_how_are_you))
    nlu = NatexNLU(
        feelings_pos_and_received_how_are_you,
        macros={
            "ONT": ONTE(kb),
            "ONT_NEG": ONT_NEG(kb)
        },
    )
    m = nlu.match("pretty well how are you", debugging=False)
    assert m
    m = nlu.match("great how are you", debugging=False)
    assert m
    m = nlu.match("not too bad how are you", debugging=False)
    assert m
    m = nlu.match("not bad how are you", debugging=False)
    assert m
    m = nlu.match("ok i guess", debugging=False)
    assert not m
    m = nlu.match("ok", debugging=False)
    assert not m
    m = nlu.match("i seem to be ok thanks", debugging=False)
    assert not m
    m = nlu.match("great i guess", debugging=False)
    assert not m
    m = nlu.match("great", debugging=False)
    assert not m
    m = nlu.match("i seem to be pretty great thanks", debugging=False)
    assert not m
    m = nlu.match("not bad", debugging=False)
    assert not m
    m = nlu.match("thanks im not bad dude", debugging=False)
    assert not m
    m = nlu.match("ok how are you", debugging=False)
    assert not m
    m = nlu.match("not well how are you", debugging=False)
    assert not m
    m = nlu.match("how are you im not well", debugging=False)
    assert not m
    m = nlu.match("bad i guess", debugging=False)
    assert not m
    m = nlu.match("bad", debugging=False)
    assert not m
    m = nlu.match("i seem to be pretty bad thanks", debugging=False)
    assert not m
    m = nlu.match("not good", debugging=False)
    assert not m
    m = nlu.match("thanks im not ok dude", debugging=False)
    assert not m
    feelings_neg_and_received_how_are_you = (
        "{"
        "[!#ONT_NEG(ont_negation), [#ONT(ont_feelings_negative)], [%s]],"
        "[#ONT(ont_negation), {#ONT(ont_feelings_positive),#ONT(ont_feelings_neutral)}, %s],"
        "<#IsNegativeSentiment, %s>"
        "}" % (receive_how_are_you, receive_how_are_you, receive_how_are_you))
    nlu = NatexNLU(
        feelings_neg_and_received_how_are_you,
        macros={
            "ONT": ONTE(kb),
            "ONT_NEG": ONT_NEG(kb)
        },
    )
    m = nlu.match("not well how are you", debugging=False)
    assert m
    m = nlu.match("bad how are you", debugging=False)
    assert m
    m = nlu.match("im bad how are you", debugging=False)
    assert m
    m = nlu.match("ok i guess", debugging=False)
    assert not m
    m = nlu.match("ok", debugging=False)
    assert not m
    m = nlu.match("i seem to be ok thanks", debugging=False)
    assert not m
    m = nlu.match("great i guess", debugging=False)
    assert not m
    m = nlu.match("great", debugging=False)
    assert not m
    m = nlu.match("i seem to be pretty great thanks", debugging=False)
    assert not m
    m = nlu.match("not bad", debugging=False)
    assert not m
    m = nlu.match("thanks im not bad dude", debugging=False)
    assert not m
    m = nlu.match("ok how are you", debugging=False)
    assert not m
    m = nlu.match("bad i guess", debugging=False)
    assert not m
    m = nlu.match("bad", debugging=False)
    assert not m
    m = nlu.match("i seem to be pretty bad thanks", debugging=False)
    assert not m
    m = nlu.match("not good", debugging=False)
    assert not m
    m = nlu.match("thanks im not ok dude", debugging=False)
    assert not m
    m = nlu.match("pretty well how are you", debugging=False)
    assert not m
    m = nlu.match("great how are you", debugging=False)
    assert not m
    feelings_neutral_and_received_how_are_you = (
        "[!#ONT_NEG(ont_negation), [#ONT(ont_feelings_neutral)], [%s]]" %
        (receive_how_are_you))
    nlu = NatexNLU(
        feelings_neutral_and_received_how_are_you,
        macros={
            "ONT": ONTE(kb),
            "ONT_NEG": ONT_NEG(kb)
        },
    )
    m = nlu.match("ok but how are you", debugging=False)
    assert m
    m = nlu.match("not ok how are you", debugging=False)
    assert not m
    m = nlu.match("im not ok how are you", debugging=False)
    assert not m
    m = nlu.match("not well how are you", debugging=False)
    assert not m
    m = nlu.match("bad how are you", debugging=False)
    assert not m
    m = nlu.match("im bad how are you", debugging=False)
    assert not m
    m = nlu.match("ok i guess", debugging=False)
    assert not m
    m = nlu.match("ok", debugging=False)
    assert not m
    m = nlu.match("i seem to be ok thanks", debugging=False)
    assert not m
    m = nlu.match("great i guess", debugging=False)
    assert not m
    m = nlu.match("great", debugging=False)
    assert not m
    m = nlu.match("i seem to be pretty great thanks", debugging=False)
    assert not m
    m = nlu.match("not bad", debugging=False)
    assert not m
    m = nlu.match("thanks im not bad dude", debugging=False)
    assert not m
    m = nlu.match("bad i guess", debugging=False)
    assert not m
    m = nlu.match("bad", debugging=False)
    assert not m
    m = nlu.match("i seem to be pretty bad thanks", debugging=False)
    assert not m
    m = nlu.match("not good", debugging=False)
    assert not m
    m = nlu.match("thanks im not ok dude", debugging=False)
    assert not m
    m = nlu.match("pretty well how are you", debugging=False)
    assert not m
    m = nlu.match("great how are you", debugging=False)
    assert not m
    decline_share = (
        "{"
        "[#ONT(ont_negation), {talk, talking, discuss, discussing, share, sharing, tell, telling, say, saying}],"
        "[#ONT(ont_fillers), #ONT(ont_negative)],"
        "[#ONT(ont_negative)]"
        "<{dont,do not}, know>,"
        "<not, sure>"
        "}")
    nlu = NatexNLU(decline_share,
                   macros={
                       "ONT": ONTE(kb),
                       "ONT_NEG": ONT_NEG(kb)
                   })
    m = nlu.match("i dont know", debugging=False)
    assert m
    m = nlu.match("im not sure", debugging=False)
    assert m
    m = nlu.match("i dont want to tell you", debugging=False)
    assert m
    m = nlu.match("no", debugging=False)
    assert m
    m = nlu.match("i dont want to talk about it", debugging=False)
    assert m
    m = nlu.match("ok but how are you", debugging=False)
    assert not m
    m = nlu.match("not ok how are you", debugging=False)
    assert not m
    m = nlu.match("im not ok how are you", debugging=False)
    assert not m
    m = nlu.match("not well how are you", debugging=False)
    assert not m
    m = nlu.match("bad how are you", debugging=False)
    assert not m
    m = nlu.match("im bad how are you", debugging=False)
    assert not m
    m = nlu.match("ok i guess", debugging=False)
    assert not m
    m = nlu.match("ok", debugging=False)
    assert not m
    m = nlu.match("i seem to be ok thanks", debugging=False)
    assert not m
    m = nlu.match("great i guess", debugging=False)
    assert not m
    m = nlu.match("great", debugging=False)
    assert not m
    m = nlu.match("i seem to be pretty great thanks", debugging=False)
    assert not m
    m = nlu.match("not bad", debugging=False)
    assert not m
    m = nlu.match("thanks im not bad dude", debugging=False)
    assert not m
    m = nlu.match("bad i guess", debugging=False)
    assert not m
    m = nlu.match("bad", debugging=False)
    assert not m
    m = nlu.match("i seem to be pretty bad thanks", debugging=False)
    assert not m
    m = nlu.match("not good", debugging=False)
    assert not m
    m = nlu.match("thanks im not ok dude", debugging=False)
    assert not m
    m = nlu.match("pretty well how are you", debugging=False)
    assert not m
    m = nlu.match("great how are you", debugging=False)
    assert not m
Exemple #29
0
def test_regex():
    natex = NatexNLU("/[a-c]+/")
    assert natex.match("abccba", debugging=False)
    assert not natex.match("abcdabcd", debugging=False)
Exemple #30
0
def test_kleene_star():
    natex = NatexNLU("[!i, really*, love, sports]")
    assert natex.match("i really love sports")
    assert natex.match("i love sports")
    assert natex.match("i really really really love sports", debugging=False)
    assert not natex.match("i sports")