Spaces:
Runtime error
Runtime error
File size: 1,419 Bytes
e42dbc0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
import sqlite3, json
from contextlib import closing
from extract_keywords import extract_keywords
punctuation = '!"#\'(),:;?[]^`}{'
punctuation2 = '-/&._~+*=@<>[]\\'
remove_punctuation = str.maketrans(punctuation2, ' ' * len(punctuation2), punctuation)
def load_questions(sqlite_filename):
all_questions = []
with closing(sqlite3.connect(sqlite_filename)) as db:
db.row_factory = sqlite3.Row
with closing(db.cursor()) as cursor:
results = cursor.execute(
"SELECT id, articleId, title, category, section, questions FROM articles WHERE articleType = ? AND doNotUse IS NULL OR doNotUse = 0",
('article',)
).fetchall()
for res in results:
section = res['section'].lower()
title = res['title'].lower()
if section == 'служебная информация':
section = ''
title = ''
questions = json.loads(res['questions'])
for q in questions:
q['query'] = " ".join(section.split() + title.split() + q['question'].split()).translate(remove_punctuation).lower()
q['articleId'] = res['articleId']
all_questions += questions
return all_questions
#print("Loading questions from db...")
#questions = load_questions("omnidesk-ai-chatgpt-questions.sqlite")
#for q in questions:
# keywords = extract_keywords(q['query'])
# if (len(keywords) == 0):
# print(q)
# break |