Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PLWN_API
Manage
Activity
Members
Labels
Plan
Issues
10
Issue boards
Milestones
Wiki
Redmine
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Libraries
PLWN_API
Commits
63c558e4
Commit
63c558e4
authored
2 years ago
by
Grzegorz Kuboń
Browse files
Options
Downloads
Patches
Plain Diff
sql script changed
parent
079422f2
Branches
Branches containing commit
4 merge requests
!10
Revert "test if load_default will download dump"
,
!9
Merge request
,
!8
Revert "test if load_default will download dump"
,
!7
Revert "test if load_default will download dump"
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
plwn/storages/sqlite.py
+136
-150
136 additions, 150 deletions
plwn/storages/sqlite.py
with
136 additions
and
150 deletions
plwn/storages/sqlite.py
+
136
−
150
View file @
63c558e4
...
...
@@ -63,202 +63,188 @@ _DB_SCHEMA_SCRIPT = u"""
PRAGMA foreign_keys = ON;
-- Metadata table. Used for version number, currently
CREATE TABLE plwn_meta (
name TEXT UNIQUE
NOT NULL,
value BLOB
CREATE TABLE
"
tbl_
plwn_meta
"
(
"
name
"
VARCHAR(255)
NOT NULL
,
"
value
"
BLOB
NULL
);
-- Tables for constant values
CREATE TABLE pos (
id INTEGER PRIMARY KEY,
value TEXT UNIQUE NOT NULL
CREATE TABLE
"
tbl_pos
"
(
"
id
"
INTEGER NOT NULL ,
"
value
"
VARCHAR(255) NOT NULL ,
PRIMARY KEY (
"
id
"
)
);
CREATE TABLE verbaspect (
id INTEGER PRIMARY KEY,
value TEXT UNIQUE NOT NULL
CREATE TABLE
"
tbl_verbaspect
"
(
"
id
"
INTEGER NOT NULL ,
"
value
"
VARCHAR(255) NOT NULL ,
PRIMARY KEY (
"
id
"
)
);
CREATE TABLE emotionmark (
id INTEGER PRIMARY KEY,
value TEXT UNIQUE NOT NULL
CREATE TABLE
"
tbl_emotionmark
"
(
"
id
"
INTEGER NOT NULL ,
"
value
"
VARCHAR(255) NOT NULL ,
PRIMARY KEY (
"
id
"
)
);
CREATE TABLE emotionname (
id INTEGER PRIMARY KEY,
value TEXT UNIQUE NOT NULL COLLATE locale
CREATE TABLE
"
tbl_emotionname
"
(
"
id
"
INTEGER NOT NULL ,
"
value
"
VARCHAR(255) NOT NULL ,
PRIMARY KEY (
"
id
"
)
);
CREATE TABLE emotionvaluation (
id INTEGER PRIMARY KEY,
value TEXT UNIQUE NOT NULL COLLATE locale
CREATE TABLE
"
tbl_emotionvaluation
"
(
"
id
"
INTEGER NOT NULL ,
"
value
"
VARCHAR(255) NOT NULL ,
PRIMARY KEY (
"
id
"
)
);
CREATE TABLE domain (
id INTEGER PRIMARY KEY,
value TEXT UNIQUE NOT NULL COLLATE locale
CREATE TABLE
"
tbl_domain
"
(
"
id
"
INTEGER NOT NULL ,
"
value
"
VARCHAR(255) NOT NULL ,
PRIMARY KEY (
"
id
"
)
);
CREATE UNIQUE INDEX
"
value
"
ON
"
tbl_domain
"
(
"
value
"
);
-- Synset only gets one simple table
CREATE TABLE synset (
id INTEGER PRIMARY KEY,
definition TEXT COLLATE locale,
isartificial INTEGER NOT NULL DEFAULT 0
CREATE TABLE
"
tbl_synset
"
(
"
id
"
BLOB NOT NULL ,
"
legacy_id
"
INTEGER NULL ,
"
definition
"
TEXT NULL ,
"
isartificial
"
INTEGER NOT NULL DEFAULT
'
0
'
,
PRIMARY KEY (
"
id
"
)
);
-- Lexical units have several tables, since they have several list-like
-- properties. They also need indexes for lookup.
CREATE TABLE lexicalunit (
id INTEGER PRIMARY KEY,
lemma TEXT NOT NULL COLLATE locale,
pos INTEGER NOT NULL
REFERENCES pos (id),
variant INTEGER NOT NULL,
synset INTEGER NOT NULL
REFERENCES synset (id),
unitindex INTEGER NOT NULL,
definition TEXT COLLATE locale,
domain INTEGER NOT NULL
REFERENCES domain (id),
verbaspect INTEGER
REFERENCES verbaspect (id),
isemotional INTEGER,
emotionmark INTEGER
REFERENCES emotionmark (id),
emotionexample1 TEXT COLLATE locale,
emotionexample2 TEXT COLLATE locale,
UNIQUE (lemma, pos, variant),
-- Also, each unit needs its of place in synset
UNIQUE (synset, unitindex)
CREATE TABLE
"
tbl_lexicalunit
"
(
"
id
"
BLOB NOT NULL ,
"
legacy_id
"
INTEGER NULL ,
"
lemma
"
VARCHAR(255) NOT NULL ,
"
pos
"
INTEGER NOT NULL ,
"
variant
"
INTEGER NOT NULL ,
"
synset
"
BLOB NOT NULL ,
"
unitindex
"
INTEGER NOT NULL ,
"
definition
"
TEXT NULL ,
"
domain
"
INTEGER NOT NULL ,
"
verbaspect
"
INTEGER NULL ,
"
isemotional
"
INTEGER NULL ,
"
emotionmark
"
INTEGER NULL ,
"
emotionexample1
"
TEXT NULL ,
"
emotionexample2
"
TEXT NULL ,
PRIMARY KEY (
"
id
"
)
);
-- lem-pos-var and synset-unitindex indexes (and partial ones) are
-- automatically made because of UNIQUE constraint, but additional indexes
-- need to be created.
CREATE INDEX lex_i_lem_var ON lexicalunit (lemma, variant);
CREATE INDEX lex_i_pos ON lexicalunit (pos);
-- No index for variant itself - it
'
s not an useful use case
CREATE UNIQUE INDEX
"
lemma
"
ON
"
tbl_lexicalunit
"
(
"
lemma
"
,
"
pos
"
,
"
variant
"
);
CREATE INDEX
"
lex_i_lem_var
"
ON
"
tbl_lexicalunit
"
(
"
lemma
"
,
"
variant
"
);
CREATE INDEX
"
lex_i_pos
"
ON
"
tbl_lexicalunit
"
(
"
pos
"
);
CREATE UNIQUE INDEX
"
synset
"
ON
"
tbl_lexicalunit
"
(
"
synset
"
,
"
unitindex
"
);
-- Tables dependant on lexicalunit
CREATE TABLE senseexample (
unitid INTEGER NOT NULL
REFERENCES lexicalunit (id),
example TEXT NOT NULL COLLATE locale,
source TEXT NOT NULL COLLATE locale
CREATE TABLE
"
tbl_senseexample
"
(
"
unitid
"
BLOB NOT NULL ,
"
example
"
TEXT NOT NULL ,
"
source
"
TEXT NOT NULL
);
CREATE INDEX sen_i ON senseexample (unitid);
CREATE INDEX
"
sen_i
"
ON
"
tbl_
senseexample
"
(
"
unitid
"
);
CREATE TABLE externallink (
unitid INTEGER NOT NULL
REFERENCES lexicalunit (id),
link TEXT NOT NULL COLLATE locale
CREATE TABLE
"
tbl_externallink
"
(
"
unitid
"
BLOB NOT NULL ,
"
link
"
TEXT NOT NULL
);
CREATE INDEX link_i ON externallink (unitid);
CREATE INDEX
"
link_i
"
ON
"
tbl_
externallink
"
(
"
unitid
"
);
CREATE TABLE usagenote (
unitid INTEGER NOT NULL
REFERENCES lexicalunit (id),
note TEXT NOT NULL COLLATE locale
CREATE TABLE
"
tbl_usagenote
"
(
"
unitid
"
BLOB NOT NULL ,
"
note
"
TEXT NOT NULL
);
CREATE INDEX note_i ON usagenote (unitid);
CREATE TABLE unitemotionname (
unitid INTEGER NOT NULL
REFERENCES lexicalunit (id),
nameid INTEGER NOT NULL
REFERENCES emotionname (id),
CREATE INDEX
"
note_i
"
ON
"
tbl_usagenote
"
(
"
unitid
"
);
PRIMARY KEY (unitid, nameid)
CREATE TABLE
"
tbl_unitemotionname
"
(
"
unitid
"
BLOB NOT NULL ,
"
nameid
"
INTEGER NOT NULL ,
PRIMARY KEY (
"
unitid
"
,
"
nameid
"
)
);
CREATE TABLE unitemotionvaluation (
unitid INTEGER NOT NULL
REFERENCES lexicalunit (id),
valuationid INTEGER NOT NULL
REFERENCES emotionvaluation (id),
PRIMARY KEY (unitid, valuationid)
CREATE TABLE
"
tbl_unitemotionvaluation
"
(
"
unitid
"
BLOB NOT NULL ,
"
valuationid
"
INTEGER NOT NULL ,
PRIMARY KEY (
"
unitid
"
,
"
valuationid
"
)
);
-- Relation tables --
-- The for below are used to gather combinations of parent / child relation
-- names.
CREATE TABLE synsetrelationparentpart (
id INTEGER PRIMARY KEY,
name TEXT UNIQUE NOT NULL COLLATE locale
CREATE TABLE
"
tbl_synsetrelationparentpart
"
(
"
id
"
INTEGER NOT NULL ,
"
name
"
VARCHAR(255) NOT NULL ,
PRIMARY KEY (
"
id
"
)
);
CREATE TABLE synsetrelationchildpart (
id INTEGER PRIMARY KEY,
name TEXT UNIQUE NOT NULL COLLATE locale
CREATE TABLE
"
tbl_synsetrelationchildpart
"
(
"
id
"
INTEGER NOT NULL ,
"
name
"
VARCHAR(255) NOT NULL ,
PRIMARY KEY (
"
id
"
)
);
CREATE TABLE lexicalrelationparentpart (
id INTEGER PRIMARY KEY,
name TEXT UNIQUE NOT NULL COLLATE locale
CREATE TABLE
"
tbl_lexicalrelationparentpart
"
(
"
id
"
INTEGER NOT NULL ,
"
name
"
VARCHAR(255) NOT NULL ,
PRIMARY KEY (
"
id
"
)
);
CREATE TABLE lexicalrelationchildpart (
id INTEGER PRIMARY KEY,
name TEXT UNIQUE NOT NULL COLLATE locale
CREATE TABLE
"
tbl_lexicalrelationchildpart
"
(
"
id
"
INTEGER NOT NULL ,
"
name
"
VARCHAR(255) NOT NULL ,
PRIMARY KEY (
"
id
"
)
);
CREATE UNIQUE INDEX
"
name
"
ON
"
tbl_lexicalrelationchildpart
"
(
"
name
"
);
CREATE UNIQUE INDEX
"
parentpart
"
ON
"
tbl_lexicalrelationtype
"
(
"
parentpart
"
,
"
childpart
"
);
-- Next, gather these parts into relation types themselves.
-- Parent can
'
t be NULL - the no-parent case will be handled by a special empty
-- string parent. This is so that UNIQUE works correctly.
CREATE TABLE synsetrelationtype (
id INTEGER PRIMARY KEY,
parentpart INTEGER NOT NULL
REFERENCES synsetrelationparentpart (id),
childpart INTEGER NOT NULL
REFERENCES synsetrelationchildpart (id),
UNIQUE (parentpart, childpart)
CREATE TABLE
"
tbl_synsetrelationtype
"
(
"
id
"
BLOB NOT NULL ,
"
legacy_id
"
INTEGER NULL ,
"
parentpart
"
INTEGER NOT NULL ,
"
childpart
"
INTEGER NOT NULL ,
PRIMARY KEY (
"
id
"
)
);
CREATE TABLE lexicalrelationtype (
id INTEGER PRIMARY KEY,
parentpart INTEGER NOT NULL
REFERENCES lexicalrelationparentpart (id),
childpart INTEGER NOT NULL
REFERENCES lexicalrelationchildpart (id),
UNIQUE (parentpart, childpart)
CREATE TABLE
"
tbl_lexicalrelationtype
"
(
"
id
"
BLOB NOT NULL ,
"
legacy_id
"
INTEGER NULL ,
"
parentpart
"
INTEGER NOT NULL ,
"
childpart
"
INTEGER NOT NULL ,
PRIMARY KEY (
"
id
"
)
);
-- The below tables are simply maps of relation aliases to their main IDs.
-- Reverse indexes are needed, too.
CREATE TABLE synsetrelationalias (
name TEXT PRIMARY KEY NOT NULL COLLATE locale
,
relationid
INTEGER
NOT NULL
REFERENCES synsetrelationtype (id
)
CREATE TABLE
"
tbl_
synsetrelationalias
"
(
"
name
"
VARCHAR(255) NOT NULL
,
"
relationid
"
BLOB
NOT NULL
,
PRIMARY KEY (
"
name
"
)
);
CREATE INDEX synsetrelationalias_irev ON synsetrelationalias (relationid);
CREATE TABLE lexicalrelationalias (
name TEXT PRIMARY KEY NOT NULL COLLATE locale
,
relationid
INTEGER
NOT NULL
REFERENCES lexicalrelationtype (id
)
CREATE INDEX
"
synsetrelationalias_irev
"
ON
"
tbl_
synsetrelationalias
"
(
"
relationid
"
);
CREATE TABLE
"
tbl_
lexicalrelationalias
"
(
"
name
"
VARCHAR(255) NOT NULL
,
"
relationid
"
BLOB
NOT NULL
,
PRIMARY KEY (
"
name
"
)
);
CREATE INDEX lexicalrelationalias_irev ON lexicalrelationalias (relationid);
CREATE INDEX
"
lexicalrelationalias_irev
"
ON
"
tbl_
lexicalrelationalias
"
(
"
relationid
"
);
-- Next are finally the relation instances
CREATE TABLE synsetrelation (
source INTEGER NOT NULL
REFERENCES synset (id),
relationtype INTEGER NOT NULL
REFERENCES synsetrelationtype (id),
target INTEGER NOT NULL
REFERENCES synset (id),
PRIMARY KEY (source, relationtype, target)
CREATE TABLE
"
tbl_synsetrelation
"
(
"
source
"
BLOB NOT NULL ,
"
relationtype
"
BLOB NOT NULL ,
"
target
"
BLOB NOT NULL ,
PRIMARY KEY (
"
source
"
,
"
relationtype
"
,
"
target
"
)
);
CREATE TABLE lexicalrelation (
source INTEGER NOT NULL
REFERENCES lexicalunit (id),
relationtype INTEGER NOT NULL
REFERENCES lexicalrelationtype (id),
target INTEGER NOT NULL
REFERENCES lexicalunit (id),
PRIMARY KEY (source, relationtype, target)
CREATE TABLE
"
tbl_lexicalrelation
"
(
"
source
"
BLOB NOT NULL ,
"
relationtype
"
BLOB NOT NULL ,
"
target
"
BLOB NOT NULL ,
PRIMARY KEY (
"
source
"
,
"
relationtype
"
,
"
target
"
)
);
-- Insert the special empty values for the parent part tables
...
...
@@ -267,24 +253,24 @@ INSERT INTO lexicalrelationparentpart (name) VALUES ('');
"""
# }}}
_RELTYPE_TABLES
=
{
en
.
RelationKind
.
synset
:
u
'
synsetrelationtype
'
,
en
.
RelationKind
.
lexical
:
u
'
lexicalrelationtype
'
,
en
.
RelationKind
.
synset
:
u
'
tbl_
synsetrelationtype
'
,
en
.
RelationKind
.
lexical
:
u
'
tbl_
lexicalrelationtype
'
,
}
_RELALIAS_TABLES
=
{
en
.
RelationKind
.
synset
:
u
'
synsetrelationalias
'
,
en
.
RelationKind
.
lexical
:
u
'
lexicalrelationalias
'
,
en
.
RelationKind
.
synset
:
u
'
tbl_
synsetrelationalias
'
,
en
.
RelationKind
.
lexical
:
u
'
tbl_
lexicalrelationalias
'
,
}
_RELPARENTPART_TABLES
=
{
en
.
RelationKind
.
synset
:
u
'
synsetrelationparentpart
'
,
en
.
RelationKind
.
lexical
:
u
'
lexicalrelationparentpart
'
,
en
.
RelationKind
.
synset
:
u
'
tbl_
synsetrelationparentpart
'
,
en
.
RelationKind
.
lexical
:
u
'
tbl_
lexicalrelationparentpart
'
,
}
_RELCHILDPART_TABLES
=
{
en
.
RelationKind
.
synset
:
u
'
synsetrelationchildpart
'
,
en
.
RelationKind
.
lexical
:
u
'
lexicalrelationchildpart
'
,
en
.
RelationKind
.
synset
:
u
'
tbl_
synsetrelationchildpart
'
,
en
.
RelationKind
.
lexical
:
u
'
tbl_
lexicalrelationchildpart
'
,
}
_RELINST_TABLES
=
{
en
.
RelationKind
.
synset
:
u
'
synsetrelation
'
,
en
.
RelationKind
.
lexical
:
u
'
lexicalrelation
'
,
en
.
RelationKind
.
synset
:
u
'
tbl_
synsetrelation
'
,
en
.
RelationKind
.
lexical
:
u
'
tbl_
lexicalrelation
'
,
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment