示例#1
0
def test_parser_intents_add(intents,text,match):
	test	= []
	test.append(parser.Intents(intents[0]))
	test.append(test[0]+parser.Intents(intents[1]))
	test.append(test[1]+intents[2])
	test.append(parser.Intents(str(test[2]),True))
	for i in range(len(text)):
		result	= test[i].match(text[i])
		assert match[i] == result
示例#2
0
if __name__ == "__main__":
    alma_intents = {
        "alma": [{
            "stem": "alma",
            "wordclass": "noun"
        }],
        "szed": [{
            "stem": "szed",
            "wordclass": "verb"
        }],
        "piros": [{
            "stem": "piros",
            "wordclass": "adjective"
        }]
    }
    alma_test = parser.Intents(alma_intents)
    print(alma_test.match("Mikor szedjük le a pirosabb almákat?"))

    igekoto_intents = {
        "to_do": [{
            "stem": "csinál",
            "wordclass": "verb"
        }],
    }
    igekoto_test = parser.Intents(igekoto_intents)

    print(igekoto_test.match("Ő mit csinál a szobában?"))
    print(igekoto_test.match("Mit fogok még csinálni?"))
    print(igekoto_test.match("Mikor csináltad meg a szekrényt?"))
    print(igekoto_test.match("Megcsináltatták a berendezést."))
    print(
示例#3
0
def test_parser_intents_match_zeros(intent,text,best):
	test	= parser.Intents(intent)
	for i in range(len(text)):
		result	= test.match(text[i],True)
		assert best[i] == result
示例#4
0
def test_parser_intents_clean(intents,text,cleaned):
	for i in range(len(intents)):
		test	= parser.Intents(intents[i])
		result	= nlp.trim(test.clean(text[i]))
		assert cleaned[i] == result
示例#5
0
import os.path, sys

sys.path.append(
    os.path.join(os.path.dirname(os.path.realpath(__file__)), os.pardir))
from lara import parser, entities
''' Basic Chatbot that just prints out replies '''

if __name__ == "__main__":

    user_text = 'Már órák óta várok! Kérem adjon információt arról, hogy mennyi az egyenlegem. Köszönöm.'

    ###

    tone = entities.tone()
    tone_match = parser.Intents(tone).match_best(user_text, 1)  # match_best
    common = entities.common()
    common_match = parser.Intents(common).match_set(user_text)

    if 'formal' in tone_match:
        if 'profanity' in common_match:
            print(
                'Elnézését kérem a kellemetlenségét, de nem szükséges káromkodnia.'
            )  # nem fogja kiírni
        print('Kérése feldolgozása folyamatban van.')
    elif 'informal' in tone_match:
        if 'profanity' in common_match:
            print('Sajnálom, hogy hibáztam, de azért nem kell így beszélni.'
                  )  # nem fogja kiírni
        print('Kérésedet elkezdtük feldolgozni.')  # nem fogja kiírni
    else:  # nem eldönthető
示例#6
0
def test_parser_intents_match_set(intent,text,match):
	test	= parser.Intents(intent)
	for i in range(len(text)):
		result	= test.match_set(text[i])
		assert set(match[i]) == result
示例#7
0
''' Basic Chatbot that just prints out replies '''

if __name__ == "__main__":

	user_text = 'Szia! Nem akarok rendelni semmit, csak érdekel, hogy hogy vagy!'

	###

	order = {
		"pizza": [{"stem": "pizza", "wordclass": "noun"}],
		"cheese": [{"stem": "sajt", "wordclass": "noun"}],
		"pepperoni": [{"stem": "szalámi", "wordclass": "noun"}],
		"pineapple": [{"stem": "ananász", "wordclass": "noun"}],
	}
	order_match = parser.Intents(order).match_set(user_text)

	common = entities.common()
	common_match = parser.Intents(common).match_set(user_text)

	smalltalk = entities.smalltalk()
	smalltalk_match = parser.Intents(smalltalk).match_set(user_text)

	if 'hi' in common_match:
		print('Szia!')  # kiíródik a 'Szia' miatt
	if 'thx' in common_match:
		print('Nagyon szívesen!')  # nem fog kiíródni

	if 'pizza' in order_match:
		print('Ha jól értem egy pizzát szeretnél rendelni:')  # nem fog kiíródni
		if 'cheese' in order_match:
示例#8
0
# -*- coding: UTF-8 -*-

import os.path, sys
sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), os.pardir))
from lara import parser, entities

''' Basic Chatbot that just prints out replies '''

