structs package¶
Submodules¶
structs.basecompare module¶
- filename
sppas.src.structs.basecompare.py
- author
Brigitte Bigi
- contact
- summary
Base classes to compare data in the filter system.
- class structs.basecompare.sppasBaseCompare[source]¶
Bases:
object
Base class for comparisons.
- class structs.basecompare.sppasListCompare[source]¶
Bases:
structs.basecompare.sppasBaseCompare
Comparison methods for two lists.
- static leq(elements, x)[source]¶
Return True if number of elements in the list is equal to x.
- Parameters
elements – (list)
x – (int)
- Returns
(bool)
- static lge(elements, x)[source]¶
Return True if number of elements in the list is greater or equal than x.
- Parameters
elements – (list)
x – (int)
- Returns
(bool)
- static lgt(elements, x)[source]¶
Return True if number of elements in the list is greater than x.
- Parameters
elements – (list)
x – (int)
- Returns
(bool)
- static lle(elements, x)[source]¶
Return True if number of elements in the list is lower or equal than x.
- Parameters
elements – (list)
x – (int)
- Returns
(bool)
structs.basefilters module¶
src.structs.basefilters.py¶
- class structs.basefilters.sppasBaseFilters(obj)[source]¶
Bases:
object
Base class for any filter system.
- Author
Brigitte Bigi
- Organization
Laboratoire Parole et Langage, Aix-en-Provence, France
- Contact
- License
GPL, v3
- Copyright
Copyright (C) 2011-2019 Brigitte Bigi
- __init__(obj)[source]¶
Create a sppasBaseFilters instance.
- Parameters
obj – (object) The object to be filtered.
- static fix_function_values(comparator, **kwargs)[source]¶
Return the list of function names and the expected value.
- Parameters
comparator – (sppasBaseComparator)
- static fix_functions(comparator, **kwargs)[source]¶
Parse the args to get the list of function/value/complement.
- Parameters
comparator – (sppasBaseComparator)
- static fix_logic_bool(**kwargs)[source]¶
Return the value of a logic boolean predicate.
Expect the “logic_bool” argument.
- Returns
(str) “and” or “or”. By default, the logical “and” is returned.
- Raise
sppasValueError
structs.basefset module¶
structs.basefset.py¶
Base class for the result of any kind of SPPAS filter.
- class structs.basefset.sppasBaseSet[source]¶
Bases:
object
Manager for a set of data.
- Author
Brigitte Bigi
- Organization
Laboratoire Parole et Langage, Aix-en-Provence, France
- Contact
- License
GPL, v3
- Copyright
Copyright (C) 2011-2019 Brigitte Bigi
Mainly used with the data that are the result of the filter system.
A sppasBaseSet() manages a dictionary with:
key: an object
value: a list of strings
It implements the operators ‘|’ and ‘&’.
- append(data, value)[source]¶
Append a data in the data set, with the given value.
- Parameters
data – (object)
value – (list of str) List of any string.
structs.baseoption module¶
structs.baseoption.py¶
- class structs.baseoption.sppasBaseOption(option_type, option_value='')[source]¶
Bases:
object
Class to deal with one option.
- Author
Brigitte Bigi
- Organization
Laboratoire Parole et Langage, Aix-en-Provence, France
- Contact
- License
GPL, v3
- Copyright
Copyright (C) 2011-2019 Brigitte Bigi
In many situations, we have to store an un-typed data and its type separately, plus eventually other information like a description. Such data is called “option”.
An option is a set of data with a main value and its type, plus 3 other variables to store any kind of information. By default, the type of an option is “str”, the value is an empty string and the name, text and description are all empty strings.
>>> o = sppasBaseOption("integer", "3") >>> v = o.get_value() >>> type(v) >>> <type 'int'> >>> v = o.get_untypedvalue() >>> type(v) >>> <type 'str'>
- __init__(option_type, option_value='')[source]¶
Create a sppasBaseOption instance.
The type of an option is one of the key of type_mapping (i.e. ‘int’, ‘bool’, ‘float’, …). Notice that the type will be normalized. For example, ‘int, ‘integer’, ‘long or ‘short’ will be all stored into ‘int’ type.
- Parameters
option_type – (str) Type of the option.
option_value – (str) Value of the option.
- get_untypedvalue()[source]¶
Return the value as it was given.
i.e. without taking the given type into account.
- set(other)[source]¶
Set self from another instance.
- Parameters
other – (sppasBaseOption) The option from which to get info.
- set_description(description)[source]¶
Set a long text to describe the option.
- Parameters
description – (str) Option description.
- set_name(name)[source]¶
Set a name to describe the option.
- Parameters
name – (str) Option description.
- set_text(text)[source]¶
Set a brief text to describe the option.
- Parameters
text – (str) Option description.
- set_type(option_type)[source]¶
Set a new type.
Possible types are: ‘int’, ‘bool’, ‘float’, ‘str’. If the given type is not valid, it will be set to ‘str’.
- Parameters
option_type – (str) Type of the option
- Returns
True if option_type is valid and set.
- set_value(value)[source]¶
Set a new value.
- Parameters
value – (any type) Un-typed value of the option.
- type_mappings = {'bool': <function sppasBaseOption.<lambda>>, 'file': <class 'str'>, 'float': <class 'float'>, 'int': <class 'int'>, 'str': <class 'str'>}¶
- class structs.baseoption.sppasOption(option_key, option_type='str', option_value='')[source]¶
Bases:
structs.baseoption.sppasBaseOption
Adds a key to a sppasBaseOption.
- Author
Brigitte Bigi
- Organization
Laboratoire Parole et Langage, Aix-en-Provence, France
- Contact
- License
GPL, v3
- Copyright
Copyright (C) 2011-2019 Brigitte Bigi
structs.dag module¶
annotations.dag.py¶
- class structs.dag.DAG[source]¶
Bases:
object
Direct Acyclic Graph.
Implementation inspired from: http://www.python.org/doc/essays/graphs/
- property Graph¶
- __init__()[source]¶
Create a new DAG instance.
This class represents the DAG as a dictionary. For example:
A -> B
A -> C
B -> C
B -> D
C -> D
will be represented as: {‘A’: [‘B’, ‘C’], ‘B’: [‘C’, ‘D’], ‘C’: [‘D’],}
- find_path(start, end, path=[])[source]¶
Determine a path between two nodes.
It takes a graph and the start and end nodes as arguments. It will return a list of nodes (including the start and end nodes) comprising the path. When no path can be found, it returns None. Note: The same node will not occur more than once on the path returned (i.e. it won’t contain cycles).
>>> find_path(graph, 'A', 'C') >>> ['A', 'B', 'C']
structs.lang module¶
structs.lang.py¶
- class structs.lang.sppasLangResource[source]¶
Bases:
object
Manage information of a resource for a language.
- Author
Brigitte Bigi
- Organization
Laboratoire Parole et Langage, Aix-en-Provence, France
- Contact
- License
GPL, v3
- Copyright
Copyright (C) 2011-2018 Brigitte Bigi
In most of the automatic annotations, we have to deal with language resources. Here, we store information about the type of resources, the path to get them, etc.
- RESOURCES_TYPES = ['file', 'directory']¶
- get_lang()[source]¶
Return the language name.
Language names in SPPAS are commonly represented in iso-639-3. It is a code that aims to define three-letter identifiers for all known human languages. “und” is representing an undetermined language. See <http://www-01.sil.org/iso639-3/> for details…
- Returns
(str) Language code or an empty string if no lang was set.
- set(rtype, rpath, rname='', rext='', rlang=True)[source]¶
Set resources then fix the list of available languages.
- Parameters
rtype – (str) Resource type. One of: “file” or “directory”
rpath – (str) Resource path
rname – (str) Resource file name
rext – (str) Resource extension
rlang – (bool) Language-dependent resource
- set_extension(resource_extension)[source]¶
Fix the language resource file extension.
- Parameters
resource_extension – (str) Resource filename extension.
- set_filename(resource_filename)[source]¶
Fix the language resource filename.
- Parameters
resource_filename – (str) Resource filename.
- set_lang(lang)[source]¶
Set the language.
To reset the language, fix lang to None.
- Parameters
lang – (str) The language must be either UNDETERMINED
or one of the language of the list.
structs.metainfo module¶
structs.metainfo.py¶
- class structs.metainfo.sppasMetaInfo[source]¶
Bases:
object
Meta information manager.
- Author
Brigitte Bigi
- Organization
Laboratoire Parole et Langage, Aix-en-Provence, France
- Contact
- License
GPL, v3
- Copyright
Copyright (C) 2011-2019 Brigitte Bigi
Meta-information is a sorted collection of pairs (key, value) where value is a tuple with first argument of type boolean to indicate the state of the key: enabled/disabled.
Manage meta information of type (key,value). Allows to enable/disable each one. Keys are unicode strings, and values can be of any type.
>>> m = sppasMetaInfo() >>> m.add_metainfo('author', 'Brigitte Bigi') >>> m.add_metainfo('version', (1,8,2))
- add_metainfo(key, strv)[source]¶
Fix a meta information or update it.
- Parameters
key – (str) The key of the meta-information
strv – (str)
- enable_metainfo(key, value=True)[source]¶
Enable/Disable a meta information.
- Parameters
key – (str) The key of the meta-information
value – (bool) Status of the meta-information
- Raises
MetaKeyError
- get_metainfo(key)[source]¶
Return the value of a given key.
- Parameters
key – (str) The key of the meta-information
- Raises
MetaKeyError
- is_enable_metainfo(key)[source]¶
Return the status of a given key.
- Parameters
key – (str) The key of the meta-information
- Raises
MetaKeyError
structs.structsexc module¶
structs.structsexc.py¶
- exception structs.structsexc.LangNameError(lang)[source]¶
Bases:
ValueError
:ERROR 6028:.
The language must be “und” or one of the language list. Unknown language {lang}.
- exception structs.structsexc.LangPathError(folder)[source]¶
Bases:
TypeError
:ERROR 6024:.
The resource folder {dirname} does not exists.
structs.tips module¶
ui.tips.py¶
- class structs.tips.sppasTips[source]¶
Bases:
object
Manage a set of tips.
- Author
Brigitte Bigi
- Organization
Laboratoire Parole et Langage, Aix-en-Provence, France
- Contact
- License
GPL, v3
- Copyright
Copyright (C) 2011-2018 Brigitte Bigi
Tips is a set of short help messages that a software tool can display when it’s starting. Some users find them useful…
Tips are stored into a file with name TIPS_FILE. This file format is with one tip a line.
>>> t = sppasTips() >>> print(t.get_message())
- add_message(message)[source]¶
Add a new message tips in the list of tips.
- Parameters
message – (str) A help message.
Module contents¶
- filename
sppas.src.structs.__init__.py
- author
Brigitte Bigi
- contact
- summary
Package for the data structures of SPPAS.
structs: access and manage data structures.¶
This package includes classes to manage data like un-typed options, a language, a dag…
Requires the following other packages:
config
utils
- class structs.sppasBaseCompare[source]¶
Bases:
object
Base class for comparisons.
- class structs.sppasBaseFilters(obj)[source]¶
Bases:
object
Base class for any filter system.
- Author
Brigitte Bigi
- Organization
Laboratoire Parole et Langage, Aix-en-Provence, France
- Contact
- License
GPL, v3
- Copyright
Copyright (C) 2011-2019 Brigitte Bigi
- __init__(obj)[source]¶
Create a sppasBaseFilters instance.
- Parameters
obj – (object) The object to be filtered.
- static fix_function_values(comparator, **kwargs)[source]¶
Return the list of function names and the expected value.
- Parameters
comparator – (sppasBaseComparator)
- static fix_functions(comparator, **kwargs)[source]¶
Parse the args to get the list of function/value/complement.
- Parameters
comparator – (sppasBaseComparator)
- static fix_logic_bool(**kwargs)[source]¶
Return the value of a logic boolean predicate.
Expect the “logic_bool” argument.
- Returns
(str) “and” or “or”. By default, the logical “and” is returned.
- Raise
sppasValueError
- class structs.sppasBaseOption(option_type, option_value='')[source]¶
Bases:
object
Class to deal with one option.
- Author
Brigitte Bigi
- Organization
Laboratoire Parole et Langage, Aix-en-Provence, France
- Contact
- License
GPL, v3
- Copyright
Copyright (C) 2011-2019 Brigitte Bigi
In many situations, we have to store an un-typed data and its type separately, plus eventually other information like a description. Such data is called “option”.
An option is a set of data with a main value and its type, plus 3 other variables to store any kind of information. By default, the type of an option is “str”, the value is an empty string and the name, text and description are all empty strings.
>>> o = sppasBaseOption("integer", "3") >>> v = o.get_value() >>> type(v) >>> <type 'int'> >>> v = o.get_untypedvalue() >>> type(v) >>> <type 'str'>
- __init__(option_type, option_value='')[source]¶
Create a sppasBaseOption instance.
The type of an option is one of the key of type_mapping (i.e. ‘int’, ‘bool’, ‘float’, …). Notice that the type will be normalized. For example, ‘int, ‘integer’, ‘long or ‘short’ will be all stored into ‘int’ type.
- Parameters
option_type – (str) Type of the option.
option_value – (str) Value of the option.
- get_untypedvalue()[source]¶
Return the value as it was given.
i.e. without taking the given type into account.
- set(other)[source]¶
Set self from another instance.
- Parameters
other – (sppasBaseOption) The option from which to get info.
- set_description(description)[source]¶
Set a long text to describe the option.
- Parameters
description – (str) Option description.
- set_name(name)[source]¶
Set a name to describe the option.
- Parameters
name – (str) Option description.
- set_text(text)[source]¶
Set a brief text to describe the option.
- Parameters
text – (str) Option description.
- set_type(option_type)[source]¶
Set a new type.
Possible types are: ‘int’, ‘bool’, ‘float’, ‘str’. If the given type is not valid, it will be set to ‘str’.
- Parameters
option_type – (str) Type of the option
- Returns
True if option_type is valid and set.
- set_value(value)[source]¶
Set a new value.
- Parameters
value – (any type) Un-typed value of the option.
- type_mappings = {'bool': <function sppasBaseOption.<lambda>>, 'file': <class 'str'>, 'float': <class 'float'>, 'int': <class 'int'>, 'str': <class 'str'>}¶
- class structs.sppasBaseSet[source]¶
Bases:
object
Manager for a set of data.
- Author
Brigitte Bigi
- Organization
Laboratoire Parole et Langage, Aix-en-Provence, France
- Contact
- License
GPL, v3
- Copyright
Copyright (C) 2011-2019 Brigitte Bigi
Mainly used with the data that are the result of the filter system.
A sppasBaseSet() manages a dictionary with:
key: an object
value: a list of strings
It implements the operators ‘|’ and ‘&’.
- append(data, value)[source]¶
Append a data in the data set, with the given value.
- Parameters
data – (object)
value – (list of str) List of any string.
- class structs.sppasLangResource[source]¶
Bases:
object
Manage information of a resource for a language.
- Author
Brigitte Bigi
- Organization
Laboratoire Parole et Langage, Aix-en-Provence, France
- Contact
- License
GPL, v3
- Copyright
Copyright (C) 2011-2018 Brigitte Bigi
In most of the automatic annotations, we have to deal with language resources. Here, we store information about the type of resources, the path to get them, etc.
- RESOURCES_TYPES = ['file', 'directory']¶
- get_lang()[source]¶
Return the language name.
Language names in SPPAS are commonly represented in iso-639-3. It is a code that aims to define three-letter identifiers for all known human languages. “und” is representing an undetermined language. See <http://www-01.sil.org/iso639-3/> for details…
- Returns
(str) Language code or an empty string if no lang was set.
- set(rtype, rpath, rname='', rext='', rlang=True)[source]¶
Set resources then fix the list of available languages.
- Parameters
rtype – (str) Resource type. One of: “file” or “directory”
rpath – (str) Resource path
rname – (str) Resource file name
rext – (str) Resource extension
rlang – (bool) Language-dependent resource
- set_extension(resource_extension)[source]¶
Fix the language resource file extension.
- Parameters
resource_extension – (str) Resource filename extension.
- set_filename(resource_filename)[source]¶
Fix the language resource filename.
- Parameters
resource_filename – (str) Resource filename.
- set_lang(lang)[source]¶
Set the language.
To reset the language, fix lang to None.
- Parameters
lang – (str) The language must be either UNDETERMINED
or one of the language of the list.
- class structs.sppasListCompare[source]¶
Bases:
structs.basecompare.sppasBaseCompare
Comparison methods for two lists.
- static leq(elements, x)[source]¶
Return True if number of elements in the list is equal to x.
- Parameters
elements – (list)
x – (int)
- Returns
(bool)
- static lge(elements, x)[source]¶
Return True if number of elements in the list is greater or equal than x.
- Parameters
elements – (list)
x – (int)
- Returns
(bool)
- static lgt(elements, x)[source]¶
Return True if number of elements in the list is greater than x.
- Parameters
elements – (list)
x – (int)
- Returns
(bool)
- static lle(elements, x)[source]¶
Return True if number of elements in the list is lower or equal than x.
- Parameters
elements – (list)
x – (int)
- Returns
(bool)
- class structs.sppasMetaInfo[source]¶
Bases:
object
Meta information manager.
- Author
Brigitte Bigi
- Organization
Laboratoire Parole et Langage, Aix-en-Provence, France
- Contact
- License
GPL, v3
- Copyright
Copyright (C) 2011-2019 Brigitte Bigi
Meta-information is a sorted collection of pairs (key, value) where value is a tuple with first argument of type boolean to indicate the state of the key: enabled/disabled.
Manage meta information of type (key,value). Allows to enable/disable each one. Keys are unicode strings, and values can be of any type.
>>> m = sppasMetaInfo() >>> m.add_metainfo('author', 'Brigitte Bigi') >>> m.add_metainfo('version', (1,8,2))
- add_metainfo(key, strv)[source]¶
Fix a meta information or update it.
- Parameters
key – (str) The key of the meta-information
strv – (str)
- enable_metainfo(key, value=True)[source]¶
Enable/Disable a meta information.
- Parameters
key – (str) The key of the meta-information
value – (bool) Status of the meta-information
- Raises
MetaKeyError
- get_metainfo(key)[source]¶
Return the value of a given key.
- Parameters
key – (str) The key of the meta-information
- Raises
MetaKeyError
- is_enable_metainfo(key)[source]¶
Return the status of a given key.
- Parameters
key – (str) The key of the meta-information
- Raises
MetaKeyError
- class structs.sppasOption(option_key, option_type='str', option_value='')[source]¶
Bases:
structs.baseoption.sppasBaseOption
Adds a key to a sppasBaseOption.
- Author
Brigitte Bigi
- Organization
Laboratoire Parole et Langage, Aix-en-Provence, France
- Contact
- License
GPL, v3
- Copyright
Copyright (C) 2011-2019 Brigitte Bigi
- class structs.sppasTips[source]¶
Bases:
object
Manage a set of tips.
- Author
Brigitte Bigi
- Organization
Laboratoire Parole et Langage, Aix-en-Provence, France
- Contact
- License
GPL, v3
- Copyright
Copyright (C) 2011-2018 Brigitte Bigi
Tips is a set of short help messages that a software tool can display when it’s starting. Some users find them useful…
Tips are stored into a file with name TIPS_FILE. This file format is with one tip a line.
>>> t = sppasTips() >>> print(t.get_message())
- add_message(message)[source]¶
Add a new message tips in the list of tips.
- Parameters
message – (str) A help message.