コード例 #1
0
ファイル: mensa_regexes_test.py プロジェクト: kdbz/adviser
def test_request_mensa_pork():
    """
    
    Tests exemplary whether a given synonym, i.e. a user utterance, is recognized as belonging to a certain slot

    """
    domain = MensaDomain()
    nlu = MensaNLU(domain)

    act_out = UserAct()
    act_out.type = UserActionType.Request
    act_out.slot = "pork"

    usr_utt = nlu.extract_user_acts(nlu, user_utterance='does it contain pork')
    assert 'user_acts' in usr_utt
    assert usr_utt['user_acts'][0] == act_out
コード例 #2
0
ファイル: courses_regexes_test.py プロジェクト: kdbz/adviser
def test_request_time_slot():
    """
	
	Tests exemplary whether a given synonym, i.e. a user utterance, is recognized as belonging to a certain slot

	"""
    domain = JSONLookupDomain('ImsCourses')
    nlu = HandcraftedNLU(domain)

    act_out = UserAct()
    act_out.type = UserActionType.Request
    act_out.slot = "time_slot"

    usr_utt = nlu.extract_user_acts(nlu, user_utterance='at what time')
    assert 'user_acts' in usr_utt
    assert usr_utt['user_acts'][0] == act_out
コード例 #3
0
def test_request_superheroes_last_known_location(nlu):
    """
    
    Tests exemplary whether a given user utterance, is recognized as belonging to a certain slot

    Args: 
        nlu: NLU Object (given in conftest.py)

    """
    act_out = UserAct()
    act_out.type = UserActionType.Request
    act_out.slot = "last_known_location"

    usr_utt = nlu.extract_user_acts(nlu, user_utterance='what is their location')
    assert 'user_acts' in usr_utt
    assert usr_utt['user_acts'][0] == act_out
コード例 #4
0
ファイル: mensa_regexes_test.py プロジェクト: kdbz/adviser
def test_inform_binary_mensa_vegan():
    """
    
    Tests exemplary whether a given synonym, i.e. a user utterance, is recognized as belonging to a certain binary slot-value pair

    """
    domain = MensaDomain()
    nlu = MensaNLU(domain)

    act_out = UserAct()
    act_out.type = UserActionType.Inform
    act_out.slot = "vegan"
    act_out.value = "true"

    usr_utt = nlu.extract_user_acts(nlu, user_utterance='vegan, please')
    assert 'user_acts' in usr_utt
    assert usr_utt['user_acts'][0] == act_out
コード例 #5
0
def test_inform_lecturers_department():
    """

    Tests exemplary whether a given synonym, i.e. a user utterance, is recognized as belonging to a certain slot-value pair

    """
    domain = JSONLookupDomain('ImsLecturers')
    nlu = HandcraftedNLU(domain)

    act_out = UserAct()
    act_out.type = UserActionType.Inform
    act_out.slot = "department"
    act_out.value = "external"

    usr_utt = nlu.extract_user_acts(nlu, user_utterance='informatics')
    assert 'user_acts' in usr_utt
    assert usr_utt['user_acts'][0] == act_out
コード例 #6
0
def test_request_lecturers_office_hours():
    """
    
    Tests exemplary whether a given synonym, i.e. a user utterance, is recognized as belonging to a certain slot

    """
    domain = JSONLookupDomain('ImsLecturers')
    nlu = HandcraftedNLU(domain)

    act_out = UserAct()
    act_out.type = UserActionType.Request
    act_out.slot = "office_hours"

    usr_utt = nlu.extract_user_acts(
        nlu, user_utterance='when are the consultation hours')
    assert 'user_acts' in usr_utt
    assert usr_utt['user_acts'][0] == act_out
コード例 #7
0
ファイル: general_regexes_test.py プロジェクト: kdbz/adviser
def test_reqalts(nlu):
    """

    Tests whether a given user input is identified as general act: RequestAlternatives

    Args:
        nlu: NLU Object (given in conftest.py)

    """
    for input in ["something else", "anything else", "different one", "another one", "don't want that", "other options"]:
        act_out = UserAct()
        act_out.type = UserActionType.RequestAlternatives

        usr_utt = nlu.extract_user_acts(nlu, user_utterance='something else') 

        assert 'user_acts' in usr_utt
        assert usr_utt['user_acts'][0] == act_out
