Skip to content

Commit

Permalink
Add ability to mark lexicons as modified
Browse files Browse the repository at this point in the history
Related to #17
  • Loading branch information
goodmami committed Feb 11, 2021
1 parent 5306b6d commit 6140ccb
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 13 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
* Support for detecting and loading ILI tab-separated-value exports;
not directly accessible through the public API at this time ([#23])
* Support for adding ILI resources to the database ([#23])
* `wn.Lexicon.modified()` ([#17])

### Fixed

Expand Down Expand Up @@ -67,6 +68,7 @@
* All extendable tables are now linked to their lexicon ([#91])
* Added rowid to tables with metadata
* Added source-sense to definitions table ([#65])
* Preemptively added a `modified` column to `lexicons` table ([#17])


## [v0.5.1]
Expand Down Expand Up @@ -259,6 +261,7 @@ abandoned, but this is an entirely new codebase.
[unreleased]: ../../tree/main

[#15]: https://github.com/goodmami/wn/issues/15
[#17]: https://github.com/goodmami/wn/issues/17
[#23]: https://github.com/goodmami/wn/issues/23
[#47]: https://github.com/goodmami/wn/issues/47
[#58]: https://github.com/goodmami/wn/issues/58
Expand Down
1 change: 1 addition & 0 deletions docs/api/wn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ The Lexicon Class

.. automethod:: metadata
.. automethod:: specifier
.. automethod:: modified

The wn.config Object
--------------------
Expand Down
5 changes: 3 additions & 2 deletions wn/_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def _add_lmf(
continue

cur.execute(
'INSERT INTO lexicons VALUES (null,?,?,?,?,?,?,?,?,?)',
'INSERT INTO lexicons VALUES (null,?,?,?,?,?,?,?,?,?,?)',
(lexicon.id,
lexicon.label,
lexicon.language,
Expand All @@ -121,7 +121,8 @@ def _add_lmf(
lexicon.version,
lexicon.url,
lexicon.citation,
lexicon.meta))
lexicon.meta,
False))
lexid = cur.lastrowid

counts = info['counts']
Expand Down
25 changes: 15 additions & 10 deletions wn/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
find_senses,
find_synsets,
get_lexicon,
get_modified,
get_form_tags,
get_entry_senses,
get_sense_relations,
Expand Down Expand Up @@ -115,16 +116,16 @@ class Lexicon(_DatabaseEntity):
_ENTITY_TYPE = 'lexicons'

def __init__(
self,
id: str,
label: str,
language: str,
email: str,
license: str,
version: str,
url: str = None,
citation: str = None,
_id: int = NON_ROWID,
self,
id: str,
label: str,
language: str,
email: str,
license: str,
version: str,
url: str = None,
citation: str = None,
_id: int = NON_ROWID,
):
super().__init__(_id=_id)
self.id = id
Expand All @@ -148,6 +149,10 @@ def specifier(self) -> str:
"""Return the *id:version* lexicon specifier."""
return f'{self.id}:{self.version}'

def modified(self) -> bool:
"""Return True if the lexicon has local modifications."""
return get_modified(self._id)


class _LexiconElement(_DatabaseEntity):
__slots__ = '_lexid', '_wordnet'
Expand Down
2 changes: 1 addition & 1 deletion wn/_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
# >>> wn._db.schema_hash(conn)
#
COMPATIBLE_SCHEMA_HASHES = {
'd2cc6989a7a13dc76a7e332841d5f51d9a54368a',
'c400433b9d05fcb235f361b5bafdf831a12ea994',
}


Expand Down
5 changes: 5 additions & 0 deletions wn/_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ def _get_lexicon_rowids_for_lexicon(
return lex_match


def get_modified(rowid: int) -> bool:
query = 'SELECT modified FROM lexicons WHERE rowid = ?'
return connect().execute(query, (rowid,)).fetchone()[0]


def find_ilis(
id: str = None,
status: str = None,
Expand Down
1 change: 1 addition & 0 deletions wn/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ CREATE TABLE lexicons (
url TEXT,
citation TEXT,
metadata META,
modified BOOLEAN CHECK( modified IN (0, 1) ) DEFAULT 0 NOT NULL,
UNIQUE (id, version)
);

Expand Down

0 comments on commit 6140ccb

Please sign in to comment.