Dictionary of meta data including a required 'id'.
Meta data keys and values are unicode strings.
Dictionary of meta data including a required 'id'.
Meta data keys and values are unicode strings.
Create a sppasMetaData instance.
Add a GUID-like in the dictionary of metadata, with key "id".
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()
Return the identifier of this object.
def get_id(self):
"""Return the identifier of this object."""
return self.__metadata['id']
Re-generate an 'id'.
def gen_id(self):
"""Re-generate an 'id'."""
self.__metadata['id'] = str(uuid.uuid4())
Check if an entry is a key in the list of metadata.
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
Return the value of the given key.
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)
Return the list of metadata keys.
def get_meta_keys(self):
"""Return the list of metadata keys."""
return self.__metadata.keys()
Set or update a metadata.
key, and value are formatted and stored in unicode.
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
Remove a metadata from its key.
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 metadata about the license applied to the object (GPLv3).
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 AGPL V3')
self.set_meta('file_license_url_%s' % idx, 'https://www.gnu.org/licenses/gpl-3.0.en.html')
Add metadata about this software.
TODO: CHECK IF KEYS NOT ALREADY EXISTING.
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 metadata about the language (und).
TODO: CHECK IF KEYS NOT ALREADY EXISTING.
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 metadata about the project this object is included-in.
Currently do not assign any value. TODO: CHECK IF KEYS NOT ALREADY EXISTING.
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 metadata about an annotator.
TODO: CHECK IF KEYS ARE NOT ALREADY EXISTING.
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)
def __len__(self):
return len(self.__metadata)