コード例 #8
0
ファイル: mensa_regexes_test.py プロジェクト: kdbz/adviser
def test_inform_mensa_type():
    """

    Tests exemplary whether a given synonym, i.e. a user utterance, is recognized as belonging to a certain slot-value pair

    """
    domain = MensaDomain()
    nlu = MensaNLU(domain)

    act_out = UserAct()
    act_out.type = UserActionType.Inform
    act_out.slot = "type"
    act_out.value = "starter"

    usr_utt = nlu.extract_user_acts(nlu, user_utterance='I want a starter')
    assert 'user_acts' in usr_utt
    assert usr_utt['user_acts'][0] == act_out
コード例 #9
0
ファイル: courses_regexes_test.py プロジェクト: kdbz/adviser
def test_inform_courses_language():
    """
	
	Tests exemplary whether a given synonym, i.e. a user utterance, is recognized as belonging to a certain slot-value pair

	"""
    domain = JSONLookupDomain('ImsCourses')
    nlu = HandcraftedNLU(domain)

    act_out = UserAct()
    act_out.type = UserActionType.Inform
    act_out.slot = "lang"
    act_out.value = "de"

    usr_utt = nlu.extract_user_acts(nlu, user_utterance='german')
    assert 'user_acts' in usr_utt
    assert usr_utt['user_acts'][0] == act_out
コード例 #10
0
def test_request_lecturers_phone():
    """
    
    Tests exemplary whether a given synonym, i.e. a user utterance, is recognized as belonging to a certain slot

    """
    domain = JSONLookupDomain('ImsLecturers')
    nlu = HandcraftedNLU(domain)

    act_out = UserAct()
    act_out.type = UserActionType.Request
    act_out.slot = "phone"

    usr_utt = nlu.extract_user_acts(
        nlu, user_utterance='can you tell me the phone number')
    assert 'user_acts' in usr_utt
    assert usr_utt['user_acts'][0] == act_out
コード例 #11
0
def test_inform_superheroes_primary_uniform_color(nlu):
    """

    Tests exemplary whether a given user utterance, is recognized as belonging to a certain slot-value pair

    Args: 
        nlu: NLU Object (given in conftest.py)

    """
    act_out = UserAct()
    act_out.type = UserActionType.Inform
    act_out.slot = "primary_uniform_color"
    act_out.value = "Purple"

    usr_utt = nlu.extract_user_acts(nlu, user_utterance='the uniform should be Purple')
    assert 'user_acts' in usr_utt
    assert usr_utt['user_acts'][0] == act_out
コード例 #12
0
ファイル: general_regexes_test.py プロジェクト: kdbz/adviser
def test_affirm(nlu):
    """

    Tests whether a given user input is identified as general act: Affirm

    Args:
        nlu: NLU Object (given in conftest.py)

    """
    for input in ["yes", "Yeah", "Ok", "Sure", "right", "correct"]:
        act_out = UserAct()
        act_out.type = UserActionType.Affirm

        usr_utt = nlu.extract_user_acts(nlu, user_utterance=input) 

        assert 'user_acts' in usr_utt
        assert usr_utt['user_acts'][0] == act_out
コード例 #13
0
ファイル: general_regexes_test.py プロジェクト: kdbz/adviser
def test_thanks(nlu):
    """

    Tests whether a given user input is identified as general act: Thanks

    Args:
        nlu: NLU Object (given in conftest.py)

    """
    for input in ["Great", "Thanks", "thank you", "awesome", "thank you so much"]:
        act_out = UserAct()
        act_out.type = UserActionType.Thanks

        usr_utt = nlu.extract_user_acts(nlu, user_utterance=input) 

        assert 'user_acts' in usr_utt
        assert usr_utt['user_acts'][0] == act_out
コード例 #14
0
ファイル: general_regexes_test.py プロジェクト: kdbz/adviser
def test_deny(nlu):
    """

    Tests whether a given user input is identified as general act: Deny

    Args:
        nlu: NLU Object (given in conftest.py)

    """
    for input in ["no", "not true", "wrong", "error", "n", "nope", "incorrect", "not correct"]:
        act_out = UserAct()
        act_out.type = UserActionType.Deny

        usr_utt = nlu.extract_user_acts(nlu, user_utterance=input) 
        
        assert 'user_acts' in usr_utt
        assert usr_utt['user_acts'][0] == act_out
