diff --git a/relational.db b/relational.db new file mode 100644 index 0000000..e28f4ca Binary files /dev/null and b/relational.db differ diff --git a/relational.py b/relational.py index 0a7265d..d494967 100644 --- a/relational.py +++ b/relational.py @@ -11,6 +11,27 @@ ] class AnnotationProcessor(Processor): +import csv +import sqlite3 +connection = sqlite3.connect("relational.db") +cursor = connection.cursor() +create_table = '''CREATE TABLE annotations( + id STRING PRIMARY KEY, + body STRING NOT NULL, + target STRING NOT NULL, + motivation STRING NOT NULL); + ''' +cursor.execute(create_table) +with open("data/annotations.csv") as file: + contents = csv.reader(file) + insert_records = "INSERT INTO annotations (id, body, target, motivation) VALUES(?, ?, ?, ?)" + cursor.executemany(insert_records, contents) + select_all = "SELECT * FROM annotations" + rows = cursor.execute(select_all).fetchall() + for r in rows: + print(r) + connection.commit() + connection.close() def uploadData(): """it takes in input the path of a CSV file containing annotations and uploads them in the database. @@ -19,13 +40,33 @@ def uploadData(): class MetadataProcessor(Processor): +import csv +import sqlite3 +connection = sqlite3.connect("relational.db") +cursor = connection.cursor() +create_table = '''CREATE TABLE metadata( + id STRING PRIMARY KEY, + title STRING NOT NULL, + creator STRING NOT NULL); + ''' +cursor.execute(create_table) +with open("data/metadata.csv") as file: + contents = csv.reader(file) + insert_records = "INSERT INTO metadata (id, title, creator) VALUES(?, ?, ?)" + cursor.executemany(insert_records, contents) + select_all = "SELECT * FROM metadata" + rows = cursor.execute(select_all).fetchall() + for r in rows: + print(r) + connection.commit() + connection.close() def uploadData(): """it takes in input the path of a CSV file containing metadata and uploads them in the database. This method can be called everytime there is a need to upload annotations in the database.""" pass - + class QueryProcessor(Processor): def getEntityById():