added evaluate.py file

This commit is contained in:
Jakub Henyk 2023-05-04 17:30:47 +02:00
parent b27bb2e0f9
commit c6513b6060
4 changed files with 58 additions and 14 deletions

Binary file not shown.

43
evaluate.py Normal file
View File

@ -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}%')

View File

@ -33,20 +33,21 @@ def nlu(utterance):
return {'act': 'null', 'slots': []} return {'act': 'null', 'slots': []}
def predict(utterance):
utterance = utterance.lower()
punctuation = '''!;:/?,.'''
utterance = 'jakie, napoje gazowane'.lower() for i in utterance:
punctuation = '''!;:/?,.'''
for i in utterance:
if i in punctuation: if i in punctuation:
utterance = utterance.replace(i, "") 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) return matched
print(get_dialog_act(matched[0]))

View File

@ -2,7 +2,7 @@
grammar zakupyOnline; grammar zakupyOnline;
public <command> = [<greeting> {hello}] [<polite>] <commandType>{commandType} <item>{product} [<rest> {rest}] [<bye> {bye}]; public <command> = [<greeting> {hello}] [<polite>] <commandType>{commandType} [<item>{product}] [<rest> {rest}] [<bye> {bye}];
<commandType> = (<buyCommand> | <cartCommand> | <filterCommand> | <questionCommand> | <searchCommand> | <helpCommand> | <accountCommand> | <paymentCommand> | <shippingCommand> | <returnCommand> | <promoCommand> | <storeCommand> | <serviceCommand> | <affOrNegCommand>); <commandType> = (<buyCommand> | <cartCommand> | <filterCommand> | <questionCommand> | <searchCommand> | <helpCommand> | <accountCommand> | <paymentCommand> | <shippingCommand> | <returnCommand> | <promoCommand> | <storeCommand> | <serviceCommand> | <affOrNegCommand>);
@ -14,7 +14,7 @@ public <command> = [<greeting> {hello}] [<polite>] <commandType>{commandType} <i
<greeting> = (dzień dobry | cześć | witaj); <greeting> = (dzień dobry | cześć | witaj);
<bye> = (do widzenia | cześć | pa); <bye> = (do widzenia | cześć | pa | dziekuję);
<cartCommand> = (dodaj | usuń | edytuj | zaktualizuj | zobacz | anuluj | potwierdź); <cartCommand> = (dodaj | usuń | edytuj | zaktualizuj | zobacz | anuluj | potwierdź);