コード例 #15
0
ファイル: general_regexes_test.py プロジェクト: kdbz/adviser
def test_bye(nlu):
    """

    Tests whether a given user input is identified as general act: Bye

    Args:
        nlu: NLU Object (given in conftest.py)

    """
    for input in ["bye", "goodbye", "that is all", "that's all"]:
        act_out = UserAct()
        act_out.type = UserActionType.Bye

        usr_utt = nlu.extract_user_acts(nlu, user_utterance=input)
    
        assert 'user_acts' in usr_utt
        assert usr_utt['user_acts'][0] == act_out
コード例 #16
0
ファイル: general_regexes_test.py プロジェクト: kdbz/adviser
def test_hello(nlu):
    """

    Tests whether a given user input is identified as general act: Hello

    Args:
        nlu: NlU Object (given in conftest.py)

    """
    for input in ["hi", "hello", "howdy", "hey"]:
        act_out = UserAct()
        act_out.type = UserActionType.Hello

        usr_utt = nlu.extract_user_acts(nlu, user_utterance=input)

        assert 'user_acts' in usr_utt
        assert usr_utt['user_acts'][0] == act_out
コード例 #17
0
def test_inform_lecturers_name():
    """
    
    Tests exemplary whether a given synonym, i.e. a user utterance, is recognized as belonging to a certain slot-value pair

    """
    domain = JSONLookupDomain('ImsLecturers')
    nlu = HandcraftedNLU(domain)

    act_out = UserAct()
    act_out.type = UserActionType.Inform
    act_out.slot = "name"
    act_out.value = "apl. prof. dr. agatha christie"

    usr_utt = nlu.extract_user_acts(nlu, user_utterance='agatha christie')
    assert 'user_acts' in usr_utt
    assert usr_utt['user_acts'][0] == act_out
コード例 #18
0
def test_inform_superheroes_loyalty(nlu):
    """
    
    Tests exemplary whether a given user utterance, is recognized as belonging to a certain slot-value pair

    Args: 
        nlu: NLU Object (given in conftest.py)

    """
    act_out = UserAct()
    act_out.type = UserActionType.Inform
    act_out.slot = "loyalty"
    act_out.value = "Avengers"

    usr_utt = nlu.extract_user_acts(nlu, user_utterance='they should be part of Avengers')
    assert 'user_acts' in usr_utt
    assert usr_utt['user_acts'][0] == act_out
コード例 #19
0
def _create_general_json(domain: JSONLookupDomain, template: RegexFile):
    general_regex_json = {}
    for general_act_name in domain.get_discourse_acts():
        if general_act_name in ('none', 'silence'):
            continue
        general_act = UserAct(act_type=UserActionType(general_act_name))
        general_regex_json[general_act_name] = template.create_regex(
            general_act)
    return general_regex_json
コード例 #20
0
def _create_inform_json(domain: JSONLookupDomain, template: RegexFile):
    inform_regex_json = {}
    for slot in domain.get_informable_slots():
        inform_regex_json[slot] = {}
        for value in domain.get_possible_values(slot):
            inform_act = UserAct(act_type=UserActionType.Inform,
                                 slot=slot,
                                 value=value)
            inform_regex_json[slot][value] = template.create_regex(inform_act)
    return inform_regex_json
コード例 #21
0
ファイル: nlu_test.py プロジェクト: kdbz/adviser
def test_assigned_score(nlu):
    """

	Tests if assigned score is 1.0 

	Args:
		nlu: NlU Object (given in conftest.py)

	"""
    act = UserAct()
    assert act.score == 1.0
コード例 #22
0
ファイル: nlu_test.py プロジェクト: kdbz/adviser
def test_match_general_act_bye(nlu):
    """

	Tests if general act bye are matched properly

	Args:
		nlu: NlU Object (given in conftest.py)

	"""
    nlu.user_acts = []
    nlu._match_general_act(user_utterance="bye")
    expected_user_act = [UserAct("hello", UserActionType.Bye, None, None, 1.0)]
    assert nlu.user_acts == expected_user_act
コード例 #23
0
ファイル: nlu_test.py プロジェクト: kdbz/adviser
def test_match_general_act_hello(nlu):
    """

	Tests if general act hello are matched properly

	Args:
		nlu: NlU Object (given in conftest.py)

	"""
    nlu.user_acts = []
    nlu._match_general_act(user_utterance="hello")
    assert nlu.user_acts == [
        UserAct("hello", UserActionType.Hello, None, None, 1.0)
    ]
