diff --git a/__pycache__/example_nlu.cpython-310.pyc b/__pycache__/example_nlu.cpython-310.pyc new file mode 100644 index 0000000..074e70e Binary files /dev/null and b/__pycache__/example_nlu.cpython-310.pyc differ diff --git a/evaluate.py b/evaluate.py new file mode 100644 index 0000000..6e6ab2d --- /dev/null +++ b/evaluate.py @@ -0,0 +1,43 @@ +import csv +import example_nlu as en + +rows = [] + + +def readData(): + ii = [5, 6, 7, 8] + jj = [1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18] + kk = [1, 2] + + for i in ii: + for j in jj: + for k in kk: + try: + if j < 10: + with open(f'./data/dialog-0{i}-0{j}-0{k}.tsv', 'r') as read_obj: + csv_reader = csv.reader(read_obj, delimiter='\t') + for row in csv_reader: + if 'user' in row[0]: + rows.append(row[1]) + else: + with open(f'./data/dialog-0{i}-{j}-0{k}.tsv', 'r') as read_obj: + csv_reader = csv.reader(read_obj, delimiter='\t') + for row in csv_reader: + if 'user' in row[0]: + rows.append(row[1]) + except: + pass + +if __name__ == "__main__": + readData() + #l = en.predict('Kup cztery wody') + #print(l) + + good = 0 + + for r in rows: + l = en.predict(str(r)) + if l != []: + good += 1 + + print(f'Accuracy: {good/len(rows)*100}%') \ No newline at end of file diff --git a/example_nlu.py b/example_nlu.py index 8857a1f..a4df15f 100644 --- a/example_nlu.py +++ b/example_nlu.py @@ -33,20 +33,21 @@ def nlu(utterance): return {'act': 'null', 'slots': []} +def predict(utterance): + utterance = utterance.lower() + punctuation = '''!;:/?,.''' -utterance = 'jakie, napoje gazowane'.lower() - -punctuation = '''!;:/?,.''' - -for i in utterance: - if i in punctuation: - utterance = utterance.replace(i, "") + for i in utterance: + if i in punctuation: + utterance = utterance.replace(i, "") -matched = book_grammar.find_matching_rules(utterance) + matched = book_grammar.find_matching_rules(utterance) + nlu(utterance) -print(matched) + try: + print(get_dialog_act(matched[0])) + except: + pass -nlu(utterance) - -print(get_dialog_act(matched[0])) \ No newline at end of file + return matched \ No newline at end of file diff --git a/grammar3.jsgf b/grammar3.jsgf index 607c55c..0c7441c 100644 --- a/grammar3.jsgf +++ b/grammar3.jsgf @@ -2,7 +2,7 @@ grammar zakupyOnline; -public = [ {hello}] [] {commandType} {product} [ {rest}] [ {bye}]; +public = [ {hello}] [] {commandType} [{product}] [ {rest}] [ {bye}]; = ( | | | | | | | | | | | | | ); @@ -14,7 +14,7 @@ public = [ {hello}] [] {commandType} = (dzień dobry | cześć | witaj); - = (do widzenia | cześć | pa); + = (do widzenia | cześć | pa | dziekuję); = (dodaj | usuń | edytuj | zaktualizuj | zobacz | anuluj | potwierdź);