SPPAS 4.20

Module sppas.src.anndata

Class sppasMetaData

Description

Dictionary of meta data including a required 'id'.

Meta data keys and values are unicode strings.

Constructor

Create a sppasMetaData instance.

Add a GUID-like in the dictionary of metadata, with key "id".

View Source
def __init__(self):
    """Create a sppasMetaData instance.

    Add a GUID-like in the dictionary of metadata, with key "id".

    """
    self.__metadata = OrderedDict()
    self.gen_id()

Public functions

get_id

Return the identifier of this object.

View Source
def get_id(self):
    """Return the identifier of this object."""
    return self.__metadata['id']
gen_id

Re-generate an 'id'.

View Source
def gen_id(self):
    """Re-generate an 'id'."""
    self.__metadata['id'] = str(uuid.uuid4())
is_meta_key

Check if an entry is a key in the list of metadata.

Parameters
  • entry: (str) Entry to check
Returns
  • (Boolean)
View Source
def is_meta_key(self, entry):
    """Check if an entry is a key in the list of metadata.

        :param entry: (str) Entry to check
        :returns: (Boolean)

        """
    return entry in self.__metadata
get_meta

Return the value of the given key.

Parameters
  • entry: (str) Entry to be checked as a key.
  • default: (str) Default value to return if entry is not a key.
Returns
  • (str) meta data value or default value
View Source
def get_meta(self, entry, default=''):
    """Return the value of the given key.

        :param entry: (str) Entry to be checked as a key.
        :param default: (str) Default value to return if entry is not a key.
        :returns: (str) meta data value or default value

        """
    return self.__metadata.get(entry, default)
get_meta_keys

Return the list of metadata keys.

View Source
def get_meta_keys(self):
    """Return the list of metadata keys."""
    return self.__metadata.keys()
set_meta

Set or update a metadata.

Parameters
  • key: (str) The key of the metadata.
  • value: (str) The value assigned to the key.

key, and value are formatted and stored in unicode.

View Source
def set_meta(self, key, value):
    """Set or update a metadata.

        :param key: (str) The key of the metadata.
        :param value: (str) The value assigned to the key.

        key, and value are formatted and stored in unicode.

        """
    if value is None:
        value = ''
    su = sppasUnicode(key)
    key = su.to_strip()
    su = sppasUnicode(value)
    value = su.to_strip()
    self.__metadata[key] = value
pop_meta

Remove a metadata from its key.

Parameters
  • key: (str)
View Source
def pop_meta(self, key):
    """Remove a metadata from its key.

        :param key: (str)

        """
    if key == 'id':
        raise ValueError("Identifier key can't be removed of the metadata.")
    if key in self.__metadata:
        del self.__metadata[key]
add_license_metadata

Add metadata about the license applied to the object (GPLv3).

Parameters
  • idx
View Source
def add_license_metadata(self, idx):
    """Add metadata about the license applied to the object (GPLv3)."""
    self.set_meta('file_license_text_%s' % idx, 'GNU GPL V3')
    self.set_meta('file_license_url_%s' % idx, 'https://www.gnu.org/licenses/gpl-3.0.en.html')
add_software_metadata

Add metadata about this software.

TODO: CHECK IF KEYS NOT ALREADY EXISTING.

View Source
def add_software_metadata(self):
    """Add metadata about this software.

        TODO: CHECK IF KEYS NOT ALREADY EXISTING.

        """
    self.set_meta('software_name', sg.__name__)
    self.set_meta('software_version', sg.__version__)
    self.set_meta('software_url', sg.__url__)
    self.set_meta('software_author', sg.__author__)
    self.set_meta('software_contact', sg.__contact__)
    self.set_meta('software_copyright', sg.__copyright__)
add_language_metadata

Add metadata about the language (und).

TODO: CHECK IF KEYS NOT ALREADY EXISTING.

View Source
def add_language_metadata(self):
    """Add metadata about the language (und).

        TODO: CHECK IF KEYS NOT ALREADY EXISTING.

        """
    self.set_meta('language_iso', 'iso639-3')
    self.set_meta('language_code_0', 'und')
    self.set_meta('language_name_0', 'Undetermined')
    self.set_meta('language_url_0', 'https://iso639-3.sil.org/code/und')
add_project_metadata

Add metadata about the project this object is included-in.

Currently do not assign any value.

TODO: CHECK IF KEYS NOT ALREADY EXISTING.

View Source
def add_project_metadata(self):
    """Add metadata about the project this object is included-in.

        Currently do not assign any value.
        TODO: CHECK IF KEYS NOT ALREADY EXISTING.

        """
    self.set_meta('project_description', '')
    self.set_meta('project_corpus_owner', '')
    self.set_meta('project_corpus_type', '')
    self.set_meta('project_license', '')
    self.set_meta('project_environment', '')
    self.set_meta('project_collection', '')
    self.set_meta('project_title', '')
    self.set_meta('project_noises', '')
add_annotator_metadata

Add metadata about an annotator.

Parameters
  • name: (str)
  • version: (str)
  • version_date: (str)

TODO: CHECK IF KEYS ARE NOT ALREADY EXISTING.

View Source
def add_annotator_metadata(self, name='', version='', version_date=''):
    """Add metadata about an annotator.

        :param name: (str)
        :param version: (str)
        :param version_date: (str)

        TODO: CHECK IF KEYS ARE NOT ALREADY EXISTING.

        """
    self.set_meta('annotator_name', name)
    self.set_meta('annotator_version', version)
    self.set_meta('annotator_version_date', version_date)

Overloads

__len__
View Source
def __len__(self):
    return len(self.__metadata)