コード例 #24
0
ファイル: mensa_regexes_test.py プロジェクト: kdbz/adviser
def test_multiple_user_acts_mensa():
    """
    
    Tests exemplary whether a given sentence with multiple user acts is understood properly
    
    """
    domain = MensaDomain()
    nlu = MensaNLU(domain)

    usr_utt = nlu.extract_user_acts(
        nlu, user_utterance='Hi, I want a dish with fish')
    assert 'user_acts' in usr_utt

    act_out = UserAct()
    act_out.type = UserActionType.Hello
    assert usr_utt['user_acts'][0] == act_out

    act_out = UserAct()
    act_out.type = UserActionType.Inform
    act_out.slot = "fish"
    act_out.value = "true"
    assert usr_utt['user_acts'][1] == act_out
コード例 #25
0
ファイル: courses_regexes_test.py プロジェクト: kdbz/adviser
def test_multiple_user_acts_courses():
    """
    
    Tests exemplary whether a given sentence with multiple user acts is understood properly
    
    """
    domain = JSONLookupDomain('ImsCourses')
    nlu = HandcraftedNLU(domain)

    usr_utt = nlu.extract_user_acts(
        nlu,
        user_utterance='Hi, I want a course that is related to linguistics')
    assert 'user_acts' in usr_utt

    act_out = UserAct()
    act_out.type = UserActionType.Hello
    assert usr_utt['user_acts'][0] == act_out

    act_out = UserAct()
    act_out.type = UserActionType.Inform
    act_out.slot = "linguistics"
    act_out.value = "true"
    assert usr_utt['user_acts'][1] == act_out
コード例 #26
0
def test_multiple_user_acts_lecturers():
    """
    
    Tests exemplary whether a given sentence with multiple user acts is understood properly
    
    """
    domain = JSONLookupDomain('ImsLecturers')
    nlu = HandcraftedNLU(domain)

    usr_utt = nlu.extract_user_acts(
        nlu,
        user_utterance=
        'Hi, I want a lecturer who is responsible for gender issues')
    assert 'user_acts' in usr_utt

    act_out = UserAct()
    act_out.type = UserActionType.Hello
    assert usr_utt['user_acts'][0] == act_out

    act_out = UserAct()
    act_out.type = UserActionType.Inform
    act_out.slot = "position"
    act_out.value = "gender"
    assert usr_utt['user_acts'][1] == act_out
コード例 #27
0
ファイル: nlu_test.py プロジェクト: kdbz/adviser
def test_match_general_act_dontcare(nlu, domain):
    """

    Tests if general act dontcare is matched properly

    Args:
        nlu: NlU Object (given in conftest.py)

    """
    nlu.__init__(domain)
    nlu.user_acts = []
    nlu.sys_act_info['last_act'] = SysAct(
        act_type=SysActionType.Request,
        slot_values={"primary_uniform_color": []})

    nlu.lastRequestSlot = "primary_uniform_color"

    nlu._match_general_act(user_utterance="I dont care")
    expected_user_act = UserAct("",
                                act_type=UserActionType.Inform,
                                slot='primary_uniform_color',
                                value="dontcare",
                                score=1.0)
    assert nlu.user_acts[0] == expected_user_act
コード例 #28
0
    def _add_new_command(self):
        if self._current_block_level == 0:
            self._add_top_level_command()
        else:
            self._command_stack[-1].add_inner_command(self._current_command)
        self._command_stack.append(self._current_command)

    def _add_top_level_command(self):
        if isinstance(self._current_command, Rule):
            self._rules.append(self._current_command)
        elif isinstance(self._current_command, Function):
            self._functions.append(self._current_command)
        else:
            raise BaseException(
                'Only function or rule commands can be defined on top level!')


if __name__ == '__main__':
    domain = JSONLookupDomain(
        'ImsLecturers',
        os.path.join('resources', 'databases', 'ImsLecturers-rules.json'),
        os.path.join('resources', 'databases',
                     'ImsLecturersConfidential-dbase.db'))
    regex_file = RegexFile(
        '/home/mo/Job/ADvISER/diasys/adviser/resources/regexes/ImsLecturers.nlu',
        domain)

    # user_act = UserAct('', UserActionType.Inform, 'name', 'agnieska falenska')
    user_act = UserAct('', UserActionType.Hello)
    print(regex_file.create_regex(user_act))
コード例 #29
0
def _create_request_json(domain: JSONLookupDomain, template: RegexFile):
    request_regex_json = {}
    for slot in domain.get_requestable_slots():
        request_act = UserAct(act_type=UserActionType.Request, slot=slot)
        request_regex_json[slot] = template.create_regex(request_act)
    return request_regex_json