From 8817984f3730baac1e50874ecc9d5d9f57ad6bab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Grzegorz=20Kubo=C5=84?= <g_kubon@e-science.pl> Date: Thu, 9 Mar 2023 15:03:24 +0100 Subject: [PATCH] fix some tests, add test_load job to gitlab CI --- .gitlab-ci.yml | 8 ++++++ plwn/storages/sqlite.py | 56 +++++++++++++++++++++++------------------ 2 files changed, 40 insertions(+), 24 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b80625c..1b9fe29 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -10,6 +10,7 @@ cache: stages: - check_style - tests + - test_load - push_wheel pep8: @@ -44,3 +45,10 @@ push_wheel: --repository-url https://pypi.clarin-pl.eu/ -u $PIPY_USER -p $PIPY_PASS dist/plwn_api*.whl +test_load: + stage: test_load + before_script: + - pip install --upgrade pip + - pip install . + script: + - python -c 'import plwn; print(plwn.load_default().lexical_unit("pies", plwn.PoS.noun_pl, 2).definition)' diff --git a/plwn/storages/sqlite.py b/plwn/storages/sqlite.py index 54f5f32..6f48144 100644 --- a/plwn/storages/sqlite.py +++ b/plwn/storages/sqlite.py @@ -198,10 +198,7 @@ CREATE TABLE tbl_lexicalrelationchildpart ( 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 @@ -220,6 +217,10 @@ CREATE TABLE tbl_lexicalrelationtype ( childpart INTEGER NOT NULL , PRIMARY KEY (id) ); +CREATE UNIQUE INDEX parentpart ON tbl_lexicalrelationtype ( + parentpart, + childpart +); -- The below tables are simply maps of relation aliases to their main IDs. -- Reverse indexes are needed, too. @@ -255,8 +256,8 @@ CREATE TABLE tbl_lexicalrelation ( ); -- Insert the special empty values for the parent part tables -INSERT INTO synsetrelationparentpart (name) VALUES (''); -INSERT INTO lexicalrelationparentpart (name) VALUES (''); +INSERT INTO tbl_synsetrelationparentpart (name) VALUES (''); +INSERT INTO tbl_lexicalrelationparentpart (name) VALUES (''); """ # }}} _RELTYPE_TABLES = { @@ -1343,18 +1344,23 @@ class _DBBuilder(object): # Synset to lexical units relations also need to be deferred. self._synid2lexids = coll.defaultdict(list) # Cache IDs of constant values - with closing(db.execute(u"SELECT value, id FROM pos")) as cur: + with closing(db.execute(u"SELECT value, id FROM tbl_pos")) as cur: self._posids = dict(cur) - with closing(db.execute(u"SELECT value, id FROM verbaspect")) as cur: + with closing(db.execute(u"SELECT value, id FROM tbl_verbaspect")) \ + as cur: self._vaids = dict(cur) - with closing(db.execute(u"SELECT value, id FROM emotionmark")) as cur: + with closing(db.execute(u"SELECT value, id FROM tbl_emotionmark")) \ + as cur: self._emids = dict(cur) - with closing(db.execute(u"SELECT value, id FROM emotionname")) as cur: - self._enids = dict(cur) - with closing(db.execute(u"SELECT value, id FROM emotionvaluation")) \ + with closing(db.execute(u"SELECT value, id FROM tbl_emotionname")) \ as cur: + self._enids = dict(cur) + with closing(db.execute(u""" + SELECT value, id + FROM tbl_emotionvaluation + """)) as cur: self._evids = dict(cur) - with closing(db.execute(u"SELECT value, id FROM domain")) as cur: + with closing(db.execute(u"SELECT value, id FROM tbl_domain")) as cur: self._dmids = dict(cur) def __call__(self, reader): @@ -1381,7 +1387,7 @@ class _DBBuilder(object): def _insert_synset(self, syn_node): self._db.execute( u""" - INSERT INTO synset (id, definition, isartificial) + INSERT INTO tbl_synset (id, definition, isartificial) VALUES (?, ?, ?) """, (syn_node.id, syn_node.definition, syn_node.is_artificial), @@ -1432,7 +1438,7 @@ class _DBBuilder(object): try: cur.execute( u""" - INSERT INTO lexicalunit ( + INSERT INTO tbl_lexicalunit ( id, lemma, pos, variant, synset, unitindex, definition, domain, verbaspect, @@ -1483,7 +1489,7 @@ class _DBBuilder(object): cur.executemany( u""" - INSERT INTO senseexample (unitid, example, source) + INSERT INTO tbl_senseexample (unitid, example, source) VALUES (?, ?, ?) """, ( @@ -1494,14 +1500,14 @@ class _DBBuilder(object): ) cur.executemany( u""" - INSERT INTO usagenote (unitid, note) + INSERT INTO tbl_usagenote (unitid, note) VALUES (?, ?) """, ((lu_node.id, note) for note in lu_node.usage_notes), ) cur.executemany( u""" - INSERT INTO externallink (unitid, link) + INSERT INTO tbl_externallink (unitid, link) VALUES (?, ?) """, ((lu_node.id, link) @@ -1509,7 +1515,7 @@ class _DBBuilder(object): ) cur.executemany( u""" - INSERT INTO unitemotionname (unitid, nameid) + INSERT INTO tbl_unitemotionname (unitid, nameid) VALUES (?, ?) """, ( @@ -1519,7 +1525,8 @@ class _DBBuilder(object): ) cur.executemany( u""" - INSERT INTO unitemotionvaluation (unitid, valuationid) + INSERT INTO tbl_unitemotionvaluation + (unitid, valuationid) VALUES (?, ?) """, ( @@ -1656,10 +1663,11 @@ class _DBBuilder(object): with closing(self._db.cursor()) as cur: cur.execute( u""" - SELECT synset.id - FROM synset - LEFT JOIN lexicalunit ON synset.id = lexicalunit.synset - WHERE lexicalunit.synset IS NULL + SELECT tbl_synset.id + FROM tbl_synset + LEFT JOIN tbl_lexicalunit + ON tbl_synset.id = tbl_lexicalunit.synset + WHERE tbl_lexicalunit.synset IS NULL """, ) empties = tuple(row[0] for row in cur) -- GitLab