From e21b72aafcce89ca280d9ad497dbfeaa914b70fd Mon Sep 17 00:00:00 2001 From: Le Tuan Anh Date: Thu, 13 May 2021 16:34:25 +0800 Subject: [PATCH 1/6] update README --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7172e57..d7f9577 100644 --- a/README.md +++ b/README.md @@ -17,8 +17,9 @@ Yawlib is available on [PyPI](https://pypi.org/project/yawlib/) pip install yawlib ``` -Download prebuilt database files are available on the author's [Open Science Framework project page: https://osf.io/9udjk/](https://osf.io/9udjk/) and extract them to your home folder at `~/wordnet/`. -On Linux it should look something like +Prebuilt database files are available on the author's [Open Science Framework project page: https://osf.io/9udjk/](https://osf.io/9udjk/). +Download them and extract those to your home folder at `~/wordnet/`. +On Linux it should look something like: ``` /home/username/wordnet/ From a606bc62d47c8709f7e3fbc7796bf7f039cc6683 Mon Sep 17 00:00:00 2001 From: Le Tuan Anh Date: Thu, 13 May 2021 16:38:57 +0800 Subject: [PATCH 2/6] Update README.md --- README.md | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index d7f9577..feda8fb 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,13 @@ -YAWlib - Yet Another WordNet library for Python -=============== +# YAWlib - Yet Another WordNet library for Python A Python library for accessing major WordNet releases using relational databases for high performance batch processing. -Supporting Wordnets: - - Princeton Wordnet 3.0 - NTU Open Multilingual WordNet - Gloss WordNet +- and more to be added in future versions -# Installation +## Installation Yawlib is available on [PyPI](https://pypi.org/project/yawlib/) @@ -50,7 +48,7 @@ To verify that yawlib is working properly, you can use the `info` command. python3 -m yawlib info ``` -# Command-line tools +## Command-line tools `yawlib` includes a command-line tool for querying wordnets directly from terminal. @@ -88,10 +86,11 @@ Looking for synsets by term (Provided: research | pos = None) Found 4 synset(s) ``` -# Development +## Development Go to yawlib folder, execute the config script and then run wntk.sh to generate the glosstab DB file. -``` + +```bash git clone https://github.com/letuananh/yawlib cd yawlib @@ -148,7 +147,7 @@ The run the `create` command to generate the database python -m yawlib create ``` -# Original sources +## Original sources - WordNet 3.0 SQLite: https://sourceforge.net/projects/wnsql/files/wnsql3/sqlite/3.0/ - WordNet glosstag (XML): http://wordnet.princeton.edu/glosstag.shtml From fe4f75b3144a35967ce22bea7d251ca99716d24a Mon Sep 17 00:00:00 2001 From: Le Tuan Anh Date: Thu, 13 May 2021 16:51:13 +0800 Subject: [PATCH 3/6] update version info --- setup.py | 2 +- yawlib/__version__.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/setup.py b/setup.py index 7ee797e..9d1873d 100755 --- a/setup.py +++ b/setup.py @@ -89,7 +89,7 @@ def read(*filenames, **kwargs): test_suite='test', # Reference: https://pypi.python.org/pypi?%3Aaction=list_classifiers classifiers=['Programming Language :: Python', - 'Development Status :: 2 - Pre-Alpha', + 'Development Status :: {}'.format(pkg_info['__status__']), 'Natural Language :: English', 'Environment :: Plugins', 'Intended Audience :: Developers', diff --git a/yawlib/__version__.py b/yawlib/__version__.py index 3216af4..71108fe 100644 --- a/yawlib/__version__.py +++ b/yawlib/__version__.py @@ -6,10 +6,10 @@ __copyright__ = "Copyright (c) 2014, Le Tuan Anh" __credits__ = [] __license__ = "MIT License" -__description__ = "YAWLib - Yet another WordNet library for Python" +__description__ = "Python library for accessing major wordnet releases using relational databases for high performance batch processing" __url__ = "https://github.com/letuananh/yawlib" __maintainer__ = "Le Tuan Anh" __version_major__ = "0.1" -__version__ = "{}a3".format(__version_major__) -__version_long__ = "{} - Alpha 3".format(__version_major__) -__status__ = "3 - Alpha" +__version__ = "{}rc".format(__version_major__) +__version_long__ = "{} - Release Candidate".format(__version_major__) +__status__ = "4 - Beta" From 929340f6c59196d329303fc618cd54e273df0d2c Mon Sep 17 00:00:00 2001 From: Le Tuan Anh Date: Thu, 13 May 2021 16:51:41 +0800 Subject: [PATCH 4/6] use texttaglib 0.1.1 release --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 1ccf197..ef1cd24 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1 @@ -texttaglib>=0.1.1a4 +texttaglib>=0.1.1, <0.2 From dfe3b6d3a12660e34757415ee73e8fc4269b1d48 Mon Sep 17 00:00:00 2001 From: Le Tuan Anh Date: Thu, 13 May 2021 17:29:22 +0800 Subject: [PATCH 5/6] code clean up. yawlib 0.1 ready --- setup.py | 1 - yawlib/__init__.py | 11 ++--- yawlib/__main__.py | 4 ++ yawlib/__version__.py | 10 ++-- yawlib/common.py | 58 +++-------------------- yawlib/config.py | 48 ++++--------------- yawlib/glosswordnet/__init__.py | 42 +++-------------- yawlib/glosswordnet/gwnmodels.py | 76 +++++++++--------------------- yawlib/glosswordnet/gwnsqlite.py | 56 +++++----------------- yawlib/glosswordnet/gwnxml.py | 74 +++++++++-------------------- yawlib/helpers.py | 68 +++++++-------------------- yawlib/models.py | 80 ++++++++------------------------ yawlib/omwsql.py | 38 ++------------- yawlib/wntk.py | 54 +++++---------------- yawlib/wordnetsql.py | 54 +++++---------------- yawlib/yawol/app.py | 48 +++---------------- yawlib/yawol/django/urls.py | 4 ++ yawlib/yawol/django/views.py | 58 +++++------------------ 18 files changed, 176 insertions(+), 608 deletions(-) diff --git a/setup.py b/setup.py index 9d1873d..40dacbc 100755 --- a/setup.py +++ b/setup.py @@ -57,7 +57,6 @@ def read(*filenames, **kwargs): with open('requirements.txt', 'r') as infile: requirements = infile.read().splitlines() - print(requirements) setup( diff --git a/yawlib/__init__.py b/yawlib/__init__.py index d3d1bb5..ab9a254 100644 --- a/yawlib/__init__.py +++ b/yawlib/__init__.py @@ -2,14 +2,13 @@ # -*- coding: utf-8 -*- ''' -YAWLib - Yet another WordNet library for Python - -Latest version can be found at https://github.com/letuananh/yawlib - -:copyright: (c) 2012 Le Tuan Anh -:license: MIT, see LICENSE for more details. +Python library for accessing major wordnet releases using relational databases for high performance batch processing ''' +# This code is a part of yawlib library: https://github.com/letuananh/yawlib +# :copyright: (c) 2014 Le Tuan Anh +# :license: MIT, see LICENSE for more details. + from . import __version__ as version_info from .__version__ import __author__, __email__, __copyright__, __maintainer__ from .__version__ import __credits__, __license__, __description__, __url__ diff --git a/yawlib/__main__.py b/yawlib/__main__.py index 5ae6070..8ade83a 100644 --- a/yawlib/__main__.py +++ b/yawlib/__main__.py @@ -1,2 +1,6 @@ +# This code is a part of yawlib library: https://github.com/letuananh/yawlib +# :copyright: (c) 2014 Le Tuan Anh +# :license: MIT, see LICENSE for more details. + from . import wntk wntk.main() diff --git a/yawlib/__version__.py b/yawlib/__version__.py index 71108fe..b2e55a3 100644 --- a/yawlib/__version__.py +++ b/yawlib/__version__.py @@ -1,5 +1,9 @@ # -*- coding: utf-8 -*- +# This code is a part of yawlib library: https://github.com/letuananh/yawlib +# :copyright: (c) 2014 Le Tuan Anh +# :license: MIT, see LICENSE for more details. + # yawlib's package version information __author__ = "Le Tuan Anh" __email__ = "tuananh.ke@gmail.com" @@ -10,6 +14,6 @@ __url__ = "https://github.com/letuananh/yawlib" __maintainer__ = "Le Tuan Anh" __version_major__ = "0.1" -__version__ = "{}rc".format(__version_major__) -__version_long__ = "{} - Release Candidate".format(__version_major__) -__status__ = "4 - Beta" +__version__ = "{}".format(__version_major__) +__version_long__ = "{} Stable".format(__version_major__) +__status__ = "5 - Production/Stable" diff --git a/yawlib/common.py b/yawlib/common.py index 7c2c59b..bcb7a75 100644 --- a/yawlib/common.py +++ b/yawlib/common.py @@ -1,63 +1,17 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -''' +""" Shared Wordnet features -Latest version can be found at https://github.com/letuananh/yawlib +""" -References: - Python documentation: - https://docs.python.org/ - PEP 0008 - Style Guide for Python Code - https://www.python.org/dev/peps/pep-0008/ - PEP 257 - Python Docstring Conventions: - https://www.python.org/dev/peps/pep-0257/ +# This code is a part of yawlib library: https://github.com/letuananh/yawlib +# :copyright: (c) 2014 Le Tuan Anh +# :license: MIT, see LICENSE for more details. -@author: Le Tuan Anh -''' - -# Copyright (c) 2017, Le Tuan Anh -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. - -__author__ = "Le Tuan Anh" -__email__ = "" -__copyright__ = "Copyright 2017, yawlib" -__license__ = "MIT" -__maintainer__ = "Le Tuan Anh" -__version__ = "0.1" -__status__ = "Prototype" -__credits__ = [] - -######################################################################## - -# ------------------------------------------------------------------------------- -# Configuration -# ------------------------------------------------------------------------------- - - -# ------------------------------------------------------------------------------- -# Exceptions -# ------------------------------------------------------------------------------- class WordnetException(Exception): - ''' Base class for Wordnet exception ''' + """ Base class for Wordnet exception """ pass diff --git a/yawlib/config.py b/yawlib/config.py index b0ac640..c28fc25 100644 --- a/yawlib/config.py +++ b/yawlib/config.py @@ -1,43 +1,13 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -''' +""" Global configuration file for YAWLib -Latest version can be found at https://github.com/letuananh/yawlib - -Adapted from: https://github.com/letuananh/lelesk - -@author: Le Tuan Anh -''' - -# Copyright (c) 2016, Le Tuan Anh -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. - -__author__ = "Le Tuan Anh " -__copyright__ = "Copyright 2017, yawlib" -__credits__ = [] -__license__ = "MIT" -__version__ = "0.1" -__maintainer__ = "Le Tuan Anh" -__email__ = "" -__status__ = "Prototype" +""" + +# This code is a part of yawlib library: https://github.com/letuananh/yawlib +# :copyright: (c) 2014 Le Tuan Anh +# :license: MIT, see LICENSE for more details. import os import logging @@ -61,9 +31,9 @@ def getLogger(): def _get_config_manager(): - ''' Internal function for retrieving application config manager object + """ Internal function for retrieving application config manager object Don't use this directly, use read_config() method instead - ''' + """ return __app_config @@ -90,7 +60,7 @@ def home_dir(): def config_file_path(): - ''' get config location ''' + """ get config location """ return _get_config_manager().locate_config() diff --git a/yawlib/glosswordnet/__init__.py b/yawlib/glosswordnet/__init__.py index 944a6f3..df408aa 100644 --- a/yawlib/glosswordnet/__init__.py +++ b/yawlib/glosswordnet/__init__.py @@ -1,9 +1,7 @@ # -*- coding: utf-8 -*- -''' -Gloss WordNet XML Data Access Object - Access Gloss WordNet in either -XML or SQLite format -Latest version can be found at https://github.com/letuananh/lelesk +""" +Gloss WordNet XML Data Access Object - Access Gloss WordNet in either XML or SQLite format Usage: @@ -15,43 +13,15 @@ or from glosswordnet import SQLiteGWordNet -[TODO] WIP +""" -@author: Le Tuan Anh -''' +# This code is a part of yawlib library: https://github.com/letuananh/yawlib +# :copyright: (c) 2014 Le Tuan Anh +# :license: MIT, see LICENSE for more details. -# Copyright (c) 2014, Le Tuan Anh -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. - -__author__ = "Le Tuan Anh " -__copyright__ = "Copyright 2014, lelesk" -__credits__ = [] -__license__ = "MIT" -__version__ = "0.1" -__maintainer__ = "Le Tuan Anh" -__email__ = "" -__status__ = "Prototype" from .gwnmodels import GlossedSynset, GlossRaw, Gloss, GlossItem, GlossGroup, SenseTag from .gwnxml import GWordnetXML from .gwnsqlite import GWordnetSQLite - __all__ = ['GlossedSynset', 'GWordnetXML', 'GWordnetSQLite', 'GlossRaw', 'Gloss', 'GlossItem', 'GlossGroup', 'SenseTag'] diff --git a/yawlib/glosswordnet/gwnmodels.py b/yawlib/glosswordnet/gwnmodels.py index 5eaacce..796f366 100644 --- a/yawlib/glosswordnet/gwnmodels.py +++ b/yawlib/glosswordnet/gwnmodels.py @@ -1,43 +1,13 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -''' +""" Gloss WordNet Data Transfer Object -Latest version can be found at https://github.com/letuananh/yawlib - -Adapted from: https://github.com/letuananh/lelesk - -@author: Le Tuan Anh -''' - -# Copyright (c) 2016, Le Tuan Anh -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. - -__author__ = "Le Tuan Anh " -__copyright__ = "Copyright 2014, yawlib" -__credits__ = [] -__license__ = "MIT" -__version__ = "0.1" -__maintainer__ = "Le Tuan Anh" -__email__ = "" -__status__ = "Prototype" +""" + +# This code is a part of yawlib library: https://github.com/letuananh/yawlib +# :copyright: (c) 2014 Le Tuan Anh +# :license: MIT, see LICENSE for more details. import logging import re @@ -64,8 +34,8 @@ def getLogger(): # ----------------------------------------------------------------------- class GlossedSynset(Synset): - ''' Each synset object comes with sensekeys (ref: SenseKey), terms (ref: Term), and 3 glosses (ref: GlossRaw). - ''' + """ Each synset object comes with sensekeys (ref: SenseKey), terms (ref: Term), and 3 glosses (ref: GlossRaw). + """ def __init__(self, sid, keys=None, lemmas=None, defs=None, exes=None): super().__init__(sid, keys, lemmas, defs, exes) @@ -74,13 +44,13 @@ def __init__(self, sid, keys=None, lemmas=None, defs=None, exes=None): @property def definition(self): - ''' Override Synset.definition ''' + """ Override Synset.definition """ def_obj = self.get_def() return None if def_obj is None else def_obj.surface @property def examples(self): - ''' Override Synset.examples ''' + """ Override Synset.examples """ return [ex.surface for ex in self.get_examples()] def get_def(self): @@ -112,7 +82,7 @@ def get_surface(self): return orig.gloss if orig is not None else '' def get_orig(self): - ''' Get orig gloss (aux + def + examples) ''' + """ Get orig gloss (aux + def + examples) """ for gr in self.raw_glosses: if gr.cat == 'orig': return gr @@ -131,7 +101,7 @@ def get_tags(self): return keys def match_surface(self, raws=None): - ''' Match tokens in each gloss to original synset def+ex string ''' + """ Match tokens in each gloss to original synset def+ex string """ raws = self.get_orig().split() if raws is None else list(raws) glosses = list(self.glosses) # remaining glosses logger = getLogger() @@ -203,9 +173,9 @@ def __str__(self): class GlossRaw: - ''' Raw glosses extracted from WordNet Gloss Corpus. + """ Raw glosses extracted from WordNet Gloss Corpus. Each synset has a orig_gloss, a text_gloss and a wsd_gloss - ''' + """ # Categories ORIG = 'orig' @@ -304,7 +274,7 @@ def text(self): return StringTool.detokenize((x.text for x in self.items)) def to_ttl(self, doc=None): - ''' Export to TextTagLib format (Read more: :mod:`~chirptext.texttaglib`) ''' + """ Export to TextTagLib format (Read more: :mod:`~chirptext.texttaglib`) """ sid = self.origid if self.origid else "{}{}_{}".format(self.synset.ID.offset, self.synset.ID.pos, self.cat) if doc is not None: sent = doc.new_sent(text=self.text()) @@ -346,8 +316,8 @@ def __str__(self): class GlossItem: - ''' A word token (belong to a gloss) - ''' + """ A word token (belong to a gloss) + """ def __init__(self, gloss, tag, lemma, pos, cat, coll, rdf, origid, sep=None, text=None, itemid=-1): self.itemid = itemid self.gloss = gloss @@ -367,11 +337,11 @@ def get_lemma(self): return self.text if self.text else self.lemma def get_gramwords(self, nopunc=True): - ''' + """ Return grammatical words from lemma E.g. prefer%2|preferred%3 => ['prefer', 'preferred'] - ''' + """ if nopunc and self.cat == 'punc': return set() lemmata = set() @@ -392,8 +362,8 @@ def __str__(self): class GlossGroup: - ''' A group tag (i.e. labelled GlossItem group) - ''' + """ A group tag (i.e. labelled GlossItem group) + """ def __init__(self, label=''): self.label = label @@ -401,8 +371,8 @@ def __init__(self, label=''): class SenseTag: - ''' Sense annotation object - ''' + """ Sense annotation object + """ def __init__(self, item, cat, tag, glob, glemma, glob_id, coll, origid, sid, sk, lemma, tagid=-1): self.tagid = tagid # tag id self.cat = cat # coll, tag, etc. diff --git a/yawlib/glosswordnet/gwnsqlite.py b/yawlib/glosswordnet/gwnsqlite.py index 35bdf1e..138ec56 100644 --- a/yawlib/glosswordnet/gwnsqlite.py +++ b/yawlib/glosswordnet/gwnsqlite.py @@ -1,45 +1,13 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -''' +""" Gloss WordNet SQLite Data Access Object - Access Gloss WordNet in SQLite format -Latest version can be found at https://github.com/letuananh/yawlib - -Adapted from: https://github.com/letuananh/lelesk - -@author: Le Tuan Anh -''' - -# Copyright (c) 2016, Le Tuan Anh -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. - -__author__ = "Le Tuan Anh " -__copyright__ = "Copyright 2014, yawlib" -__credits__ = [] -__license__ = "MIT" -__version__ = "0.1" -__maintainer__ = "Le Tuan Anh" -__email__ = "" -__status__ = "Prototype" - -# ----------------------------------------------------------------------- +""" + +# This code is a part of yawlib library: https://github.com/letuananh/yawlib +# :copyright: (c) 2014 Le Tuan Anh +# :license: MIT, see LICENSE for more details. import os import logging @@ -92,14 +60,14 @@ def __init__(self, db_path, **kwargs): @with_ctx def insert_synset(self, synset, ctx=None): - ''' Helper method for storing a single synset - ''' + """ Helper method for storing a single synset + """ self.insert_synsets([synset], ctx=ctx) @with_ctx def insert_synsets(self, synsets, ctx=None): - ''' Store synsets with related information (sensekeys, terms, gloss, etc.) - ''' + """ Store synsets with related information (sensekeys, terms, gloss, etc.) + """ # synset; for synset in synsets: sid = synset.ID.to_gwnsql() @@ -180,7 +148,7 @@ def results_to_synsets(self, results, synsets=None, ctx=None, **kwargs): @with_ctx def get_synsets(self, synsetids, ctx=None, **kwargs): - ''' Get synsets by synsetids ''' + """ Get synsets by synsetids """ synsets = SynsetCollection() for sid in synsetids: ss = self.get_synset(sid, ctx=ctx, **kwargs) @@ -265,7 +233,7 @@ def hypehypo(self, synsetid, deep_select=False, ctx=None): @with_ctx def tagged_sensekeys(self, ctx=None): - ''' Get all sensekeys used for tagging ''' + """ Get all sensekeys used for tagging """ results = ctx.sensetag.select(columns=['sk']) return set((x.sk for x in results)) diff --git a/yawlib/glosswordnet/gwnxml.py b/yawlib/glosswordnet/gwnxml.py index d4f5109..874df15 100644 --- a/yawlib/glosswordnet/gwnxml.py +++ b/yawlib/glosswordnet/gwnxml.py @@ -1,45 +1,13 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -''' +""" Gloss WordNet XML Data Access Object - Access Gloss WordNet in XML format -Latest version can be found at https://github.com/letuananh/yawlib +""" -Adapted from: https://github.com/letuananh/lelesk - -@author: Le Tuan Anh -''' - -# Copyright (c) 2016, Le Tuan Anh -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. - -__author__ = "Le Tuan Anh " -__copyright__ = "Copyright 2014, yawlib" -__credits__ = [] -__license__ = "MIT" -__version__ = "0.1" -__maintainer__ = "Le Tuan Anh" -__email__ = "" -__status__ = "Prototype" - -# ----------------------------------------------------------------------- +# This code is a part of yawlib library: https://github.com/letuananh/yawlib +# :copyright: (c) 2014 Le Tuan Anh +# :license: MIT, see LICENSE for more details. import logging try: @@ -66,8 +34,8 @@ class GWordnetXML: - ''' GWordNet XML Data Access Object - ''' + """ GWordNet XML Data Access Object + """ def __init__(self, filenames=None, memory_save=False, verbose=False): self.synsets = SynsetCollection() self.memory_save = memory_save @@ -77,14 +45,14 @@ def __init__(self, filenames=None, memory_save=False, verbose=False): self.readfiles(filenames) def readfiles(self, files): - ''' Read from multiple XML files - ''' + """ Read from multiple XML files + """ for filename in files: self.read(filename) def read(self, filename): - ''' Read all synsets from an XML file - ''' + """ Read all synsets from an XML file + """ logging.info('Loading %s' % filename) with open(filename, 'rb') as infile: tree = etree.iterparse(infile) @@ -131,8 +99,8 @@ def parse_synset(self, element): return synset def parse_gloss(self, a_node, gloss): - ''' Parse a def node or ex node in Gloss WordNet - ''' + """ Parse a def node or ex node in Gloss WordNet + """ # What to be expected in a node? aux/mwf/wf/cf/qf # mwf <- wf | cf # aux <- mwf | qf | wf | cf @@ -142,14 +110,14 @@ def parse_gloss(self, a_node, gloss): pass def parse_node(self, a_node, gloss): - ''' Parse node in a def node or an ex node. + """ Parse node in a def node or an ex node. There are 5 possible tags: wf : single-word form cf : collocation form mwf: multi-word form qf : single- and double-quoted forms aux: auxiliary info - ''' + """ if a_node.tag == 'wf': return self.parse_wf(a_node, gloss) elif a_node.tag == 'cf': @@ -165,8 +133,8 @@ def parse_node(self, a_node, gloss): pass def tag_glossitem(self, id_node, glossitem, tag_obj): - ''' Parse ID element and tag a glossitem - ''' + """ Parse ID element and tag a glossitem + """ sk = StringTool.strip(id_node.get('sk')) origid = StringTool.strip(id_node.get('id')) coll = StringTool.strip(id_node.get('coll')) @@ -195,8 +163,8 @@ def get_node_text(self, wf_node): def parse_wf(self, wf_node, gloss): - ''' Parse a word feature node and then add to gloss object - ''' + """ Parse a word feature node and then add to gloss object + """ tag = wf_node.get('tag') if not self.memory_save else '' lemma = wf_node.get('lemma') if not self.memory_save else '' pos = wf_node.get('pos') @@ -214,8 +182,8 @@ def parse_wf(self, wf_node, gloss): return wf_obj def parse_cf(self, cf_node, gloss): - ''' Parse a word feature node and then add to gloss object - ''' + """ Parse a word feature node and then add to gloss object + """ tag = cf_node.get('tag') if not self.memory_save else '' lemma = StringTool.strip(cf_node.get('lemma')) if not self.memory_save else '' pos = cf_node.get('pos') diff --git a/yawlib/helpers.py b/yawlib/helpers.py index a85e9d2..7b724a7 100644 --- a/yawlib/helpers.py +++ b/yawlib/helpers.py @@ -1,46 +1,12 @@ # -*- coding: utf-8 -*- -''' +""" Useful functions for working with synsets -Latest version can be found at https://github.com/letuananh/yawlib - -Usage: - - [TODO] WIP - -Adapted from: https://github.com/letuananh/lelesk - -@author: Le Tuan Anh -''' - -# Copyright (c) 2016, Le Tuan Anh -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. - -__author__ = "Le Tuan Anh " -__copyright__ = "Copyright 2016, yawlib" -__credits__ = [] -__license__ = "MIT" -__version__ = "0.1" -__maintainer__ = "Le Tuan Anh" -__email__ = "" -__status__ = "Prototype" +""" + +# This code is a part of yawlib library: https://github.com/letuananh/yawlib +# :copyright: (c) 2014 Le Tuan Anh +# :license: MIT, see LICENSE for more details. import os.path import itertools @@ -82,7 +48,7 @@ def getLogger(): def get_synset_by_id(wn, synsetid_str, report_file=None, compact=True, lang=None): - ''' Search synset in WordNet Gloss Corpus by synset ID''' + """ Search synset in WordNet Gloss Corpus by synset ID""" if report_file is None: report_file = TextReport() # Default to stdout report_file.print("Looking for synsets by synsetid (Provided: %s)" % synsetid_str) @@ -98,7 +64,7 @@ def get_synset_by_id(wn, synsetid_str, report_file=None, compact=True, lang=None def get_synset_by_sk(wn, sk, report_file=None, compact=True, lang=None): - ''' Search synset in WordNet Gloss Corpus by sensekey''' + """ Search synset in WordNet Gloss Corpus by sensekey""" if report_file is None: report_file = TextReport() # Default to stdout report_file.print("Looking for synsets by sensekey (Provided: %s)" % sk) @@ -109,7 +75,7 @@ def get_synset_by_sk(wn, sk, report_file=None, compact=True, lang=None): def get_synsets_by_term(wn, t, pos=None, report_file=None, compact=True, lang=None, with_eng=True): - ''' Search synset in WordNet Gloss Corpus by term''' + """ Search synset in WordNet Gloss Corpus by term""" if report_file is None: report_file = TextReport() # Default to stdout report_file.print("Looking for synsets by term (Provided: %s | pos = %s)" % (t, pos)) @@ -129,7 +95,7 @@ def get_synsets_by_term(wn, t, pos=None, report_file=None, compact=True, lang=No def smart_wn_search(wn, query, pos=None, report_file=None, compact=True, lang='eng', with_eng=True): - ''' Search synset in WordNet Gloss Corpus by term''' + """ Search synset in WordNet Gloss Corpus by term""" if report_file is None: report_file = TextReport() # Default to stdout report_file.print("Search Wordnet: Query=%s | POS=%s" % (query, pos)) @@ -180,12 +146,12 @@ def search_wn_full_text(wn, query, pos=None, lang='eng', auto_wrap=True, ctx=Non def dump_synsets(*synsets, report_file=None, compact=True): - ''' Dump a SynsetCollection to stdout + """ Dump a SynsetCollection to stdout Arguments: *synsets -- Lists of synsets to dump report_file -- An instance of TextReport - ''' + """ if report_file is None: report_file = TextReport() # Default to stdout @@ -202,7 +168,7 @@ def dump_synsets(*synsets, report_file=None, compact=True): def dump_synset(*synset_langs, compact_gloss=False, compact_tags=False, more_compact=True, report_file=None, compact=True): - ''' Print synset details for debugging purpose + """ Print synset details for debugging purpose Arguments: synset_langs -- Synset objects (in different languages) to dump @@ -211,7 +177,7 @@ def dump_synset(*synset_langs, compact_gloss=False, compact_tags=False, more_com more_compact -- Don't dump full details of synset report_file -- Report file to write to - ''' + """ if report_file is None: report_file = TextReport() # Default to stdout if synset_langs is None or len(synset_langs) == 0: @@ -322,7 +288,7 @@ def get_omw(args=None): def add_wordnet_config(parser): - '''Where to find different wordnets data''' + """Where to find different wordnets data""" parser.add_argument('-i', '--gloss_xml', help='Path to Gloss WordNet folder', default=YLConfig.GWN30_PATH) parser.add_argument('-w', '--wnsql', help='Path to WordNet SQLite 3.0 DB', default=YLConfig.WNSQL30_PATH) parser.add_argument('-g', '--glossdb', help='Path to Gloss WordNet SQLite DB', default=YLConfig.GWN30_DB) @@ -340,8 +306,8 @@ def _file_flag(a_path): def show_info(cli, args): - ''' Show configuration information - ''' + """ Show configuration information + """ report = TextReport(args.output) if 'output' in args else TextReport() report.header("{} - Version: {}".format(version_info.__description__, version_info.__version__), level='h0') home_flag = _dir_flag(config.home_dir()) diff --git a/yawlib/models.py b/yawlib/models.py index f2aa5da..499bdab 100644 --- a/yawlib/models.py +++ b/yawlib/models.py @@ -1,45 +1,13 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -''' +""" Shared data models -Latest version can be found at https://github.com/letuananh/yawlib - -Adapted from: https://github.com/letuananh/lelesk - -@author: Le Tuan Anh -''' - -# Copyright (c) 2014, Le Tuan Anh -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. - -__author__ = "Le Tuan Anh " -__copyright__ = "Copyright 2014, lelesk" -__credits__ = ["Le Tuan Anh"] -__license__ = "MIT" -__version__ = "0.1" -__maintainer__ = "Le Tuan Anh" -__email__ = "" -__status__ = "Prototype" +""" -######################################################################## +# This code is a part of yawlib library: https://github.com/letuananh/yawlib +# :copyright: (c) 2014 Le Tuan Anh +# :license: MIT, see LICENSE for more details. import json import re @@ -88,7 +56,7 @@ def __init__(self, offset, pos): @staticmethod def from_string(synsetid, **kwargs): - ''' Parse a synsetID string to SynsetID object. When failed, return default argument is provided or an exception will be raised ''' + """ Parse a synsetID string to SynsetID object. When failed, return default argument is provided or an exception will be raised """ if synsetid is None: if 'default' in kwargs: return kwargs['default'] @@ -114,17 +82,17 @@ def from_string(synsetid, **kwargs): raise InvalidSynsetID("Invalid synsetid format (provided: {})".format(synsetid)) def to_canonical(self): - ''' Wordnet synset ID (canonical format: 12345678-x) - ''' + """ Wordnet synset ID (canonical format: 12345678-x) + """ return "{offset}-{pos}".format(offset=self.offset, pos=self.pos) def to_wnsql(self): - '''WordNet SQLite synsetID format (112345678) - Reference: https://sourceforge.net/projects/wnsql/''' + """WordNet SQLite synsetID format (112345678) + Reference: https://sourceforge.net/projects/wnsql/""" return "{posnum}{offset}".format(offset=self.offset, posnum=POS.pos2num(self.pos)) def to_gwnsql(self): - '''Gloss WordNet SQLite synsetID format (x12345678)''' + """Gloss WordNet SQLite synsetID format (x12345678)""" return "{pos}{offset}".format(offset=self.offset, pos=self.pos) def __hash__(self): @@ -197,7 +165,7 @@ def add_def(self, definition): @property def lemma(self): - ''' Synset canonical lemma ''' + """ Synset canonical lemma """ if self.lemmas is None or len(self.lemmas) == 0: return None else: @@ -236,12 +204,12 @@ def add_example(self, example): # Aliases @property def synsetid(self): - ''' An alias of synset.ID ''' + """ An alias of synset.ID """ return self.__sid @synsetid.setter def synsetid(self, value): - ''' An alias of synset.ID ''' + """ An alias of synset.ID """ self.ID = value @property @@ -250,12 +218,12 @@ def keys(self): @property def defs(self): - ''' An alias of synset.definitions ''' + """ An alias of synset.definitions """ return self.definitions @property def exes(self): - ''' An alias of synset.examples ''' + """ An alias of synset.examples """ return self.examples def get_tokens(self): @@ -291,8 +259,8 @@ def __str__(self): class SynsetCollection(object): - ''' Synset collection which provides basic synset search function (by_sid, by_sk, etc.) - ''' + """ Synset collection which provides basic synset search function (by_sid, by_sk, etc.) + """ def __init__(self, synsets=None, lang='eng'): self.synsets = [] self.sid_map = {} @@ -341,7 +309,7 @@ def count(self): return len(self.synsets) def merge(self, another_scol): - ''' Add synsets from another synset collection ''' + """ Add synsets from another synset collection """ for synset in another_scol.synsets: if synset.ID not in self: self.add(synset) @@ -355,13 +323,3 @@ def to_json(self): def to_json_str(self): return json.dumps(self.to_json()) - - -######################################################################## - -def main(): - print("This is a library, not a tool") - - -if __name__ == "__main__": - main() diff --git a/yawlib/omwsql.py b/yawlib/omwsql.py index cca24b2..eba6cd7 100644 --- a/yawlib/omwsql.py +++ b/yawlib/omwsql.py @@ -3,41 +3,11 @@ ''' Open Multi-lingual WordNet - SQLite adaptor -Latest version can be found at https://github.com/letuananh/yawlib - -@author: Le Tuan Anh ''' -# Copyright (c) 2017, Le Tuan Anh -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. - -__author__ = "Le Tuan Anh " -__copyright__ = "Copyright 2017, yawlib" -__credits__ = [] -__license__ = "MIT" -__version__ = "0.1" -__maintainer__ = "Le Tuan Anh" -__email__ = "" -__status__ = "Prototype" - -# ----------------------------------------------------------------------- +# This code is a part of yawlib library: https://github.com/letuananh/yawlib +# :copyright: (c) 2014 Le Tuan Anh +# :license: MIT, see LICENSE for more details. import logging from texttaglib.puchikarui import Schema, with_ctx @@ -45,8 +15,6 @@ from yawlib.common import WordnetFeatureNotSupported, InvalidSynsetID -# ----------------------------------------------------------------------- - def getLogger(): return logging.getLogger(__name__) diff --git a/yawlib/wntk.py b/yawlib/wntk.py index d6b2c22..29ec40f 100755 --- a/yawlib/wntk.py +++ b/yawlib/wntk.py @@ -1,9 +1,8 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -''' +""" YAWLib console application -Latest version can be found at https://github.com/letuananh/yawlib Usage: # Search sysets by term (word form) = `love' and POS is verb @@ -17,40 +16,11 @@ # Create SQLite database for searching python3 wntk.py -c -i ~/wordnet/glosstag -g ~/wordnet/gwn.db +""" -This script is used to be a part of lelesk project (https://github.com/letuananh/lelesk) - -@author: Le Tuan Anh -''' - -# Copyright (c) 2016, Le Tuan Anh -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. - -__author__ = "Le Tuan Anh " -__copyright__ = "Copyright 2016, yawlib" -__credits__ = [] -__license__ = "MIT" -__version__ = "0.1" -__maintainer__ = "Le Tuan Anh" -__email__ = "" -__status__ = "Prototype" +# This code is a part of yawlib library: https://github.com/letuananh/yawlib +# :copyright: (c) 2014 Le Tuan Anh +# :license: MIT, see LICENSE for more details. import os.path import logging @@ -86,8 +56,8 @@ def get_logger(): # ----------------------------------------------------------------------- def convert(cli, args): - ''' Convert Gloss WordNet XML into SQLite format - ''' + """ Convert Gloss WordNet XML into SQLite format + """ if not _LXML_AVAILABLE: print("WARNING: lxml library is required for parsing XML") exit() @@ -125,27 +95,27 @@ def get_wn_profile(cli, args): def search_by_id(cli, args): - ''' Retrieve synset information by synsetid ''' + """ Retrieve synset information by synsetid """ wn = get_wn_profile(cli, args) get_synset_by_id(wn, args.synsetid, compact=not args.detail, lang=args.lang) def search_by_key(cli, args): - ''' Retrieve synset information by sensekey''' + """ Retrieve synset information by sensekey""" wn = get_wn_profile(cli, args) get_synset_by_sk(wn, args.sensekey, compact=not args.detail, lang=args.lang) pass def search_by_lemma(cli, args): - ''' Retrieve synset information by lemma (term)''' + """ Retrieve synset information by lemma (term)""" wn = get_wn_profile(cli, args) get_synsets_by_term(wn, args.lemma, args.pos, compact=not args.detail, lang=args.lang) pass def search_everywhere(cli, args): - ''' Search for lemma and definitions''' + """ Search for lemma and definitions""" wn = get_wn_profile(cli, args) smart_wn_search(wn, args.query, args.pos, compact=not args.detail, lang=args.lang) pass @@ -156,7 +126,7 @@ def search_everywhere(cli, args): ############################################################## def main(): - '''Wordnet toolkit - CLI main() ''' + """Wordnet toolkit - CLI main() """ setup_logging('logging.json', 'logs') app = CLIApp(desc="WordNet Toolkit - For accessing and manipulating WordNet", logger=__name__) add_wordnet_config(app.parser) diff --git a/yawlib/wordnetsql.py b/yawlib/wordnetsql.py index 7c3f7fc..eecb01f 100644 --- a/yawlib/wordnetsql.py +++ b/yawlib/wordnetsql.py @@ -1,43 +1,13 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -''' +""" WordNet SQLite wrapper -Latest version can be found at https://github.com/letuananh/lelesk - -@author: Le Tuan Anh -''' - -# Copyright (c) 2014, Le Tuan Anh -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. - -__author__ = "Le Tuan Anh " -__copyright__ = "Copyright 2014, lelesk" -__credits__ = [] -__license__ = "MIT" -__version__ = "0.1" -__maintainer__ = "Le Tuan Anh" -__email__ = "" -__status__ = "Prototype" - -# ----------------------------------------------------------------------- +""" + +# This code is a part of yawlib library: https://github.com/letuananh/yawlib +# :copyright: (c) 2014 Le Tuan Anh +# :license: MIT, see LICENSE for more details. import logging from collections import defaultdict as dd @@ -45,15 +15,13 @@ from yawlib.models import SynsetID, Synset, SynsetCollection -# ----------------------------------------------------------------------- - def getLogger(): return logging.getLogger(__name__) class Wordnet3Schema(Schema): - '''SQLite schema for WordnetSQL (Princeton WordNet version 3.0)''' + """SQLite schema for WordnetSQL (Princeton WordNet version 3.0)""" def __init__(self, data_source=None): Schema.__init__(self, data_source) self.add_table('wordsXsensesXsynsets', 'wordid lemma casedwordid synsetid senseid sensenum lexid tagcount sensekey pos lexdomainid definition'.split(), alias='wss') @@ -76,7 +44,7 @@ def __init__(self, db_path, **kwargs): self.tagcount_cache = dd(lambda: 0) def ensure_sid(self, sid): - '''Ensure that a given synset ID is an instance of SynsetID''' + """Ensure that a given synset ID is an instance of SynsetID""" if isinstance(sid, SynsetID): sid = sid.to_wnsql() else: @@ -107,7 +75,7 @@ def get_synset(self, synsetid, ctx=None, **kwargs): @with_ctx def get_synsets(self, synsetids, ctx=None, **kwargs): - ''' Get synsets by synsetids ''' + """ Get synsets by synsetids """ synsets = SynsetCollection() for sid in synsetids: ss = self.get_synset(sid, ctx=ctx) @@ -182,8 +150,8 @@ def search(self, lemma, pos=None, deep_select=True, synsets=None, ignore_case=Tr @with_ctx def hypehypo(self, sid, ctx=None): - ''' Get all hypernyms and hyponyms of a given synset - ''' + """ Get all hypernyms and hyponyms of a given synset + """ sid = SynsetID.from_string(str(sid)) if sid in self.hypehypo_cache: return self.hypehypo_cache[sid] diff --git a/yawlib/yawol/app.py b/yawlib/yawol/app.py index eaa494e..964afee 100755 --- a/yawlib/yawol/app.py +++ b/yawlib/yawol/app.py @@ -1,49 +1,13 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -''' +""" YAWOL - Yet Another Wordnet Online (REST server) -Latest version can be found at https://github.com/letuananh/yawlib - -References: - Python documentation: - https://docs.python.org/ - PEP 257 - Python Docstring Conventions: - https://www.python.org/dev/peps/pep-0257/ - -@author: Le Tuan Anh -''' - -# Copyright (c) 2017, Le Tuan Anh -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. - -__author__ = "Le Tuan Anh " -__copyright__ = "Copyright 2017, yawlib" -__credits__ = [] -__license__ = "MIT" -__version__ = "0.1" -__maintainer__ = "Le Tuan Anh" -__email__ = "" -__status__ = "Prototype" - -######################################################################## +""" + +# This code is a part of yawlib library: https://github.com/letuananh/yawlib +# :copyright: (c) 2014 Le Tuan Anh +# :license: MIT, see LICENSE for more details. import json import logging diff --git a/yawlib/yawol/django/urls.py b/yawlib/yawol/django/urls.py index e3291c8..5be9470 100644 --- a/yawlib/yawol/django/urls.py +++ b/yawlib/yawol/django/urls.py @@ -1,3 +1,7 @@ +# This code is a part of yawlib library: https://github.com/letuananh/yawlib +# :copyright: (c) 2014 Le Tuan Anh +# :license: MIT, see LICENSE for more details. + from django.conf.urls import url from . import views diff --git a/yawlib/yawol/django/views.py b/yawlib/yawol/django/views.py index 427f205..920f671 100644 --- a/yawlib/yawol/django/views.py +++ b/yawlib/yawol/django/views.py @@ -1,49 +1,13 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -''' +""" YAWOL-Django - Yet Another Wordnet Online (REST server) for Django -Latest version can be found at https://github.com/letuananh/yawlib +""" -References: - Python documentation: - https://docs.python.org/ - PEP 257 - Python Docstring Conventions: - https://www.python.org/dev/peps/pep-0257/ - -@author: Le Tuan Anh -''' - -# Copyright (c) 2017, Le Tuan Anh -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. - -__author__ = "Le Tuan Anh " -__copyright__ = "Copyright 2017, yawlib" -__credits__ = [] -__license__ = "MIT" -__version__ = "0.1" -__maintainer__ = "Le Tuan Anh" -__email__ = "" -__status__ = "Prototype" - -######################################################################## +# This code is a part of yawlib library: https://github.com/letuananh/yawlib +# :copyright: (c) 2014 Le Tuan Anh +# :license: MIT, see LICENSE for more details. import os import json @@ -63,7 +27,7 @@ def jsonp(func): - ''' JSON/JSONP decorator ''' + """ JSON/JSONP decorator """ def decorator(request, *args, **kwargs): objects = func(request, *args, **kwargs) # ignore HttpResponse @@ -86,8 +50,8 @@ def decorator(request, *args, **kwargs): @jsonp def get_synset(request, synsetid): - ''' Get a synset by ID - Mapping: /yawol/synset/ ''' + """ Get a synset by ID + Mapping: /yawol/synset/ """ ss = wsql.get_synset_by_id(synsetid) if ss is None and omwsql is not None: # try to search in OMW @@ -100,9 +64,9 @@ def get_synset(request, synsetid): @jsonp def search(request, query): - ''' Search by lemma, sensekey or synsetID + """ Search by lemma, sensekey or synsetID Mapping: /yawol/search/ - ''' + """ # assume that query is a synset? sid = SynsetID.from_string(query.strip(), default=None) if sid: @@ -141,7 +105,7 @@ def search(request, query): def index(request): - ''' Yawol-django root ''' + """ Yawol-django root """ return HttpResponse('Yawol {yv} - yawol-django/Django-{dv}'.format(yv=__version__, dv=django.get_version()), 'text/html') From 9af9821a8bc475639a6059bcd2e6af6cc3b49527 Mon Sep 17 00:00:00 2001 From: Le Tuan Anh Date: Thu, 13 May 2021 17:33:46 +0800 Subject: [PATCH 6/6] remove unused dependencies --- requirements-dev.txt | 3 --- requirements-optional.txt | 2 -- 2 files changed, 5 deletions(-) delete mode 100644 requirements-dev.txt delete mode 100644 requirements-optional.txt diff --git a/requirements-dev.txt b/requirements-dev.txt deleted file mode 100644 index 058dad0..0000000 --- a/requirements-dev.txt +++ /dev/null @@ -1,3 +0,0 @@ -lxml -fuzzywuzzy -python-levenshtein diff --git a/requirements-optional.txt b/requirements-optional.txt deleted file mode 100644 index 7426a56..0000000 --- a/requirements-optional.txt +++ /dev/null @@ -1,2 +0,0 @@ -flask >= 1.0 -django >= 2.0