id int32 0 252k | repo stringlengths 7 55 | path stringlengths 4 127 | func_name stringlengths 1 88 | original_string stringlengths 75 19.8k | language stringclasses 1
value | code stringlengths 51 19.8k | code_tokens list | docstring stringlengths 3 17.3k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 87 242 |
|---|---|---|---|---|---|---|---|---|---|---|---|
246,000 | readbeyond/aeneas | aeneas/syncmap/fragmentlist.py | SyncMapFragmentList.has_zero_length_fragments | 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 | def has_zero_length_fragments(self, min_index=None, max_index=None):
min_index, max_index = self._check_min_max_indices(min_index, max_index)
zero = [i for i in range(min_index, max_index) if self[i].has_zero_length]
self.log([u"Fragments with zero length: %s", zero])
return (len(zero) >... | [
"def",
"has_zero_length_fragments",
"(",
"self",
",",
"min_index",
"=",
"None",
",",
"max_index",
"=",
"None",
")",
":",
"min_index",
",",
"max_index",
"=",
"self",
".",
"_check_min_max_indices",
"(",
"min_index",
",",
"max_index",
")",
"zero",
"=",
"[",
"i"... | 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 with index greater than or equal to this index (i.e., included)
:param int max_in... | [
"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",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/syncmap/fragmentlist.py#L294-L309 |
246,001 | readbeyond/aeneas | aeneas/syncmap/fragmentlist.py | SyncMapFragmentList.has_adjacent_fragments_only | 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 | def has_adjacent_fragments_only(self, min_index=None, max_index=None):
min_index, max_index = self._check_min_max_indices(min_index, max_index)
for i in range(min_index, max_index - 1):
current_interval = self[i].interval
next_interval = self[i + 1].interval
if not cu... | [
"def",
"has_adjacent_fragments_only",
"(",
"self",
",",
"min_index",
"=",
"None",
",",
"max_index",
"=",
"None",
")",
":",
"min_index",
",",
"max_index",
"=",
"self",
".",
"_check_min_max_indices",
"(",
"min_index",
",",
"max_index",
")",
"for",
"i",
"in",
"... | 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)
:param int max_index: examine fragments with index smaller than this index (i.e., excluded)
... | [
"Return",
"True",
"if",
"the",
"list",
"contains",
"only",
"adjacent",
"fragments",
"that",
"is",
"if",
"it",
"does",
"not",
"have",
"gaps",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/syncmap/fragmentlist.py#L311-L331 |
246,002 | readbeyond/aeneas | aeneas/syncmap/fragmentlist.py | SyncMapFragmentList.offset | 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 | def offset(self, offset):
self.log(u"Applying offset to all fragments...")
self.log([u" Offset %.3f", offset])
for fragment in self.fragments:
fragment.interval.offset(
offset=offset,
allow_negative=False,
min_begin_value=self.begin,
... | [
"def",
"offset",
"(",
"self",
",",
"offset",
")",
":",
"self",
".",
"log",
"(",
"u\"Applying offset to all fragments...\"",
")",
"self",
".",
"log",
"(",
"[",
"u\" Offset %.3f\"",
",",
"offset",
"]",
")",
"for",
"fragment",
"in",
"self",
".",
"fragments",
... | 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`` | [
"Move",
"all",
"the",
"intervals",
"in",
"the",
"list",
"by",
"the",
"given",
"offset",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/syncmap/fragmentlist.py#L360-L377 |
246,003 | readbeyond/aeneas | aeneas/syncmap/fragmentlist.py | SyncMapFragmentList.move_transition_point | 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 | def move_transition_point(self, fragment_index, value):
self.log(u"Called move_transition_point with")
self.log([u" fragment_index %d", fragment_index])
self.log([u" value %.3f", value])
if (fragment_index < 0) or (fragment_index > (len(self) - 3)):
self.log(u"Bad ... | [
"def",
"move_transition_point",
"(",
"self",
",",
"fragment_index",
",",
"value",
")",
":",
"self",
".",
"log",
"(",
"u\"Called move_transition_point with\"",
")",
"self",
".",
"log",
"(",
"[",
"u\" fragment_index %d\"",
",",
"fragment_index",
"]",
")",
"self",
... | 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 conditions holds:
* ``fragment_index`` is negative
* ``fra... | [
"Change",
"the",
"transition",
"point",
"between",
"fragment",
"fragment_index",
"and",
"the",
"next",
"fragment",
"to",
"the",
"time",
"value",
"value",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/syncmap/fragmentlist.py#L379-L416 |
246,004 | readbeyond/aeneas | aeneas/syncmap/fragmentlist.py | SyncMapFragmentList.inject_long_nonspeech_fragments | 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 | def inject_long_nonspeech_fragments(self, pairs, replacement_string):
self.log(u"Called inject_long_nonspeech_fragments")
# set the appropriate fragment text
if replacement_string in [None, gc.PPV_TASK_ADJUST_BOUNDARY_NONSPEECH_REMOVE]:
self.log(u" Remove long nonspeech")
... | [
"def",
"inject_long_nonspeech_fragments",
"(",
"self",
",",
"pairs",
",",
"replacement_string",
")",
":",
"self",
".",
"log",
"(",
"u\"Called inject_long_nonspeech_fragments\"",
")",
"# set the appropriate fragment text",
"if",
"replacement_string",
"in",
"[",
"None",
","... | 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``.
:param list pairs: list of ``(TimeInterval, int)`` pairs,
... | [
"Inject",
"nonspeech",
"fragments",
"corresponding",
"to",
"the",
"given",
"intervals",
"in",
"this",
"fragment",
"list",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/syncmap/fragmentlist.py#L507-L550 |
246,005 | readbeyond/aeneas | aeneas/dtw.py | DTWAligner.compute_accumulated_cost_matrix | 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 | def compute_accumulated_cost_matrix(self):
self._setup_dtw()
if self.dtw is None:
self.log(u"Inner self.dtw is None => returning None")
return None
self.log(u"Returning accumulated cost matrix")
return self.dtw.compute_accumulated_cost_matrix() | [
"def",
"compute_accumulated_cost_matrix",
"(",
"self",
")",
":",
"self",
".",
"_setup_dtw",
"(",
")",
"if",
"self",
".",
"dtw",
"is",
"None",
":",
"self",
".",
"log",
"(",
"u\"Inner self.dtw is None => returning None\"",
")",
"return",
"None",
"self",
".",
"lo... | 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)
:raises: RuntimeError: if both the C extension and
... | [
"Compute",
"the",
"accumulated",
"cost",
"matrix",
"and",
"return",
"it",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/dtw.py#L160-L178 |
246,006 | readbeyond/aeneas | aeneas/dtw.py | DTWAligner.compute_path | 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 | def compute_path(self):
self._setup_dtw()
if self.dtw is None:
self.log(u"Inner self.dtw is None => returning None")
return None
self.log(u"Computing path...")
wave_path = self.dtw.compute_path()
self.log(u"Computing path... done")
self.log(u"Trans... | [
"def",
"compute_path",
"(",
"self",
")",
":",
"self",
".",
"_setup_dtw",
"(",
")",
"if",
"self",
".",
"dtw",
"is",
"None",
":",
"self",
".",
"log",
"(",
"u\"Inner self.dtw is None => returning None\"",
")",
"return",
"None",
"self",
".",
"log",
"(",
"u\"Co... | 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`` are the indices in the real wave
an... | [
"Compute",
"the",
"min",
"cost",
"path",
"between",
"the",
"two",
"waves",
"and",
"return",
"it",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/dtw.py#L180-L224 |
246,007 | readbeyond/aeneas | aeneas/dtw.py | DTWAligner.compute_boundaries | 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 | def compute_boundaries(self, synt_anchors):
self._setup_dtw()
if self.dtw is None:
self.log(u"Inner self.dtw is None => returning artificial boundary indices")
begin = self.real_wave_mfcc.middle_begin
end = self.real_wave_mfcc.tail_begin
n = len(synt_ancho... | [
"def",
"compute_boundaries",
"(",
"self",
",",
"synt_anchors",
")",
":",
"self",
".",
"_setup_dtw",
"(",
")",
"if",
"self",
".",
"dtw",
"is",
"None",
":",
"self",
".",
"log",
"(",
"u\"Inner self.dtw is None => returning artificial boundary indices\"",
")",
"begin"... | 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,
the returned array will have ``k+1`` elements,
accounting ... | [
"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",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/dtw.py#L226-L296 |
246,008 | readbeyond/aeneas | aeneas/dtw.py | DTWAligner._setup_dtw | 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 | def _setup_dtw(self):
# 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 None):
self.log_exc(u"The real wave MFCCs are... | [
"def",
"_setup_dtw",
"(",
"self",
")",
":",
"# 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",
")",
"... | Set the DTW object up. | [
"Set",
"the",
"DTW",
"object",
"up",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/dtw.py#L298-L363 |
246,009 | readbeyond/aeneas | check_dependencies.py | check_import | 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 | def check_import():
try:
import aeneas
print_success(u"aeneas OK")
return False
except ImportError:
print_error(u"aeneas ERROR")
print_info(u" Unable to load the aeneas Python package")
print_info(u" This error is probably caused by:")
pr... | [
"def",
"check_import",
"(",
")",
":",
"try",
":",
"import",
"aeneas",
"print_success",
"(",
"u\"aeneas OK\"",
")",
"return",
"False",
"except",
"ImportError",
":",
"print_error",
"(",
"u\"aeneas ERROR\"",
")",
"print_info",
"(",
"u\" Unable to load th... | Try to import the aeneas package and return ``True`` if that fails. | [
"Try",
"to",
"import",
"the",
"aeneas",
"package",
"and",
"return",
"True",
"if",
"that",
"fails",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/check_dependencies.py#L86-L105 |
246,010 | readbeyond/aeneas | check_dependencies.py | main | 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 | def main():
# 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_all()
if errors:
sys.exit(1)
i... | [
"def",
"main",
"(",
")",
":",
"# 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",
"Diagnos... | The entry point for this module | [
"The",
"entry",
"point",
"for",
"this",
"module"
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/check_dependencies.py#L108-L127 |
246,011 | readbeyond/aeneas | aeneas/tree.py | Tree.is_pleasant | 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 | def is_pleasant(self):
levels = sorted([n.level for n in self.leaves])
return levels[0] == levels[-1] | [
"def",
"is_pleasant",
"(",
"self",
")",
":",
"levels",
"=",
"sorted",
"(",
"[",
"n",
".",
"level",
"for",
"n",
"in",
"self",
".",
"leaves",
"]",
")",
"return",
"levels",
"[",
"0",
"]",
"==",
"levels",
"[",
"-",
"1",
"]"
] | Return ``True`` if all the leaves
in the subtree rooted at this node
are at the same level.
:rtype: bool | [
"Return",
"True",
"if",
"all",
"the",
"leaves",
"in",
"the",
"subtree",
"rooted",
"at",
"this",
"node",
"are",
"at",
"the",
"same",
"level",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/tree.py#L208-L217 |
246,012 | readbeyond/aeneas | aeneas/tree.py | Tree.add_child | 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 | def add_child(self, node, as_last=True):
if not isinstance(node, Tree):
self.log_exc(u"node is not an instance of Tree", None, True, TypeError)
if as_last:
self.__children.append(node)
else:
self.__children = [node] + self.__children
node.__parent = se... | [
"def",
"add_child",
"(",
"self",
",",
"node",
",",
"as_last",
"=",
"True",
")",
":",
"if",
"not",
"isinstance",
"(",
"node",
",",
"Tree",
")",
":",
"self",
".",
"log_exc",
"(",
"u\"node is not an instance of Tree\"",
",",
"None",
",",
"True",
",",
"TypeE... | 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 of ``node``.
:param node: the child node to be adde... | [
"Add",
"the",
"given",
"child",
"to",
"the",
"current",
"list",
"of",
"children",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/tree.py#L219-L243 |
246,013 | readbeyond/aeneas | aeneas/tree.py | Tree.remove_child | 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 | def remove_child(self, index):
if index < 0:
index = index + len(self)
self.__children = self.__children[0:index] + self.__children[(index + 1):] | [
"def",
"remove_child",
"(",
"self",
",",
"index",
")",
":",
"if",
"index",
"<",
"0",
":",
"index",
"=",
"index",
"+",
"len",
"(",
"self",
")",
"self",
".",
"__children",
"=",
"self",
".",
"__children",
"[",
"0",
":",
"index",
"]",
"+",
"self",
".... | Remove the child at the given index
from the current list of children.
:param int index: the index of the child to be removed | [
"Remove",
"the",
"child",
"at",
"the",
"given",
"index",
"from",
"the",
"current",
"list",
"of",
"children",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/tree.py#L245-L254 |
246,014 | readbeyond/aeneas | aeneas/tree.py | Tree.remove | 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 | def remove(self):
if self.parent is not None:
for i, child in enumerate(self.parent.children):
if id(child) == id(self):
self.parent.remove_child(i)
self.parent = None
break | [
"def",
"remove",
"(",
"self",
")",
":",
"if",
"self",
".",
"parent",
"is",
"not",
"None",
":",
"for",
"i",
",",
"child",
"in",
"enumerate",
"(",
"self",
".",
"parent",
".",
"children",
")",
":",
"if",
"id",
"(",
"child",
")",
"==",
"id",
"(",
"... | 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 | [
"Remove",
"this",
"node",
"from",
"the",
"list",
"of",
"children",
"of",
"its",
"current",
"parent",
"if",
"the",
"current",
"parent",
"is",
"not",
"None",
"otherwise",
"do",
"nothing",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/tree.py#L256-L268 |
246,015 | readbeyond/aeneas | aeneas/tree.py | Tree.remove_children | 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 | def remove_children(self, reset_parent=True):
if reset_parent:
for child in self.children:
child.parent = None
self.__children = [] | [
"def",
"remove_children",
"(",
"self",
",",
"reset_parent",
"=",
"True",
")",
":",
"if",
"reset_parent",
":",
"for",
"child",
"in",
"self",
".",
"children",
":",
"child",
".",
"parent",
"=",
"None",
"self",
".",
"__children",
"=",
"[",
"]"
] | Remove all the children of this node.
:param bool reset_parent: if ``True``, set to ``None`` the parent attribute
of the children | [
"Remove",
"all",
"the",
"children",
"of",
"this",
"node",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/tree.py#L270-L280 |
246,016 | readbeyond/aeneas | aeneas/tree.py | Tree.leaves_not_empty | 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 | def leaves_not_empty(self):
return [n for n in self.dfs if ((n.is_leaf) and (not n.is_empty))] | [
"def",
"leaves_not_empty",
"(",
"self",
")",
":",
"return",
"[",
"n",
"for",
"n",
"in",
"self",
".",
"dfs",
"if",
"(",
"(",
"n",
".",
"is_leaf",
")",
"and",
"(",
"not",
"n",
".",
"is_empty",
")",
")",
"]"
] | 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",
"the",
"list",
"of",
"leaves",
"not",
"empty",
"in",
"the",
"tree",
"rooted",
"at",
"this",
"node",
"in",
"DFS",
"order",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/tree.py#L335-L343 |
246,017 | readbeyond/aeneas | aeneas/tree.py | Tree.height | 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 | def height(self):
return max([n.level for n in self.subtree]) - self.level + 1 | [
"def",
"height",
"(",
"self",
")",
":",
"return",
"max",
"(",
"[",
"n",
".",
"level",
"for",
"n",
"in",
"self",
".",
"subtree",
"]",
")",
"-",
"self",
".",
"level",
"+",
"1"
] | 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 | [
"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",
"si... | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/tree.py#L357-L368 |
246,018 | readbeyond/aeneas | aeneas/tree.py | Tree.levels | 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 | def levels(self):
ret = [[] for i in range(self.height)]
for node in self.subtree:
ret[node.level - self.level].append(node)
return ret | [
"def",
"levels",
"(",
"self",
")",
":",
"ret",
"=",
"[",
"[",
"]",
"for",
"i",
"in",
"range",
"(",
"self",
".",
"height",
")",
"]",
"for",
"node",
"in",
"self",
".",
"subtree",
":",
"ret",
"[",
"node",
".",
"level",
"-",
"self",
".",
"level",
... | 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` | [
"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",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/tree.py#L397-L409 |
246,019 | readbeyond/aeneas | aeneas/tree.py | Tree.level_at_index | 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 | def level_at_index(self, index):
if not isinstance(index, int):
self.log_exc(u"Index is not an integer", None, True, TypeError)
levels = self.levels
if (index < 0) or (index >= len(levels)):
self.log_exc(u"The given level index '%d' is not valid" % (index), None, True, Va... | [
"def",
"level_at_index",
"(",
"self",
",",
"index",
")",
":",
"if",
"not",
"isinstance",
"(",
"index",
",",
"int",
")",
":",
"self",
".",
"log_exc",
"(",
"u\"Index is not an integer\"",
",",
"None",
",",
"True",
",",
"TypeError",
")",
"levels",
"=",
"sel... | 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 | [
"Return",
"the",
"list",
"of",
"nodes",
"at",
"level",
"index",
"in",
"DFS",
"order",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/tree.py#L425-L440 |
246,020 | readbeyond/aeneas | aeneas/tree.py | Tree.ancestor | 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 | def ancestor(self, index):
if not isinstance(index, int):
self.log_exc(u"index is not an integer", None, True, TypeError)
if index < 0:
self.log_exc(u"index cannot be negative", None, True, ValueError)
parent_node = self
for i in range(index):
if paren... | [
"def",
"ancestor",
"(",
"self",
",",
"index",
")",
":",
"if",
"not",
"isinstance",
"(",
"index",
",",
"int",
")",
":",
"self",
".",
"log_exc",
"(",
"u\"index is not an integer\"",
",",
"None",
",",
"True",
",",
"TypeError",
")",
"if",
"index",
"<",
"0"... | 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 ``index`` is not an int
:raises: ValueErro... | [
"Return",
"the",
"index",
"-",
"th",
"ancestor",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/tree.py#L454-L476 |
246,021 | readbeyond/aeneas | aeneas/tree.py | Tree.keep_levels | 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 | def keep_levels(self, level_indices):
if not isinstance(level_indices, list):
self.log_exc(u"level_indices is not an instance of list", None, True, TypeError)
for l in level_indices:
if not isinstance(l, int):
self.log_exc(u"level_indices contains an element not i... | [
"def",
"keep_levels",
"(",
"self",
",",
"level_indices",
")",
":",
"if",
"not",
"isinstance",
"(",
"level_indices",
",",
"list",
")",
":",
"self",
".",
"log_exc",
"(",
"u\"level_indices is not an instance of list\"",
",",
"None",
",",
"True",
",",
"TypeError",
... | 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 empty list,
only this node will be returned, with ... | [
"Rearrange",
"the",
"tree",
"rooted",
"at",
"this",
"node",
"to",
"keep",
"only",
"the",
"given",
"levels",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/tree.py#L478-L521 |
246,022 | readbeyond/aeneas | thirdparty/mfcc.py | s2dctmat | 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 | def s2dctmat(nfilt,ncep,freqstep):
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'))
melcos[:,0] = melcos[:,0] * 0.5
return melcos | [
"def",
"s2dctmat",
"(",
"nfilt",
",",
"ncep",
",",
"freqstep",
")",
":",
"melcos",
"=",
"numpy",
".",
"empty",
"(",
"(",
"ncep",
",",
"nfilt",
")",
",",
"'double'",
")",
"for",
"i",
"in",
"range",
"(",
"0",
",",
"ncep",
")",
":",
"freq",
"=",
"... | Return the 'legacy' not-quite-DCT matrix used by Sphinx | [
"Return",
"the",
"legacy",
"not",
"-",
"quite",
"-",
"DCT",
"matrix",
"used",
"by",
"Sphinx"
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/thirdparty/mfcc.py#L146-L153 |
246,023 | readbeyond/aeneas | thirdparty/mfcc.py | logspec2s2mfc | 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 | def logspec2s2mfc(logspec, ncep=13):
nframes, nfilt = logspec.shape
melcos = s2dctmat(nfilt, ncep, 1./nfilt)
return numpy.dot(logspec, melcos.T) / nfilt | [
"def",
"logspec2s2mfc",
"(",
"logspec",
",",
"ncep",
"=",
"13",
")",
":",
"nframes",
",",
"nfilt",
"=",
"logspec",
".",
"shape",
"melcos",
"=",
"s2dctmat",
"(",
"nfilt",
",",
"ncep",
",",
"1.",
"/",
"nfilt",
")",
"return",
"numpy",
".",
"dot",
"(",
... | Convert log-power-spectrum bins to MFCC using the 'legacy'
Sphinx transform | [
"Convert",
"log",
"-",
"power",
"-",
"spectrum",
"bins",
"to",
"MFCC",
"using",
"the",
"legacy",
"Sphinx",
"transform"
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/thirdparty/mfcc.py#L155-L160 |
246,024 | readbeyond/aeneas | thirdparty/mfcc.py | dct | 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 | def dct(input, K=13):
nframes, N = input.shape
freqstep = numpy.pi / N
cosmat = dctmat(N,K,freqstep)
return numpy.dot(input, cosmat) * numpy.sqrt(2.0 / N) | [
"def",
"dct",
"(",
"input",
",",
"K",
"=",
"13",
")",
":",
"nframes",
",",
"N",
"=",
"input",
".",
"shape",
"freqstep",
"=",
"numpy",
".",
"pi",
"/",
"N",
"cosmat",
"=",
"dctmat",
"(",
"N",
",",
"K",
",",
"freqstep",
")",
"return",
"numpy",
"."... | Convert log-power-spectrum to MFCC using the orthogonal DCT-II | [
"Convert",
"log",
"-",
"power",
"-",
"spectrum",
"to",
"MFCC",
"using",
"the",
"orthogonal",
"DCT",
"-",
"II"
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/thirdparty/mfcc.py#L174-L179 |
246,025 | readbeyond/aeneas | thirdparty/mfcc.py | dct2 | 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 | def dct2(input, K=13):
nframes, N = input.shape
freqstep = numpy.pi / N
cosmat = dctmat(N,K,freqstep,False)
return numpy.dot(input, cosmat) * (2.0 / N) | [
"def",
"dct2",
"(",
"input",
",",
"K",
"=",
"13",
")",
":",
"nframes",
",",
"N",
"=",
"input",
".",
"shape",
"freqstep",
"=",
"numpy",
".",
"pi",
"/",
"N",
"cosmat",
"=",
"dctmat",
"(",
"N",
",",
"K",
",",
"freqstep",
",",
"False",
")",
"return... | Convert log-power-spectrum to MFCC using the normalized DCT-II | [
"Convert",
"log",
"-",
"power",
"-",
"spectrum",
"to",
"MFCC",
"using",
"the",
"normalized",
"DCT",
"-",
"II"
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/thirdparty/mfcc.py#L181-L186 |
246,026 | readbeyond/aeneas | aeneas/audiofile.py | AudioFile.read_properties | 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 | def read_properties(self):
self.log(u"Reading properties...")
# check the file can be read
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)
# get the file size
self.log([u"Getting file size... | [
"def",
"read_properties",
"(",
"self",
")",
":",
"self",
".",
"log",
"(",
"u\"Reading properties...\"",
")",
"# check the file can be read",
"if",
"not",
"gf",
".",
"file_can_be_read",
"(",
"self",
".",
"file_path",
")",
":",
"self",
".",
"log_exc",
"(",
"u\"F... | 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.AudioFileProbeError`: if the path to the ``ffprob... | [
"Populate",
"this",
"object",
"by",
"reading",
"the",
"audio",
"properties",
"of",
"the",
"file",
"at",
"the",
"given",
"path",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/audiofile.py#L330-L376 |
246,027 | readbeyond/aeneas | aeneas/audiofile.py | AudioFile.read_samples_from_file | 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 | def read_samples_from_file(self):
self.log(u"Loading audio data...")
# check the file can be read
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)
# determine if we need to convert the audio file
... | [
"def",
"read_samples_from_file",
"(",
"self",
")",
":",
"self",
".",
"log",
"(",
"u\"Loading audio data...\"",
")",
"# check the file can be read",
"if",
"not",
"gf",
".",
"file_can_be_read",
"(",
"self",
".",
"file_path",
")",
":",
"self",
".",
"log_exc",
"(",
... | 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 will be read from this temporary file,
which will... | [
"Load",
"the",
"audio",
"samples",
"from",
"file",
"into",
"memory",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/audiofile.py#L378-L464 |
246,028 | readbeyond/aeneas | aeneas/audiofile.py | AudioFile.preallocate_memory | 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 | def preallocate_memory(self, capacity):
if capacity < 0:
raise ValueError(u"The capacity value cannot be negative")
if self.__samples is None:
self.log(u"Not initialized")
self.__samples = numpy.zeros(capacity)
self.__samples_length = 0
else:
... | [
"def",
"preallocate_memory",
"(",
"self",
",",
"capacity",
")",
":",
"if",
"capacity",
"<",
"0",
":",
"raise",
"ValueError",
"(",
"u\"The capacity value cannot be negative\"",
")",
"if",
"self",
".",
"__samples",
"is",
"None",
":",
"self",
".",
"log",
"(",
"... | 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`` zeros.
If ``capacity`` is larger than the current ca... | [
"Preallocate",
"memory",
"to",
"store",
"audio",
"samples",
"to",
"avoid",
"repeated",
"new",
"allocations",
"and",
"copies",
"while",
"performing",
"several",
"consecutive",
"append",
"operations",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/audiofile.py#L466-L499 |
246,029 | readbeyond/aeneas | aeneas/audiofile.py | AudioFile.minimize_memory | 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 | def minimize_memory(self):
if self.__samples is None:
self.log(u"Not initialized, returning")
else:
self.log(u"Initialized, minimizing memory...")
self.preallocate_memory(self.__samples_length)
self.log(u"Initialized, minimizing memory... done") | [
"def",
"minimize_memory",
"(",
"self",
")",
":",
"if",
"self",
".",
"__samples",
"is",
"None",
":",
"self",
".",
"log",
"(",
"u\"Not initialized, returning\"",
")",
"else",
":",
"self",
".",
"log",
"(",
"u\"Initialized, minimizing 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 | [
"Reduce",
"the",
"allocated",
"memory",
"to",
"the",
"minimum",
"required",
"to",
"store",
"the",
"current",
"audio",
"samples",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/audiofile.py#L501-L517 |
246,030 | readbeyond/aeneas | aeneas/audiofile.py | AudioFile.add_samples | 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 | def add_samples(self, samples, reverse=False):
self.log(u"Adding samples...")
samples_length = len(samples)
current_length = self.__samples_length
future_length = current_length + samples_length
if (self.__samples is None) or (self.__samples_capacity < future_length):
... | [
"def",
"add_samples",
"(",
"self",
",",
"samples",
",",
"reverse",
"=",
"False",
")",
":",
"self",
".",
"log",
"(",
"u\"Adding samples...\"",
")",
"samples_length",
"=",
"len",
"(",
"samples",
")",
"current_length",
"=",
"self",
".",
"__samples_length",
"fut... | 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.
:param samples: the new samples to be concatenated
... | [
"Concatenate",
"the",
"given",
"new",
"samples",
"to",
"the",
"current",
"audio",
"data",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/audiofile.py#L519-L547 |
246,031 | readbeyond/aeneas | aeneas/audiofile.py | AudioFile.reverse | 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 | def reverse(self):
if self.__samples is None:
if self.file_path is None:
self.log_exc(u"AudioFile object not initialized", None, True, AudioFileNotInitializedError)
else:
self.read_samples_from_file()
self.log(u"Reversing...")
self.__sample... | [
"def",
"reverse",
"(",
"self",
")",
":",
"if",
"self",
".",
"__samples",
"is",
"None",
":",
"if",
"self",
".",
"file_path",
"is",
"None",
":",
"self",
".",
"log_exc",
"(",
"u\"AudioFile object not initialized\"",
",",
"None",
",",
"True",
",",
"AudioFileNo... | Reverse the audio data.
:raises: :class:`~aeneas.audiofile.AudioFileNotInitializedError`: if the audio file is not initialized yet
.. versionadded:: 1.2.0 | [
"Reverse",
"the",
"audio",
"data",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/audiofile.py#L549-L564 |
246,032 | readbeyond/aeneas | aeneas/audiofile.py | AudioFile.trim | 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 | def trim(self, begin=None, length=None):
for variable, name in [(begin, "begin"), (length, "length")]:
if (variable is not None) and (not isinstance(variable, TimeValue)):
raise TypeError(u"%s is not None or TimeValue" % name)
self.log(u"Trimming...")
if (begin is Non... | [
"def",
"trim",
"(",
"self",
",",
"begin",
"=",
"None",
",",
"length",
"=",
"None",
")",
":",
"for",
"variable",
",",
"name",
"in",
"[",
"(",
"begin",
",",
"\"begin\"",
")",
",",
"(",
"length",
",",
"\"length\"",
")",
"]",
":",
"if",
"(",
"variabl... | 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.exacttiming.TimeValue`
:param length: the position, in secon... | [
"Get",
"a",
"slice",
"of",
"the",
"audio",
"data",
"of",
"length",
"seconds",
"starting",
"from",
"begin",
"seconds",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/audiofile.py#L566-L605 |
246,033 | readbeyond/aeneas | aeneas/audiofile.py | AudioFile.write | 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 | def write(self, file_path):
if self.__samples is None:
if self.file_path is None:
self.log_exc(u"AudioFile object not initialized", None, True, AudioFileNotInitializedError)
else:
self.read_samples_from_file()
self.log([u"Writing audio file '%s'...... | [
"def",
"write",
"(",
"self",
",",
"file_path",
")",
":",
"if",
"self",
".",
"__samples",
"is",
"None",
":",
"if",
"self",
".",
"file_path",
"is",
"None",
":",
"self",
".",
"log_exc",
"(",
"u\"AudioFile object not initialized\"",
",",
"None",
",",
"True",
... | 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 initialized yet
.. versionadded:: 1.2.0 | [
"Write",
"the",
"audio",
"data",
"to",
"file",
".",
"Return",
"True",
"on",
"success",
"or",
"False",
"otherwise",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/audiofile.py#L607-L630 |
246,034 | readbeyond/aeneas | aeneas/audiofile.py | AudioFile.clear_data | 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 | def clear_data(self):
self.log(u"Clear audio_data")
self.__samples_capacity = 0
self.__samples_length = 0
self.__samples = None | [
"def",
"clear_data",
"(",
"self",
")",
":",
"self",
".",
"log",
"(",
"u\"Clear audio_data\"",
")",
"self",
".",
"__samples_capacity",
"=",
"0",
"self",
".",
"__samples_length",
"=",
"0",
"self",
".",
"__samples",
"=",
"None"
] | Clear the audio data, freeing memory. | [
"Clear",
"the",
"audio",
"data",
"freeing",
"memory",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/audiofile.py#L632-L639 |
246,035 | readbeyond/aeneas | aeneas/audiofile.py | AudioFile._update_length | 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 | def _update_length(self):
if (self.audio_sample_rate is not None) and (self.__samples is not None):
# NOTE computing TimeValue (... / ...) yields wrong results,
# see issue #168
# self.audio_length = TimeValue(self.__samples_length / self.audio_sample_rate)
... | [
"def",
"_update_length",
"(",
"self",
")",
":",
"if",
"(",
"self",
".",
"audio_sample_rate",
"is",
"not",
"None",
")",
"and",
"(",
"self",
".",
"__samples",
"is",
"not",
"None",
")",
":",
"# NOTE computing TimeValue (... / ...) yields wrong results,",
"# see ... | 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``. | [
"Update",
"the",
"audio",
"length",
"property",
"according",
"to",
"the",
"length",
"of",
"the",
"current",
"audio",
"data",
"and",
"audio",
"sample",
"rate",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/audiofile.py#L641-L653 |
246,036 | readbeyond/aeneas | aeneas/audiofilemfcc.py | AudioFileMFCC.masked_middle_mfcc | 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 | def masked_middle_mfcc(self):
begin, end = self._masked_middle_begin_end()
return (self.masked_mfcc)[:, begin:end] | [
"def",
"masked_middle_mfcc",
"(",
"self",
")",
":",
"begin",
",",
"end",
"=",
"self",
".",
"_masked_middle_begin_end",
"(",
")",
"return",
"(",
"self",
".",
"masked_mfcc",
")",
"[",
":",
",",
"begin",
":",
"end",
"]"
] | Return the MFCC speech frames
in the MIDDLE portion of the wave.
:rtype: :class:`numpy.ndarray` (2D) | [
"Return",
"the",
"MFCC",
"speech",
"frames",
"in",
"the",
"MIDDLE",
"portion",
"of",
"the",
"wave",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/audiofilemfcc.py#L327-L335 |
246,037 | readbeyond/aeneas | aeneas/audiofilemfcc.py | AudioFileMFCC.masked_middle_map | 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 | def masked_middle_map(self):
begin, end = self._masked_middle_begin_end()
return self.__mfcc_mask_map[begin:end] | [
"def",
"masked_middle_map",
"(",
"self",
")",
":",
"begin",
",",
"end",
"=",
"self",
".",
"_masked_middle_begin_end",
"(",
")",
"return",
"self",
".",
"__mfcc_mask_map",
"[",
"begin",
":",
"end",
"]"
] | 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) | [
"Return",
"the",
"map",
"from",
"the",
"MFCC",
"speech",
"frame",
"indices",
"in",
"the",
"MIDDLE",
"portion",
"of",
"the",
"wave",
"to",
"the",
"MFCC",
"FULL",
"frame",
"indices",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/audiofilemfcc.py#L349-L359 |
246,038 | readbeyond/aeneas | aeneas/audiofilemfcc.py | AudioFileMFCC._binary_search_intervals | 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 | def _binary_search_intervals(cls, intervals, index):
start = 0
end = len(intervals) - 1
while start <= end:
middle_index = start + ((end - start) // 2)
middle = intervals[middle_index]
if (middle[0] <= index) and (index < middle[1]):
return mid... | [
"def",
"_binary_search_intervals",
"(",
"cls",
",",
"intervals",
",",
"index",
")",
":",
"start",
"=",
"0",
"end",
"=",
"len",
"(",
"intervals",
")",
"-",
"1",
"while",
"start",
"<=",
"end",
":",
"middle_index",
"=",
"start",
"+",
"(",
"(",
"end",
"-... | Binary search for the interval containing index,
assuming there is such an interval.
This function should never return ``None``. | [
"Binary",
"search",
"for",
"the",
"interval",
"containing",
"index",
"assuming",
"there",
"is",
"such",
"an",
"interval",
".",
"This",
"function",
"should",
"never",
"return",
"None",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/audiofilemfcc.py#L423-L440 |
246,039 | readbeyond/aeneas | aeneas/audiofilemfcc.py | AudioFileMFCC.middle_begin | 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 | def middle_begin(self, index):
if (index < 0) or (index > self.all_length):
raise ValueError(u"The given index is not valid")
self.__middle_begin = index | [
"def",
"middle_begin",
"(",
"self",
",",
"index",
")",
":",
"if",
"(",
"index",
"<",
"0",
")",
"or",
"(",
"index",
">",
"self",
".",
"all_length",
")",
":",
"raise",
"ValueError",
"(",
"u\"The given index is not valid\"",
")",
"self",
".",
"__middle_begin"... | Set the index where MIDDLE starts.
:param int index: the new index for MIDDLE begin | [
"Set",
"the",
"index",
"where",
"MIDDLE",
"starts",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/audiofilemfcc.py#L452-L460 |
246,040 | readbeyond/aeneas | aeneas/audiofilemfcc.py | AudioFileMFCC._compute_mfcc_c_extension | 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 | def _compute_mfcc_c_extension(self):
self.log(u"Computing MFCCs using C extension...")
try:
self.log(u"Importing cmfcc...")
import aeneas.cmfcc.cmfcc
self.log(u"Importing cmfcc... done")
self.__mfcc = (aeneas.cmfcc.cmfcc.compute_from_data(
... | [
"def",
"_compute_mfcc_c_extension",
"(",
"self",
")",
":",
"self",
".",
"log",
"(",
"u\"Computing MFCCs using C extension...\"",
")",
"try",
":",
"self",
".",
"log",
"(",
"u\"Importing cmfcc...\"",
")",
"import",
"aeneas",
".",
"cmfcc",
".",
"cmfcc",
"self",
"."... | Compute MFCCs using the Python C extension cmfcc. | [
"Compute",
"MFCCs",
"using",
"the",
"Python",
"C",
"extension",
"cmfcc",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/audiofilemfcc.py#L509-L534 |
246,041 | readbeyond/aeneas | aeneas/audiofilemfcc.py | AudioFileMFCC._compute_mfcc_pure_python | 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 | def _compute_mfcc_pure_python(self):
self.log(u"Computing MFCCs using pure Python code...")
try:
self.__mfcc = MFCC(
rconf=self.rconf,
logger=self.logger
).compute_from_data(
self.audio_file.audio_samples,
self.audio... | [
"def",
"_compute_mfcc_pure_python",
"(",
"self",
")",
":",
"self",
".",
"log",
"(",
"u\"Computing MFCCs using pure Python code...\"",
")",
"try",
":",
"self",
".",
"__mfcc",
"=",
"MFCC",
"(",
"rconf",
"=",
"self",
".",
"rconf",
",",
"logger",
"=",
"self",
".... | Compute MFCCs using the pure Python code. | [
"Compute",
"MFCCs",
"using",
"the",
"pure",
"Python",
"code",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/audiofilemfcc.py#L536-L553 |
246,042 | readbeyond/aeneas | aeneas/audiofilemfcc.py | AudioFileMFCC.reverse | 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 | def reverse(self):
self.log(u"Reversing...")
all_length = self.all_length
self.__mfcc = self.__mfcc[:, ::-1]
tmp = self.__middle_end
self.__middle_end = all_length - self.__middle_begin
self.__middle_begin = all_length - tmp
if self.__mfcc_mask is not None:
... | [
"def",
"reverse",
"(",
"self",
")",
":",
"self",
".",
"log",
"(",
"u\"Reversing...\"",
")",
"all_length",
"=",
"self",
".",
"all_length",
"self",
".",
"__mfcc",
"=",
"self",
".",
"__mfcc",
"[",
":",
",",
":",
":",
"-",
"1",
"]",
"tmp",
"=",
"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. | [
"Reverse",
"the",
"audio",
"file",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/audiofilemfcc.py#L555-L582 |
246,043 | readbeyond/aeneas | aeneas/audiofilemfcc.py | AudioFileMFCC.run_vad | 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 | def run_vad(
self,
log_energy_threshold=None,
min_nonspeech_length=None,
extend_before=None,
extend_after=None
):
def _compute_runs(array):
"""
Compute runs as a list of arrays,
each containing the indices of a contiguous run.
... | [
"def",
"run_vad",
"(",
"self",
",",
"log_energy_threshold",
"=",
"None",
",",
"min_nonspeech_length",
"=",
"None",
",",
"extend_before",
"=",
"None",
",",
"extend_after",
"=",
"None",
")",
":",
"def",
"_compute_runs",
"(",
"array",
")",
":",
"\"\"\"\n ... | Determine which frames contain speech and nonspeech,
and store the resulting boolean mask internally.
The four parameters might be ``None``:
in this case, the corresponding RuntimeConfiguration values
are applied.
:param float log_energy_threshold: the minimum log energy thresh... | [
"Determine",
"which",
"frames",
"contain",
"speech",
"and",
"nonspeech",
"and",
"store",
"the",
"resulting",
"boolean",
"mask",
"internally",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/audiofilemfcc.py#L584-L636 |
246,044 | readbeyond/aeneas | aeneas/audiofilemfcc.py | AudioFileMFCC.set_head_middle_tail | 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 | def set_head_middle_tail(self, head_length=None, middle_length=None, tail_length=None):
for variable, name in [
(head_length, "head_length"),
(middle_length, "middle_length"),
(tail_length, "tail_length")
]:
if (variable is not None) and (not isinstance(va... | [
"def",
"set_head_middle_tail",
"(",
"self",
",",
"head_length",
"=",
"None",
",",
"middle_length",
"=",
"None",
",",
"tail_length",
"=",
"None",
")",
":",
"for",
"variable",
",",
"name",
"in",
"[",
"(",
"head_length",
",",
"\"head_length\"",
")",
",",
"(",... | 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.
:param head_length: the length of HEAD, in seconds
:type head_length: :class:`~aeneas.exa... | [
"Set",
"the",
"HEAD",
"MIDDLE",
"TAIL",
"explicitly",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/audiofilemfcc.py#L638-L676 |
246,045 | readbeyond/aeneas | aeneas/textfile.py | TextFragment.chars | 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 | def chars(self):
if self.lines is None:
return 0
return sum([len(line) for line in self.lines]) | [
"def",
"chars",
"(",
"self",
")",
":",
"if",
"self",
".",
"lines",
"is",
"None",
":",
"return",
"0",
"return",
"sum",
"(",
"[",
"len",
"(",
"line",
")",
"for",
"line",
"in",
"self",
".",
"lines",
"]",
")"
] | Return the number of characters of the text fragment,
not including the line separators.
:rtype: int | [
"Return",
"the",
"number",
"of",
"characters",
"of",
"the",
"text",
"fragment",
"not",
"including",
"the",
"line",
"separators",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/textfile.py#L355-L364 |
246,046 | readbeyond/aeneas | aeneas/textfile.py | TextFile.children_not_empty | 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 | def children_not_empty(self):
children = []
for child_node in self.fragments_tree.children_not_empty:
child_text_file = self.get_subtree(child_node)
child_text_file.set_language(child_node.value.language)
children.append(child_text_file)
return children | [
"def",
"children_not_empty",
"(",
"self",
")",
":",
"children",
"=",
"[",
"]",
"for",
"child_node",
"in",
"self",
".",
"fragments_tree",
".",
"children_not_empty",
":",
"child_text_file",
"=",
"self",
".",
"get_subtree",
"(",
"child_node",
")",
"child_text_file"... | Return the direct not empty children of the root of the fragments tree,
as ``TextFile`` objects.
:rtype: list of :class:`~aeneas.textfile.TextFile` | [
"Return",
"the",
"direct",
"not",
"empty",
"children",
"of",
"the",
"root",
"of",
"the",
"fragments",
"tree",
"as",
"TextFile",
"objects",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/textfile.py#L455-L467 |
246,047 | readbeyond/aeneas | aeneas/textfile.py | TextFile.characters | 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 | def characters(self):
chars = 0
for fragment in self.fragments:
chars += fragment.characters
return chars | [
"def",
"characters",
"(",
"self",
")",
":",
"chars",
"=",
"0",
"for",
"fragment",
"in",
"self",
".",
"fragments",
":",
"chars",
"+=",
"fragment",
".",
"characters",
"return",
"chars"
] | The number of characters in this text file.
:rtype: int | [
"The",
"number",
"of",
"characters",
"in",
"this",
"text",
"file",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/textfile.py#L525-L534 |
246,048 | readbeyond/aeneas | aeneas/textfile.py | TextFile.add_fragment | 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 | def add_fragment(self, fragment, as_last=True):
if not isinstance(fragment, TextFragment):
self.log_exc(u"fragment is not an instance of TextFragment", None, True, TypeError)
self.fragments_tree.add_child(Tree(value=fragment), as_last=as_last) | [
"def",
"add_fragment",
"(",
"self",
",",
"fragment",
",",
"as_last",
"=",
"True",
")",
":",
"if",
"not",
"isinstance",
"(",
"fragment",
",",
"TextFragment",
")",
":",
"self",
".",
"log_exc",
"(",
"u\"fragment is not an instance of TextFragment\"",
",",
"None",
... | 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: if ``True`` append fragment, otherwise prepend it | [
"Add",
"the",
"given",
"text",
"fragment",
"as",
"the",
"first",
"or",
"last",
"child",
"of",
"the",
"root",
"node",
"of",
"the",
"text",
"file",
"tree",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/textfile.py#L547-L558 |
246,049 | readbeyond/aeneas | aeneas/textfile.py | TextFile.set_language | 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 | def set_language(self, language):
self.log([u"Setting language: '%s'", language])
for fragment in self.fragments:
fragment.language = language | [
"def",
"set_language",
"(",
"self",
",",
"language",
")",
":",
"self",
".",
"log",
"(",
"[",
"u\"Setting language: '%s'\"",
",",
"language",
"]",
")",
"for",
"fragment",
"in",
"self",
".",
"fragments",
":",
"fragment",
".",
"language",
"=",
"language"
] | Set the given language for all the text fragments.
:param language: the language of the text fragments
:type language: :class:`~aeneas.language.Language` | [
"Set",
"the",
"given",
"language",
"for",
"all",
"the",
"text",
"fragments",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/textfile.py#L598-L607 |
246,050 | readbeyond/aeneas | aeneas/textfile.py | TextFile._read_from_file | 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 | def _read_from_file(self):
# 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 TextFileFormat.ALLOWED_VALUES:
self.log_exc(u"Text fil... | [
"def",
"_read_from_file",
"(",
"self",
")",
":",
"# 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",
".",
"fi... | Read text fragments from file. | [
"Read",
"text",
"fragments",
"from",
"file",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/textfile.py#L638-L669 |
246,051 | readbeyond/aeneas | aeneas/textfile.py | TextFile._mplain_word_separator | 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 | def _mplain_word_separator(self):
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"):
return u" "
elif word_separator == "equal":
return u"="
elif word_separator... | [
"def",
"_mplain_word_separator",
"(",
"self",
")",
":",
"word_separator",
"=",
"gf",
".",
"safe_get",
"(",
"self",
".",
"parameters",
",",
"gc",
".",
"PPN_TASK_IS_TEXT_MPLAIN_WORD_SEPARATOR",
",",
"u\" \"",
")",
"if",
"(",
"word_separator",
"is",
"None",
")",
... | Get the word separator to split words in mplain format.
:rtype: string | [
"Get",
"the",
"word",
"separator",
"to",
"split",
"words",
"in",
"mplain",
"format",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/textfile.py#L671-L686 |
246,052 | readbeyond/aeneas | aeneas/textfile.py | TextFile._read_mplain | 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 | def _read_mplain(self, lines):
self.log(u"Parsing fragments from subtitles text format")
word_separator = self._mplain_word_separator()
self.log([u"Word separator is: '%s'", word_separator])
lines = [line.strip() for line in lines]
pairs = []
i = 1
current = 0
... | [
"def",
"_read_mplain",
"(",
"self",
",",
"lines",
")",
":",
"self",
".",
"log",
"(",
"u\"Parsing fragments from subtitles text format\"",
")",
"word_separator",
"=",
"self",
".",
"_mplain_word_separator",
"(",
")",
"self",
".",
"log",
"(",
"[",
"u\"Word separator ... | Read text fragments from a multilevel format text file.
:param list lines: the lines of the subtitles text file | [
"Read",
"text",
"fragments",
"from",
"a",
"multilevel",
"format",
"text",
"file",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/textfile.py#L688-L760 |
246,053 | readbeyond/aeneas | aeneas/textfile.py | TextFile._read_subtitles | 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 | def _read_subtitles(self, lines):
self.log(u"Parsing fragments from subtitles text format")
id_format = self._get_id_format()
lines = [line.strip() for line in lines]
pairs = []
i = 1
current = 0
while current < len(lines):
line_text = lines[current]
... | [
"def",
"_read_subtitles",
"(",
"self",
",",
"lines",
")",
":",
"self",
".",
"log",
"(",
"u\"Parsing fragments from subtitles text format\"",
")",
"id_format",
"=",
"self",
".",
"_get_id_format",
"(",
")",
"lines",
"=",
"[",
"line",
".",
"strip",
"(",
")",
"f... | 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 | [
"Read",
"text",
"fragments",
"from",
"a",
"subtitles",
"format",
"text",
"file",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/textfile.py#L851-L877 |
246,054 | readbeyond/aeneas | aeneas/textfile.py | TextFile._read_parsed | 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 | def _read_parsed(self, lines):
self.log(u"Parsing fragments from parsed text format")
pairs = []
for line in lines:
pieces = line.split(gc.PARSED_TEXT_SEPARATOR)
if len(pieces) == 2:
identifier = pieces[0].strip()
text = pieces[1].strip()
... | [
"def",
"_read_parsed",
"(",
"self",
",",
"lines",
")",
":",
"self",
".",
"log",
"(",
"u\"Parsing fragments from parsed text format\"",
")",
"pairs",
"=",
"[",
"]",
"for",
"line",
"in",
"lines",
":",
"pieces",
"=",
"line",
".",
"split",
"(",
"gc",
".",
"P... | 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) | [
"Read",
"text",
"fragments",
"from",
"a",
"parsed",
"format",
"text",
"file",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/textfile.py#L879-L896 |
246,055 | readbeyond/aeneas | aeneas/textfile.py | TextFile._read_plain | 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 | def _read_plain(self, lines):
self.log(u"Parsing fragments from plain text format")
id_format = self._get_id_format()
lines = [line.strip() for line in lines]
pairs = []
i = 1
for line in lines:
identifier = id_format % i
text = line.strip()
... | [
"def",
"_read_plain",
"(",
"self",
",",
"lines",
")",
":",
"self",
".",
"log",
"(",
"u\"Parsing fragments from plain text format\"",
")",
"id_format",
"=",
"self",
".",
"_get_id_format",
"(",
")",
"lines",
"=",
"[",
"line",
".",
"strip",
"(",
")",
"for",
"... | 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: if the id regex is not valid | [
"Read",
"text",
"fragments",
"from",
"a",
"plain",
"format",
"text",
"file",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/textfile.py#L898-L917 |
246,056 | readbeyond/aeneas | aeneas/textfile.py | TextFile._read_unparsed | 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 | def _read_unparsed(self, lines):
from bs4 import BeautifulSoup
def filter_attributes():
""" Return a dict with the bs4 filter parameters """
attributes = {}
for attribute_name, filter_name in [
("class", gc.PPN_TASK_IS_TEXT_UNPARSED_CLASS_REGEX),
... | [
"def",
"_read_unparsed",
"(",
"self",
",",
"lines",
")",
":",
"from",
"bs4",
"import",
"BeautifulSoup",
"def",
"filter_attributes",
"(",
")",
":",
"\"\"\" Return a dict with the bs4 filter parameters \"\"\"",
"attributes",
"=",
"{",
"}",
"for",
"attribute_name",
",",
... | Read text fragments from an unparsed format text file.
:param list lines: the lines of the unparsed text file | [
"Read",
"text",
"fragments",
"from",
"an",
"unparsed",
"format",
"text",
"file",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/textfile.py#L919-L978 |
246,057 | readbeyond/aeneas | aeneas/textfile.py | TextFile._get_id_format | 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 | def _get_id_format(self):
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
except (TypeError, ValueError) as exc:
... | [
"def",
"_get_id_format",
"(",
"self",
")",
":",
"id_format",
"=",
"gf",
".",
"safe_get",
"(",
"self",
".",
"parameters",
",",
"gc",
".",
"PPN_TASK_OS_FILE_ID_REGEX",
",",
"self",
".",
"DEFAULT_ID_FORMAT",
",",
"can_return_none",
"=",
"False",
")",
"try",
":"... | Return the id regex from the parameters | [
"Return",
"the",
"id",
"regex",
"from",
"the",
"parameters"
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/textfile.py#L980-L992 |
246,058 | readbeyond/aeneas | aeneas/textfile.py | TextFile._create_text_fragments | 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 | def _create_text_fragments(self, pairs):
self.log(u"Creating TextFragment objects")
text_filter = self._build_text_filter()
for pair in pairs:
self.add_fragment(
TextFragment(
identifier=pair[0],
lines=pair[1],
... | [
"def",
"_create_text_fragments",
"(",
"self",
",",
"pairs",
")",
":",
"self",
".",
"log",
"(",
"u\"Creating TextFragment objects\"",
")",
"text_filter",
"=",
"self",
".",
"_build_text_filter",
"(",
")",
"for",
"pair",
"in",
"pairs",
":",
"self",
".",
"add_frag... | 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]) | [
"Create",
"text",
"fragment",
"objects",
"and",
"append",
"them",
"to",
"this",
"list",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/textfile.py#L994-L1009 |
246,059 | readbeyond/aeneas | aeneas/textfile.py | TextFile._build_text_filter | 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 | def _build_text_filter(self):
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,
TextFilterIgnoreRegex,
"regex"
... | [
"def",
"_build_text_filter",
"(",
"self",
")",
":",
"text_filter",
"=",
"TextFilter",
"(",
"logger",
"=",
"self",
".",
"logger",
")",
"self",
".",
"log",
"(",
"u\"Created TextFilter object\"",
")",
"for",
"key",
",",
"cls",
",",
"param_name",
"in",
"[",
"(... | Build a suitable TextFilter object. | [
"Build",
"a",
"suitable",
"TextFilter",
"object",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/textfile.py#L1011-L1043 |
246,060 | readbeyond/aeneas | aeneas/textfile.py | TextFilter.add_filter | 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 | def add_filter(self, new_filter, as_last=True):
if as_last:
self.filters.append(new_filter)
else:
self.filters = [new_filter] + self.filters | [
"def",
"add_filter",
"(",
"self",
",",
"new_filter",
",",
"as_last",
"=",
"True",
")",
":",
"if",
"as_last",
":",
"self",
".",
"filters",
".",
"append",
"(",
"new_filter",
")",
"else",
":",
"self",
".",
"filters",
"=",
"[",
"new_filter",
"]",
"+",
"s... | 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 the left | [
"Compose",
"this",
"filter",
"with",
"the",
"given",
"new_filter",
"filter",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/textfile.py#L1071-L1082 |
246,061 | readbeyond/aeneas | aeneas/textfile.py | TextFilter.apply_filter | 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 | def apply_filter(self, strings):
result = strings
for filt in self.filters:
result = filt.apply_filter(result)
self.log([u"Applying regex: '%s' => '%s'", strings, result])
return result | [
"def",
"apply_filter",
"(",
"self",
",",
"strings",
")",
":",
"result",
"=",
"strings",
"for",
"filt",
"in",
"self",
".",
"filters",
":",
"result",
"=",
"filt",
".",
"apply_filter",
"(",
"result",
")",
"self",
".",
"log",
"(",
"[",
"u\"Applying regex: '%... | Apply the text filter filter to the given list of strings.
:param list strings: the list of input strings | [
"Apply",
"the",
"text",
"filter",
"filter",
"to",
"the",
"given",
"list",
"of",
"strings",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/textfile.py#L1084-L1094 |
246,062 | readbeyond/aeneas | aeneas/textfile.py | TransliterationMap._build_map | 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 | def _build_map(self):
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, "r", encoding="utf-8") as file_obj:
contents =... | [
"def",
"_build_map",
"(",
"self",
")",
":",
"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"... | Read the map file at path. | [
"Read",
"the",
"map",
"file",
"at",
"path",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/textfile.py#L1241-L1255 |
246,063 | readbeyond/aeneas | aeneas/textfile.py | TransliterationMap._process_map_rule | 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 | def _process_map_rule(self, line):
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(2))
for char in what:
self.trans_map[char] = repla... | [
"def",
"_process_map_rule",
"(",
"self",
",",
"line",
")",
":",
"result",
"=",
"self",
".",
"REPLACE_REGEX",
".",
"match",
"(",
"line",
")",
"if",
"result",
"is",
"not",
"None",
":",
"what",
"=",
"self",
".",
"_process_first_group",
"(",
"result",
".",
... | Process the line string containing a map rule. | [
"Process",
"the",
"line",
"string",
"containing",
"a",
"map",
"rule",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/textfile.py#L1257-L1274 |
246,064 | readbeyond/aeneas | aeneas/textfile.py | TransliterationMap._process_first_group | 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 | def _process_first_group(self, group):
if "-" in group:
# range
if len(group.split("-")) == 2:
arr = group.split("-")
start = self._parse_codepoint(arr[0])
end = self._parse_codepoint(arr[1])
else:
# single char/U+xxxx
... | [
"def",
"_process_first_group",
"(",
"self",
",",
"group",
")",
":",
"if",
"\"-\"",
"in",
"group",
":",
"# range",
"if",
"len",
"(",
"group",
".",
"split",
"(",
"\"-\"",
")",
")",
"==",
"2",
":",
"arr",
"=",
"group",
".",
"split",
"(",
"\"-\"",
")",... | Process the first group of a rule. | [
"Process",
"the",
"first",
"group",
"of",
"a",
"rule",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/textfile.py#L1276-L1294 |
246,065 | readbeyond/aeneas | aeneas/executejob.py | ExecuteJob.load_job | 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 | def load_job(self, job):
if not isinstance(job, Job):
self.log_exc(u"job is not an instance of Job", None, True, ExecuteJobInputError)
self.job = job | [
"def",
"load_job",
"(",
"self",
",",
"job",
")",
":",
"if",
"not",
"isinstance",
"(",
"job",
",",
"Job",
")",
":",
"self",
".",
"log_exc",
"(",
"u\"job is not an instance of Job\"",
",",
"None",
",",
"True",
",",
"ExecuteJobInputError",
")",
"self",
".",
... | 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` | [
"Load",
"the",
"job",
"from",
"the",
"given",
"Job",
"object",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/executejob.py#L110-L120 |
246,066 | readbeyond/aeneas | aeneas/executejob.py | ExecuteJob.execute | 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 | def execute(self):
self.log(u"Executing job")
if self.job is None:
self.log_exc(u"The job object is None", None, True, ExecuteJobExecutionError)
if len(self.job) == 0:
self.log_exc(u"The job has no tasks", None, True, ExecuteJobExecutionError)
job_max_tasks = sel... | [
"def",
"execute",
"(",
"self",
")",
":",
"self",
".",
"log",
"(",
"u\"Executing job\"",
")",
"if",
"self",
".",
"job",
"is",
"None",
":",
"self",
".",
"log_exc",
"(",
"u\"The job object is None\"",
",",
"None",
",",
"True",
",",
"ExecuteJobExecutionError",
... | 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 | [
"Execute",
"the",
"job",
"that",
"is",
"execute",
"all",
"of",
"its",
"tasks",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/executejob.py#L187-L218 |
246,067 | readbeyond/aeneas | aeneas/executejob.py | ExecuteJob.write_output_container | 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 | def write_output_container(self, output_directory_path):
self.log(u"Writing output container for this job")
if self.job is None:
self.log_exc(u"The job object is None", None, True, ExecuteJobOutputError)
if len(self.job) == 0:
self.log_exc(u"The job has no tasks", None, ... | [
"def",
"write_output_container",
"(",
"self",
",",
"output_directory_path",
")",
":",
"self",
".",
"log",
"(",
"u\"Writing output container for this job\"",
")",
"if",
"self",
".",
"job",
"is",
"None",
":",
"self",
".",
"log_exc",
"(",
"u\"The job object is None\"",... | 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_directory_path: the path to a directory where
... | [
"Write",
"the",
"output",
"container",
"for",
"this",
"job",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/executejob.py#L220-L296 |
246,068 | readbeyond/aeneas | aeneas/executejob.py | ExecuteJob.clean | 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 | def clean(self, remove_working_directory=True):
if remove_working_directory is not None:
self.log(u"Removing working directory... ")
gf.delete_directory(self.working_directory)
self.working_directory = None
self.log(u"Removing working directory... done")
s... | [
"def",
"clean",
"(",
"self",
",",
"remove_working_directory",
"=",
"True",
")",
":",
"if",
"remove_working_directory",
"is",
"not",
"None",
":",
"self",
".",
"log",
"(",
"u\"Removing working directory... \"",
")",
"gf",
".",
"delete_directory",
"(",
"self",
".",... | 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
the working directory ... | [
"Remove",
"the",
"temporary",
"directory",
".",
"If",
"remove_working_directory",
"is",
"True",
"remove",
"the",
"working",
"directory",
"as",
"well",
"otherwise",
"just",
"remove",
"the",
"temporary",
"directory",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/executejob.py#L298-L316 |
246,069 | readbeyond/aeneas | aeneas/tools/plot_waveform.py | PlotWaveformCLI._read_syncmap_file | 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 | def _read_syncmap_file(self, path, extension, text=False):
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.fragments]
return [(f.begin, f.end, f.text_frag... | [
"def",
"_read_syncmap_file",
"(",
"self",
",",
"path",
",",
"extension",
",",
"text",
"=",
"False",
")",
":",
"syncmap",
"=",
"SyncMap",
"(",
"logger",
"=",
"self",
".",
"logger",
")",
"syncmap",
".",
"read",
"(",
"extension",
",",
"path",
",",
"parame... | Read labels from a SyncMap file | [
"Read",
"labels",
"from",
"a",
"SyncMap",
"file"
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/tools/plot_waveform.py#L156-L162 |
246,070 | readbeyond/aeneas | aeneas/syncmap/__init__.py | SyncMap.has_adjacent_leaves_only | 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 | def has_adjacent_leaves_only(self):
leaves = self.leaves()
for i in range(len(leaves) - 1):
current_interval = leaves[i].interval
next_interval = leaves[i + 1].interval
if not current_interval.is_adjacent_before(next_interval):
return False
ret... | [
"def",
"has_adjacent_leaves_only",
"(",
"self",
")",
":",
"leaves",
"=",
"self",
".",
"leaves",
"(",
")",
"for",
"i",
"in",
"range",
"(",
"len",
"(",
"leaves",
")",
"-",
"1",
")",
":",
"current_interval",
"=",
"leaves",
"[",
"i",
"]",
".",
"interval"... | 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 | [
"Return",
"True",
"if",
"the",
"sync",
"map",
"fragments",
"which",
"are",
"the",
"leaves",
"of",
"the",
"sync",
"map",
"tree",
"are",
"all",
"adjacent",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/syncmap/__init__.py#L169-L185 |
246,071 | readbeyond/aeneas | aeneas/syncmap/__init__.py | SyncMap.json_string | 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 | def json_string(self):
def visit_children(node):
""" Recursively visit the fragments_tree """
output_fragments = []
for child in node.children_not_empty:
fragment = child.value
text = fragment.text_fragment
output_fragments.appe... | [
"def",
"json_string",
"(",
"self",
")",
":",
"def",
"visit_children",
"(",
"node",
")",
":",
"\"\"\" Recursively visit the fragments_tree \"\"\"",
"output_fragments",
"=",
"[",
"]",
"for",
"child",
"in",
"node",
".",
"children_not_empty",
":",
"fragment",
"=",
"ch... | Return a JSON representation of the sync map.
:rtype: string
.. versionadded:: 1.3.1 | [
"Return",
"a",
"JSON",
"representation",
"of",
"the",
"sync",
"map",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/syncmap/__init__.py#L248-L274 |
246,072 | readbeyond/aeneas | aeneas/syncmap/__init__.py | SyncMap.add_fragment | 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 | def add_fragment(self, fragment, as_last=True):
if not isinstance(fragment, SyncMapFragment):
self.log_exc(u"fragment is not an instance of SyncMapFragment", None, True, TypeError)
self.fragments_tree.add_child(Tree(value=fragment), as_last=as_last) | [
"def",
"add_fragment",
"(",
"self",
",",
"fragment",
",",
"as_last",
"=",
"True",
")",
":",
"if",
"not",
"isinstance",
"(",
"fragment",
",",
"SyncMapFragment",
")",
":",
"self",
".",
"log_exc",
"(",
"u\"fragment is not an instance of SyncMapFragment\"",
",",
"No... | 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`
:param bool as_last: if ``True``, append fragment; otherwise p... | [
"Add",
"the",
"given",
"sync",
"map",
"fragment",
"as",
"the",
"first",
"or",
"last",
"child",
"of",
"the",
"root",
"node",
"of",
"the",
"sync",
"map",
"tree",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/syncmap/__init__.py#L276-L290 |
246,073 | readbeyond/aeneas | aeneas/syncmap/__init__.py | SyncMap.output_html_for_tuning | 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 | def output_html_for_tuning(
self,
audio_file_path,
output_file_path,
parameters=None
):
if not gf.file_can_be_written(output_file_path):
self.log_exc(u"Cannot output HTML file '%s'. Wrong permissions?" % (output_file_path), None, True, OSError)
... | [
"def",
"output_html_for_tuning",
"(",
"self",
",",
"audio_file_path",
",",
"output_file_path",
",",
"parameters",
"=",
"None",
")",
":",
"if",
"not",
"gf",
".",
"file_can_be_written",
"(",
"output_file_path",
")",
":",
"self",
".",
"log_exc",
"(",
"u\"Cannot out... | 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 output_file_path: the path to the output file to write
:param dict parameters: additional parameters
.. versionadded:: 1.3.1 | [
"Output",
"an",
"HTML",
"file",
"for",
"fine",
"tuning",
"the",
"sync",
"map",
"manually",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/syncmap/__init__.py#L309-L368 |
246,074 | readbeyond/aeneas | aeneas/mfcc.py | MFCC._create_dct_matrix | 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 | def _create_dct_matrix(self):
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.filter_bank_size
self.s2dct[i] = numpy.cos(freq * numpy.arange(0.5, 0.5 + self.filter_bank_size, 1.0, 'float64'))
... | [
"def",
"_create_dct_matrix",
"(",
"self",
")",
":",
"self",
".",
"s2dct",
"=",
"numpy",
".",
"zeros",
"(",
"(",
"self",
".",
"mfcc_size",
",",
"self",
".",
"filter_bank_size",
")",
")",
"for",
"i",
"in",
"range",
"(",
"0",
",",
"self",
".",
"mfcc_siz... | Create the not-quite-DCT matrix as used by Sphinx,
and store it in ```self.s2dct```. | [
"Create",
"the",
"not",
"-",
"quite",
"-",
"DCT",
"matrix",
"as",
"used",
"by",
"Sphinx",
"and",
"store",
"it",
"in",
"self",
".",
"s2dct",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/mfcc.py#L104-L114 |
246,075 | readbeyond/aeneas | aeneas/mfcc.py | MFCC._create_mel_filter_bank | 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 | def _create_mel_filter_bank(self):
self.filters = numpy.zeros((1 + (self.fft_order // 2), self.filter_bank_size), 'd')
dfreq = float(self.sample_rate) / self.fft_order
nyquist_frequency = self.sample_rate / 2
if self.upper_frequency > nyquist_frequency:
self.log_exc(u"Upper f... | [
"def",
"_create_mel_filter_bank",
"(",
"self",
")",
":",
"self",
".",
"filters",
"=",
"numpy",
".",
"zeros",
"(",
"(",
"1",
"+",
"(",
"self",
".",
"fft_order",
"//",
"2",
")",
",",
"self",
".",
"filter_bank_size",
")",
",",
"'d'",
")",
"dfreq",
"=",
... | 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`. | [
"Create",
"the",
"Mel",
"filter",
"bank",
"and",
"store",
"it",
"in",
"self",
".",
"filters",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/mfcc.py#L116-L160 |
246,076 | readbeyond/aeneas | aeneas/mfcc.py | MFCC._pre_emphasis | def _pre_emphasis(self):
"""
Pre-emphasize the entire signal at once by self.emphasis_factor,
overwriting ``self.data``.
"""
self.data = numpy.append(self.data[0], self.data[1:] - self.emphasis_factor * self.data[:-1]) | python | def _pre_emphasis(self):
self.data = numpy.append(self.data[0], self.data[1:] - self.emphasis_factor * self.data[:-1]) | [
"def",
"_pre_emphasis",
"(",
"self",
")",
":",
"self",
".",
"data",
"=",
"numpy",
".",
"append",
"(",
"self",
".",
"data",
"[",
"0",
"]",
",",
"self",
".",
"data",
"[",
"1",
":",
"]",
"-",
"self",
".",
"emphasis_factor",
"*",
"self",
".",
"data",... | Pre-emphasize the entire signal at once by self.emphasis_factor,
overwriting ``self.data``. | [
"Pre",
"-",
"emphasize",
"the",
"entire",
"signal",
"at",
"once",
"by",
"self",
".",
"emphasis_factor",
"overwriting",
"self",
".",
"data",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/mfcc.py#L162-L167 |
246,077 | readbeyond/aeneas | aeneas/mfcc.py | MFCC.compute_from_data | def compute_from_data(self, data, sample_rate):
"""
Compute MFCCs for the given audio data.
The audio data must be a 1D :class:`numpy.ndarray`,
that is, it must represent a monoaural (single channel)
array of ``float64`` values in ``[-1.0, 1.0]``.
:param data: the audio... | python | def compute_from_data(self, data, sample_rate):
def _process_frame(self, frame):
"""
Process each frame, returning the log(power()) of it.
"""
# apply Hamming window
frame *= self.hamming_window
# compute RFFT
fft = numpy.fft.rf... | [
"def",
"compute_from_data",
"(",
"self",
",",
"data",
",",
"sample_rate",
")",
":",
"def",
"_process_frame",
"(",
"self",
",",
"frame",
")",
":",
"\"\"\"\n Process each frame, returning the log(power()) of it.\n \"\"\"",
"# apply Hamming window",
"frame"... | Compute MFCCs for the given audio data.
The audio data must be a 1D :class:`numpy.ndarray`,
that is, it must represent a monoaural (single channel)
array of ``float64`` values in ``[-1.0, 1.0]``.
:param data: the audio data
:type data: :class:`numpy.ndarray` (1D)
:para... | [
"Compute",
"MFCCs",
"for",
"the",
"given",
"audio",
"data",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/mfcc.py#L169-L265 |
246,078 | readbeyond/aeneas | aeneas/wavfile.py | write | def write(filename, rate, data):
"""
Write a numpy array as a WAV file
Parameters
----------
filename : string or open file handle
Output wav file
rate : int
The sample rate (in samples/sec).
data : ndarray
A 1-D or 2-D numpy array of either integer or float data-typ... | python | def write(filename, rate, data):
if hasattr(filename, 'write'):
fid = filename
else:
fid = open(filename, 'wb')
try:
dkind = data.dtype.kind
if not (dkind == 'i' or dkind == 'f' or (dkind == 'u' and
data.dtype.itemsize == 1)):... | [
"def",
"write",
"(",
"filename",
",",
"rate",
",",
"data",
")",
":",
"if",
"hasattr",
"(",
"filename",
",",
"'write'",
")",
":",
"fid",
"=",
"filename",
"else",
":",
"fid",
"=",
"open",
"(",
"filename",
",",
"'wb'",
")",
"try",
":",
"dkind",
"=",
... | Write a numpy array as a WAV file
Parameters
----------
filename : string or open file handle
Output wav file
rate : int
The sample rate (in samples/sec).
data : ndarray
A 1-D or 2-D numpy array of either integer or float data-type.
Notes
-----
* The file can be... | [
"Write",
"a",
"numpy",
"array",
"as",
"a",
"WAV",
"file"
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/wavfile.py#L200-L270 |
246,079 | readbeyond/aeneas | aeneas/globalfunctions.py | safe_print | def safe_print(msg):
"""
Safely print a given Unicode string to stdout,
possibly replacing characters non-printable
in the current stdout encoding.
:param string msg: the message
"""
try:
print(msg)
except UnicodeEncodeError:
try:
# NOTE encoding and decoding... | python | def safe_print(msg):
try:
print(msg)
except UnicodeEncodeError:
try:
# NOTE encoding and decoding so that in Python 3 no b"..." is printed
encoded = msg.encode(sys.stdout.encoding, "replace")
decoded = encoded.decode(sys.stdout.encoding, "replace")
... | [
"def",
"safe_print",
"(",
"msg",
")",
":",
"try",
":",
"print",
"(",
"msg",
")",
"except",
"UnicodeEncodeError",
":",
"try",
":",
"# NOTE encoding and decoding so that in Python 3 no b\"...\" is printed",
"encoded",
"=",
"msg",
".",
"encode",
"(",
"sys",
".",
"std... | Safely print a given Unicode string to stdout,
possibly replacing characters non-printable
in the current stdout encoding.
:param string msg: the message | [
"Safely",
"print",
"a",
"given",
"Unicode",
"string",
"to",
"stdout",
"possibly",
"replacing",
"characters",
"non",
"-",
"printable",
"in",
"the",
"current",
"stdout",
"encoding",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/globalfunctions.py#L65-L84 |
246,080 | readbeyond/aeneas | aeneas/globalfunctions.py | print_error | def print_error(msg, color=True):
"""
Print an error message.
:param string msg: the message
:param bool color: if ``True``, print with POSIX color
"""
if color and is_posix():
safe_print(u"%s[ERRO] %s%s" % (ANSI_ERROR, msg, ANSI_END))
else:
safe_print(u"[ERRO] %s" % (msg)) | python | def print_error(msg, color=True):
if color and is_posix():
safe_print(u"%s[ERRO] %s%s" % (ANSI_ERROR, msg, ANSI_END))
else:
safe_print(u"[ERRO] %s" % (msg)) | [
"def",
"print_error",
"(",
"msg",
",",
"color",
"=",
"True",
")",
":",
"if",
"color",
"and",
"is_posix",
"(",
")",
":",
"safe_print",
"(",
"u\"%s[ERRO] %s%s\"",
"%",
"(",
"ANSI_ERROR",
",",
"msg",
",",
"ANSI_END",
")",
")",
"else",
":",
"safe_print",
"... | Print an error message.
:param string msg: the message
:param bool color: if ``True``, print with POSIX color | [
"Print",
"an",
"error",
"message",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/globalfunctions.py#L87-L97 |
246,081 | readbeyond/aeneas | aeneas/globalfunctions.py | print_success | def print_success(msg, color=True):
"""
Print a success message.
:param string msg: the message
:param bool color: if ``True``, print with POSIX color
"""
if color and is_posix():
safe_print(u"%s[INFO] %s%s" % (ANSI_OK, msg, ANSI_END))
else:
safe_print(u"[INFO] %s" % (msg)) | python | def print_success(msg, color=True):
if color and is_posix():
safe_print(u"%s[INFO] %s%s" % (ANSI_OK, msg, ANSI_END))
else:
safe_print(u"[INFO] %s" % (msg)) | [
"def",
"print_success",
"(",
"msg",
",",
"color",
"=",
"True",
")",
":",
"if",
"color",
"and",
"is_posix",
"(",
")",
":",
"safe_print",
"(",
"u\"%s[INFO] %s%s\"",
"%",
"(",
"ANSI_OK",
",",
"msg",
",",
"ANSI_END",
")",
")",
"else",
":",
"safe_print",
"(... | Print a success message.
:param string msg: the message
:param bool color: if ``True``, print with POSIX color | [
"Print",
"a",
"success",
"message",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/globalfunctions.py#L110-L120 |
246,082 | readbeyond/aeneas | aeneas/globalfunctions.py | print_warning | def print_warning(msg, color=True):
"""
Print a warning message.
:param string msg: the message
:param bool color: if ``True``, print with POSIX color
"""
if color and is_posix():
safe_print(u"%s[WARN] %s%s" % (ANSI_WARNING, msg, ANSI_END))
else:
safe_print(u"[WARN] %s" % (m... | python | def print_warning(msg, color=True):
if color and is_posix():
safe_print(u"%s[WARN] %s%s" % (ANSI_WARNING, msg, ANSI_END))
else:
safe_print(u"[WARN] %s" % (msg)) | [
"def",
"print_warning",
"(",
"msg",
",",
"color",
"=",
"True",
")",
":",
"if",
"color",
"and",
"is_posix",
"(",
")",
":",
"safe_print",
"(",
"u\"%s[WARN] %s%s\"",
"%",
"(",
"ANSI_WARNING",
",",
"msg",
",",
"ANSI_END",
")",
")",
"else",
":",
"safe_print",... | Print a warning message.
:param string msg: the message
:param bool color: if ``True``, print with POSIX color | [
"Print",
"a",
"warning",
"message",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/globalfunctions.py#L123-L133 |
246,083 | readbeyond/aeneas | aeneas/globalfunctions.py | file_extension | def file_extension(path):
"""
Return the file extension.
Examples: ::
/foo/bar.baz => baz
None => None
:param string path: the file path
:rtype: string
"""
if path is None:
return None
ext = os.path.splitext(os.path.basename(path))[1]
if ext.startsw... | python | def file_extension(path):
if path is None:
return None
ext = os.path.splitext(os.path.basename(path))[1]
if ext.startswith("."):
ext = ext[1:]
return ext | [
"def",
"file_extension",
"(",
"path",
")",
":",
"if",
"path",
"is",
"None",
":",
"return",
"None",
"ext",
"=",
"os",
".",
"path",
".",
"splitext",
"(",
"os",
".",
"path",
".",
"basename",
"(",
"path",
")",
")",
"[",
"1",
"]",
"if",
"ext",
".",
... | Return the file extension.
Examples: ::
/foo/bar.baz => baz
None => None
:param string path: the file path
:rtype: string | [
"Return",
"the",
"file",
"extension",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/globalfunctions.py#L196-L213 |
246,084 | readbeyond/aeneas | aeneas/globalfunctions.py | mimetype_from_path | def mimetype_from_path(path):
"""
Return a mimetype from the file extension.
:param string path: the file path
:rtype: string
"""
extension = file_extension(path)
if extension is not None:
extension = extension.lower()
if extension in gc.MIMETYPE_MAP:
return gc.M... | python | def mimetype_from_path(path):
extension = file_extension(path)
if extension is not None:
extension = extension.lower()
if extension in gc.MIMETYPE_MAP:
return gc.MIMETYPE_MAP[extension]
return None | [
"def",
"mimetype_from_path",
"(",
"path",
")",
":",
"extension",
"=",
"file_extension",
"(",
"path",
")",
"if",
"extension",
"is",
"not",
"None",
":",
"extension",
"=",
"extension",
".",
"lower",
"(",
")",
"if",
"extension",
"in",
"gc",
".",
"MIMETYPE_MAP"... | Return a mimetype from the file extension.
:param string path: the file path
:rtype: string | [
"Return",
"a",
"mimetype",
"from",
"the",
"file",
"extension",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/globalfunctions.py#L216-L228 |
246,085 | readbeyond/aeneas | aeneas/globalfunctions.py | file_name_without_extension | def file_name_without_extension(path):
"""
Return the file name without extension.
Examples: ::
/foo/bar.baz => bar
/foo/bar => bar
None => None
:param string path: the file path
:rtype: string
"""
if path is None:
return None
return os.path... | python | def file_name_without_extension(path):
if path is None:
return None
return os.path.splitext(os.path.basename(path))[0] | [
"def",
"file_name_without_extension",
"(",
"path",
")",
":",
"if",
"path",
"is",
"None",
":",
"return",
"None",
"return",
"os",
".",
"path",
".",
"splitext",
"(",
"os",
".",
"path",
".",
"basename",
"(",
"path",
")",
")",
"[",
"0",
"]"
] | Return the file name without extension.
Examples: ::
/foo/bar.baz => bar
/foo/bar => bar
None => None
:param string path: the file path
:rtype: string | [
"Return",
"the",
"file",
"name",
"without",
"extension",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/globalfunctions.py#L231-L246 |
246,086 | readbeyond/aeneas | aeneas/globalfunctions.py | safe_float | def safe_float(string, default=None):
"""
Safely parse a string into a float.
On error return the ``default`` value.
:param string string: string value to be converted
:param float default: default value to be used in case of failure
:rtype: float
"""
value = default
try:
v... | python | def safe_float(string, default=None):
value = default
try:
value = float(string)
except TypeError:
pass
except ValueError:
pass
return value | [
"def",
"safe_float",
"(",
"string",
",",
"default",
"=",
"None",
")",
":",
"value",
"=",
"default",
"try",
":",
"value",
"=",
"float",
"(",
"string",
")",
"except",
"TypeError",
":",
"pass",
"except",
"ValueError",
":",
"pass",
"return",
"value"
] | Safely parse a string into a float.
On error return the ``default`` value.
:param string string: string value to be converted
:param float default: default value to be used in case of failure
:rtype: float | [
"Safely",
"parse",
"a",
"string",
"into",
"a",
"float",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/globalfunctions.py#L272-L289 |
246,087 | readbeyond/aeneas | aeneas/globalfunctions.py | safe_int | def safe_int(string, default=None):
"""
Safely parse a string into an int.
On error return the ``default`` value.
:param string string: string value to be converted
:param int default: default value to be used in case of failure
:rtype: int
"""
value = safe_float(string, default)
i... | python | def safe_int(string, default=None):
value = safe_float(string, default)
if value is not None:
value = int(value)
return value | [
"def",
"safe_int",
"(",
"string",
",",
"default",
"=",
"None",
")",
":",
"value",
"=",
"safe_float",
"(",
"string",
",",
"default",
")",
"if",
"value",
"is",
"not",
"None",
":",
"value",
"=",
"int",
"(",
"value",
")",
"return",
"value"
] | Safely parse a string into an int.
On error return the ``default`` value.
:param string string: string value to be converted
:param int default: default value to be used in case of failure
:rtype: int | [
"Safely",
"parse",
"a",
"string",
"into",
"an",
"int",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/globalfunctions.py#L292-L305 |
246,088 | readbeyond/aeneas | aeneas/globalfunctions.py | safe_get | def safe_get(dictionary, key, default_value, can_return_none=True):
"""
Safely perform a dictionary get,
returning the default value if the key is not found.
:param dict dictionary: the dictionary
:param string key: the key
:param variant default_value: the default value to be returned
:par... | python | def safe_get(dictionary, key, default_value, can_return_none=True):
return_value = default_value
try:
return_value = dictionary[key]
if (return_value is None) and (not can_return_none):
return_value = default_value
except (KeyError, TypeError):
# KeyError if key is not pr... | [
"def",
"safe_get",
"(",
"dictionary",
",",
"key",
",",
"default_value",
",",
"can_return_none",
"=",
"True",
")",
":",
"return_value",
"=",
"default_value",
"try",
":",
"return_value",
"=",
"dictionary",
"[",
"key",
"]",
"if",
"(",
"return_value",
"is",
"Non... | Safely perform a dictionary get,
returning the default value if the key is not found.
:param dict dictionary: the dictionary
:param string key: the key
:param variant default_value: the default value to be returned
:param bool can_return_none: if ``True``, the function can return ``None``;
... | [
"Safely",
"perform",
"a",
"dictionary",
"get",
"returning",
"the",
"default",
"value",
"if",
"the",
"key",
"is",
"not",
"found",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/globalfunctions.py#L308-L330 |
246,089 | readbeyond/aeneas | aeneas/globalfunctions.py | norm_join | def norm_join(prefix, suffix):
"""
Join ``prefix`` and ``suffix`` paths
and return the resulting path, normalized.
:param string prefix: the prefix path
:param string suffix: the suffix path
:rtype: string
"""
if (prefix is None) and (suffix is None):
return "."
if prefix is... | python | def norm_join(prefix, suffix):
if (prefix is None) and (suffix is None):
return "."
if prefix is None:
return os.path.normpath(suffix)
if suffix is None:
return os.path.normpath(prefix)
return os.path.normpath(os.path.join(prefix, suffix)) | [
"def",
"norm_join",
"(",
"prefix",
",",
"suffix",
")",
":",
"if",
"(",
"prefix",
"is",
"None",
")",
"and",
"(",
"suffix",
"is",
"None",
")",
":",
"return",
"\".\"",
"if",
"prefix",
"is",
"None",
":",
"return",
"os",
".",
"path",
".",
"normpath",
"(... | Join ``prefix`` and ``suffix`` paths
and return the resulting path, normalized.
:param string prefix: the prefix path
:param string suffix: the suffix path
:rtype: string | [
"Join",
"prefix",
"and",
"suffix",
"paths",
"and",
"return",
"the",
"resulting",
"path",
"normalized",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/globalfunctions.py#L333-L348 |
246,090 | readbeyond/aeneas | aeneas/globalfunctions.py | copytree | def copytree(source_directory, destination_directory, ignore=None):
"""
Recursively copy the contents of a source directory
into a destination directory.
Both directories must exist.
This function does not copy the root directory ``source_directory``
into ``destination_directory``.
Since `... | python | def copytree(source_directory, destination_directory, ignore=None):
if os.path.isdir(source_directory):
if not os.path.isdir(destination_directory):
os.makedirs(destination_directory)
files = os.listdir(source_directory)
if ignore is not None:
ignored = ignore(source_... | [
"def",
"copytree",
"(",
"source_directory",
",",
"destination_directory",
",",
"ignore",
"=",
"None",
")",
":",
"if",
"os",
".",
"path",
".",
"isdir",
"(",
"source_directory",
")",
":",
"if",
"not",
"os",
".",
"path",
".",
"isdir",
"(",
"destination_direct... | Recursively copy the contents of a source directory
into a destination directory.
Both directories must exist.
This function does not copy the root directory ``source_directory``
into ``destination_directory``.
Since ``shutil.copytree(src, dst)`` requires ``dst`` not to exist,
we cannot use fo... | [
"Recursively",
"copy",
"the",
"contents",
"of",
"a",
"source",
"directory",
"into",
"a",
"destination",
"directory",
".",
"Both",
"directories",
"must",
"exist",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/globalfunctions.py#L501-L534 |
246,091 | readbeyond/aeneas | aeneas/globalfunctions.py | ensure_parent_directory | def ensure_parent_directory(path, ensure_parent=True):
"""
Ensures the parent directory exists.
:param string path: the path of the file
:param bool ensure_parent: if ``True``, ensure the parent directory of ``path`` exists;
if ``False``, ensure ``path`` exists
:raise... | python | def ensure_parent_directory(path, ensure_parent=True):
parent_directory = os.path.abspath(path)
if ensure_parent:
parent_directory = os.path.dirname(parent_directory)
if not os.path.exists(parent_directory):
try:
os.makedirs(parent_directory)
except (IOError, OSError):
... | [
"def",
"ensure_parent_directory",
"(",
"path",
",",
"ensure_parent",
"=",
"True",
")",
":",
"parent_directory",
"=",
"os",
".",
"path",
".",
"abspath",
"(",
"path",
")",
"if",
"ensure_parent",
":",
"parent_directory",
"=",
"os",
".",
"path",
".",
"dirname",
... | Ensures the parent directory exists.
:param string path: the path of the file
:param bool ensure_parent: if ``True``, ensure the parent directory of ``path`` exists;
if ``False``, ensure ``path`` exists
:raises: OSError: if the path cannot be created | [
"Ensures",
"the",
"parent",
"directory",
"exists",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/globalfunctions.py#L537-L553 |
246,092 | readbeyond/aeneas | aeneas/globalfunctions.py | can_run_c_extension | def can_run_c_extension(name=None):
"""
Determine whether the given Python C extension loads correctly.
If ``name`` is ``None``, tests all Python C extensions,
and return ``True`` if and only if all load correctly.
:param string name: the name of the Python C extension to test
:rtype: bool
... | python | def can_run_c_extension(name=None):
def can_run_cdtw():
""" Python C extension for computing DTW """
try:
import aeneas.cdtw.cdtw
return True
except ImportError:
return False
def can_run_cmfcc():
""" Python C extension for computing MFCC """
... | [
"def",
"can_run_c_extension",
"(",
"name",
"=",
"None",
")",
":",
"def",
"can_run_cdtw",
"(",
")",
":",
"\"\"\" Python C extension for computing DTW \"\"\"",
"try",
":",
"import",
"aeneas",
".",
"cdtw",
".",
"cdtw",
"return",
"True",
"except",
"ImportError",
":",
... | Determine whether the given Python C extension loads correctly.
If ``name`` is ``None``, tests all Python C extensions,
and return ``True`` if and only if all load correctly.
:param string name: the name of the Python C extension to test
:rtype: bool | [
"Determine",
"whether",
"the",
"given",
"Python",
"C",
"extension",
"loads",
"correctly",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/globalfunctions.py#L805-L857 |
246,093 | readbeyond/aeneas | aeneas/globalfunctions.py | run_c_extension_with_fallback | def run_c_extension_with_fallback(
log_function,
extension,
c_function,
py_function,
args,
rconf
):
"""
Run a function calling a C extension, falling back
to a pure Python function if the former does not succeed.
:param function log_function: a logger fun... | python | def run_c_extension_with_fallback(
log_function,
extension,
c_function,
py_function,
args,
rconf
):
computed = False
if not rconf[u"c_extensions"]:
log_function(u"C extensions disabled")
elif extension not in rconf:
log_function([u"C extension ... | [
"def",
"run_c_extension_with_fallback",
"(",
"log_function",
",",
"extension",
",",
"c_function",
",",
"py_function",
",",
"args",
",",
"rconf",
")",
":",
"computed",
"=",
"False",
"if",
"not",
"rconf",
"[",
"u\"c_extensions\"",
"]",
":",
"log_function",
"(",
... | Run a function calling a C extension, falling back
to a pure Python function if the former does not succeed.
:param function log_function: a logger function
:param string extension: the name of the extension
:param function c_function: the (Python) function calling the C extension
:param function p... | [
"Run",
"a",
"function",
"calling",
"a",
"C",
"extension",
"falling",
"back",
"to",
"a",
"pure",
"Python",
"function",
"if",
"the",
"former",
"does",
"not",
"succeed",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/globalfunctions.py#L860-L908 |
246,094 | readbeyond/aeneas | aeneas/globalfunctions.py | file_can_be_read | def file_can_be_read(path):
"""
Return ``True`` if the file at the given ``path`` can be read.
:param string path: the file path
:rtype: bool
.. versionadded:: 1.4.0
"""
if path is None:
return False
try:
with io.open(path, "rb") as test_file:
pass
r... | python | def file_can_be_read(path):
if path is None:
return False
try:
with io.open(path, "rb") as test_file:
pass
return True
except (IOError, OSError):
pass
return False | [
"def",
"file_can_be_read",
"(",
"path",
")",
":",
"if",
"path",
"is",
"None",
":",
"return",
"False",
"try",
":",
"with",
"io",
".",
"open",
"(",
"path",
",",
"\"rb\"",
")",
"as",
"test_file",
":",
"pass",
"return",
"True",
"except",
"(",
"IOError",
... | Return ``True`` if the file at the given ``path`` can be read.
:param string path: the file path
:rtype: bool
.. versionadded:: 1.4.0 | [
"Return",
"True",
"if",
"the",
"file",
"at",
"the",
"given",
"path",
"can",
"be",
"read",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/globalfunctions.py#L911-L928 |
246,095 | readbeyond/aeneas | aeneas/globalfunctions.py | file_can_be_written | def file_can_be_written(path):
"""
Return ``True`` if a file can be written at the given ``path``.
:param string path: the file path
:rtype: bool
.. warning:: This function will attempt to open the given ``path``
in write mode, possibly destroying the file previously existing ther... | python | def file_can_be_written(path):
if path is None:
return False
try:
with io.open(path, "wb") as test_file:
pass
delete_file(None, path)
return True
except (IOError, OSError):
pass
return False | [
"def",
"file_can_be_written",
"(",
"path",
")",
":",
"if",
"path",
"is",
"None",
":",
"return",
"False",
"try",
":",
"with",
"io",
".",
"open",
"(",
"path",
",",
"\"wb\"",
")",
"as",
"test_file",
":",
"pass",
"delete_file",
"(",
"None",
",",
"path",
... | Return ``True`` if a file can be written at the given ``path``.
:param string path: the file path
:rtype: bool
.. warning:: This function will attempt to open the given ``path``
in write mode, possibly destroying the file previously existing there.
.. versionadded:: 1.4.0 | [
"Return",
"True",
"if",
"a",
"file",
"can",
"be",
"written",
"at",
"the",
"given",
"path",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/globalfunctions.py#L931-L952 |
246,096 | readbeyond/aeneas | aeneas/globalfunctions.py | read_file_bytes | def read_file_bytes(input_file_path):
"""
Read the file at the given file path
and return its contents as a byte string,
or ``None`` if an error occurred.
:param string input_file_path: the file path
:rtype: bytes
"""
contents = None
try:
with io.open(input_file_path, "rb") ... | python | def read_file_bytes(input_file_path):
contents = None
try:
with io.open(input_file_path, "rb") as input_file:
contents = input_file.read()
except:
pass
return contents | [
"def",
"read_file_bytes",
"(",
"input_file_path",
")",
":",
"contents",
"=",
"None",
"try",
":",
"with",
"io",
".",
"open",
"(",
"input_file_path",
",",
"\"rb\"",
")",
"as",
"input_file",
":",
"contents",
"=",
"input_file",
".",
"read",
"(",
")",
"except",... | Read the file at the given file path
and return its contents as a byte string,
or ``None`` if an error occurred.
:param string input_file_path: the file path
:rtype: bytes | [
"Read",
"the",
"file",
"at",
"the",
"given",
"file",
"path",
"and",
"return",
"its",
"contents",
"as",
"a",
"byte",
"string",
"or",
"None",
"if",
"an",
"error",
"occurred",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/globalfunctions.py#L1101-L1116 |
246,097 | readbeyond/aeneas | aeneas/globalfunctions.py | human_readable_number | def human_readable_number(number, suffix=""):
"""
Format the given number into a human-readable string.
Code adapted from http://stackoverflow.com/a/1094933
:param variant number: the number (int or float)
:param string suffix: the unit of the number
:rtype: string
"""
for unit in ["",... | python | def human_readable_number(number, suffix=""):
for unit in ["", "K", "M", "G", "T", "P", "E", "Z"]:
if abs(number) < 1024.0:
return "%3.1f%s%s" % (number, unit, suffix)
number /= 1024.0
return "%.1f%s%s" % (number, "Y", suffix) | [
"def",
"human_readable_number",
"(",
"number",
",",
"suffix",
"=",
"\"\"",
")",
":",
"for",
"unit",
"in",
"[",
"\"\"",
",",
"\"K\"",
",",
"\"M\"",
",",
"\"G\"",
",",
"\"T\"",
",",
"\"P\"",
",",
"\"E\"",
",",
"\"Z\"",
"]",
":",
"if",
"abs",
"(",
"nu... | Format the given number into a human-readable string.
Code adapted from http://stackoverflow.com/a/1094933
:param variant number: the number (int or float)
:param string suffix: the unit of the number
:rtype: string | [
"Format",
"the",
"given",
"number",
"into",
"a",
"human",
"-",
"readable",
"string",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/globalfunctions.py#L1119-L1133 |
246,098 | readbeyond/aeneas | aeneas/globalfunctions.py | safe_unichr | def safe_unichr(codepoint):
"""
Safely return a Unicode string of length one,
containing the Unicode character with given codepoint.
:param int codepoint: the codepoint
:rtype: string
"""
if is_py2_narrow_build():
return ("\\U%08x" % codepoint).decode("unicode-escape")
elif PY2:... | python | def safe_unichr(codepoint):
if is_py2_narrow_build():
return ("\\U%08x" % codepoint).decode("unicode-escape")
elif PY2:
return unichr(codepoint)
return chr(codepoint) | [
"def",
"safe_unichr",
"(",
"codepoint",
")",
":",
"if",
"is_py2_narrow_build",
"(",
")",
":",
"return",
"(",
"\"\\\\U%08x\"",
"%",
"codepoint",
")",
".",
"decode",
"(",
"\"unicode-escape\"",
")",
"elif",
"PY2",
":",
"return",
"unichr",
"(",
"codepoint",
")",... | Safely return a Unicode string of length one,
containing the Unicode character with given codepoint.
:param int codepoint: the codepoint
:rtype: string | [
"Safely",
"return",
"a",
"Unicode",
"string",
"of",
"length",
"one",
"containing",
"the",
"Unicode",
"character",
"with",
"given",
"codepoint",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/globalfunctions.py#L1192-L1204 |
246,099 | readbeyond/aeneas | aeneas/globalfunctions.py | safe_unicode_stdin | def safe_unicode_stdin(string):
"""
Safely convert the given string to a Unicode string,
decoding using ``sys.stdin.encoding`` if needed.
If running from a frozen binary, ``utf-8`` encoding is assumed.
:param variant string: the byte string or Unicode string to convert
:rtype: string
"""
... | python | def safe_unicode_stdin(string):
if string is None:
return None
if is_bytes(string):
if FROZEN:
return string.decode("utf-8")
try:
return string.decode(sys.stdin.encoding)
except UnicodeDecodeError:
return string.decode(sys.stdin.encoding, "repl... | [
"def",
"safe_unicode_stdin",
"(",
"string",
")",
":",
"if",
"string",
"is",
"None",
":",
"return",
"None",
"if",
"is_bytes",
"(",
"string",
")",
":",
"if",
"FROZEN",
":",
"return",
"string",
".",
"decode",
"(",
"\"utf-8\"",
")",
"try",
":",
"return",
"... | Safely convert the given string to a Unicode string,
decoding using ``sys.stdin.encoding`` if needed.
If running from a frozen binary, ``utf-8`` encoding is assumed.
:param variant string: the byte string or Unicode string to convert
:rtype: string | [
"Safely",
"convert",
"the",
"given",
"string",
"to",
"a",
"Unicode",
"string",
"decoding",
"using",
"sys",
".",
"stdin",
".",
"encoding",
"if",
"needed",
"."
] | 9d95535ad63eef4a98530cfdff033b8c35315ee1 | https://github.com/readbeyond/aeneas/blob/9d95535ad63eef4a98530cfdff033b8c35315ee1/aeneas/globalfunctions.py#L1235-L1256 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.