Skip to content

Commit

Permalink
Merge pull request #46 from Ammar-tcd/Oscar-Backend
Browse files Browse the repository at this point in the history
Oscar backend
  • Loading branch information
DanPreda90 authored Mar 11, 2024
2 parents 4bb035f + 5b218f8 commit d9705ed
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
48 changes: 48 additions & 0 deletions Backend/database.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import sqlite3

#Creates new database if one with the same name doesn't already exist
def create_table():
conn = sqlite3.connect('test.db')
cur = conn.cursor()

sql = '''
CREATE TABLE IF NOT EXISTS TestTable (
name TEXT PRIMARY KEY,
url TEXT NOT NULL,
image_path TEXT NOT NULL,
description TEXT NOT NULL
)
'''
cur.execute(sql)
conn.commit()
conn.close()

#Function to insert a row into the database
def insert(name, url, image_path, description):
conn = sqlite3.connect('test.db')
cur = conn.cursor()
cur.execute('''INSERT OR REPLACE INTO TestTable (name, url, image_path, description)
VALUES (?, ?, ?, ?)''', (name, url, image_path, description))
conn.commit()
conn.close()

# Retrieve a row from the database
def retrieve(name):
conn = sqlite3.connect('test.db')
cur = conn.cursor()
cur.execute('''SELECT * FROM TestTable WHERE name = ?''', (name,))
row = cur.fetchone()
conn.close()
return row


create_table()

insert("Laptop", "https://examplelaptop.com", "/path/to/image.jpg", "this is a laptop")
insert("Monitor", "https://examplemonitor.com", "/path/to/image2.jpg", "this is a monitor")
insert("Adapter", "https://exampleadapter.com", "/path/to/image3.jpg", "this is an adapter")


TestTable = retrieve("Adapter")
for entity in TestTable:
print(entity)
Binary file added Backend/test.db
Binary file not shown.
4 changes: 2 additions & 2 deletions Training_Data/weijian.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
"stringIndexType": "Utf16CodeUnit",
"metadata": {
"projectKind": "CustomEntityRecognition",
"storageInputContainerName": "????????",
"storageInputContainerName": "training-data",
"settings": {
"confidenceThreshold": 0
},
"projectName": "??????????",
"projectName": "SemanticProductLink",
"multilingual": false,
"description": "",
"language": "en"
Expand Down

0 comments on commit d9705ed

Please sign in to comment.