telegram-bot-systemy-dialogowe/evaluate.py
2021-05-16 23:13:40 +02:00

33 lines
872 B
Python

import os
import re
import jsgf
import pandas as pd
import numpy as np
PATTERN = r'[^(]*'
# Algorytm sprawdzający
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]
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:
hits += 1
print(f"Accuracy: {(hits / rows)*100}")
# Dokładność 30%