Commit 48fd28a0 authored by Mateusz Gniewkowski's avatar Mateusz Gniewkowski

Merge branch 'CI_for_PLWN_API' into 'master'

Ci for plwn api

See merge request !1
parents f492369b d2873d5e
Pipeline #818 failed with stages
in 57 seconds
image: clarinpl/python:3.6
before_script:
- pip install tox==2.9.1
cache:
paths:
- .tox
stages:
- check_style
- push_wheel
pep8:
stage: check_style
script:
- tox -v -e pep8
docstyle:
stage: check_style
script:
- tox -v -e docstyle
push_wheel:
before_script:
- pip install twine
only:
- master
stage: push_wheel
when: on_success
script:
- python setup.py sdist bdist_wheel
- python -m twine upload
--repository-url https://pypi.clarin-pl.eu/
-u $PIPY_USER -p $PIPY_PASS dist/plwn_api*.whl
from ._loading import *
from ._loading import read
from ._loading import load
from ._loading import show_source_formats
from ._loading import show_storage_formats
from .enums import PoS
# Setup logging for the package (not)
import logging as _logging
_logging.getLogger('plwn').addHandler(_logging.NullHandler())
__all__ = [
"PoS",
"read",
"load",
"show_storage_formats",
"show_source_formats",
]
"""Defines user-facing functions that allow simple construction of
:class:`PLWordnetBase` instances, with selected storages and readers.
"""Defines user-facing functions.
That allow simple construction of :class:`PLWordnetBase` instances,
with selected storages and readers.
"""
from __future__ import absolute_import, division, print_function
......@@ -63,8 +65,10 @@ def read(source_file,
source_format=None,
storage_file=None,
storage_format=None):
"""Read plWordNet data from a file and return the right
:class:`PLWordnetBase` subclass instance for the selected parameters.
"""Read plWordNet data from a file.
Return the right :class:`PLWordnetBase` subclass instance for
the selected parameters.
Where defaults are mentioned, those values may change with each minor
version of PLWN API. If you depend on some particular format for a long
......@@ -89,15 +93,15 @@ def read(source_file,
:rtype: PLWordnetBase
"""
stor_cls = _imp_storage(_STORAGES[storage_format].modname)
rdr = _imp_reader(_READERS[source_format].modname)
return stor_cls.from_reader(rdr(source_file), storage_file)
def load(storage_file, storage_format=None):
"""Read plWordNet data from a cached file with internal PLWN API
representation.
"""Read plWordNet data from a cached file.
With internal PLWN API representation.
This function is much faster than :func:`read` if such file is available.
......@@ -109,30 +113,29 @@ def load(storage_file, storage_format=None):
:rtype: PLWordnetBase
"""
stor_cls = _imp_storage(_STORAGES[storage_format].modname)
return stor_cls.from_dump(storage_file)
def show_source_formats():
"""Print names and short descriptions of available source file formats to
``stdout``.
"""Print names and short descriptions.
Of available source file formats to ``stdout``.
This function is primarily meant to be informative in interactive shell
mode.
"""
_show(_READERS)
def show_storage_formats():
"""Print names and short descriptions of available storage formats to
``stdout``.
"""Print names and short descriptions.
Of available storage formats to ``stdout``.
This function is primarily meant to be informative in interactive shell
mode.
"""
_show(_STORAGES)
......
"""Base, abstract classes for plWordNet objects, implementing common
functionality independent of structures holding wordnet data.
"""Base, abstract classes for plWordNet objects.
Implementing common functionality independent of structures holding
wordnet data.
"""
from __future__ import absolute_import, division
......@@ -40,8 +42,10 @@ class PLWordNetBase(object):
@classmethod
def from_reader(cls, reader, dump_to=None):
"""Create a new instance from a source reader, optionally saving it in
an internal representation format in another file.
"""Create a new instance from a source reader.
Optionally saving it in an internal representation format
in another file.
:param reader: Generator that yields :class:`SynsetNone` and
:class:`LexicalUnitNode` from a source representation.
......@@ -54,7 +58,6 @@ class PLWordNetBase(object):
:returns: New instance of PLWN API entry point.
:rtype: PLWordNetBase
"""
raise NotImplementedError()
@classmethod
......@@ -70,16 +73,17 @@ class PLWordNetBase(object):
:returns: New instance of PLWN API entry point.
:rtype: PLWordNetBase
"""
return NotImplementedError()
def __init__(self):
"""Initialize PLWordNetBase."""
self._rel_resolver = get_default_relation_resolver()
@abc.abstractmethod
def synsets(self, lemma=None, pos=None, variant=None):
"""Iterate over synsets form plWordNet, filtered by lemma, part of
speech and variant.
"""Iterate over synsets form plWordNet.
Filtered by lemma, part ofspeech and variant.
If a parameter is omitted, then any value is accepted (so ``synsets()``
iterates over all synsets).
......@@ -101,13 +105,13 @@ class PLWordNetBase(object):
:raises InvalidPoSException: If a query is made for a PoS that is not
one of the valid constants.
"""
pass
@abc.abstractmethod
def synset(self, lemma, pos, variant):
"""Get the synset containing the unit with the lemma, part of speech
and variant.
"""Get the synset.
Containing the unit with the lemma, part of speech and variant.
Unlike :meth:`.synsets`, all parameters of this method are mandatory.
It either returns a single synset, or raises and exception if no
......@@ -129,7 +133,6 @@ class PLWordNetBase(object):
:raises InvalidPoSException: If a query is made for a PoS that is not
one of the valid constants.
"""
pass
@abc.abstractmethod
......@@ -147,13 +150,13 @@ class PLWordNetBase(object):
:raises InvalidSynsetIdentifierException: If there's no synset with
the ID in plWordnet.
"""
pass
@abc.abstractmethod
def lexical_units(self, lemma=None, pos=None, variant=None):
"""Iterate over lexical units form plWordNet, filtered by lemma, part
of speech and variant.
"""Iterate over lexical units form plWordNet.
Filtered by lemma, part of speech and variant.
If a parameter is omitted, then any value is accepted (so
``lexical_units()`` iterates over all units).
......@@ -171,7 +174,6 @@ class PLWordNetBase(object):
:raises InvalidPoSException: If a query is made for a PoS that is not
one of the valid constants.
"""
pass
@abc.abstractmethod
......@@ -196,7 +198,6 @@ class PLWordNetBase(object):
:raises InvalidPoSException: If a query is made for a PoS that is not
one of the valid constants.
"""
pass
@abc.abstractmethod
......@@ -213,13 +214,13 @@ class PLWordNetBase(object):
:raises InvalidLexicalUnitIdentifierException: If there's no lexical
unit with the ID in plWordnet.
"""
pass
@abc.abstractmethod
def synset_relation_edges(self, include=None, exclude=None):
"""Iterate over all synset relation instances in plWordnet, yielding
them as tuples.
"""Iterate over all synset relation instances in plWordnet.
Yielding them as tuples.
Named tuples in format ``(source, relation, target)``
(:data:`RelationEdge`) are yielded by this method.
......@@ -241,25 +242,23 @@ class PLWordNetBase(object):
:returns: Generator of tuples representing synset relation edges.
:rtype: Iterable[Tuple[SynsetBase,str,SynsetBase]]
"""
pass
@abc.abstractmethod
def lexical_relation_edges(self, include=None, exclude=None):
"""Iterate over all lexical relation instances in plWordnet, yielding
them as tuples.
"""Iterate over all lexical relation instances in plWordnet.
Yielding them as tuples.
This method behaves very closely to :meth:`.synset_relation_edges`, but
for lexical relations.
:rtype: Iterable[Tuple[LexicalUnitBase,str,LexicalUnitBase]]
"""
pass
def close(self):
"""Perform necessary cleanup operations and close this PLWordNet
instance.
"""Perform necessary cleanup operations, close this PLWordNet instance.
Often, temporary files are created when reading and parsing plWordNet,
and non-temporary files may be opened. Call this method to properly
......@@ -271,7 +270,6 @@ class PLWordNetBase(object):
It's legal to call this method several times. It's not legal to call
any other methods after :meth:`.close` has been called.
"""
pass
def to_graphml(self,
......@@ -291,8 +289,9 @@ class PLWordNetBase(object):
excluded_synset_nodes=None,
included_lexical_unit_nodes=None,
excluded_lexical_unit_nodes=None):
"""Export the wordnet as graph in `GraphML
<http://graphml.graphdrawing.org/>`_ format.
"""Export the wordnet as graph.
In `GraphML <http://graphml.graphdrawing.org/>`_ format.
Normally, nodes of the graph are synsets, and edges are relations
between synsets. It's possible to make the graph made of lexical units
......@@ -416,7 +415,6 @@ class PLWordNetBase(object):
:raises ValueError: If ``graph_type`` is not one of the allowed values.
"""
gwn = go.GraphMLWordNet()
gb = go.GraphMLBuilder(self, gwn)
......@@ -447,16 +445,16 @@ class PLWordNetBase(object):
include_attributes=include_attributes,
included_synset_attributes=included_synset_attributes,
excluded_synset_attributes=excluded_synset_attributes,
included_lexical_unit_attributes=
included_lexical_unit_attributes,
excluded_lexical_unit_attributes=
excluded_lexical_unit_attributes,
included_lexical_unit_attributes=(
included_lexical_unit_attributes),
excluded_lexical_unit_attributes=(
excluded_lexical_unit_attributes),
included_synset_relations=included_synset_relations,
excluded_synset_relations=excluded_synset_relations,
included_lexical_unit_relations=
included_lexical_unit_relations,
excluded_lexical_unit_relations=
excluded_lexical_unit_relations,
included_lexical_unit_relations=(
included_lexical_unit_relations),
excluded_lexical_unit_relations=(
excluded_lexical_unit_relations),
included_synset_nodes=included_synset_nodes,
excluded_synset_nodes=excluded_synset_nodes,
included_lexical_unit_nodes=included_lexical_unit_nodes,
......@@ -491,17 +489,16 @@ class SynsetBase(object):
@abc.abstractproperty
def id(self):
"""``int``
"""``int``.
The internal identifier of the synset in plWordnet. It is unique among
all synsets.
"""
pass
@abc.abstractproperty
def lexical_units(self):
"""``Tuple[LexicalUnitBase]``
"""``Tuple[LexicalUnitBase]``.
Lexical units contained in the synsets. Ordering of units within the
tuple is arbitrary, but constant. The first unit is the synset's head,
......@@ -509,27 +506,24 @@ class SynsetBase(object):
At least one lexical unit is always present in every synset.
"""
pass
@abc.abstractproperty
def definition(self):
"""``str``
"""``str``.
Textual description of the synset's meaning.
Will be an empty string if the definition is not present in plWordNet.
"""
pass
@abc.abstractproperty
def relations(self):
"""``Tuple[str]``
"""``Tuple[str]``.
Tuple of all outward relations that lead from this synset.
"""
pass
@abc.abstractmethod
......@@ -544,13 +538,12 @@ class SynsetBase(object):
:raises InvalidRelationNameException: If ``relation_name`` is not a
valid name of a synset relation in plWordNet.
"""
pass
def to_dict(self, include_related=True, include_units_data=True):
"""
Create a JSON-compatible dictionary with all the public properties of
the synset.
"""Create a JSON-compatible dictionary.
With all the public properties of the synset.
Enums are converted to their values and all collections are converted
to tuples.
......@@ -574,7 +567,6 @@ class SynsetBase(object):
:returns: Dictionary contain data of the synset.
:rtype: Mapping[str, Any]
"""
syn_dict = {
u'id': self.id,
u'definition': self.definition,
......@@ -598,10 +590,7 @@ class SynsetBase(object):
return syn_dict
def short_str(self):
"""
Shorter version of ``str`` cast that displays only the first unit.
"""
"""Shorter version of ``str`` cast that displays only the first unit."""
sstr = [u'{', six.text_type(self.lexical_units[0])]
if len(self.lexical_units) > 1:
sstr.append(
......@@ -664,70 +653,64 @@ class LexicalUnitBase(object):
@abc.abstractproperty
def id(self):
"""``int``
"""``int``.
The internal identifier of the lexical unit in plWordnet. It is unique
among all units.
"""
pass
@abc.abstractproperty
def lemma(self):
"""``str``
"""``str``.
Lemma of the unit, basic form of the word(s) the unit represents.
"""
pass
@abc.abstractproperty
def pos(self):
"""``PoS``
"""``PoS``.
Part of speech of the unit. This will be one of enumeration constants
from :class:`PoS`. To get the textual value, use ``pos.value``.
"""
pass
@abc.abstractproperty
def variant(self):
"""``int``
"""``int``.
If the same lemma has different meanings as the same part of speech,
this number will be used to tell them apart. The first meaning has the
number 1.
"""
pass
@abc.abstractproperty
def definition(self):
"""``str``
"""``str``.
Textual description of the lexical unit's meaning.
Will be an empty string if the definition is not present in plWordNet.
"""
pass
@abc.abstractproperty
def sense_examples(self):
"""``Tuple[str]``
"""``Tuple[str]``.
Fragments of text that show how the lexical unit is used in the
language.
May be an empty collection, if no examples are present.
"""
pass
@abc.abstractproperty
def sense_examples_sources(self):
"""``Tuple[str]``
"""``Tuple[str]``.
Symbolic representations of sources from which the sense examples were
taken.
......@@ -739,24 +722,22 @@ class LexicalUnitBase(object):
To get pairs of of examples with their sources, use
``zip(sense_examples, sense_examples_sources)``
"""
# TODO List of source symbols, link to?
pass
@abc.abstractproperty
def external_links(self):
"""``Tuple[str]``
"""``Tuple[str]``.
URLs to webpages describing the meaning of the lexical unit.
May be an empty collection, if no examples are present.
"""
pass
@abc.abstractproperty
def usage_notes(self):
"""``Tuple[str]``
"""``Tuple[str]``.
Symbols denoting certain properties of how the lexical unit is used.
......@@ -764,31 +745,28 @@ class LexicalUnitBase(object):
May be an empty collection.
"""
pass
@abc.abstractproperty
def domain(self):
"""``Domain``
"""``Domain``.
Wordnet domain the lexical unit belongs to.
"""
pass
@abc.abstractproperty
def verb_aspect(self):
"""``Optional[VerbAspect]``
"""``Optional[VerbAspect]``.
Aspect of a verb. This will be one of the constants from
:class:`VerbAspect`, or ``None``, if the lexical unit is not a verb.
"""
pass
@abc.abstractproperty
def emotion_markedness(self):
"""``Optional[EmotionMarkedness]``
"""``Optional[EmotionMarkedness]``.
Markedness of emotional connotations of the lexical unit. May be
``None``, if the unit has no emotional markedness.
......@@ -796,61 +774,54 @@ class LexicalUnitBase(object):
If this property is ``None``, then all other ``emotion_*`` properties
will be ``None`` or empty.
"""
pass
@abc.abstractproperty
def emotion_names(self):
"""``Tuple[str, ...]``
"""``Tuple[str, ...]``.
Names of emotions associated with this lexical unit.
"""
pass
@abc.abstractproperty
def emotion_valuations(self):
"""``Tuple[str, ...]``
"""``Tuple[str, ...]``.
Valuations of emotions associated with this lexical unit.
"""
pass
@abc.abstractproperty
def emotion_example(self):
"""``Optional[str]``
"""``Optional[str]``.
An example of an emotionally loaded sentence using the lexical unit.
"""
pass
@abc.abstractproperty
def emotion_example_secondary(self):
"""``Optional[str]``
"""``Optional[str]``.
This property is not ``None`` only if ``emotion_markedness`` is
``amb``. In such case, :attr:`.emotion_example` will be an
example of a positive sentence, and this one will be a negative
sentence.
"""
pass
@abc.abstractproperty
def synset(self):
"""``SynsetBase``
"""``SynsetBase``.
The synset the unit belongs to.
"""
pass
@abc.abstractmethod
def related(self, relation_name):
"""Iterate over lexical units to whom this unit has a
certain relation.
"""Iterate over lexical units to whom this unit has a certain relation.
:param str relation_name: The name of the relation to follow.
......@@ -860,22 +831,20 @@ class LexicalUnitBase(object):
:raises InvalidRelationNameException: If ``relation_name`` is not a
valid name of a lexical relation in plWordNet.
"""
pass
@abc.abstractproperty
def relations(self):
"""``Tuple[str]``
"""``Tuple[str]``.
Tuple of all outward relations that lead from this lexical unit.
"""
pass
def to_dict(self, include_related=True):
"""
Create a JSON-compatible dictionary with all the public properties of
the lexical unit.
"""Create a JSON-compatible dictionary.
With all the public properties of the lexical unit.
Enums are converted to their values and all collections are converted
to tuples.
......@@ -894,7 +863,6 @@ class LexicalUnitBase(object):
:returns: Dictionary contain data of the lexical unit.
:rtype: Mapping[str, Any]