_id stringlengths 2 7 | title stringlengths 1 88 | partition stringclasses 3
values | text stringlengths 75 19.8k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q227500 | Validator.check_file_encoding | train | def check_file_encoding(self, input_file_path):
"""
Check whether the given file is UTF-8 encoded.
:param string input_file_path: the path of the file to be checked
:rtype: :class:`~aeneas.validator.ValidatorResult`
"""
self.log([u"Checking encoding of file '%s'", input_... | python | {
"resource": ""
} |
q227501 | Validator.check_config_xml | train | def check_config_xml(self, contents):
"""
Check whether the given XML config file contents
is well-formed and it has all the required parameters.
:param string contents: the XML config file contents or XML config string
:param bool is_config_string: if ``True``, contents is a co... | python | {
"resource": ""
} |
q227502 | Validator.check_container | train | def check_container(self, container_path, container_format=None, config_string=None):
"""
Check whether the given container is well-formed.
:param string container_path: the path of the container to be checked
:param container_format: the format of the container
:type container... | python | {
"resource": ""
} |
q227503 | Validator._are_safety_checks_disabled | train | def _are_safety_checks_disabled(self, caller=u"unknown_function"):
"""
Return ``True`` if safety checks are disabled.
:param string caller: the name of the caller function
:rtype: bool
"""
if self.rconf.safety_checks:
return False
self.log_warn([u"Saf... | python | {
"resource": ""
} |
q227504 | Validator._failed | train | def _failed(self, msg):
"""
Log a validation failure.
:param string msg: the error message
"""
self.log(msg)
self.result.passed = False
self.result.add_error(msg)
self.log(u"Failed") | python | {
"resource": ""
} |
q227505 | Validator._check_utf8_encoding | train | def _check_utf8_encoding(self, bstring):
"""
Check whether the given sequence of bytes
is properly encoded in UTF-8.
:param bytes bstring: the byte string to be checked
"""
if not gf.is_bytes(bstring):
self._failed(u"The given string is not a sequence of byte... | python | {
"resource": ""
} |
q227506 | Validator._check_reserved_characters | train | def _check_reserved_characters(self, ustring):
"""
Check whether the given Unicode string contains reserved characters.
:param string ustring: the string to be checked
"""
forbidden = [c for c in gc.CONFIG_RESERVED_CHARACTERS if c in ustring]
if len(forbidden) > 0:
... | python | {
"resource": ""
} |
q227507 | Validator._check_allowed_values | train | def _check_allowed_values(self, parameters):
"""
Check whether the given parameter value is allowed.
Log messages into ``self.result``.
:param dict parameters: the given parameters
"""
for key, allowed_values in self.ALLOWED_VALUES:
self.log([u"Checking allow... | python | {
"resource": ""
} |
q227508 | Validator._check_implied_parameters | train | def _check_implied_parameters(self, parameters):
"""
Check whether at least one of the keys in implied_keys
is in ``parameters``,
when a given ``key=value`` is present in ``parameters``,
for some value in values.
Log messages into ``self.result``.
:param dict par... | python | {
"resource": ""
} |
q227509 | Validator._check_required_parameters | train | def _check_required_parameters(
self,
required_parameters,
parameters
):
"""
Check whether the given parameter dictionary contains
all the required paramenters.
Log messages into ``self.result``.
:param list required_parameters: required p... | python | {
"resource": ""
} |
q227510 | Validator._check_analyzed_job | train | def _check_analyzed_job(self, job, container):
"""
Check that the job object generated from the given container
is well formed, that it has at least one task,
and that the text file of each task has the correct encoding.
Log messages into ``self.result``.
:param job: the... | python | {
"resource": ""
} |
q227511 | ValidatorResult.pretty_print | train | def pretty_print(self, warnings=False):
"""
Pretty print warnings and errors.
:param bool warnings: if ``True``, also print warnings.
:rtype: string
"""
msg = []
if (warnings) and (len(self.warnings) > 0):
msg.append(u"Warnings:")
for warn... | python | {
"resource": ""
} |
q227512 | FFMPEGWrapper.convert | train | def convert(
self,
input_file_path,
output_file_path,
head_length=None,
process_length=None
):
"""
Convert the audio file at ``input_file_path``
into ``output_file_path``,
using the parameters set in the constructor
... | python | {
"resource": ""
} |
q227513 | SyncMapFragment.rate_lack | train | def rate_lack(self, max_rate):
"""
The time interval that this fragment lacks
to respect the given max rate.
A positive value means that the current fragment
is faster than the max rate (bad).
A negative or zero value means that the current fragment
has rate slow... | python | {
"resource": ""
} |
q227514 | SyncMapFragment.rate_slack | train | def rate_slack(self, max_rate):
"""
The maximum time interval that can be stolen to this fragment
while keeping it respecting the given max rate.
For ``REGULAR`` fragments this value is
the opposite of the ``rate_lack``.
For ``NONSPEECH`` fragments this value is equal to... | python | {
"resource": ""
} |
q227515 | RunVADCLI.write_to_file | train | def write_to_file(self, output_file_path, intervals, template):
"""
Write intervals to file.
:param output_file_path: path of the output file to be written;
if ``None``, print to stdout
:type output_file_path: string (path)
:param intervals: a l... | python | {
"resource": ""
} |
q227516 | ExecuteJobCLI.print_parameters | train | def print_parameters(self):
"""
Print the list of parameters and exit.
"""
self.print_info(u"Available parameters:")
self.print_generic(u"\n" + u"\n".join(self.PARAMETERS) + u"\n")
return self.HELP_EXIT_CODE | python | {
"resource": ""
} |
q227517 | main | train | def main():
"""
Run ``aeneas.cew``, reading input text from file and writing audio and interval data to file.
"""
# make sure we have enough parameters
if len(sys.argv) < 6:
print("You must pass five arguments: QUIT_AFTER BACKWARDS TEXT_FILE_PATH AUDIO_FILE_PATH DATA_FILE_PATH")
ret... | python | {
"resource": ""
} |
q227518 | SyncMapFormatSMIL.parse | train | def parse(self, input_text, syncmap):
"""
Read from SMIL file.
Limitations:
1. parses only ``<par>`` elements, in order
2. timings must have ``hh:mm:ss.mmm`` or ``ss.mmm`` format (autodetected)
3. both ``clipBegin`` and ``clipEnd`` attributes of ``<audio>`` must be popul... | python | {
"resource": ""
} |
q227519 | SyncMapFragmentList._is_valid_index | train | def _is_valid_index(self, index):
"""
Return ``True`` if and only if the given ``index``
is valid.
"""
if isinstance(index, int):
return (index >= 0) and (index < len(self))
if isinstance(index, list):
valid = True
for i in index:
... | python | {
"resource": ""
} |
q227520 | SyncMapFragmentList._check_boundaries | train | def _check_boundaries(self, fragment):
"""
Check that the interval of the given fragment
is within the boundaries of the list.
Raises an error if not OK.
"""
if not isinstance(fragment, SyncMapFragment):
raise TypeError(u"fragment is not an instance of SyncMap... | python | {
"resource": ""
} |
q227521 | SyncMapFragmentList.remove | train | def remove(self, indices):
"""
Remove the fragments corresponding to the given list of indices.
:param indices: the list of indices to be removed
:type indices: list of int
:raises ValueError: if one of the indices is not valid
"""
if not self._is_valid_index(in... | python | {
"resource": ""
} |
q227522 | SyncMapFragmentList.sort | train | def sort(self):
"""
Sort the fragments in the list.
:raises ValueError: if there is a fragment which violates
the list constraints
"""
if self.is_guaranteed_sorted:
self.log(u"Already sorted, returning")
return
self.log... | python | {
"resource": ""
} |
q227523 | SyncMapFragmentList.remove_nonspeech_fragments | train | def remove_nonspeech_fragments(self, zero_length_only=False):
"""
Remove ``NONSPEECH`` fragments from the list.
If ``zero_length_only`` is ``True``, remove only
those fragments with zero length,
and make all the others ``REGULAR``.
:param bool zero_length_only: remove o... | python | {
"resource": ""
} |
q227524 | SyncMapFragmentList.has_zero_length_fragments | train | def has_zero_length_fragments(self, min_index=None, max_index=None):
"""
Return ``True`` if the list has at least one interval
with zero length withing ``min_index`` and ``max_index``.
If the latter are not specified, check all intervals.
:param int min_index: examine fragments ... | python | {
"resource": ""
} |
q227525 | SyncMapFragmentList.has_adjacent_fragments_only | train | def has_adjacent_fragments_only(self, min_index=None, max_index=None):
"""
Return ``True`` if the list contains only adjacent fragments,
that is, if it does not have gaps.
:param int min_index: examine fragments with index greater than or equal to this index (i.e., included)
:pa... | python | {
"resource": ""
} |
q227526 | SyncMapFragmentList.offset | train | def offset(self, offset):
"""
Move all the intervals in the list by the given ``offset``.
:param offset: the shift to be applied
:type offset: :class:`~aeneas.exacttiming.TimeValue`
:raises TypeError: if ``offset`` is not an instance of ``TimeValue``
"""
self.lo... | python | {
"resource": ""
} |
q227527 | SyncMapFragmentList.move_transition_point | train | def move_transition_point(self, fragment_index, value):
"""
Change the transition point between fragment ``fragment_index``
and the next fragment to the time value ``value``.
This method fails silently
(without changing the fragment list)
if at least one of the following... | python | {
"resource": ""
} |
q227528 | SyncMapFragmentList.inject_long_nonspeech_fragments | train | def inject_long_nonspeech_fragments(self, pairs, replacement_string):
"""
Inject nonspeech fragments corresponding to the given intervals
in this fragment list.
It is assumed that ``pairs`` are consistent, e.g. they are produced
by ``fragments_ending_inside_nonspeech_intervals``... | python | {
"resource": ""
} |
q227529 | DTWAligner.compute_accumulated_cost_matrix | train | def compute_accumulated_cost_matrix(self):
"""
Compute the accumulated cost matrix, and return it.
Return ``None`` if the accumulated cost matrix cannot be computed
because one of the two waves is empty after masking (if requested).
:rtype: :class:`numpy.ndarray` (2D)
:... | python | {
"resource": ""
} |
q227530 | DTWAligner.compute_path | train | def compute_path(self):
"""
Compute the min cost path between the two waves, and return it.
Return the computed path as a tuple with two elements,
each being a :class:`numpy.ndarray` (1D) of ``int`` indices: ::
([r_1, r_2, ..., r_k], [s_1, s_2, ..., s_k])
where ``r_i``... | python | {
"resource": ""
} |
q227531 | DTWAligner.compute_boundaries | train | def compute_boundaries(self, synt_anchors):
"""
Compute the min cost path between the two waves,
and return a list of boundary points,
representing the argmin values with respect to
the provided ``synt_anchors`` timings.
If ``synt_anchors`` has ``k`` elements,
th... | python | {
"resource": ""
} |
q227532 | DTWAligner._setup_dtw | train | def _setup_dtw(self):
"""
Set the DTW object up.
"""
# check if the DTW object has already been set up
if self.dtw is not None:
return
# check we have the AudioFileMFCC objects
if (self.real_wave_mfcc is None) or (self.real_wave_mfcc.middle_mfcc is No... | python | {
"resource": ""
} |
q227533 | check_import | train | def check_import():
"""
Try to import the aeneas package and return ``True`` if that fails.
"""
try:
import aeneas
print_success(u"aeneas OK")
return False
except ImportError:
print_error(u"aeneas ERROR")
print_info(u" Unable to load the aenea... | python | {
"resource": ""
} |
q227534 | main | train | def main():
""" The entry point for this module """
# first, check we can import aeneas package, exiting on failure
if check_import():
sys.exit(1)
# import and run the built-in diagnostics
from aeneas.diagnostics import Diagnostics
errors, warnings, c_ext_warnings = Diagnostics.check_al... | python | {
"resource": ""
} |
q227535 | Tree.is_pleasant | train | def is_pleasant(self):
"""
Return ``True`` if all the leaves
in the subtree rooted at this node
are at the same level.
:rtype: bool
"""
levels = sorted([n.level for n in self.leaves])
return levels[0] == levels[-1] | python | {
"resource": ""
} |
q227536 | Tree.add_child | train | def add_child(self, node, as_last=True):
"""
Add the given child to the current list of children.
The new child is appended as the last child if ``as_last``
is ``True``, or as the first child if ``as_last`` is ``False``.
This call updates the ``__parent`` and ``__level`` fields... | python | {
"resource": ""
} |
q227537 | Tree.remove_child | train | def remove_child(self, index):
"""
Remove the child at the given index
from the current list of children.
:param int index: the index of the child to be removed
"""
if index < 0:
index = index + len(self)
self.__children = self.__children[0:index] + s... | python | {
"resource": ""
} |
q227538 | Tree.remove | train | def remove(self):
"""
Remove this node from the list of children of its current parent,
if the current parent is not ``None``, otherwise do nothing.
.. versionadded:: 1.7.0
"""
if self.parent is not None:
for i, child in enumerate(self.parent.children):
... | python | {
"resource": ""
} |
q227539 | Tree.remove_children | train | def remove_children(self, reset_parent=True):
"""
Remove all the children of this node.
:param bool reset_parent: if ``True``, set to ``None`` the parent attribute
of the children
"""
if reset_parent:
for child in self.children:
... | python | {
"resource": ""
} |
q227540 | Tree.leaves_not_empty | train | def leaves_not_empty(self):
"""
Return the list of leaves not empty
in the tree rooted at this node,
in DFS order.
:rtype: list of :class:`~aeneas.tree.Tree`
"""
return [n for n in self.dfs if ((n.is_leaf) and (not n.is_empty))] | python | {
"resource": ""
} |
q227541 | Tree.height | train | def height(self):
"""
Return the height of the tree
rooted at this node,
that is, the difference between the level
of a deepest leaf and the level of this node.
Return ``1`` for a single-node tree,
``2`` for a two-levels tree, etc.
:rtype: int
"""... | python | {
"resource": ""
} |
q227542 | Tree.levels | train | def levels(self):
"""
Return a list of lists of nodes.
The outer list is indexed by the level.
Each inner list contains the nodes at that level,
in DFS order.
:rtype: list of lists of :class:`~aeneas.tree.Tree`
"""
ret = [[] for i in range(self.height)]
... | python | {
"resource": ""
} |
q227543 | Tree.level_at_index | train | def level_at_index(self, index):
"""
Return the list of nodes at level ``index``,
in DFS order.
:param int index: the index
:rtype: list of :class:`~aeneas.tree.Tree`
:raises: ValueError if the given ``index`` is not valid
"""
if not isinstance(index, in... | python | {
"resource": ""
} |
q227544 | Tree.ancestor | train | def ancestor(self, index):
"""
Return the ``index``-th ancestor.
The 0-th ancestor is the node itself,
the 1-th ancestor is its parent node,
etc.
:param int index: the number of levels to go up
:rtype: :class:`~aeneas.tree.Tree`
:raises: TypeError if ``i... | python | {
"resource": ""
} |
q227545 | Tree.keep_levels | train | def keep_levels(self, level_indices):
"""
Rearrange the tree rooted at this node
to keep only the given levels.
The returned Tree will still be rooted
at the current node, i.e. this function
implicitly adds ``0`` to ``level_indices``.
If ``level_indices`` is an ... | python | {
"resource": ""
} |
q227546 | s2dctmat | train | def s2dctmat(nfilt,ncep,freqstep):
"""Return the 'legacy' not-quite-DCT matrix used by Sphinx"""
melcos = numpy.empty((ncep, nfilt), 'double')
for i in range(0,ncep):
freq = numpy.pi * float(i) / nfilt
melcos[i] = numpy.cos(freq * numpy.arange(0.5, float(nfilt)+0.5, 1.0, 'double'))
melco... | python | {
"resource": ""
} |
q227547 | logspec2s2mfc | train | def logspec2s2mfc(logspec, ncep=13):
"""Convert log-power-spectrum bins to MFCC using the 'legacy'
Sphinx transform"""
nframes, nfilt = logspec.shape
melcos = s2dctmat(nfilt, ncep, 1./nfilt)
return numpy.dot(logspec, melcos.T) / nfilt | python | {
"resource": ""
} |
q227548 | dct | train | def dct(input, K=13):
"""Convert log-power-spectrum to MFCC using the orthogonal DCT-II"""
nframes, N = input.shape
freqstep = numpy.pi / N
cosmat = dctmat(N,K,freqstep)
return numpy.dot(input, cosmat) * numpy.sqrt(2.0 / N) | python | {
"resource": ""
} |
q227549 | dct2 | train | def dct2(input, K=13):
"""Convert log-power-spectrum to MFCC using the normalized DCT-II"""
nframes, N = input.shape
freqstep = numpy.pi / N
cosmat = dctmat(N,K,freqstep,False)
return numpy.dot(input, cosmat) * (2.0 / N) | python | {
"resource": ""
} |
q227550 | AudioFile.read_properties | train | def read_properties(self):
"""
Populate this object by reading
the audio properties of the file at the given path.
Currently this function uses
:class:`~aeneas.ffprobewrapper.FFPROBEWrapper`
to get the audio file properties.
:raises: :class:`~aeneas.audiofile.Au... | python | {
"resource": ""
} |
q227551 | AudioFile.read_samples_from_file | train | def read_samples_from_file(self):
"""
Load the audio samples from file into memory.
If ``self.file_format`` is ``None`` or it is not
``("pcm_s16le", 1, self.rconf.sample_rate)``,
the file will be first converted
to a temporary PCM16 mono WAVE file.
Audio data wil... | python | {
"resource": ""
} |
q227552 | AudioFile.preallocate_memory | train | def preallocate_memory(self, capacity):
"""
Preallocate memory to store audio samples,
to avoid repeated new allocations and copies
while performing several consecutive append operations.
If ``self.__samples`` is not initialized,
it will become an array of ``capacity`` z... | python | {
"resource": ""
} |
q227553 | AudioFile.minimize_memory | train | def minimize_memory(self):
"""
Reduce the allocated memory to the minimum
required to store the current audio samples.
This function is meant to be called
when building a wave incrementally,
after the last append operation.
.. versionadded:: 1.5.0
"""
... | python | {
"resource": ""
} |
q227554 | AudioFile.add_samples | train | def add_samples(self, samples, reverse=False):
"""
Concatenate the given new samples to the current audio data.
This function initializes the memory if no audio data
is present already.
If ``reverse`` is ``True``, the new samples
will be reversed and then concatenated.
... | python | {
"resource": ""
} |
q227555 | AudioFile.reverse | train | def reverse(self):
"""
Reverse the audio data.
:raises: :class:`~aeneas.audiofile.AudioFileNotInitializedError`: if the audio file is not initialized yet
.. versionadded:: 1.2.0
"""
if self.__samples is None:
if self.file_path is None:
self.l... | python | {
"resource": ""
} |
q227556 | AudioFile.trim | train | def trim(self, begin=None, length=None):
"""
Get a slice of the audio data of ``length`` seconds,
starting from ``begin`` seconds.
If audio data is not loaded, load it and then slice it.
:param begin: the start position, in seconds
:type begin: :class:`~aeneas.exacttim... | python | {
"resource": ""
} |
q227557 | AudioFile.write | train | def write(self, file_path):
"""
Write the audio data to file.
Return ``True`` on success, or ``False`` otherwise.
:param string file_path: the path of the output file to be written
:raises: :class:`~aeneas.audiofile.AudioFileNotInitializedError`: if the audio file is not initial... | python | {
"resource": ""
} |
q227558 | AudioFile.clear_data | train | def clear_data(self):
"""
Clear the audio data, freeing memory.
"""
self.log(u"Clear audio_data")
self.__samples_capacity = 0
self.__samples_length = 0
self.__samples = None | python | {
"resource": ""
} |
q227559 | AudioFile._update_length | train | def _update_length(self):
"""
Update the audio length property,
according to the length of the current audio data
and audio sample rate.
This function fails silently if one of the two is ``None``.
"""
if (self.audio_sample_rate is not None) and (self.__samples is... | python | {
"resource": ""
} |
q227560 | AudioFileMFCC.masked_middle_mfcc | train | def masked_middle_mfcc(self):
"""
Return the MFCC speech frames
in the MIDDLE portion of the wave.
:rtype: :class:`numpy.ndarray` (2D)
"""
begin, end = self._masked_middle_begin_end()
return (self.masked_mfcc)[:, begin:end] | python | {
"resource": ""
} |
q227561 | AudioFileMFCC.masked_middle_map | train | def masked_middle_map(self):
"""
Return the map
from the MFCC speech frame indices
in the MIDDLE portion of the wave
to the MFCC FULL frame indices.
:rtype: :class:`numpy.ndarray` (1D)
"""
begin, end = self._masked_middle_begin_end()
return self._... | python | {
"resource": ""
} |
q227562 | AudioFileMFCC._binary_search_intervals | train | def _binary_search_intervals(cls, intervals, index):
"""
Binary search for the interval containing index,
assuming there is such an interval.
This function should never return ``None``.
"""
start = 0
end = len(intervals) - 1
while start <= end:
... | python | {
"resource": ""
} |
q227563 | AudioFileMFCC.middle_begin | train | def middle_begin(self, index):
"""
Set the index where MIDDLE starts.
:param int index: the new index for MIDDLE begin
"""
if (index < 0) or (index > self.all_length):
raise ValueError(u"The given index is not valid")
self.__middle_begin = index | python | {
"resource": ""
} |
q227564 | AudioFileMFCC._compute_mfcc_c_extension | train | def _compute_mfcc_c_extension(self):
"""
Compute MFCCs using the Python C extension cmfcc.
"""
self.log(u"Computing MFCCs using C extension...")
try:
self.log(u"Importing cmfcc...")
import aeneas.cmfcc.cmfcc
self.log(u"Importing cmfcc... done")... | python | {
"resource": ""
} |
q227565 | AudioFileMFCC._compute_mfcc_pure_python | train | def _compute_mfcc_pure_python(self):
"""
Compute MFCCs using the pure Python code.
"""
self.log(u"Computing MFCCs using pure Python code...")
try:
self.__mfcc = MFCC(
rconf=self.rconf,
logger=self.logger
).compute_from_data(... | python | {
"resource": ""
} |
q227566 | AudioFileMFCC.reverse | train | def reverse(self):
"""
Reverse the audio file.
The reversing is done efficiently using NumPy views inplace
instead of swapping values.
Only speech and nonspeech intervals are actually recomputed
as Python lists.
"""
self.log(u"Reversing...")
all_... | python | {
"resource": ""
} |
q227567 | AudioFileMFCC.run_vad | train | def run_vad(
self,
log_energy_threshold=None,
min_nonspeech_length=None,
extend_before=None,
extend_after=None
):
"""
Determine which frames contain speech and nonspeech,
and store the resulting boolean mask internally.
The four parameters mig... | python | {
"resource": ""
} |
q227568 | AudioFileMFCC.set_head_middle_tail | train | def set_head_middle_tail(self, head_length=None, middle_length=None, tail_length=None):
"""
Set the HEAD, MIDDLE, TAIL explicitly.
If a parameter is ``None``, it will be ignored.
If both ``middle_length`` and ``tail_length`` are specified,
only ``middle_length`` will be applied.... | python | {
"resource": ""
} |
q227569 | TextFragment.chars | train | def chars(self):
"""
Return the number of characters of the text fragment,
not including the line separators.
:rtype: int
"""
if self.lines is None:
return 0
return sum([len(line) for line in self.lines]) | python | {
"resource": ""
} |
q227570 | TextFile.children_not_empty | train | def children_not_empty(self):
"""
Return the direct not empty children of the root of the fragments tree,
as ``TextFile`` objects.
:rtype: list of :class:`~aeneas.textfile.TextFile`
"""
children = []
for child_node in self.fragments_tree.children_not_empty:
... | python | {
"resource": ""
} |
q227571 | TextFile.characters | train | def characters(self):
"""
The number of characters in this text file.
:rtype: int
"""
chars = 0
for fragment in self.fragments:
chars += fragment.characters
return chars | python | {
"resource": ""
} |
q227572 | TextFile.add_fragment | train | def add_fragment(self, fragment, as_last=True):
"""
Add the given text fragment as the first or last child of the root node
of the text file tree.
:param fragment: the text fragment to be added
:type fragment: :class:`~aeneas.textfile.TextFragment`
:param bool as_last: ... | python | {
"resource": ""
} |
q227573 | TextFile.set_language | train | def set_language(self, language):
"""
Set the given language for all the text fragments.
:param language: the language of the text fragments
:type language: :class:`~aeneas.language.Language`
"""
self.log([u"Setting language: '%s'", language])
for fragment in se... | python | {
"resource": ""
} |
q227574 | TextFile._read_from_file | train | def _read_from_file(self):
"""
Read text fragments from file.
"""
# test if we can read the given file
if not gf.file_can_be_read(self.file_path):
self.log_exc(u"File '%s' cannot be read" % (self.file_path), None, True, OSError)
if self.file_format not in Tex... | python | {
"resource": ""
} |
q227575 | TextFile._mplain_word_separator | train | def _mplain_word_separator(self):
"""
Get the word separator to split words in mplain format.
:rtype: string
"""
word_separator = gf.safe_get(self.parameters, gc.PPN_TASK_IS_TEXT_MPLAIN_WORD_SEPARATOR, u" ")
if (word_separator is None) or (word_separator == "space"):
... | python | {
"resource": ""
} |
q227576 | TextFile._read_mplain | train | def _read_mplain(self, lines):
"""
Read text fragments from a multilevel format text file.
:param list lines: the lines of the subtitles text file
"""
self.log(u"Parsing fragments from subtitles text format")
word_separator = self._mplain_word_separator()
self.lo... | python | {
"resource": ""
} |
q227577 | TextFile._read_subtitles | train | def _read_subtitles(self, lines):
"""
Read text fragments from a subtitles format text file.
:param list lines: the lines of the subtitles text file
:raises: ValueError: if the id regex is not valid
"""
self.log(u"Parsing fragments from subtitles text format")
id... | python | {
"resource": ""
} |
q227578 | TextFile._read_parsed | train | def _read_parsed(self, lines):
"""
Read text fragments from a parsed format text file.
:param list lines: the lines of the parsed text file
:param dict parameters: additional parameters for parsing
(e.g., class/id regex strings)
"""
self.l... | python | {
"resource": ""
} |
q227579 | TextFile._read_plain | train | def _read_plain(self, lines):
"""
Read text fragments from a plain format text file.
:param list lines: the lines of the plain text file
:param dict parameters: additional parameters for parsing
(e.g., class/id regex strings)
:raises: ValueError: ... | python | {
"resource": ""
} |
q227580 | TextFile._read_unparsed | train | def _read_unparsed(self, lines):
"""
Read text fragments from an unparsed format text file.
:param list lines: the lines of the unparsed text file
"""
from bs4 import BeautifulSoup
def filter_attributes():
""" Return a dict with the bs4 filter parameters """... | python | {
"resource": ""
} |
q227581 | TextFile._get_id_format | train | def _get_id_format(self):
""" Return the id regex from the parameters"""
id_format = gf.safe_get(
self.parameters,
gc.PPN_TASK_OS_FILE_ID_REGEX,
self.DEFAULT_ID_FORMAT,
can_return_none=False
)
try:
identifier = id_format % 1
... | python | {
"resource": ""
} |
q227582 | TextFile._create_text_fragments | train | def _create_text_fragments(self, pairs):
"""
Create text fragment objects and append them to this list.
:param list pairs: a list of pairs, each pair being (id, [line_1, ..., line_n])
"""
self.log(u"Creating TextFragment objects")
text_filter = self._build_text_filter()
... | python | {
"resource": ""
} |
q227583 | TextFile._build_text_filter | train | def _build_text_filter(self):
"""
Build a suitable TextFilter object.
"""
text_filter = TextFilter(logger=self.logger)
self.log(u"Created TextFilter object")
for key, cls, param_name in [
(
gc.PPN_TASK_IS_TEXT_FILE_IGNORE_REGEX,
... | python | {
"resource": ""
} |
q227584 | TextFilter.add_filter | train | def add_filter(self, new_filter, as_last=True):
"""
Compose this filter with the given ``new_filter`` filter.
:param new_filter: the filter to be composed
:type new_filter: :class:`~aeneas.textfile.TextFilter`
:param bool as_last: if ``True``, compose to the right, otherwise to... | python | {
"resource": ""
} |
q227585 | TextFilter.apply_filter | train | def apply_filter(self, strings):
"""
Apply the text filter filter to the given list of strings.
:param list strings: the list of input strings
"""
result = strings
for filt in self.filters:
result = filt.apply_filter(result)
self.log([u"Applying regex... | python | {
"resource": ""
} |
q227586 | TransliterationMap._build_map | train | def _build_map(self):
"""
Read the map file at path.
"""
if gf.is_py2_narrow_build():
self.log_warn(u"Running on a Python 2 narrow build: be aware that Unicode chars above 0x10000 cannot be replaced correctly.")
self.trans_map = {}
with io.open(self.file_path,... | python | {
"resource": ""
} |
q227587 | TransliterationMap._process_map_rule | train | def _process_map_rule(self, line):
"""
Process the line string containing a map rule.
"""
result = self.REPLACE_REGEX.match(line)
if result is not None:
what = self._process_first_group(result.group(1))
replacement = self._process_second_group(result.group... | python | {
"resource": ""
} |
q227588 | TransliterationMap._process_first_group | train | def _process_first_group(self, group):
"""
Process the first group of a rule.
"""
if "-" in group:
# range
if len(group.split("-")) == 2:
arr = group.split("-")
start = self._parse_codepoint(arr[0])
end = self._parse... | python | {
"resource": ""
} |
q227589 | ExecuteJob.load_job | train | def load_job(self, job):
"""
Load the job from the given ``Job`` object.
:param job: the job to load
:type job: :class:`~aeneas.job.Job`
:raises: :class:`~aeneas.executejob.ExecuteJobInputError`: if ``job`` is not an instance of :class:`~aeneas.job.Job`
"""
if n... | python | {
"resource": ""
} |
q227590 | ExecuteJob.execute | train | def execute(self):
"""
Execute the job, that is, execute all of its tasks.
Each produced sync map will be stored
inside the corresponding task object.
:raises: :class:`~aeneas.executejob.ExecuteJobExecutionError`: if there is a problem during the job execution
"""
... | python | {
"resource": ""
} |
q227591 | ExecuteJob.write_output_container | train | def write_output_container(self, output_directory_path):
"""
Write the output container for this job.
Return the path to output container,
which is the concatenation of ``output_directory_path``
and of the output container file or directory name.
:param string output_di... | python | {
"resource": ""
} |
q227592 | ExecuteJob.clean | train | def clean(self, remove_working_directory=True):
"""
Remove the temporary directory.
If ``remove_working_directory`` is ``True``
remove the working directory as well,
otherwise just remove the temporary directory.
:param bool remove_working_directory: if ``True``, remove
... | python | {
"resource": ""
} |
q227593 | PlotWaveformCLI._read_syncmap_file | train | def _read_syncmap_file(self, path, extension, text=False):
""" Read labels from a SyncMap file """
syncmap = SyncMap(logger=self.logger)
syncmap.read(extension, path, parameters=None)
if text:
return [(f.begin, f.end, u" ".join(f.text_fragment.lines)) for f in syncmap.fragmen... | python | {
"resource": ""
} |
q227594 | SyncMap.has_adjacent_leaves_only | train | def has_adjacent_leaves_only(self):
"""
Return ``True`` if the sync map fragments
which are the leaves of the sync map tree
are all adjacent.
:rtype: bool
.. versionadded:: 1.7.0
"""
leaves = self.leaves()
for i in range(len(leaves) - 1):
... | python | {
"resource": ""
} |
q227595 | SyncMap.json_string | train | def json_string(self):
"""
Return a JSON representation of the sync map.
:rtype: string
.. versionadded:: 1.3.1
"""
def visit_children(node):
""" Recursively visit the fragments_tree """
output_fragments = []
for child in node.childre... | python | {
"resource": ""
} |
q227596 | SyncMap.add_fragment | train | def add_fragment(self, fragment, as_last=True):
"""
Add the given sync map fragment,
as the first or last child of the root node
of the sync map tree.
:param fragment: the sync map fragment to be added
:type fragment: :class:`~aeneas.syncmap.fragment.SyncMapFragment`
... | python | {
"resource": ""
} |
q227597 | SyncMap.output_html_for_tuning | train | def output_html_for_tuning(
self,
audio_file_path,
output_file_path,
parameters=None
):
"""
Output an HTML file for fine tuning the sync map manually.
:param string audio_file_path: the path to the associated audio file
:param string o... | python | {
"resource": ""
} |
q227598 | MFCC._create_dct_matrix | train | def _create_dct_matrix(self):
"""
Create the not-quite-DCT matrix as used by Sphinx,
and store it in ```self.s2dct```.
"""
self.s2dct = numpy.zeros((self.mfcc_size, self.filter_bank_size))
for i in range(0, self.mfcc_size):
freq = numpy.pi * float(i) / self.fi... | python | {
"resource": ""
} |
q227599 | MFCC._create_mel_filter_bank | train | def _create_mel_filter_bank(self):
"""
Create the Mel filter bank,
and store it in ``self.filters``.
Note that it is a function of the audio sample rate,
so it cannot be created in the class initializer,
but only later in :func:`aeneas.mfcc.MFCC.compute_from_data`.
... | python | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.