Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PLWN_API
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Redmine
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Libraries
PLWN_API
Commits
63c558e4
Commit
63c558e4
authored
Mar 8, 2023
by
Grzegorz Kuboń
Browse files
Options
Downloads
Patches
Plain Diff
sql script changed
parent
079422f2
No related branches found
No related tags found
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
Show 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"""
...
@@ -63,202 +63,188 @@ _DB_SCHEMA_SCRIPT = u"""
PRAGMA foreign_keys = ON;
PRAGMA foreign_keys = ON;
-- Metadata table. Used for version number, currently
-- Metadata table. Used for version number, currently
CREATE TABLE plwn_meta (
CREATE TABLE
"
tbl_
plwn_meta
"
(
name TEXT UNIQUE
NOT NULL,
"
name
"
VARCHAR(255)
NOT NULL
,
value BLOB
"
value
"
BLOB
NULL
);
);
-- Tables for constant values
-- Tables for constant values
CREATE TABLE pos (
CREATE TABLE
"
tbl_pos
"
(
id INTEGER PRIMARY KEY,
"
id
"
INTEGER NOT NULL ,
value TEXT UNIQUE NOT NULL
"
value
"
VARCHAR(255) NOT NULL ,
PRIMARY KEY (
"
id
"
)
);
);
CREATE TABLE verbaspect (
CREATE TABLE
"
tbl_verbaspect
"
(
id INTEGER PRIMARY KEY,
"
id
"
INTEGER NOT NULL ,
value TEXT UNIQUE NOT NULL
"
value
"
VARCHAR(255) NOT NULL ,
PRIMARY KEY (
"
id
"
)
);
);
CREATE TABLE emotionmark (
CREATE TABLE
"
tbl_emotionmark
"
(
id INTEGER PRIMARY KEY,
"
id
"
INTEGER NOT NULL ,
value TEXT UNIQUE NOT NULL
"
value
"
VARCHAR(255) NOT NULL ,
PRIMARY KEY (
"
id
"
)
);
);
CREATE TABLE emotionname (
CREATE TABLE
"
tbl_emotionname
"
(
id INTEGER PRIMARY KEY,
"
id
"
INTEGER NOT NULL ,
value TEXT UNIQUE NOT NULL COLLATE locale
"
value
"
VARCHAR(255) NOT NULL ,
PRIMARY KEY (
"
id
"
)
);
);
CREATE TABLE emotionvaluation (
CREATE TABLE
"
tbl_emotionvaluation
"
(
id INTEGER PRIMARY KEY,
"
id
"
INTEGER NOT NULL ,
value TEXT UNIQUE NOT NULL COLLATE locale
"
value
"
VARCHAR(255) NOT NULL ,
PRIMARY KEY (
"
id
"
)
);
);
CREATE TABLE domain (
CREATE TABLE
"
tbl_domain
"
(
id INTEGER PRIMARY KEY,
"
id
"
INTEGER NOT NULL ,
value TEXT UNIQUE NOT NULL COLLATE locale
"
value
"
VARCHAR(255) NOT NULL ,
PRIMARY KEY (
"
id
"
)
);
);
CREATE UNIQUE INDEX
"
value
"
ON
"
tbl_domain
"
(
"
value
"
);
-- Synset only gets one simple table
-- Synset only gets one simple table
CREATE TABLE synset (
CREATE TABLE
"
tbl_synset
"
(
id INTEGER PRIMARY KEY,
"
id
"
BLOB NOT NULL ,
definition TEXT COLLATE locale,
"
legacy_id
"
INTEGER NULL ,
isartificial INTEGER NOT NULL DEFAULT 0
"
definition
"
TEXT NULL ,
"
isartificial
"
INTEGER NOT NULL DEFAULT
'
0
'
,
PRIMARY KEY (
"
id
"
)
);
);
-- Lexical units have several tables, since they have several list-like
-- Lexical units have several tables, since they have several list-like
-- properties. They also need indexes for lookup.
-- properties. They also need indexes for lookup.
CREATE TABLE lexicalunit (
id INTEGER PRIMARY KEY,
CREATE TABLE
"
tbl_lexicalunit
"
(
lemma TEXT NOT NULL COLLATE locale,
"
id
"
BLOB NOT NULL ,
pos INTEGER NOT NULL
"
legacy_id
"
INTEGER NULL ,
REFERENCES pos (id),
"
lemma
"
VARCHAR(255) NOT NULL ,
variant INTEGER NOT NULL,
"
pos
"
INTEGER NOT NULL ,
synset INTEGER NOT NULL
"
variant
"
INTEGER NOT NULL ,
REFERENCES synset (id),
"
synset
"
BLOB NOT NULL ,
unitindex INTEGER NOT NULL,
"
unitindex
"
INTEGER NOT NULL ,
definition TEXT COLLATE locale,
"
definition
"
TEXT NULL ,
domain INTEGER NOT NULL
"
domain
"
INTEGER NOT NULL ,
REFERENCES domain (id),
"
verbaspect
"
INTEGER NULL ,
verbaspect INTEGER
"
isemotional
"
INTEGER NULL ,
REFERENCES verbaspect (id),
"
emotionmark
"
INTEGER NULL ,
isemotional INTEGER,
"
emotionexample1
"
TEXT NULL ,
emotionmark INTEGER
"
emotionexample2
"
TEXT NULL ,
REFERENCES emotionmark (id),
PRIMARY KEY (
"
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)
);
);
-- lem-pos-var and synset-unitindex indexes (and partial ones) are
CREATE UNIQUE INDEX
"
lemma
"
ON
"
tbl_lexicalunit
"
(
"
lemma
"
,
"
pos
"
,
"
variant
"
);
-- automatically made because of UNIQUE constraint, but additional indexes
CREATE INDEX
"
lex_i_lem_var
"
ON
"
tbl_lexicalunit
"
(
"
lemma
"
,
"
variant
"
);
-- need to be created.
CREATE INDEX
"
lex_i_pos
"
ON
"
tbl_lexicalunit
"
(
"
pos
"
);
CREATE INDEX lex_i_lem_var ON lexicalunit (lemma, variant);
CREATE UNIQUE INDEX
"
synset
"
ON
"
tbl_lexicalunit
"
(
"
synset
"
,
"
unitindex
"
);
CREATE INDEX lex_i_pos ON lexicalunit (pos);
-- No index for variant itself - it
'
s not an useful use case
-- Tables dependant on lexicalunit
-- Tables dependant on lexicalunit
CREATE TABLE senseexample (
CREATE TABLE
"
tbl_senseexample
"
(
unitid INTEGER NOT NULL
"
unitid
"
BLOB NOT NULL ,
REFERENCES lexicalunit (id),
"
example
"
TEXT NOT NULL ,
example TEXT NOT NULL COLLATE locale,
"
source
"
TEXT NOT NULL
source TEXT NOT NULL COLLATE locale
);
);
CREATE INDEX sen_i ON senseexample (unitid);
CREATE INDEX
"
sen_i
"
ON
"
tbl_
senseexample
"
(
"
unitid
"
);
CREATE TABLE externallink (
CREATE TABLE
"
tbl_externallink
"
(
unitid INTEGER NOT NULL
"
unitid
"
BLOB NOT NULL ,
REFERENCES lexicalunit (id),
"
link
"
TEXT NOT NULL
link TEXT NOT NULL COLLATE locale
);
);
CREATE INDEX link_i ON externallink (unitid);
CREATE INDEX
"
link_i
"
ON
"
tbl_
externallink
"
(
"
unitid
"
);
CREATE TABLE usagenote (
CREATE TABLE
"
tbl_usagenote
"
(
unitid INTEGER NOT NULL
"
unitid
"
BLOB NOT NULL ,
REFERENCES lexicalunit (id),
"
note
"
TEXT NOT NULL
note TEXT NOT NULL COLLATE locale
);
);
CREATE INDEX note_i ON usagenote (unitid);
CREATE INDEX
"
note_i
"
ON
"
tbl_usagenote
"
(
"
unitid
"
);
CREATE TABLE unitemotionname (
unitid INTEGER NOT NULL
REFERENCES lexicalunit (id),
nameid INTEGER NOT NULL
REFERENCES emotionname (id),
PRIMARY KEY (unitid, nameid)
CREATE TABLE
"
tbl_unitemotionname
"
(
"
unitid
"
BLOB NOT NULL ,
"
nameid
"
INTEGER NOT NULL ,
PRIMARY KEY (
"
unitid
"
,
"
nameid
"
)
);
);
CREATE TABLE unitemotionvaluation (
CREATE TABLE
"
tbl_unitemotionvaluation
"
(
unitid INTEGER NOT NULL
"
unitid
"
BLOB NOT NULL ,
REFERENCES lexicalunit (id),
"
valuationid
"
INTEGER NOT NULL ,
valuationid INTEGER NOT NULL
PRIMARY KEY (
"
unitid
"
,
"
valuationid
"
)
REFERENCES emotionvaluation (id),
PRIMARY KEY (unitid, valuationid)
);
);
-- Relation tables --
-- Relation tables --
-- The for below are used to gather combinations of parent / child relation
-- The for below are used to gather combinations of parent / child relation
-- names.
-- names.
CREATE TABLE synsetrelationparentpart (
CREATE TABLE
"
tbl_synsetrelationparentpart
"
(
id INTEGER PRIMARY KEY,
"
id
"
INTEGER NOT NULL ,
name TEXT UNIQUE NOT NULL COLLATE locale
"
name
"
VARCHAR(255) NOT NULL ,
PRIMARY KEY (
"
id
"
)
);
);
CREATE TABLE synsetrelationchildpart (
CREATE TABLE
"
tbl_synsetrelationchildpart
"
(
id INTEGER PRIMARY KEY,
"
id
"
INTEGER NOT NULL ,
name TEXT UNIQUE NOT NULL COLLATE locale
"
name
"
VARCHAR(255) NOT NULL ,
PRIMARY KEY (
"
id
"
)
);
);
CREATE TABLE lexicalrelationparentpart (
CREATE TABLE
"
tbl_lexicalrelationparentpart
"
(
id INTEGER PRIMARY KEY,
"
id
"
INTEGER NOT NULL ,
name TEXT UNIQUE NOT NULL COLLATE locale
"
name
"
VARCHAR(255) NOT NULL ,
PRIMARY KEY (
"
id
"
)
);
);
CREATE TABLE lexicalrelationchildpart (
CREATE TABLE
"
tbl_lexicalrelationchildpart
"
(
id INTEGER PRIMARY KEY,
"
id
"
INTEGER NOT NULL ,
name TEXT UNIQUE NOT NULL COLLATE locale
"
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.
-- Next, gather these parts into relation types themselves.
-- Parent can
'
t be NULL - the no-parent case will be handled by a special empty
-- 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.
-- string parent. This is so that UNIQUE works correctly.
CREATE TABLE synsetrelationtype (
CREATE TABLE
"
tbl_synsetrelationtype
"
(
id INTEGER PRIMARY KEY,
"
id
"
BLOB NOT NULL ,
parentpart INTEGER NOT NULL
"
legacy_id
"
INTEGER NULL ,
REFERENCES synsetrelationparentpart (id),
"
parentpart
"
INTEGER NOT NULL ,
childpart INTEGER NOT NULL
"
childpart
"
INTEGER NOT NULL ,
REFERENCES synsetrelationchildpart (id),
PRIMARY KEY (
"
id
"
)
UNIQUE (parentpart, childpart)
);
);
CREATE TABLE lexicalrelationtype (
CREATE TABLE
"
tbl_lexicalrelationtype
"
(
id INTEGER PRIMARY KEY,
"
id
"
BLOB NOT NULL ,
parentpart INTEGER NOT NULL
"
legacy_id
"
INTEGER NULL ,
REFERENCES lexicalrelationparentpart (id),
"
parentpart
"
INTEGER NOT NULL ,
childpart INTEGER NOT NULL
"
childpart
"
INTEGER NOT NULL ,
REFERENCES lexicalrelationchildpart (id),
PRIMARY KEY (
"
id
"
)
UNIQUE (parentpart, childpart)
);
);
-- The below tables are simply maps of relation aliases to their main IDs.
-- The below tables are simply maps of relation aliases to their main IDs.
-- Reverse indexes are needed, too.
-- Reverse indexes are needed, too.
CREATE TABLE synsetrelationalias (
CREATE TABLE
"
tbl_
synsetrelationalias
"
(
name TEXT PRIMARY KEY NOT NULL COLLATE locale
,
"
name
"
VARCHAR(255) NOT NULL
,
relationid
INTEGER
NOT NULL
"
relationid
"
BLOB
NOT NULL
,
REFERENCES synsetrelationtype (id
)
PRIMARY KEY (
"
name
"
)
);
);
CREATE INDEX synsetrelationalias_irev ON synsetrelationalias (relationid);
CREATE INDEX
"
synsetrelationalias_irev
"
ON
"
tbl_
synsetrelationalias
"
(
"
relationid
"
);
CREATE TABLE lexicalrelationalias (
CREATE TABLE
"
tbl_
lexicalrelationalias
"
(
name TEXT PRIMARY KEY NOT NULL COLLATE locale
,
"
name
"
VARCHAR(255) NOT NULL
,
relationid
INTEGER
NOT NULL
"
relationid
"
BLOB
NOT NULL
,
REFERENCES lexicalrelationtype (id
)
PRIMARY KEY (
"
name
"
)
);
);
CREATE INDEX lexicalrelationalias_irev ON lexicalrelationalias (relationid);
CREATE INDEX
"
lexicalrelationalias_irev
"
ON
"
tbl_
lexicalrelationalias
"
(
"
relationid
"
);
-- Next are finally the relation instances
-- Next are finally the relation instances
CREATE TABLE synsetrelation (
CREATE TABLE
"
tbl_synsetrelation
"
(
source INTEGER NOT NULL
"
source
"
BLOB NOT NULL ,
REFERENCES synset (id),
"
relationtype
"
BLOB NOT NULL ,
relationtype INTEGER NOT NULL
"
target
"
BLOB NOT NULL ,
REFERENCES synsetrelationtype (id),
PRIMARY KEY (
"
source
"
,
"
relationtype
"
,
"
target
"
)
target INTEGER NOT NULL
REFERENCES synset (id),
PRIMARY KEY (source, relationtype, target)
);
);
CREATE TABLE lexicalrelation (
CREATE TABLE
"
tbl_lexicalrelation
"
(
source INTEGER NOT NULL
"
source
"
BLOB NOT NULL ,
REFERENCES lexicalunit (id),
"
relationtype
"
BLOB NOT NULL ,
relationtype INTEGER NOT NULL
"
target
"
BLOB NOT NULL ,
REFERENCES lexicalrelationtype (id),
PRIMARY KEY (
"
source
"
,
"
relationtype
"
,
"
target
"
)
target INTEGER NOT NULL
REFERENCES lexicalunit (id),
PRIMARY KEY (source, relationtype, target)
);
);
-- Insert the special empty values for the parent part tables
-- Insert the special empty values for the parent part tables
...
@@ -267,24 +253,24 @@ INSERT INTO lexicalrelationparentpart (name) VALUES ('');
...
@@ -267,24 +253,24 @@ INSERT INTO lexicalrelationparentpart (name) VALUES ('');
"""
# }}}
"""
# }}}
_RELTYPE_TABLES
=
{
_RELTYPE_TABLES
=
{
en
.
RelationKind
.
synset
:
u
'
synsetrelationtype
'
,
en
.
RelationKind
.
synset
:
u
'
tbl_
synsetrelationtype
'
,
en
.
RelationKind
.
lexical
:
u
'
lexicalrelationtype
'
,
en
.
RelationKind
.
lexical
:
u
'
tbl_
lexicalrelationtype
'
,
}
}
_RELALIAS_TABLES
=
{
_RELALIAS_TABLES
=
{
en
.
RelationKind
.
synset
:
u
'
synsetrelationalias
'
,
en
.
RelationKind
.
synset
:
u
'
tbl_
synsetrelationalias
'
,
en
.
RelationKind
.
lexical
:
u
'
lexicalrelationalias
'
,
en
.
RelationKind
.
lexical
:
u
'
tbl_
lexicalrelationalias
'
,
}
}
_RELPARENTPART_TABLES
=
{
_RELPARENTPART_TABLES
=
{
en
.
RelationKind
.
synset
:
u
'
synsetrelationparentpart
'
,
en
.
RelationKind
.
synset
:
u
'
tbl_
synsetrelationparentpart
'
,
en
.
RelationKind
.
lexical
:
u
'
lexicalrelationparentpart
'
,
en
.
RelationKind
.
lexical
:
u
'
tbl_
lexicalrelationparentpart
'
,
}
}
_RELCHILDPART_TABLES
=
{
_RELCHILDPART_TABLES
=
{
en
.
RelationKind
.
synset
:
u
'
synsetrelationchildpart
'
,
en
.
RelationKind
.
synset
:
u
'
tbl_
synsetrelationchildpart
'
,
en
.
RelationKind
.
lexical
:
u
'
lexicalrelationchildpart
'
,
en
.
RelationKind
.
lexical
:
u
'
tbl_
lexicalrelationchildpart
'
,
}
}
_RELINST_TABLES
=
{
_RELINST_TABLES
=
{
en
.
RelationKind
.
synset
:
u
'
synsetrelation
'
,
en
.
RelationKind
.
synset
:
u
'
tbl_
synsetrelation
'
,
en
.
RelationKind
.
lexical
:
u
'
lexicalrelation
'
,
en
.
RelationKind
.
lexical
:
u
'
tbl_
lexicalrelation
'
,
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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