Exemplo n.º 1
0
def test():
    utterances = ["I am from Belgrade"]
    chat = Chat("Lenka", None)
    brain = LongTermMemory()
    for utterance in utterances:
        brain_response = get_response(chat, utterance, brain)
        print('\n\n')
    return
Exemplo n.º 2
0
def test_scenario(statement, questions, gold):
    correct = 0
    chat = Chat("Lenka", fake_context())
    brain = LongTermMemory(
        clear_all=True)  # WARNING! this deletes everything in the brain, must only be used for testing

    if ',' in statement:
        for stat in statement.split(','):
            chat.add_utterance([UtteranceHypothesis(stat, 1.0)], False)
            chat.last_utterance.analyze()
            brain.update(chat.last_utterance, reason_types=True)

    else:
        chat.add_utterance([UtteranceHypothesis(statement, 1.0)], False)
        chat.last_utterance.analyze()
        brain.update(chat.last_utterance, reason_types=True)

    for question in questions:
        chat.add_utterance([UtteranceHypothesis(question, 1.0)], False)
        chat.last_utterance.analyze()
        brain_response = brain.query_brain(chat.last_utterance)
        reply = reply_to_question(brain_response)
        print(reply)
        if '-' in reply:
            reply = reply.replace('-', ' ')
        if reply.lower().strip() != gold.lower().strip():
            print('MISMATCH RESPONSE ', reply.lower().strip(), gold.lower().strip())
        else:
            correct += 1

    return correct
Exemplo n.º 3
0
    def __init__(self, backend):
        """
        Create Application

        Parameters
        ----------
        backend: AbstractBackend
        """
        super(Application, self).__init__(backend)

        self._brain = LongTermMemory()

        self._events = {
            attr: self.__getattribute__(attr)
            for attr in dir(self) if attr.startswith(self.EVENT_TAG)
            and callable(self.__getattribute__(attr))
        }

        self._log = logger.getChild(self.__class__.__name__)
        self.log.debug("Booted")
Exemplo n.º 4
0
from pepper.brain import LongTermMemory
from test.brain.utils import transform_capsule, places, bl, capsule_likes, capsule_is_from, capsule_is_from_2, \
    capsule_is_from_3, capsule_knows

from random import choice

if __name__ == "__main__":

    # Create brain connection
    brain = LongTermMemory(clear_all=True)

    capsules = [
        capsule_likes, capsule_is_from, capsule_is_from_2, capsule_is_from_3,
        capsule_knows
    ]

    for capsule in capsules:
        say = ''
        em = choice(bl)
        np = choice(bl)
        p = choice(bl)
        capsule = transform_capsule(capsule, empty=em, no_people=np, place=p)
        x = brain.update(capsule, reason_types=True)

        if capsule.context.location.label == capsule.context.location.UNKNOWN:
            y = brain.reason_location(capsule.context)
            if y is None:
                z = choice(places)
                brain.set_location_label(z)
                capsule.context.location._label = z
                say += 'Having a talk at what I will call %s' % capsule.context.location.label
Exemplo n.º 5
0
from pepper.language.generation.thoughts_phrasing import phrase_thoughts
from pepper.brain import LongTermMemory

from test.brain.utils import transform_capsule, bl, capsule_likes, capsule_is_from, capsule_is_from_2, \
    capsule_is_from_3, capsule_knows

from random import choice

if __name__ == "__main__":

    # Create brain connection
    brain = LongTermMemory(clear_all=True)

    capsules = [
        capsule_likes, capsule_is_from, capsule_is_from_2, capsule_is_from_3,
        capsule_knows
    ]

    for capsule in capsules:
        say = ''
        em = choice(bl)
        np = choice(bl)
        p = choice(bl)
        capsule = transform_capsule(capsule, empty=em, no_people=np, place=p)
        x = brain.update(capsule, reason_types=True)

        print(phrase_thoughts(x, True, True))
        print(phrase_thoughts(x, True, True))
        print(phrase_thoughts(x, True, True))
        print(phrase_thoughts(x, True, True))
        print(phrase_thoughts(x, True, True))
