36 lines
1.0 KiB
Python
36 lines
1.0 KiB
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]
|
|
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
|
|
|
|
print(f"Accuracy: {(hits / rows)*100}")
|
|
# Dokładność 44.6% |