Fritz02's picture
Fix correct test in test.py
e58ce62
from evaluate import load
import sqlite3
module = load("Fritz02/execution_accuracy")
# Create connection to the database
database_path = "database.sqlite"
connection = sqlite3.connect(database_path)
# Cursor
cursor = connection.cursor()
# Create table
cursor.execute('''CREATE TABLE IF NOT EXISTS Player
(PlayerID INTEGER PRIMARY KEY,
PlayerName TEXT NOT NULL);''')
# Insert a row of data
cursor.execute("INSERT INTO Player VALUES (1, 'Cristiano Ronaldo')")
cursor.execute("INSERT INTO Player VALUES (2, 'Lionel Messi')")
# Define the function that will execute the SQL queries
def execute(sql_query):
# Execute the SQL queries
cursor.execute(sql_query)
result = cursor.fetchall()
return result
sql_queries_pred = [
"SELECT COUNT(*) FROM Player WHERE PlayerName = 'Cristiano Ronaldo'",
"SELECT COUNT(*) FROM Player WHERE PlayerName = 'Lionel Messi'"
]
sql_queries_ref = [
"SELECT COUNT(*) FROM Player WHERE PlayerName = 'Cristiano Ronaldo'",
"SELECT COUNT(*) FROM Player WHERE PlayerName = 'Lionel Messi'"
]
# Compute the score
results = module.compute(predictions=sql_queries_pred, references=sql_queries_ref, execute_func=execute)
print(results)