-
Notifications
You must be signed in to change notification settings - Fork 0
/
indexer.py
45 lines (36 loc) · 896 Bytes
/
indexer.py
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
43
44
45
"""
This script should create SQLite database with indexed mentions.
"""
import sqlite3
import sys
query = """
CREATE VIRTUAL TABLE IF NOT EXISTS sentences
USING fts4(
left_context TEXT,
mention TEXT,
concept TEXT,
right_context TEXT,
notindexed=left_context,
notindexed=right_context,
notindexed=concept
)
"""
conn = sqlite3.connect("db_sent.sqlite")
cursor = conn.cursor()
cursor.execute(query)
cursor.close()
conn.commit()
cursor = conn.cursor()
filename = sys.argv[1]
insert_query = """
INSERT INTO sentences VALUES (?, ?, ?, ?)
"""
with open(filename) as fd:
for line in fd:
arr = line.split('\t')
if len(arr) == 4:
left_context, mention, concept, right_context = arr
cursor.execute(insert_query, (left_context, mention, concept, right_context))
else:
print("Skip:", line)
conn.commit()