SPPAS 4.22

https://sppas.org/

Module sppas.src.anndata

Class FileFormatProperty

Description

Represent one format and its properties.

Constructor

Create a FileFormatProperty instance.

Parameters
  • extension: (str) File name extension.
View Source
def __init__(self, extension: str):
    """Create a FileFormatProperty instance.

    :param extension: (str) File name extension.

    """
    self._extension = extension
    if extension.startswith('.') is False:
        self._extension = '.' + extension
    self._instance = None
    self._software = 'Unknown'
    for ext in sppasTrsRW.TRANSCRIPTION_TYPES.keys():
        if ext.lower() == extension.lower():
            self._instance = sppasTrsRW.TRANSCRIPTION_TYPES[ext]()
            self._software = self._instance.software
    try:
        self._instance.read('')
    except NotImplementedError:
        self._reader = False
    except Exception:
        self._reader = True
    try:
        self._instance.write('')
    except NotImplementedError:
        self._writer = False
    except Exception:
        self._writer = True

Public functions

get_extension

Return the extension, including the initial dot.

View Source
def get_extension(self) -> str:
    """Return the extension, including the initial dot."""
    return self._extension

get_software

Return the name of the software matching the extension.

View Source
def get_software(self) -> str:
    """Return the name of the software matching the extension."""
    return self._software

get_reader

Return True if SPPAS can read files of the extension.

View Source
def get_reader(self) -> bool:
    """Return True if SPPAS can read files of the extension."""
    return self._reader

get_writer

Return True if SPPAS can write files of the extension.

View Source
def get_writer(self) -> bool:
    """Return True if SPPAS can write files of the extension."""
    return self._writer

get_trs_type

Return the transcription type: ANNOT, MEASURE, TABLE or None.

View Source
def get_trs_type(self) -> str | None:
    """Return the transcription type: ANNOT, MEASURE, TABLE or None."""
    if self._instance is None:
        return None
    return self._instance.trs_type

Overloads

__format__

View Source
def __format__(self, fmt):
    return str(self).__format__(fmt)

__str__

View Source
def __str__(self):
    return 'FileFormatProperty() of extension {!s:s}'.format(self._extension)