How to use nlu - 10 common examples

To help you get started, we’ve selected a few nlu examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github szroland / nlu / tests / test_generator.py View on Github external
def test_class_relationship_is_one_way(self):
        nlu = NLU()
        nlu.integrate("C(Mary, person)")
        nlu.integrate("C(Joe, person)")
        nlu.integrate("C(kid, person)")

        logger.info("State: \n%s\n" % graph(nlu.working_memory))

        gen = InheritFromParentClass()
        concepts = list(gen.gen(nlu.question_store))

        logger.info("Generated concepts: %r" % concepts)

        self.assertEqual(len(concepts), 0)
github szroland / nlu / tests / test_nlu.py View on Github external
def test_class_deduction(self):
        nlu = NLU()
        nlu.integrate("C(Bp,city)")
        nlu.integrate("C(city,place)")

        q, a, c = nlu.ask("C(Bp, place)")
        logger.info("Answer to question %s: %s" % (q, nlu.create_answer(q, a)))
        self.assertIsNotNone(a)
github szroland / nlu / tests / test_nlu.py View on Github external
def test_implication_works_after_parent_statement(self):
        nlu = NLU()
        nlu.integrate("F(Joe,tired)")
        nlu.integrate("IM(F(Joe,tired),F(Joe,slow))")
        nlu.integrate("IM(F(Joe,slow),F(Joe,angry))")

        q, a, c = nlu.ask("F(Joe,angry)")
        self.assertIsNotNone(c)
        self.assertEqual(c.probability, 1.0)
github szroland / nlu / tests / test_nlu.py View on Github external
def test_integrate_defines_probability(self):
        nlu = NLU()
        nlu.integrate("IM(F(Joe,tired),F(Joe,slow))")
        q, a, c = nlu.ask("F(Joe,tired)")
        self.assertEqual(c.probability, .5)

        nlu.integrate("F(Joe,tired)")
        q, a, c = nlu.ask("F(Joe,tired)")
        self.assertIsNotNone(c)
        self.assertEqual(c.probability, 1.0)
github szroland / nlu / tests / test_nlu.py View on Github external
def test_class_other_relations(self):
        nlu = NLU()
        nlu.integrate("F(bird,fly)")
        nlu.integrate("C(penguin,bird)")
        nlu.integrate("F(penguin,swim)")

        q, a, c = nlu.ask("F(penguin, fly)")
        logger.info("State:\n%s\n" % graph(nlu.question_store))
        logger.info("Answer to question %s: %s" % (q, nlu.create_answer(q, a)))
        self.assertIsNotNone(a)
github szroland / nlu / tests / test_nlu.py View on Github external
def test_implication_with_class(self):
        nlu = NLU()
        nlu.integrate("IM(F(person,tired),F(person,slow))")
        nlu.integrate("IM(F(person,slow),F(person,angry))")
        nlu.integrate("C(Joe,person)")

        q, a, c = nlu.ask("F(Joe,angry)")
        logger.info("Answer to question %s: %s p=%r" % (q, nlu.create_answer(q, a), c.probability))

        nlu.integrate("F(Joe,tired)")

        logger.info("State:\n%s\n" % graph(nlu.working_memory))
        q, a, c = nlu.ask("F(Joe,angry)")

        logger.info("State:\n%s\n" % graph(nlu.question_store))
        logger.info("Answer to question %s: %s p=%r" % (q, nlu.create_answer(q, a), c.probability))
        self.assertIsNotNone(c)
        self.assertEqual(c.probability, 1.0)
github szroland / nlu / tests / test_nlu.py View on Github external
def test_implication_transfers_probability(self):
        nlu = NLU()
        nlu.integrate("IM(F(Joe,tired),F(Joe,slow))")
        nlu.integrate("IM(F(Joe,slow),F(Joe,angry))")
        nlu.integrate("F(Joe,tired)")

        q, a, c = nlu.ask("F(Joe,angry)")
        self.assertIsNotNone(c)
        self.assertEqual(c.probability, 1.0)
github JoshRosen / cmps140_creative_cooking_assistant / test_nlu.py View on Github external
def main():
    logger = logging.getLogger()

    confidence_threshold = .5
    nlu = NaturalLanguageUnderstander(confidence_threshold, logger)

    # Register the NLU messages we want
    nlu.register_message(YesNoMessage)
    nlu.register_message(SearchMessage)
    nlu.register_message(SystemMessage)

    fil = open('INGREDIENTS.txt', 'r')

    # Skip comments and empty lines
    input_messages = (l.strip() for l in fil if not re.search('^\s*($|#)', l))
    for line in islice(input_messages, 0, LIMIT):
        messages = nlu.parse_input(line)
        print line
        for message in messages:
            print message.__class__
            print pprint.pformat(message.frame)
github JoshRosen / cmps140_creative_cooking_assistant / test_nlu.py View on Github external
def main():
    logger = logging.getLogger()

    confidence_threshold = .5
    nlu = NaturalLanguageUnderstander(confidence_threshold, logger)

    # Register the NLU messages we want
    nlu.register_message(YesNoMessage)
    nlu.register_message(SearchMessage)
    nlu.register_message(SystemMessage)

    fil = open('INGREDIENTS.txt', 'r')

    # Skip comments and empty lines
    input_messages = (l.strip() for l in fil if not re.search('^\s*($|#)', l))
    for line in islice(input_messages, 0, LIMIT):
        messages = nlu.parse_input(line)
        print line
        for message in messages:
            print message.__class__
            print pprint.pformat(message.frame)
        print
github szroland / nlu / nlu.py View on Github external
def create_answer(question: Concept, mapping: Mapping[Concept, Concept]) -> Concept:
        if mapping is None:
            return None

        # simple
        if question.is_simple():
            if question in mapping:
                return mapping[question]
            return question

        # compound
        ap = []  # type: list[Concept]
        for p in question.parents:
            ap.append(NLU.create_answer(p, mapping))

        return Concept(question.name, question.relation, ap)