if __name__ == "__main__":
	
	user				= input('Kérlek add meg a neved: ')
	
	disallow			= entities.disallow()
	if parser.Intents(disallow).match_set(user):
		print('Sajnálom, de ezt a nevet nem választhatod, mert obszcén kifejezést tartalmaz!')
	else:
		print('Szervusz',user)
        }],
        "winning": [{
            "stem": "nyer",
            "wordclass": "verb"
        }, {
            "stem": "nyertes",
            "wordclass": "noun"
        }],
        "losing": [{
            "stem": "veszt",
            "wordclass": "verb"
        }, {
            "stem": "veszít",
            "wordclass": "verb"
        }, {
            "stem": "vesztes",
            "wordclass": "noun"
        }],
    }
    important_match = parser.Intents(important).match(article)

    location = entities.counties()
    locaiton_match = parser.Intents(location).match(article)

    print('Megtalált utalások a cikkben:')
    print(important_match)
    print(locaiton_match)

    # A kapott pontok azért duplák, mert mind a helyes,
    # mind a lehetséges "elgépelt" formákat megtalálta a szövegben az Intents()
    # Ennek működéséről a dokumentációban olvashatsz többet.
# -*- coding: UTF-8 -*-

import os.path, sys

sys.path.append(
    os.path.join(os.path.dirname(os.path.realpath(__file__)), os.pardir))
from lara import nlp, parser, entities
''' Remove previous matches from text '''

if __name__ == "__main__":

    user_text = 'Szia, köszönöm szépen a pizzát!'

    ###

    match_common = parser.Intents(entities.common()).match_set(user_text)
    print(match_common)

    if match_common:
        # vegyük ki a már megtalált részeket
        clean_user_text = parser.Intents(entities.common()).clean(user_text)
        print(' '.join(nlp.tokenize(clean_user_text)))  # maradék szöveg
    else:
        print(user_text)  # nem fogja kiírni
# -*- coding: UTF-8 -*-

import os.path, sys
sys.path.append(
    os.path.join(os.path.dirname(os.path.realpath(__file__)), os.pardir))
from lara import parser, entities, nlp
''' Basic Chatbot that just prints out replies '''

if __name__ == "__main__":

    user_text = 'Keress rá arra, hogy Chatbot!'

    ###

    common = entities.common()
    common_match = parser.Intents(common).match_set(user_text)

    commands = entities.commands()
    commands_match = parser.Intents(commands).match_set(user_text)

    if 'hi' in common_match:
        print('Szia!')  # nem fog kiíródni
    if 'thx' in common_match:
        print('Nagyon szívesen!')  # nem fog kiíródni

    if 'search' in commands_match:
        print('Keressek rá erre?')

        keywords = parser.Intents(commands).clean(user_text)
        keywords = nlp.remove_stopwords(keywords)
        keywords = nlp.remove_punctuation(keywords)
示例#12
0
# -*- coding: UTF-8 -*-

import os.path, sys
sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), os.pardir))
from lara import parser, entities

''' Basic Chatbot that just prints out replies '''

if __name__ == "__main__":
	
	user_text		= 'Hasta la vista baby!'
	
	###
	
	references		= entities.popculture()
	references_match= parser.Intents(references).match_set(user_text)
	
	if references_match:
		print('Értem, egy másik AI-ra utaltál az üzenetedben.')
		if 'terminator' in references_match:
			print('Visszatérek!')
	else:
		print('Ez egy valós üzenetnek tűnik!') # nem fogja kiírni
# -*- coding: UTF-8 -*-

import os.path, sys

sys.path.append(
    os.path.join(os.path.dirname(os.path.realpath(__file__)), os.pardir))
from lara import parser, entities
''' Basic Chatbot that just prints out replies '''

if __name__ == "__main__":

    user_text = 'Lépj vissza a főmenübe és törölj mindent! Köszönöm.'

    ###

    common = entities.common()
    common_match = parser.Intents(common).match_set(user_text)

    commands = entities.commands()
    commands_match = parser.Intents(commands).match_set(user_text)

    if 'hi' in common_match:
        print('Szia!')  # nem fog kiíródni
    if 'thx' in common_match:
        print('Nagyon szívesen!')  # kiíródik a 'Köszönöm' miatt

    if commands_match:
        print('Az alábbi feladatokat adtad ki a számomra:')
        print(commands_match)
            "wordclass": "noun"
        }],
        "cheese": [{
            "stem": "sajt",
            "wordclass": "noun"
        }],
        "pepperoni": [{
            "stem": "szalámi",
            "wordclass": "noun"
        }],
        "pineapple": [{
            "stem": "ananász",
            "wordclass": "noun"
        }],
    }
    order_match = parser.Intents(order).match_set(user_text)

    common = entities.common()
    common_match = parser.Intents(common).match_set(user_text)

    if 'hi' in common_match:
        print('Szia!')  # kiíródik a 'Szia' miatt
    if 'thx' in common_match:
        print('Nagyon szívesen!')  # nem fog kiíródni

    if 'pizza' in order_match:
        print('Ha jól értem egy pizzát szeretnél rendelni:'
              )  # kiíródik a 'pizzát' miatt
        if 'cheese' in order_match:
            print('sajttal')  # kiíródik a 'sajtos' miatt
        if 'pepperoni' in order_match:
示例#15
0
def test_parser_intents_match_order(intent,text,order,preference):
	test	= parser.Intents(intent)
	for i in range(len(text)):
		result	= test.match_order(text[i],order[i])
		assert preference[i] == result