import os import re import pandas as pd import numpy as np from chatbot.modules.nlu import NLU rows = 0 hits = 0 nlu = NLU() 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] cleaned_text = re.sub(r'\([^)]*\)', '', row[2]) user_acts = cleaned_text.split("&") nlu_match = nlu.match(sentence) if nlu_match["act"] in user_acts: hits += 1 print(f"Accuracy: {(hits / rows) * 100}")