-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrealec_db.py
More file actions
78 lines (64 loc) · 2.12 KB
/
Copy pathrealec_db.py
File metadata and controls
78 lines (64 loc) · 2.12 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# coding: utf-8
__author__ = 'liza'
import sqlite3
base = sqlite3.connect('realec_tags.db')
c = base.cursor()
def extract_mist():
mistakes = []
with open('table_mistakes.csv') as tab_m:
table = tab_m.readlines()
for line in table[1:]:
# mistake_id, text_id, type, text, attr_weight_language, cause, correction, tokens_id
mistakes.append(line.strip().split('\t'))
return mistakes
def extract_tokens():
tokens = []
with open('table_tokens.csv') as tab_m:
table = tab_m.readlines()
for line in table[1:]:
# text_id, token_id, token, POS lemma, mistake_id
tokens.append(line.strip().split('\t'))
return tokens
def extract_texts():
texts = []
with open('table_texts.csv') as tab_m:
table = tab_m.readlines()
for line in table[1:]:
# text_id, text_name
texts.append(line.strip().split('\t'))
return texts
def make_tags():
tags = extract_mist()
c.execute('''CREATE TABLE tags (mistake_id, text_id, type, text, attr_weight_language, cause, correction, tokens_id)''')
for tag in tags:
if len(tag) == 7:
tag.append('NA')
c.execute('INSERT INTO tags VALUES (?,?,?,?,?,?,?,?)', tag)
def make_tokens():
tokens = extract_tokens()
c.execute('''CREATE TABLE tokens (text_id, token_id, token, POS, lemma, mistake_id)''')
for token in tokens:
if len(token) == 4:
token.append(token[2])
token.append('NA')
elif len(token) == 5:
token.append('NA')
c.execute('INSERT INTO tokens VALUES (?,?,?,?,?,?)', token)
def make_texts():
texts = extract_texts()
c.execute('''CREATE TABLE texts (text_id, text_name)''')
for text in texts:
c.execute('INSERT INTO texts VALUES (?,?)', text)
def queries():
type = input('Which tag? ')
c.execute('SELECT text_id FROM tags WHERE type=?', (type,))
for i in c.fetchall():
print(i)
#print(c.fetchall())
if __name__ == '__main__':
#make_tags()
#make_tokens()
#make_texts()
#base.commit()
#base.close()
queries()