telegram-bot-systemy-dialogowe/evaluate.py

36 lines
1.0 KiB
Python
Raw Normal View History

2021-05-16 18:27:12 +02:00
import os
import re
import jsgf
import pandas as pd
import numpy as np
PATTERN = r'[^(]*'
2021-05-16 23:13:40 +02:00
# Algorytm sprawdzający
2021-05-16 18:27:12 +02:00
grammars = [jsgf.parse_grammar_file(f'JSGFs/{file_name}') for file_name in os.listdir('JSGFs')]
rows = 0
hits = 0
for file_name in os.listdir('data'):
df = pd.read_csv(f'data/{file_name}', sep='\t', names=['user', 'sentence', 'acts'])
df = df[df.user == 'user']
data = np.array(df)
for row in data:
rows += 1
sentence = row[1]
2021-05-17 14:13:45 +02:00
sentences = sentence.split(',')
for sentence in sentences:
for grammar in grammars:
match = grammar.find_matching_rules(sentence)
if match:
acts = row[2].split('&')
for act in acts:
user_act = re.search(PATTERN, act).group()
if user_act == grammar.name:
print(grammar.name)
hits += 1
2021-05-16 18:27:12 +02:00
print(f"Accuracy: {(hits / rows)*100}")
2021-05-17 14:13:45 +02:00
# Dokładność 44.6%