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,9 +33,8 @@ def nlu(utterance):
return {'act': 'null', 'slots': []}
utterance = 'jakie, napoje gazowane'.lower()
def predict(utterance):
utterance = utterance.lower()
punctuation = '''!;:/?,.'''
for i in utterance:
@ -44,9 +43,11 @@ for i in utterance:
matched = book_grammar.find_matching_rules(utterance)
print(matched)
nlu(utterance)
try:
print(get_dialog_act(matched[0]))
except:
pass
return matched

View File

@ -2,7 +2,7 @@
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>);
@ -14,7 +14,7 @@ public <command> = [<greeting> {hello}] [<polite>] <commandType>{commandType} <i
<greeting> = (dzień dobry | cześć | witaj);
<bye> = (do widzenia | cześć | pa);
<bye> = (do widzenia | cześć | pa | dziekuję);
<cartCommand> = (dodaj | usuń | edytuj | zaktualizuj | zobacz | anuluj | potwierdź);