Skip to content
Snippets Groups Projects
Commit 63c558e4 authored by Grzegorz Kuboń's avatar Grzegorz Kuboń
Browse files

sql script changed

parent 079422f2
No related branches found
No related tags found
4 merge requests!10Revert "test if load_default will download dump",!9Merge request,!8Revert "test if load_default will download dump",!7Revert "test if load_default will download dump"
...@@ -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',
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment