-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimport-orig.sql
More file actions
46 lines (38 loc) · 1.4 KB
/
import-orig.sql
File metadata and controls
46 lines (38 loc) · 1.4 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
begin;
.bail on
attach 'llm.db' as scowl;
.mode tabs
.import 'input-orig.tsv' orig_input
PRAGMA foreign_keys = ON;
create view orig as
with recursive split(gid, base_pos, word, rest) as (
select gid, base_pos,
trim(substr(lemmas, 1,
case when instr(lemmas, ',') > 0
then instr(lemmas, ',') - 1
else length(lemmas) end)),
case when instr(lemmas, ',') > 0
then substr(lemmas, instr(lemmas, ',') + 1)
else null end
from orig_input
union all
select gid, base_pos,
trim(substr(rest, 1,
case when instr(rest, ',') > 0
then instr(rest, ',') - 1
else length(rest) end)),
case when instr(rest, ',') > 0
then substr(rest, instr(rest, ',') + 1)
else null end
from split
where rest is not null
)
select max(gid) as gid, row_number() over (order by max(gid), word) as word_id, word, base_pos from split
group by word, base_pos;
insert into scowl.groups (group_id, base_pos)
select distinct gid, base_pos from orig;
insert into scowl.words (group_id, lemma_id, word_id, pos, word)
select gid,word_id,word_id,lemma_pos,word from orig join scowl.base_poses using (base_pos);
select max(group_id) from groups;
select max(word_id) from words;
commit;