Exemplo n.º 6
0
def test_with_triples(path):
    chat = Chat("Lenka", fake_context())
    brain = LongTermMemory(
        clear_all=True)  # WARNING! this deletes everything in the brain, must only be used for testing

    index = 0
    correct = 0
    incorrect = 0
    issues = {}
    test_suite, gold = load_golden_triples(path)

    for utterance in test_suite:
        chat.add_utterance([UtteranceHypothesis(utterance, 1.0)], False)
        chat.last_utterance.analyze()

        if chat.last_utterance.triple == None:
            print(chat.last_utterance, 'ERROR')
            incorrect += 3
            index += 1
            issues[chat.last_utterance.transcript] = 'NOT PARSED'
            continue

        t = compare_triples(chat.last_utterance.triple, gold[index])
        if t < 3:
            issues[chat.last_utterance.transcript] = t
        correct += t
        incorrect += (3 - t)

        if chat.last_utterance.type == language.UtteranceType.QUESTION:
            brain_response = brain.query_brain(chat.last_utterance)
            # reply = reply_to_question(brain_response)
            # print(reply)

        else:
            if 'perspective' in gold[index]:
                perspective = chat.last_utterance.perspective
                extracted_perspective = {'polarity': perspective.polarity, 'certainty': perspective.certainty,
                                         'sentiment': perspective.sentiment}
                for key in extracted_perspective:
                    if float(extracted_perspective[key]) != gold[index]['perspective'][key]:
                        print('MISMATCH PERSPECTIVE ', key, extracted_perspective[key], gold[index]['perspective'][key])
                        incorrect += 1
                        # print(issues[chat.last_utterance.transcript])
                        # print([extracted_perspective[key], gold[index]['perspective'][key]])
                        issues[chat.last_utterance.transcript] = [extracted_perspective[key],
                                                                  gold[index]['perspective'][key]]
                    else:
                        correct += 1

            '''
            brain_response = brain.update(chat.last_utterance, reason_types=True)
            # reply = reply_to_statement(brain_response, chat.speaker, brain)
            reply = phrase_thoughts(brain_response, True, True)
            '''

        # print(chat.last_utterance)
        # print(chat.last_utterance.triple)
        # print(reply)
        index += 1

    print(correct, incorrect)
    print('issues ', issues)

    return
Exemplo n.º 7
0
 def __init__(self, backend):
     super(BrainComponent, self).__init__(backend)
     self._brain = LongTermMemory()
Exemplo n.º 8
0
 def __init__(self, backend):
     # type: (AbstractBackend) -> None
     super(BrainComponent, self).__init__(backend)
     self._brain = LongTermMemory()
Exemplo n.º 9
0
def test():
    # "Suzana enjoys cooking", "Does Suzana enjoy cooking","What does Suzana enjoy", "Selene enjoys cooking","Who enjoys cooking"
    # *** DOES NOT WORK for "Does S love cooking" <- has issues with POS-tags bc. love gets processed as a noun

    # "Selene is from Mexico", "Where is Selene from","Who is from Mexico" <- is_from instead of be_from, but works ok
    # "I'm from Serbia", "Where am I from" <- "you told me you is from serbia"

    # "selene is your friend","who is your friend", "your name is leolani", "what is your name", "my sign is taurus", "what is my sign"

    # "bram owns a laptop", "bram owns two cats", "what does bram own", "who owns two cats"

    # "I have blue eyes", "what do I have", "who has blue eyes"

    # "you can talk", "can you talk","humans can talk", "who can talk", "I must go", "who must go"

    # "you know bram", "do you know bram", "selene knows bram", "does selene know bram"

    # "you know me", "do you know me", "who do you know", "who does selene know" <- THIS DOES NOT WORK ***

    # "you live here", "where do you live" <- WORKS,  but "who lives here", "do you live here" <- DOESN'T

    # "I live in amsterdam", "who lives in amsterdam" <- WORKS,
    # but  "do I live in amsterdam", "where do I live" <- DOESN'T (fuzzy predicate matching?)

    utterances = [
        # "My name is Suzana",
        "I am from Croatia",
        "Where am I from",
        "Who is from Croatia",
        "My favorite animal is cat",
        "What is my favorite animal",
        "Who is my friend",
        "Bram is my friend",
        "Who is my friend",
        "Where is Lenka from",
        "Lenka is from Serbia",
        "Lenka is from Germany",
        "Where is Lenka from",
        "What do you like",
        "You like tea",
        "What do you like",
        "What do you see",
        "Do you see a bottle",
        "I own a bottle",
        "What do I own",
        "I own two laptops",
        "What do I own",
        "Selene is from Mexico",
        "Where is Selene from",
        "Who is from Mexico",
        'what can birds do',
        'birds can fly',
        'what can birds do',
        'who can fly',
        'birds can poop',
        'what can birds do',
        'who can fly'
    ]

    utterances_lower = [x.lower() for x in utterances]
    utterances.extend(utterances_lower)

    people = ['Suzanna', 'Lenka', 'Bram', 'Selene', 'Piek']
    brain = LongTermMemory(
        clear_all=True
    )  # WARNING! this deletes everything in the brain, must only be used for testing
    for utterance in utterances:
        chat = Chat(choice(people), fake_context())
        chat.add_utterance([UtteranceHypothesis(utterance, 1.0)], False)
        chat.last_utterance.analyze()

        if chat.last_utterance.triple is not None:
            if chat.last_utterance.type == language.UtteranceType.QUESTION:
                brain_response = brain.query_brain(chat.last_utterance)
                reply = reply_to_question(brain_response)
            else:
                brain_response = brain.update(chat.last_utterance,
                                              reason_types=True)
                # reply = reply_to_statement(brain_response, chat.speaker, brain)
                reply = phrase_thoughts(brain_response, True, True)

            print(chat.last_utterance)
            chat.last_utterance.triple.casefold(format='triple')
            print(chat.last_utterance.triple)
            print(reply)

    return