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 75 19.8k | code_tokens list | docstring stringlengths 3 17.3k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 87 242 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
ynop/audiomate | audiomate/processing/pipeline/base.py | Step._create_buffers | def _create_buffers(self):
"""
Create a buffer for every step in the pipeline.
"""
self.buffers = {}
for step in self.graph.nodes():
num_buffers = 1
if isinstance(step, Reduction):
num_buffers = len(step.parents)
self.buffer... | python | def _create_buffers(self):
"""
Create a buffer for every step in the pipeline.
"""
self.buffers = {}
for step in self.graph.nodes():
num_buffers = 1
if isinstance(step, Reduction):
num_buffers = len(step.parents)
self.buffer... | [
"def",
"_create_buffers",
"(",
"self",
")",
":",
"self",
".",
"buffers",
"=",
"{",
"}",
"for",
"step",
"in",
"self",
".",
"graph",
".",
"nodes",
"(",
")",
":",
"num_buffers",
"=",
"1",
"if",
"isinstance",
"(",
"step",
",",
"Reduction",
")",
":",
"n... | Create a buffer for every step in the pipeline. | [
"Create",
"a",
"buffer",
"for",
"every",
"step",
"in",
"the",
"pipeline",
"."
] | 61727920b23a708293c3d526fa3000d4de9c6c21 | https://github.com/ynop/audiomate/blob/61727920b23a708293c3d526fa3000d4de9c6c21/audiomate/processing/pipeline/base.py#L372-L387 | train |
ynop/audiomate | audiomate/corpus/corpus.py | Corpus.save | def save(self, writer=None):
"""
If self.path is defined, it tries to save the corpus at the given path.
"""
if self.path is None:
raise ValueError('No path given to save the data set.')
self.save_at(self.path, writer) | python | def save(self, writer=None):
"""
If self.path is defined, it tries to save the corpus at the given path.
"""
if self.path is None:
raise ValueError('No path given to save the data set.')
self.save_at(self.path, writer) | [
"def",
"save",
"(",
"self",
",",
"writer",
"=",
"None",
")",
":",
"if",
"self",
".",
"path",
"is",
"None",
":",
"raise",
"ValueError",
"(",
"'No path given to save the data set.'",
")",
"self",
".",
"save_at",
"(",
"self",
".",
"path",
",",
"writer",
")"... | If self.path is defined, it tries to save the corpus at the given path. | [
"If",
"self",
".",
"path",
"is",
"defined",
"it",
"tries",
"to",
"save",
"the",
"corpus",
"at",
"the",
"given",
"path",
"."
] | 61727920b23a708293c3d526fa3000d4de9c6c21 | https://github.com/ynop/audiomate/blob/61727920b23a708293c3d526fa3000d4de9c6c21/audiomate/corpus/corpus.py#L69-L77 | train |
ynop/audiomate | audiomate/corpus/corpus.py | Corpus.save_at | def save_at(self, path, writer=None):
"""
Save this corpus at the given path. If the path differs from the current path set, the path
gets updated.
Parameters:
path (str): Path to save the data set to.
writer (str, CorpusWriter): The writer or the name of the rea... | python | def save_at(self, path, writer=None):
"""
Save this corpus at the given path. If the path differs from the current path set, the path
gets updated.
Parameters:
path (str): Path to save the data set to.
writer (str, CorpusWriter): The writer or the name of the rea... | [
"def",
"save_at",
"(",
"self",
",",
"path",
",",
"writer",
"=",
"None",
")",
":",
"if",
"writer",
"is",
"None",
":",
"from",
".",
"import",
"io",
"writer",
"=",
"io",
".",
"DefaultWriter",
"(",
")",
"elif",
"type",
"(",
"writer",
")",
"==",
"str",
... | Save this corpus at the given path. If the path differs from the current path set, the path
gets updated.
Parameters:
path (str): Path to save the data set to.
writer (str, CorpusWriter): The writer or the name of the reader to use. | [
"Save",
"this",
"corpus",
"at",
"the",
"given",
"path",
".",
"If",
"the",
"path",
"differs",
"from",
"the",
"current",
"path",
"set",
"the",
"path",
"gets",
"updated",
"."
] | 61727920b23a708293c3d526fa3000d4de9c6c21 | https://github.com/ynop/audiomate/blob/61727920b23a708293c3d526fa3000d4de9c6c21/audiomate/corpus/corpus.py#L79-L99 | train |
ynop/audiomate | audiomate/corpus/corpus.py | Corpus.new_file | def new_file(self, path, track_idx, copy_file=False):
"""
Adds a new audio file to the corpus with the given data.
Parameters:
path (str): Path of the file to add.
track_idx (str): The id to associate the file-track with.
copy_file (bool): If True the file is... | python | def new_file(self, path, track_idx, copy_file=False):
"""
Adds a new audio file to the corpus with the given data.
Parameters:
path (str): Path of the file to add.
track_idx (str): The id to associate the file-track with.
copy_file (bool): If True the file is... | [
"def",
"new_file",
"(",
"self",
",",
"path",
",",
"track_idx",
",",
"copy_file",
"=",
"False",
")",
":",
"new_file_idx",
"=",
"track_idx",
"new_file_path",
"=",
"os",
".",
"path",
".",
"abspath",
"(",
"path",
")",
"if",
"new_file_idx",
"in",
"self",
".",... | Adds a new audio file to the corpus with the given data.
Parameters:
path (str): Path of the file to add.
track_idx (str): The id to associate the file-track with.
copy_file (bool): If True the file is copied to the data set folder, otherwise the given
... | [
"Adds",
"a",
"new",
"audio",
"file",
"to",
"the",
"corpus",
"with",
"the",
"given",
"data",
"."
] | 61727920b23a708293c3d526fa3000d4de9c6c21 | https://github.com/ynop/audiomate/blob/61727920b23a708293c3d526fa3000d4de9c6c21/audiomate/corpus/corpus.py#L129-L166 | train |
ynop/audiomate | audiomate/corpus/corpus.py | Corpus.new_utterance | def new_utterance(self, utterance_idx, track_idx, issuer_idx=None, start=0, end=float('inf')):
"""
Add a new utterance to the corpus with the given data.
Parameters:
track_idx (str): The track id the utterance is in.
utterance_idx (str): The id to associate with the utte... | python | def new_utterance(self, utterance_idx, track_idx, issuer_idx=None, start=0, end=float('inf')):
"""
Add a new utterance to the corpus with the given data.
Parameters:
track_idx (str): The track id the utterance is in.
utterance_idx (str): The id to associate with the utte... | [
"def",
"new_utterance",
"(",
"self",
",",
"utterance_idx",
",",
"track_idx",
",",
"issuer_idx",
"=",
"None",
",",
"start",
"=",
"0",
",",
"end",
"=",
"float",
"(",
"'inf'",
")",
")",
":",
"new_utt_idx",
"=",
"utterance_idx",
"if",
"track_idx",
"not",
"in... | Add a new utterance to the corpus with the given data.
Parameters:
track_idx (str): The track id the utterance is in.
utterance_idx (str): The id to associate with the utterance.
If None or already exists, one is generated.
issuer_idx (str): ... | [
"Add",
"a",
"new",
"utterance",
"to",
"the",
"corpus",
"with",
"the",
"given",
"data",
"."
] | 61727920b23a708293c3d526fa3000d4de9c6c21 | https://github.com/ynop/audiomate/blob/61727920b23a708293c3d526fa3000d4de9c6c21/audiomate/corpus/corpus.py#L202-L246 | train |
ynop/audiomate | audiomate/corpus/corpus.py | Corpus.new_issuer | def new_issuer(self, issuer_idx, info=None):
"""
Add a new issuer to the dataset with the given data.
Parameters:
issuer_idx (str): The id to associate the issuer with. If None or already exists, one is
generated.
info (dict, list): Addition... | python | def new_issuer(self, issuer_idx, info=None):
"""
Add a new issuer to the dataset with the given data.
Parameters:
issuer_idx (str): The id to associate the issuer with. If None or already exists, one is
generated.
info (dict, list): Addition... | [
"def",
"new_issuer",
"(",
"self",
",",
"issuer_idx",
",",
"info",
"=",
"None",
")",
":",
"new_issuer_idx",
"=",
"issuer_idx",
"if",
"new_issuer_idx",
"in",
"self",
".",
"_issuers",
".",
"keys",
"(",
")",
":",
"new_issuer_idx",
"=",
"naming",
".",
"index_na... | Add a new issuer to the dataset with the given data.
Parameters:
issuer_idx (str): The id to associate the issuer with. If None or already exists, one is
generated.
info (dict, list): Additional info of the issuer.
Returns:
Issuer: The ... | [
"Add",
"a",
"new",
"issuer",
"to",
"the",
"dataset",
"with",
"the",
"given",
"data",
"."
] | 61727920b23a708293c3d526fa3000d4de9c6c21 | https://github.com/ynop/audiomate/blob/61727920b23a708293c3d526fa3000d4de9c6c21/audiomate/corpus/corpus.py#L291-L313 | train |
ynop/audiomate | audiomate/corpus/corpus.py | Corpus.new_feature_container | def new_feature_container(self, idx, path=None):
"""
Add a new feature container with the given data.
Parameters:
idx (str): An unique identifier within the dataset.
path (str): The path to store the feature file. If None a default path is used.
Returns:
... | python | def new_feature_container(self, idx, path=None):
"""
Add a new feature container with the given data.
Parameters:
idx (str): An unique identifier within the dataset.
path (str): The path to store the feature file. If None a default path is used.
Returns:
... | [
"def",
"new_feature_container",
"(",
"self",
",",
"idx",
",",
"path",
"=",
"None",
")",
":",
"new_feature_idx",
"=",
"idx",
"new_feature_path",
"=",
"path",
"if",
"new_feature_idx",
"in",
"self",
".",
"_feature_containers",
".",
"keys",
"(",
")",
":",
"new_f... | Add a new feature container with the given data.
Parameters:
idx (str): An unique identifier within the dataset.
path (str): The path to store the feature file. If None a default path is used.
Returns:
FeatureContainer: The newly added feature-container. | [
"Add",
"a",
"new",
"feature",
"container",
"with",
"the",
"given",
"data",
"."
] | 61727920b23a708293c3d526fa3000d4de9c6c21 | https://github.com/ynop/audiomate/blob/61727920b23a708293c3d526fa3000d4de9c6c21/audiomate/corpus/corpus.py#L349-L381 | train |
ynop/audiomate | audiomate/corpus/corpus.py | Corpus.import_subview | def import_subview(self, idx, subview):
"""
Add the given subview to the corpus.
Args:
idx (str): An idx that is unique in the corpus for identifying the subview.
If already a subview exists with the given id it will be overridden.
subview (Subview... | python | def import_subview(self, idx, subview):
"""
Add the given subview to the corpus.
Args:
idx (str): An idx that is unique in the corpus for identifying the subview.
If already a subview exists with the given id it will be overridden.
subview (Subview... | [
"def",
"import_subview",
"(",
"self",
",",
"idx",
",",
"subview",
")",
":",
"subview",
".",
"corpus",
"=",
"self",
"self",
".",
"_subviews",
"[",
"idx",
"]",
"=",
"subview"
] | Add the given subview to the corpus.
Args:
idx (str): An idx that is unique in the corpus for identifying the subview.
If already a subview exists with the given id it will be overridden.
subview (Subview): The subview to add. | [
"Add",
"the",
"given",
"subview",
"to",
"the",
"corpus",
"."
] | 61727920b23a708293c3d526fa3000d4de9c6c21 | https://github.com/ynop/audiomate/blob/61727920b23a708293c3d526fa3000d4de9c6c21/audiomate/corpus/corpus.py#L387-L398 | train |
ynop/audiomate | audiomate/corpus/corpus.py | Corpus.relocate_audio_to_single_container | def relocate_audio_to_single_container(self, target_path):
"""
Copies every track to a single container.
Afterwards all tracks in the container are linked against
this single container.
"""
cont = containers.AudioContainer(target_path)
cont.open()
new_tr... | python | def relocate_audio_to_single_container(self, target_path):
"""
Copies every track to a single container.
Afterwards all tracks in the container are linked against
this single container.
"""
cont = containers.AudioContainer(target_path)
cont.open()
new_tr... | [
"def",
"relocate_audio_to_single_container",
"(",
"self",
",",
"target_path",
")",
":",
"cont",
"=",
"containers",
".",
"AudioContainer",
"(",
"target_path",
")",
"cont",
".",
"open",
"(",
")",
"new_tracks",
"=",
"{",
"}",
"for",
"track",
"in",
"self",
".",
... | Copies every track to a single container.
Afterwards all tracks in the container are linked against
this single container. | [
"Copies",
"every",
"track",
"to",
"a",
"single",
"container",
".",
"Afterwards",
"all",
"tracks",
"in",
"the",
"container",
"are",
"linked",
"against",
"this",
"single",
"container",
"."
] | 61727920b23a708293c3d526fa3000d4de9c6c21 | https://github.com/ynop/audiomate/blob/61727920b23a708293c3d526fa3000d4de9c6c21/audiomate/corpus/corpus.py#L439-L469 | train |
ynop/audiomate | audiomate/corpus/corpus.py | Corpus.from_corpus | def from_corpus(cls, corpus):
"""
Create a new modifiable corpus from any other CorpusView.
This for example can be used to create a independent modifiable corpus from a subview.
Args:
corpus (CorpusView): The corpus to create a copy from.
Returns:
Corpu... | python | def from_corpus(cls, corpus):
"""
Create a new modifiable corpus from any other CorpusView.
This for example can be used to create a independent modifiable corpus from a subview.
Args:
corpus (CorpusView): The corpus to create a copy from.
Returns:
Corpu... | [
"def",
"from_corpus",
"(",
"cls",
",",
"corpus",
")",
":",
"ds",
"=",
"Corpus",
"(",
")",
"tracks",
"=",
"copy",
".",
"deepcopy",
"(",
"list",
"(",
"corpus",
".",
"tracks",
".",
"values",
"(",
")",
")",
")",
"track_mapping",
"=",
"ds",
".",
"import... | Create a new modifiable corpus from any other CorpusView.
This for example can be used to create a independent modifiable corpus from a subview.
Args:
corpus (CorpusView): The corpus to create a copy from.
Returns:
Corpus: A new corpus with the same data as the given on... | [
"Create",
"a",
"new",
"modifiable",
"corpus",
"from",
"any",
"other",
"CorpusView",
".",
"This",
"for",
"example",
"can",
"be",
"used",
"to",
"create",
"a",
"independent",
"modifiable",
"corpus",
"from",
"a",
"subview",
"."
] | 61727920b23a708293c3d526fa3000d4de9c6c21 | https://github.com/ynop/audiomate/blob/61727920b23a708293c3d526fa3000d4de9c6c21/audiomate/corpus/corpus.py#L506-L547 | train |
ynop/audiomate | audiomate/corpus/corpus.py | Corpus.merge_corpora | def merge_corpora(cls, corpora):
"""
Merge a list of corpora into one.
Args:
corpora (Iterable): An iterable of :py:class:`audiomate.corpus.CorpusView`.
Returns:
Corpus: A corpus with the data from all given corpora merged into one.
"""
ds = Cor... | python | def merge_corpora(cls, corpora):
"""
Merge a list of corpora into one.
Args:
corpora (Iterable): An iterable of :py:class:`audiomate.corpus.CorpusView`.
Returns:
Corpus: A corpus with the data from all given corpora merged into one.
"""
ds = Cor... | [
"def",
"merge_corpora",
"(",
"cls",
",",
"corpora",
")",
":",
"ds",
"=",
"Corpus",
"(",
")",
"for",
"merging_corpus",
"in",
"corpora",
":",
"ds",
".",
"merge_corpus",
"(",
"merging_corpus",
")",
"return",
"ds"
] | Merge a list of corpora into one.
Args:
corpora (Iterable): An iterable of :py:class:`audiomate.corpus.CorpusView`.
Returns:
Corpus: A corpus with the data from all given corpora merged into one. | [
"Merge",
"a",
"list",
"of",
"corpora",
"into",
"one",
"."
] | 61727920b23a708293c3d526fa3000d4de9c6c21 | https://github.com/ynop/audiomate/blob/61727920b23a708293c3d526fa3000d4de9c6c21/audiomate/corpus/corpus.py#L550-L566 | train |
ynop/audiomate | audiomate/corpus/io/common_voice.py | CommonVoiceReader.load_subset | def load_subset(corpus, path, subset_idx):
""" Load subset into corpus. """
csv_file = os.path.join(path, '{}.tsv'.format(subset_idx))
subset_utt_ids = []
entries = textfile.read_separated_lines_generator(
csv_file,
separator='\t',
max_columns=8,
... | python | def load_subset(corpus, path, subset_idx):
""" Load subset into corpus. """
csv_file = os.path.join(path, '{}.tsv'.format(subset_idx))
subset_utt_ids = []
entries = textfile.read_separated_lines_generator(
csv_file,
separator='\t',
max_columns=8,
... | [
"def",
"load_subset",
"(",
"corpus",
",",
"path",
",",
"subset_idx",
")",
":",
"csv_file",
"=",
"os",
".",
"path",
".",
"join",
"(",
"path",
",",
"'{}.tsv'",
".",
"format",
"(",
"subset_idx",
")",
")",
"subset_utt_ids",
"=",
"[",
"]",
"entries",
"=",
... | Load subset into corpus. | [
"Load",
"subset",
"into",
"corpus",
"."
] | 61727920b23a708293c3d526fa3000d4de9c6c21 | https://github.com/ynop/audiomate/blob/61727920b23a708293c3d526fa3000d4de9c6c21/audiomate/corpus/io/common_voice.py#L51-L75 | train |
ynop/audiomate | audiomate/corpus/io/common_voice.py | CommonVoiceReader.map_age | def map_age(age):
""" Map age to correct age-group. """
if age in [None, '']:
return issuers.AgeGroup.UNKNOWN
elif age == 'teens':
return issuers.AgeGroup.YOUTH
elif age in ['sixties', 'seventies', 'eighties', 'nineties']:
return issuers.AgeGroup.SENI... | python | def map_age(age):
""" Map age to correct age-group. """
if age in [None, '']:
return issuers.AgeGroup.UNKNOWN
elif age == 'teens':
return issuers.AgeGroup.YOUTH
elif age in ['sixties', 'seventies', 'eighties', 'nineties']:
return issuers.AgeGroup.SENI... | [
"def",
"map_age",
"(",
"age",
")",
":",
"if",
"age",
"in",
"[",
"None",
",",
"''",
"]",
":",
"return",
"issuers",
".",
"AgeGroup",
".",
"UNKNOWN",
"elif",
"age",
"==",
"'teens'",
":",
"return",
"issuers",
".",
"AgeGroup",
".",
"YOUTH",
"elif",
"age",... | Map age to correct age-group. | [
"Map",
"age",
"to",
"correct",
"age",
"-",
"group",
"."
] | 61727920b23a708293c3d526fa3000d4de9c6c21 | https://github.com/ynop/audiomate/blob/61727920b23a708293c3d526fa3000d4de9c6c21/audiomate/corpus/io/common_voice.py#L110-L120 | train |
ynop/audiomate | audiomate/corpus/io/common_voice.py | CommonVoiceReader.map_gender | def map_gender(gender):
""" Map gender to correct value. """
if gender == 'male':
return issuers.Gender.MALE
elif gender == 'female':
return issuers.Gender.FEMALE
else:
return issuers.Gender.UNKNOWN | python | def map_gender(gender):
""" Map gender to correct value. """
if gender == 'male':
return issuers.Gender.MALE
elif gender == 'female':
return issuers.Gender.FEMALE
else:
return issuers.Gender.UNKNOWN | [
"def",
"map_gender",
"(",
"gender",
")",
":",
"if",
"gender",
"==",
"'male'",
":",
"return",
"issuers",
".",
"Gender",
".",
"MALE",
"elif",
"gender",
"==",
"'female'",
":",
"return",
"issuers",
".",
"Gender",
".",
"FEMALE",
"else",
":",
"return",
"issuer... | Map gender to correct value. | [
"Map",
"gender",
"to",
"correct",
"value",
"."
] | 61727920b23a708293c3d526fa3000d4de9c6c21 | https://github.com/ynop/audiomate/blob/61727920b23a708293c3d526fa3000d4de9c6c21/audiomate/corpus/io/common_voice.py#L123-L131 | train |
ynop/audiomate | audiomate/utils/units.py | FrameSettings.num_frames | def num_frames(self, num_samples):
"""
Return the number of frames that will be used for a signal with the length of ``num_samples``.
"""
return math.ceil(float(max(num_samples - self.frame_size, 0)) / float(self.hop_size)) + 1 | python | def num_frames(self, num_samples):
"""
Return the number of frames that will be used for a signal with the length of ``num_samples``.
"""
return math.ceil(float(max(num_samples - self.frame_size, 0)) / float(self.hop_size)) + 1 | [
"def",
"num_frames",
"(",
"self",
",",
"num_samples",
")",
":",
"return",
"math",
".",
"ceil",
"(",
"float",
"(",
"max",
"(",
"num_samples",
"-",
"self",
".",
"frame_size",
",",
"0",
")",
")",
"/",
"float",
"(",
"self",
".",
"hop_size",
")",
")",
"... | Return the number of frames that will be used for a signal with the length of ``num_samples``. | [
"Return",
"the",
"number",
"of",
"frames",
"that",
"will",
"be",
"used",
"for",
"a",
"signal",
"with",
"the",
"length",
"of",
"num_samples",
"."
] | 61727920b23a708293c3d526fa3000d4de9c6c21 | https://github.com/ynop/audiomate/blob/61727920b23a708293c3d526fa3000d4de9c6c21/audiomate/utils/units.py#L102-L106 | train |
ynop/audiomate | audiomate/utils/units.py | FrameSettings.frame_to_seconds | def frame_to_seconds(self, frame_index, sr):
"""
Return a tuple containing the start and end of the frame in seconds.
"""
start_sample, end_sample = self.frame_to_sample(frame_index)
return sample_to_seconds(start_sample, sampling_rate=sr), sample_to_seconds(end_sample, sampling_... | python | def frame_to_seconds(self, frame_index, sr):
"""
Return a tuple containing the start and end of the frame in seconds.
"""
start_sample, end_sample = self.frame_to_sample(frame_index)
return sample_to_seconds(start_sample, sampling_rate=sr), sample_to_seconds(end_sample, sampling_... | [
"def",
"frame_to_seconds",
"(",
"self",
",",
"frame_index",
",",
"sr",
")",
":",
"start_sample",
",",
"end_sample",
"=",
"self",
".",
"frame_to_sample",
"(",
"frame_index",
")",
"return",
"sample_to_seconds",
"(",
"start_sample",
",",
"sampling_rate",
"=",
"sr",... | Return a tuple containing the start and end of the frame in seconds. | [
"Return",
"a",
"tuple",
"containing",
"the",
"start",
"and",
"end",
"of",
"the",
"frame",
"in",
"seconds",
"."
] | 61727920b23a708293c3d526fa3000d4de9c6c21 | https://github.com/ynop/audiomate/blob/61727920b23a708293c3d526fa3000d4de9c6c21/audiomate/utils/units.py#L126-L131 | train |
ynop/audiomate | audiomate/utils/units.py | FrameSettings.time_range_to_frame_range | def time_range_to_frame_range(self, start, end, sr):
"""
Calculate the frames containing samples from the given time range in seconds.
Args:
start (float): Start time in seconds.
end (float): End time in seconds.
sr (int): The sampling rate to use for time-to... | python | def time_range_to_frame_range(self, start, end, sr):
"""
Calculate the frames containing samples from the given time range in seconds.
Args:
start (float): Start time in seconds.
end (float): End time in seconds.
sr (int): The sampling rate to use for time-to... | [
"def",
"time_range_to_frame_range",
"(",
"self",
",",
"start",
",",
"end",
",",
"sr",
")",
":",
"start_sample",
"=",
"seconds_to_sample",
"(",
"start",
",",
"sr",
")",
"end_sample",
"=",
"seconds_to_sample",
"(",
"end",
",",
"sr",
")",
"return",
"self",
".... | Calculate the frames containing samples from the given time range in seconds.
Args:
start (float): Start time in seconds.
end (float): End time in seconds.
sr (int): The sampling rate to use for time-to-sample conversion.
Returns:
tuple: A tuple containi... | [
"Calculate",
"the",
"frames",
"containing",
"samples",
"from",
"the",
"given",
"time",
"range",
"in",
"seconds",
"."
] | 61727920b23a708293c3d526fa3000d4de9c6c21 | https://github.com/ynop/audiomate/blob/61727920b23a708293c3d526fa3000d4de9c6c21/audiomate/utils/units.py#L133-L149 | train |
ynop/audiomate | audiomate/processing/base.py | Processor._process_corpus | def _process_corpus(self, corpus, output_path, processing_func, frame_size=400, hop_size=160, sr=None):
""" Utility function for processing a corpus with a separate processing function. """
feat_container = containers.FeatureContainer(output_path)
feat_container.open()
sampling_rate = -... | python | def _process_corpus(self, corpus, output_path, processing_func, frame_size=400, hop_size=160, sr=None):
""" Utility function for processing a corpus with a separate processing function. """
feat_container = containers.FeatureContainer(output_path)
feat_container.open()
sampling_rate = -... | [
"def",
"_process_corpus",
"(",
"self",
",",
"corpus",
",",
"output_path",
",",
"processing_func",
",",
"frame_size",
"=",
"400",
",",
"hop_size",
"=",
"160",
",",
"sr",
"=",
"None",
")",
":",
"feat_container",
"=",
"containers",
".",
"FeatureContainer",
"(",... | Utility function for processing a corpus with a separate processing function. | [
"Utility",
"function",
"for",
"processing",
"a",
"corpus",
"with",
"a",
"separate",
"processing",
"function",
"."
] | 61727920b23a708293c3d526fa3000d4de9c6c21 | https://github.com/ynop/audiomate/blob/61727920b23a708293c3d526fa3000d4de9c6c21/audiomate/processing/base.py#L358-L384 | train |
ynop/audiomate | audiomate/utils/audio.py | process_buffer | def process_buffer(buffer, n_channels):
"""
Merge the read blocks and resample if necessary.
Args:
buffer (list): A list of blocks of samples.
n_channels (int): The number of channels of the input data.
Returns:
np.array: The samples
"""
samples = np.concatenate(buffer)... | python | def process_buffer(buffer, n_channels):
"""
Merge the read blocks and resample if necessary.
Args:
buffer (list): A list of blocks of samples.
n_channels (int): The number of channels of the input data.
Returns:
np.array: The samples
"""
samples = np.concatenate(buffer)... | [
"def",
"process_buffer",
"(",
"buffer",
",",
"n_channels",
")",
":",
"samples",
"=",
"np",
".",
"concatenate",
"(",
"buffer",
")",
"if",
"n_channels",
">",
"1",
":",
"samples",
"=",
"samples",
".",
"reshape",
"(",
"(",
"-",
"1",
",",
"n_channels",
")",... | Merge the read blocks and resample if necessary.
Args:
buffer (list): A list of blocks of samples.
n_channels (int): The number of channels of the input data.
Returns:
np.array: The samples | [
"Merge",
"the",
"read",
"blocks",
"and",
"resample",
"if",
"necessary",
"."
] | 61727920b23a708293c3d526fa3000d4de9c6c21 | https://github.com/ynop/audiomate/blob/61727920b23a708293c3d526fa3000d4de9c6c21/audiomate/utils/audio.py#L7-L24 | train |
ynop/audiomate | audiomate/utils/audio.py | read_blocks | def read_blocks(file_path, start=0.0, end=float('inf'), buffer_size=5760000):
"""
Read an audio file block after block. The blocks are yielded one by one.
Args:
file_path (str): Path to the file to read.
start (float): Start in seconds to read from.
end (float): End in seconds to re... | python | def read_blocks(file_path, start=0.0, end=float('inf'), buffer_size=5760000):
"""
Read an audio file block after block. The blocks are yielded one by one.
Args:
file_path (str): Path to the file to read.
start (float): Start in seconds to read from.
end (float): End in seconds to re... | [
"def",
"read_blocks",
"(",
"file_path",
",",
"start",
"=",
"0.0",
",",
"end",
"=",
"float",
"(",
"'inf'",
")",
",",
"buffer_size",
"=",
"5760000",
")",
":",
"buffer",
"=",
"[",
"]",
"n_buffer",
"=",
"0",
"n_samples",
"=",
"0",
"with",
"audioread",
".... | Read an audio file block after block. The blocks are yielded one by one.
Args:
file_path (str): Path to the file to read.
start (float): Start in seconds to read from.
end (float): End in seconds to read to.
``inf`` means to the end of the file.
buffer_size (int... | [
"Read",
"an",
"audio",
"file",
"block",
"after",
"block",
".",
"The",
"blocks",
"are",
"yielded",
"one",
"by",
"one",
"."
] | 61727920b23a708293c3d526fa3000d4de9c6c21 | https://github.com/ynop/audiomate/blob/61727920b23a708293c3d526fa3000d4de9c6c21/audiomate/utils/audio.py#L27-L86 | train |
ynop/audiomate | audiomate/utils/audio.py | read_frames | def read_frames(file_path, frame_size, hop_size, start=0.0,
end=float('inf'), buffer_size=5760000):
"""
Read an audio file frame by frame. The frames are yielded one after another.
Args:
file_path (str): Path to the file to read.
frame_size (int): The number of samples per f... | python | def read_frames(file_path, frame_size, hop_size, start=0.0,
end=float('inf'), buffer_size=5760000):
"""
Read an audio file frame by frame. The frames are yielded one after another.
Args:
file_path (str): Path to the file to read.
frame_size (int): The number of samples per f... | [
"def",
"read_frames",
"(",
"file_path",
",",
"frame_size",
",",
"hop_size",
",",
"start",
"=",
"0.0",
",",
"end",
"=",
"float",
"(",
"'inf'",
")",
",",
"buffer_size",
"=",
"5760000",
")",
":",
"rest_samples",
"=",
"np",
".",
"array",
"(",
"[",
"]",
"... | Read an audio file frame by frame. The frames are yielded one after another.
Args:
file_path (str): Path to the file to read.
frame_size (int): The number of samples per frame.
hop_size (int): The number of samples between two frames.
start (float): Start in seconds to read from.
... | [
"Read",
"an",
"audio",
"file",
"frame",
"by",
"frame",
".",
"The",
"frames",
"are",
"yielded",
"one",
"after",
"another",
"."
] | 61727920b23a708293c3d526fa3000d4de9c6c21 | https://github.com/ynop/audiomate/blob/61727920b23a708293c3d526fa3000d4de9c6c21/audiomate/utils/audio.py#L89-L137 | train |
ynop/audiomate | audiomate/utils/audio.py | write_wav | def write_wav(path, samples, sr=16000):
"""
Write to given samples to a wav file.
The samples are expected to be floating point numbers
in the range of -1.0 to 1.0.
Args:
path (str): The path to write the wav to.
samples (np.array): A float array .
sr (int): The sampling rat... | python | def write_wav(path, samples, sr=16000):
"""
Write to given samples to a wav file.
The samples are expected to be floating point numbers
in the range of -1.0 to 1.0.
Args:
path (str): The path to write the wav to.
samples (np.array): A float array .
sr (int): The sampling rat... | [
"def",
"write_wav",
"(",
"path",
",",
"samples",
",",
"sr",
"=",
"16000",
")",
":",
"max_value",
"=",
"np",
".",
"abs",
"(",
"np",
".",
"iinfo",
"(",
"np",
".",
"int16",
")",
".",
"min",
")",
"data",
"=",
"(",
"samples",
"*",
"max_value",
")",
... | Write to given samples to a wav file.
The samples are expected to be floating point numbers
in the range of -1.0 to 1.0.
Args:
path (str): The path to write the wav to.
samples (np.array): A float array .
sr (int): The sampling rate. | [
"Write",
"to",
"given",
"samples",
"to",
"a",
"wav",
"file",
".",
"The",
"samples",
"are",
"expected",
"to",
"be",
"floating",
"point",
"numbers",
"in",
"the",
"range",
"of",
"-",
"1",
".",
"0",
"to",
"1",
".",
"0",
"."
] | 61727920b23a708293c3d526fa3000d4de9c6c21 | https://github.com/ynop/audiomate/blob/61727920b23a708293c3d526fa3000d4de9c6c21/audiomate/utils/audio.py#L140-L153 | train |
ynop/audiomate | audiomate/utils/stats.py | DataStats.to_dict | def to_dict(self):
"""
Return the stats as a dictionary.
"""
return {
'mean': self.mean,
'var': self.var,
'min': self.min,
'max': self.max,
'num': self.num
} | python | def to_dict(self):
"""
Return the stats as a dictionary.
"""
return {
'mean': self.mean,
'var': self.var,
'min': self.min,
'max': self.max,
'num': self.num
} | [
"def",
"to_dict",
"(",
"self",
")",
":",
"return",
"{",
"'mean'",
":",
"self",
".",
"mean",
",",
"'var'",
":",
"self",
".",
"var",
",",
"'min'",
":",
"self",
".",
"min",
",",
"'max'",
":",
"self",
".",
"max",
",",
"'num'",
":",
"self",
".",
"nu... | Return the stats as a dictionary. | [
"Return",
"the",
"stats",
"as",
"a",
"dictionary",
"."
] | 61727920b23a708293c3d526fa3000d4de9c6c21 | https://github.com/ynop/audiomate/blob/61727920b23a708293c3d526fa3000d4de9c6c21/audiomate/utils/stats.py#L32-L42 | train |
ynop/audiomate | audiomate/utils/stats.py | DataStats.concatenate | def concatenate(cls, list_of_stats):
"""
Take a list of stats from different sets of data points and
merge the stats for getting stats overall data points.
Args:
list_of_stats (iterable): A list containing stats for different sets of data points.
Returns:
... | python | def concatenate(cls, list_of_stats):
"""
Take a list of stats from different sets of data points and
merge the stats for getting stats overall data points.
Args:
list_of_stats (iterable): A list containing stats for different sets of data points.
Returns:
... | [
"def",
"concatenate",
"(",
"cls",
",",
"list_of_stats",
")",
":",
"all_stats",
"=",
"np",
".",
"stack",
"(",
"[",
"stats",
".",
"values",
"for",
"stats",
"in",
"list_of_stats",
"]",
")",
"all_counts",
"=",
"all_stats",
"[",
":",
",",
"4",
"]",
"all_cou... | Take a list of stats from different sets of data points and
merge the stats for getting stats overall data points.
Args:
list_of_stats (iterable): A list containing stats for different sets of data points.
Returns:
DataStats: Stats calculated overall sets of data points... | [
"Take",
"a",
"list",
"of",
"stats",
"from",
"different",
"sets",
"of",
"data",
"points",
"and",
"merge",
"the",
"stats",
"for",
"getting",
"stats",
"overall",
"data",
"points",
"."
] | 61727920b23a708293c3d526fa3000d4de9c6c21 | https://github.com/ynop/audiomate/blob/61727920b23a708293c3d526fa3000d4de9c6c21/audiomate/utils/stats.py#L63-L85 | train |
ynop/audiomate | bench/resources/__init__.py | generate_corpus | def generate_corpus(n_issuers,
n_tracks_per_issuer,
n_utts_per_track,
n_ll_per_utt,
n_label_per_ll,
rand=None):
"""
Generate a corpus with mock data.
"""
corpus = audiomate.Corpus()
for issuer in gen... | python | def generate_corpus(n_issuers,
n_tracks_per_issuer,
n_utts_per_track,
n_ll_per_utt,
n_label_per_ll,
rand=None):
"""
Generate a corpus with mock data.
"""
corpus = audiomate.Corpus()
for issuer in gen... | [
"def",
"generate_corpus",
"(",
"n_issuers",
",",
"n_tracks_per_issuer",
",",
"n_utts_per_track",
",",
"n_ll_per_utt",
",",
"n_label_per_ll",
",",
"rand",
"=",
"None",
")",
":",
"corpus",
"=",
"audiomate",
".",
"Corpus",
"(",
")",
"for",
"issuer",
"in",
"genera... | Generate a corpus with mock data. | [
"Generate",
"a",
"corpus",
"with",
"mock",
"data",
"."
] | 61727920b23a708293c3d526fa3000d4de9c6c21 | https://github.com/ynop/audiomate/blob/61727920b23a708293c3d526fa3000d4de9c6c21/bench/resources/__init__.py#L9-L40 | train |
ynop/audiomate | audiomate/corpus/io/speech_commands.py | SpeechCommandsReader._create_subviews | def _create_subviews(path, corpus):
""" Load the subviews based on testing_list.txt and validation_list.txt """
test_list_path = os.path.join(path, 'testing_list.txt')
dev_list_path = os.path.join(path, 'validation_list.txt')
test_list = textfile.read_separated_lines(test_list_path, sep... | python | def _create_subviews(path, corpus):
""" Load the subviews based on testing_list.txt and validation_list.txt """
test_list_path = os.path.join(path, 'testing_list.txt')
dev_list_path = os.path.join(path, 'validation_list.txt')
test_list = textfile.read_separated_lines(test_list_path, sep... | [
"def",
"_create_subviews",
"(",
"path",
",",
"corpus",
")",
":",
"test_list_path",
"=",
"os",
".",
"path",
".",
"join",
"(",
"path",
",",
"'testing_list.txt'",
")",
"dev_list_path",
"=",
"os",
".",
"path",
".",
"join",
"(",
"path",
",",
"'validation_list.t... | Load the subviews based on testing_list.txt and validation_list.txt | [
"Load",
"the",
"subviews",
"based",
"on",
"testing_list",
".",
"txt",
"and",
"validation_list",
".",
"txt"
] | 61727920b23a708293c3d526fa3000d4de9c6c21 | https://github.com/ynop/audiomate/blob/61727920b23a708293c3d526fa3000d4de9c6c21/audiomate/corpus/io/speech_commands.py#L64-L86 | train |
ynop/audiomate | audiomate/formats/audacity.py | write_label_list | def write_label_list(path, label_list):
"""
Writes the given `label_list` to an audacity label file.
Args:
path (str): Path to write the file to.
label_list (audiomate.annotations.LabelList): Label list
"""
entries = []
for label in label_list:
entries.append([label.star... | python | def write_label_list(path, label_list):
"""
Writes the given `label_list` to an audacity label file.
Args:
path (str): Path to write the file to.
label_list (audiomate.annotations.LabelList): Label list
"""
entries = []
for label in label_list:
entries.append([label.star... | [
"def",
"write_label_list",
"(",
"path",
",",
"label_list",
")",
":",
"entries",
"=",
"[",
"]",
"for",
"label",
"in",
"label_list",
":",
"entries",
".",
"append",
"(",
"[",
"label",
".",
"start",
",",
"label",
".",
"end",
",",
"label",
".",
"value",
"... | Writes the given `label_list` to an audacity label file.
Args:
path (str): Path to write the file to.
label_list (audiomate.annotations.LabelList): Label list | [
"Writes",
"the",
"given",
"label_list",
"to",
"an",
"audacity",
"label",
"file",
"."
] | 61727920b23a708293c3d526fa3000d4de9c6c21 | https://github.com/ynop/audiomate/blob/61727920b23a708293c3d526fa3000d4de9c6c21/audiomate/formats/audacity.py#L30-L42 | train |
ynop/audiomate | audiomate/formats/audacity.py | read_label_file | def read_label_file(path):
"""
Read the labels from an audacity label file.
Args:
path (str): Path to the label file.
Returns:
list: List of labels (start [sec], end [sec], label)
Example::
>>> read_label_file('/path/to/label/file.txt')
[
[0.0, 0.2, 's... | python | def read_label_file(path):
"""
Read the labels from an audacity label file.
Args:
path (str): Path to the label file.
Returns:
list: List of labels (start [sec], end [sec], label)
Example::
>>> read_label_file('/path/to/label/file.txt')
[
[0.0, 0.2, 's... | [
"def",
"read_label_file",
"(",
"path",
")",
":",
"labels",
"=",
"[",
"]",
"for",
"record",
"in",
"textfile",
".",
"read_separated_lines_generator",
"(",
"path",
",",
"separator",
"=",
"'\\t'",
",",
"max_columns",
"=",
"3",
")",
":",
"value",
"=",
"''",
"... | Read the labels from an audacity label file.
Args:
path (str): Path to the label file.
Returns:
list: List of labels (start [sec], end [sec], label)
Example::
>>> read_label_file('/path/to/label/file.txt')
[
[0.0, 0.2, 'sie'],
[0.2, 2.2, 'hallo']
... | [
"Read",
"the",
"labels",
"from",
"an",
"audacity",
"label",
"file",
"."
] | 61727920b23a708293c3d526fa3000d4de9c6c21 | https://github.com/ynop/audiomate/blob/61727920b23a708293c3d526fa3000d4de9c6c21/audiomate/formats/audacity.py#L45-L73 | train |
ynop/audiomate | audiomate/utils/download.py | extract_zip | def extract_zip(zip_path, target_folder):
"""
Extract the content of the zip-file at `zip_path` into `target_folder`.
"""
with zipfile.ZipFile(zip_path) as archive:
archive.extractall(target_folder) | python | def extract_zip(zip_path, target_folder):
"""
Extract the content of the zip-file at `zip_path` into `target_folder`.
"""
with zipfile.ZipFile(zip_path) as archive:
archive.extractall(target_folder) | [
"def",
"extract_zip",
"(",
"zip_path",
",",
"target_folder",
")",
":",
"with",
"zipfile",
".",
"ZipFile",
"(",
"zip_path",
")",
"as",
"archive",
":",
"archive",
".",
"extractall",
"(",
"target_folder",
")"
] | Extract the content of the zip-file at `zip_path` into `target_folder`. | [
"Extract",
"the",
"content",
"of",
"the",
"zip",
"-",
"file",
"at",
"zip_path",
"into",
"target_folder",
"."
] | 61727920b23a708293c3d526fa3000d4de9c6c21 | https://github.com/ynop/audiomate/blob/61727920b23a708293c3d526fa3000d4de9c6c21/audiomate/utils/download.py#L23-L28 | train |
ynop/audiomate | audiomate/utils/download.py | extract_tar | def extract_tar(tar_path, target_folder):
"""
Extract the content of the tar-file at `tar_path` into `target_folder`.
"""
with tarfile.open(tar_path, 'r') as archive:
archive.extractall(target_folder) | python | def extract_tar(tar_path, target_folder):
"""
Extract the content of the tar-file at `tar_path` into `target_folder`.
"""
with tarfile.open(tar_path, 'r') as archive:
archive.extractall(target_folder) | [
"def",
"extract_tar",
"(",
"tar_path",
",",
"target_folder",
")",
":",
"with",
"tarfile",
".",
"open",
"(",
"tar_path",
",",
"'r'",
")",
"as",
"archive",
":",
"archive",
".",
"extractall",
"(",
"target_folder",
")"
] | Extract the content of the tar-file at `tar_path` into `target_folder`. | [
"Extract",
"the",
"content",
"of",
"the",
"tar",
"-",
"file",
"at",
"tar_path",
"into",
"target_folder",
"."
] | 61727920b23a708293c3d526fa3000d4de9c6c21 | https://github.com/ynop/audiomate/blob/61727920b23a708293c3d526fa3000d4de9c6c21/audiomate/utils/download.py#L31-L36 | train |
ynop/audiomate | audiomate/utils/textfile.py | read_separated_lines | def read_separated_lines(path, separator=' ', max_columns=-1, keep_empty=False):
"""
Reads a text file where each line represents a record with some separated columns.
Parameters:
path (str): Path to the file to read.
separator (str): Separator that is used to split the columns.
max... | python | def read_separated_lines(path, separator=' ', max_columns=-1, keep_empty=False):
"""
Reads a text file where each line represents a record with some separated columns.
Parameters:
path (str): Path to the file to read.
separator (str): Separator that is used to split the columns.
max... | [
"def",
"read_separated_lines",
"(",
"path",
",",
"separator",
"=",
"' '",
",",
"max_columns",
"=",
"-",
"1",
",",
"keep_empty",
"=",
"False",
")",
":",
"gen",
"=",
"read_separated_lines_generator",
"(",
"path",
",",
"separator",
",",
"max_columns",
",",
"kee... | Reads a text file where each line represents a record with some separated columns.
Parameters:
path (str): Path to the file to read.
separator (str): Separator that is used to split the columns.
max_columns (int): Number of max columns (if the separator occurs within the last column).
... | [
"Reads",
"a",
"text",
"file",
"where",
"each",
"line",
"represents",
"a",
"record",
"with",
"some",
"separated",
"columns",
"."
] | 61727920b23a708293c3d526fa3000d4de9c6c21 | https://github.com/ynop/audiomate/blob/61727920b23a708293c3d526fa3000d4de9c6c21/audiomate/utils/textfile.py#L10-L25 | train |
ynop/audiomate | audiomate/utils/textfile.py | read_separated_lines_with_first_key | def read_separated_lines_with_first_key(path: str, separator: str = ' ', max_columns: int = -1,
keep_empty: bool = False):
"""
Reads the separated lines of a file and return a dictionary with the first column as keys, value
is a list with the rest of the columns.
... | python | def read_separated_lines_with_first_key(path: str, separator: str = ' ', max_columns: int = -1,
keep_empty: bool = False):
"""
Reads the separated lines of a file and return a dictionary with the first column as keys, value
is a list with the rest of the columns.
... | [
"def",
"read_separated_lines_with_first_key",
"(",
"path",
":",
"str",
",",
"separator",
":",
"str",
"=",
"' '",
",",
"max_columns",
":",
"int",
"=",
"-",
"1",
",",
"keep_empty",
":",
"bool",
"=",
"False",
")",
":",
"gen",
"=",
"read_separated_lines_generato... | Reads the separated lines of a file and return a dictionary with the first column as keys, value
is a list with the rest of the columns.
Parameters:
path (str): Path to the file to read.
separator (str): Separator that is used to split the columns.
max_columns (str): Number of max colum... | [
"Reads",
"the",
"separated",
"lines",
"of",
"a",
"file",
"and",
"return",
"a",
"dictionary",
"with",
"the",
"first",
"column",
"as",
"keys",
"value",
"is",
"a",
"list",
"with",
"the",
"rest",
"of",
"the",
"columns",
"."
] | 61727920b23a708293c3d526fa3000d4de9c6c21 | https://github.com/ynop/audiomate/blob/61727920b23a708293c3d526fa3000d4de9c6c21/audiomate/utils/textfile.py#L28-L51 | train |
ynop/audiomate | audiomate/utils/textfile.py | write_separated_lines | def write_separated_lines(path, values, separator=' ', sort_by_column=0):
"""
Writes list or dict to file line by line. Dict can have list as value then they written
separated on the line.
Parameters:
path (str): Path to write file to.
values (dict, list): A dictionary or a list to writ... | python | def write_separated_lines(path, values, separator=' ', sort_by_column=0):
"""
Writes list or dict to file line by line. Dict can have list as value then they written
separated on the line.
Parameters:
path (str): Path to write file to.
values (dict, list): A dictionary or a list to writ... | [
"def",
"write_separated_lines",
"(",
"path",
",",
"values",
",",
"separator",
"=",
"' '",
",",
"sort_by_column",
"=",
"0",
")",
":",
"f",
"=",
"open",
"(",
"path",
",",
"'w'",
",",
"encoding",
"=",
"'utf-8'",
")",
"if",
"type",
"(",
"values",
")",
"i... | Writes list or dict to file line by line. Dict can have list as value then they written
separated on the line.
Parameters:
path (str): Path to write file to.
values (dict, list): A dictionary or a list to write to the file.
separator (str): Separator to use between columns.
sort... | [
"Writes",
"list",
"or",
"dict",
"to",
"file",
"line",
"by",
"line",
".",
"Dict",
"can",
"have",
"list",
"as",
"value",
"then",
"they",
"written",
"separated",
"on",
"the",
"line",
"."
] | 61727920b23a708293c3d526fa3000d4de9c6c21 | https://github.com/ynop/audiomate/blob/61727920b23a708293c3d526fa3000d4de9c6c21/audiomate/utils/textfile.py#L79-L116 | train |
ynop/audiomate | audiomate/utils/textfile.py | read_separated_lines_generator | def read_separated_lines_generator(path, separator=' ', max_columns=-1,
ignore_lines_starting_with=[], keep_empty=False):
"""
Creates a generator through all lines of a file and returns the splitted line.
Parameters:
path: Path to the file.
separator: Sepa... | python | def read_separated_lines_generator(path, separator=' ', max_columns=-1,
ignore_lines_starting_with=[], keep_empty=False):
"""
Creates a generator through all lines of a file and returns the splitted line.
Parameters:
path: Path to the file.
separator: Sepa... | [
"def",
"read_separated_lines_generator",
"(",
"path",
",",
"separator",
"=",
"' '",
",",
"max_columns",
"=",
"-",
"1",
",",
"ignore_lines_starting_with",
"=",
"[",
"]",
",",
"keep_empty",
"=",
"False",
")",
":",
"if",
"not",
"os",
".",
"path",
".",
"isfile... | Creates a generator through all lines of a file and returns the splitted line.
Parameters:
path: Path to the file.
separator: Separator that is used to split the columns.
max_columns: Number of max columns (if the separator occurs within the last column).
ignore_lines_starting_with:... | [
"Creates",
"a",
"generator",
"through",
"all",
"lines",
"of",
"a",
"file",
"and",
"returns",
"the",
"splitted",
"line",
"."
] | 61727920b23a708293c3d526fa3000d4de9c6c21 | https://github.com/ynop/audiomate/blob/61727920b23a708293c3d526fa3000d4de9c6c21/audiomate/utils/textfile.py#L119-L155 | train |
MichaelSolati/typeform-python-sdk | typeform/forms.py | Forms.update | def update(self, uid: str, patch=False, data: any = {}) -> typing.Union[str, dict]:
"""
Updates an existing form.
Defaults to `put`.
`put` will return the modified form as a `dict` object.
`patch` will return a `str` based on success of change, `OK` on success, otherwise an error... | python | def update(self, uid: str, patch=False, data: any = {}) -> typing.Union[str, dict]:
"""
Updates an existing form.
Defaults to `put`.
`put` will return the modified form as a `dict` object.
`patch` will return a `str` based on success of change, `OK` on success, otherwise an error... | [
"def",
"update",
"(",
"self",
",",
"uid",
":",
"str",
",",
"patch",
"=",
"False",
",",
"data",
":",
"any",
"=",
"{",
"}",
")",
"->",
"typing",
".",
"Union",
"[",
"str",
",",
"dict",
"]",
":",
"methodType",
"=",
"'put'",
"if",
"patch",
"is",
"Fa... | Updates an existing form.
Defaults to `put`.
`put` will return the modified form as a `dict` object.
`patch` will return a `str` based on success of change, `OK` on success, otherwise an error message. | [
"Updates",
"an",
"existing",
"form",
".",
"Defaults",
"to",
"put",
".",
"put",
"will",
"return",
"the",
"modified",
"form",
"as",
"a",
"dict",
"object",
".",
"patch",
"will",
"return",
"a",
"str",
"based",
"on",
"success",
"of",
"change",
"OK",
"on",
"... | 04e999be448e3226df73f238fe127385e43b1e98 | https://github.com/MichaelSolati/typeform-python-sdk/blob/04e999be448e3226df73f238fe127385e43b1e98/typeform/forms.py#L43-L51 | train |
noirbizarre/flask-fs | flask_fs/storage.py | Storage.configure | def configure(self, app):
'''
Load configuration from application configuration.
For each storage, the configuration is loaded with the following pattern::
FS_{BACKEND_NAME}_{KEY} then
{STORAGE_NAME}_FS_{KEY}
If no configuration is set for a given key, global c... | python | def configure(self, app):
'''
Load configuration from application configuration.
For each storage, the configuration is loaded with the following pattern::
FS_{BACKEND_NAME}_{KEY} then
{STORAGE_NAME}_FS_{KEY}
If no configuration is set for a given key, global c... | [
"def",
"configure",
"(",
"self",
",",
"app",
")",
":",
"config",
"=",
"Config",
"(",
")",
"prefix",
"=",
"PREFIX",
".",
"format",
"(",
"self",
".",
"name",
".",
"upper",
"(",
")",
")",
"backend_key",
"=",
"'{0}BACKEND'",
".",
"format",
"(",
"prefix",... | Load configuration from application configuration.
For each storage, the configuration is loaded with the following pattern::
FS_{BACKEND_NAME}_{KEY} then
{STORAGE_NAME}_FS_{KEY}
If no configuration is set for a given key, global config is taken as default. | [
"Load",
"configuration",
"from",
"application",
"configuration",
"."
] | 092e9327384b8411c9bb38ca257ecb558584d201 | https://github.com/noirbizarre/flask-fs/blob/092e9327384b8411c9bb38ca257ecb558584d201/flask_fs/storage.py#L87-L125 | train |
noirbizarre/flask-fs | flask_fs/storage.py | Storage.base_url | def base_url(self):
'''The public URL for this storage'''
config_value = self.config.get('url')
if config_value:
return self._clean_url(config_value)
default_url = current_app.config.get('FS_URL')
default_url = current_app.config.get('{0}URL'.format(self.backend_prefi... | python | def base_url(self):
'''The public URL for this storage'''
config_value = self.config.get('url')
if config_value:
return self._clean_url(config_value)
default_url = current_app.config.get('FS_URL')
default_url = current_app.config.get('{0}URL'.format(self.backend_prefi... | [
"def",
"base_url",
"(",
"self",
")",
":",
"config_value",
"=",
"self",
".",
"config",
".",
"get",
"(",
"'url'",
")",
"if",
"config_value",
":",
"return",
"self",
".",
"_clean_url",
"(",
"config_value",
")",
"default_url",
"=",
"current_app",
".",
"config",... | The public URL for this storage | [
"The",
"public",
"URL",
"for",
"this",
"storage"
] | 092e9327384b8411c9bb38ca257ecb558584d201 | https://github.com/noirbizarre/flask-fs/blob/092e9327384b8411c9bb38ca257ecb558584d201/flask_fs/storage.py#L132-L142 | train |
noirbizarre/flask-fs | flask_fs/storage.py | Storage.url | def url(self, filename, external=False):
'''
This function gets the URL a file uploaded to this set would be
accessed at. It doesn't check whether said file exists.
:param string filename: The filename to return the URL for.
:param bool external: If True, returns an absolute URL... | python | def url(self, filename, external=False):
'''
This function gets the URL a file uploaded to this set would be
accessed at. It doesn't check whether said file exists.
:param string filename: The filename to return the URL for.
:param bool external: If True, returns an absolute URL... | [
"def",
"url",
"(",
"self",
",",
"filename",
",",
"external",
"=",
"False",
")",
":",
"if",
"filename",
".",
"startswith",
"(",
"'/'",
")",
":",
"filename",
"=",
"filename",
"[",
"1",
":",
"]",
"if",
"self",
".",
"has_url",
":",
"return",
"self",
".... | This function gets the URL a file uploaded to this set would be
accessed at. It doesn't check whether said file exists.
:param string filename: The filename to return the URL for.
:param bool external: If True, returns an absolute URL | [
"This",
"function",
"gets",
"the",
"URL",
"a",
"file",
"uploaded",
"to",
"this",
"set",
"would",
"be",
"accessed",
"at",
".",
"It",
"doesn",
"t",
"check",
"whether",
"said",
"file",
"exists",
"."
] | 092e9327384b8411c9bb38ca257ecb558584d201 | https://github.com/noirbizarre/flask-fs/blob/092e9327384b8411c9bb38ca257ecb558584d201/flask_fs/storage.py#L156-L169 | train |
noirbizarre/flask-fs | flask_fs/storage.py | Storage.path | def path(self, filename):
'''
This returns the absolute path of a file uploaded to this set. It
doesn't actually check whether said file exists.
:param filename: The filename to return the path for.
:param folder: The subfolder within the upload set previously used
... | python | def path(self, filename):
'''
This returns the absolute path of a file uploaded to this set. It
doesn't actually check whether said file exists.
:param filename: The filename to return the path for.
:param folder: The subfolder within the upload set previously used
... | [
"def",
"path",
"(",
"self",
",",
"filename",
")",
":",
"if",
"not",
"self",
".",
"backend",
".",
"root",
":",
"raise",
"OperationNotSupported",
"(",
"'Direct file access is not supported by '",
"+",
"self",
".",
"backend",
".",
"__class__",
".",
"__name__",
")... | This returns the absolute path of a file uploaded to this set. It
doesn't actually check whether said file exists.
:param filename: The filename to return the path for.
:param folder: The subfolder within the upload set previously used
to save to.
:raises Operati... | [
"This",
"returns",
"the",
"absolute",
"path",
"of",
"a",
"file",
"uploaded",
"to",
"this",
"set",
".",
"It",
"doesn",
"t",
"actually",
"check",
"whether",
"said",
"file",
"exists",
"."
] | 092e9327384b8411c9bb38ca257ecb558584d201 | https://github.com/noirbizarre/flask-fs/blob/092e9327384b8411c9bb38ca257ecb558584d201/flask_fs/storage.py#L171-L187 | train |
noirbizarre/flask-fs | flask_fs/storage.py | Storage.read | def read(self, filename):
'''
Read a file content.
:param string filename: The storage root-relative filename
:raises FileNotFound: If the file does not exists
'''
if not self.backend.exists(filename):
raise FileNotFound(filename)
return self.backend.... | python | def read(self, filename):
'''
Read a file content.
:param string filename: The storage root-relative filename
:raises FileNotFound: If the file does not exists
'''
if not self.backend.exists(filename):
raise FileNotFound(filename)
return self.backend.... | [
"def",
"read",
"(",
"self",
",",
"filename",
")",
":",
"if",
"not",
"self",
".",
"backend",
".",
"exists",
"(",
"filename",
")",
":",
"raise",
"FileNotFound",
"(",
"filename",
")",
"return",
"self",
".",
"backend",
".",
"read",
"(",
"filename",
")"
] | Read a file content.
:param string filename: The storage root-relative filename
:raises FileNotFound: If the file does not exists | [
"Read",
"a",
"file",
"content",
"."
] | 092e9327384b8411c9bb38ca257ecb558584d201 | https://github.com/noirbizarre/flask-fs/blob/092e9327384b8411c9bb38ca257ecb558584d201/flask_fs/storage.py#L220-L229 | train |
noirbizarre/flask-fs | flask_fs/storage.py | Storage.open | def open(self, filename, mode='r', **kwargs):
'''
Open the file and return a file-like object.
:param str filename: The storage root-relative filename
:param str mode: The open mode (``(r|w)b?``)
:raises FileNotFound: If trying to read a file that does not exists
'''
... | python | def open(self, filename, mode='r', **kwargs):
'''
Open the file and return a file-like object.
:param str filename: The storage root-relative filename
:param str mode: The open mode (``(r|w)b?``)
:raises FileNotFound: If trying to read a file that does not exists
'''
... | [
"def",
"open",
"(",
"self",
",",
"filename",
",",
"mode",
"=",
"'r'",
",",
"**",
"kwargs",
")",
":",
"if",
"'r'",
"in",
"mode",
"and",
"not",
"self",
".",
"backend",
".",
"exists",
"(",
"filename",
")",
":",
"raise",
"FileNotFound",
"(",
"filename",
... | Open the file and return a file-like object.
:param str filename: The storage root-relative filename
:param str mode: The open mode (``(r|w)b?``)
:raises FileNotFound: If trying to read a file that does not exists | [
"Open",
"the",
"file",
"and",
"return",
"a",
"file",
"-",
"like",
"object",
"."
] | 092e9327384b8411c9bb38ca257ecb558584d201 | https://github.com/noirbizarre/flask-fs/blob/092e9327384b8411c9bb38ca257ecb558584d201/flask_fs/storage.py#L231-L241 | train |
noirbizarre/flask-fs | flask_fs/storage.py | Storage.write | def write(self, filename, content, overwrite=False):
'''
Write content to a file.
:param str filename: The storage root-relative filename
:param content: The content to write in the file
:param bool overwrite: Whether to wllow overwrite or not
:raises FileExists: If the ... | python | def write(self, filename, content, overwrite=False):
'''
Write content to a file.
:param str filename: The storage root-relative filename
:param content: The content to write in the file
:param bool overwrite: Whether to wllow overwrite or not
:raises FileExists: If the ... | [
"def",
"write",
"(",
"self",
",",
"filename",
",",
"content",
",",
"overwrite",
"=",
"False",
")",
":",
"if",
"not",
"self",
".",
"overwrite",
"and",
"not",
"overwrite",
"and",
"self",
".",
"backend",
".",
"exists",
"(",
"filename",
")",
":",
"raise",
... | Write content to a file.
:param str filename: The storage root-relative filename
:param content: The content to write in the file
:param bool overwrite: Whether to wllow overwrite or not
:raises FileExists: If the file exists and `overwrite` is `False` | [
"Write",
"content",
"to",
"a",
"file",
"."
] | 092e9327384b8411c9bb38ca257ecb558584d201 | https://github.com/noirbizarre/flask-fs/blob/092e9327384b8411c9bb38ca257ecb558584d201/flask_fs/storage.py#L243-L254 | train |
noirbizarre/flask-fs | flask_fs/storage.py | Storage.metadata | def metadata(self, filename):
'''
Get some metadata for a given file.
Can vary from a backend to another but some are always present:
- `filename`: the base filename (without the path/prefix)
- `url`: the file public URL
- `checksum`: a checksum expressed in the form `al... | python | def metadata(self, filename):
'''
Get some metadata for a given file.
Can vary from a backend to another but some are always present:
- `filename`: the base filename (without the path/prefix)
- `url`: the file public URL
- `checksum`: a checksum expressed in the form `al... | [
"def",
"metadata",
"(",
"self",
",",
"filename",
")",
":",
"metadata",
"=",
"self",
".",
"backend",
".",
"metadata",
"(",
"filename",
")",
"metadata",
"[",
"'filename'",
"]",
"=",
"os",
".",
"path",
".",
"basename",
"(",
"filename",
")",
"metadata",
"[... | Get some metadata for a given file.
Can vary from a backend to another but some are always present:
- `filename`: the base filename (without the path/prefix)
- `url`: the file public URL
- `checksum`: a checksum expressed in the form `algo:hash`
- 'mime': the mime type
-... | [
"Get",
"some",
"metadata",
"for",
"a",
"given",
"file",
"."
] | 092e9327384b8411c9bb38ca257ecb558584d201 | https://github.com/noirbizarre/flask-fs/blob/092e9327384b8411c9bb38ca257ecb558584d201/flask_fs/storage.py#L310-L324 | train |
noirbizarre/flask-fs | flask_fs/storage.py | Storage.serve | def serve(self, filename):
'''Serve a file given its filename'''
if not self.exists(filename):
abort(404)
return self.backend.serve(filename) | python | def serve(self, filename):
'''Serve a file given its filename'''
if not self.exists(filename):
abort(404)
return self.backend.serve(filename) | [
"def",
"serve",
"(",
"self",
",",
"filename",
")",
":",
"if",
"not",
"self",
".",
"exists",
"(",
"filename",
")",
":",
"abort",
"(",
"404",
")",
"return",
"self",
".",
"backend",
".",
"serve",
"(",
"filename",
")"
] | Serve a file given its filename | [
"Serve",
"a",
"file",
"given",
"its",
"filename"
] | 092e9327384b8411c9bb38ca257ecb558584d201 | https://github.com/noirbizarre/flask-fs/blob/092e9327384b8411c9bb38ca257ecb558584d201/flask_fs/storage.py#L350-L354 | train |
noirbizarre/flask-fs | flask_fs/images.py | make_thumbnail | def make_thumbnail(file, size, bbox=None):
'''
Generate a thumbnail for a given image file.
:param file file: The source image file to thumbnail
:param int size: The thumbnail size in pixels (Thumbnails are squares)
:param tuple bbox: An optionnal Bounding box definition for the thumbnail
'''
... | python | def make_thumbnail(file, size, bbox=None):
'''
Generate a thumbnail for a given image file.
:param file file: The source image file to thumbnail
:param int size: The thumbnail size in pixels (Thumbnails are squares)
:param tuple bbox: An optionnal Bounding box definition for the thumbnail
'''
... | [
"def",
"make_thumbnail",
"(",
"file",
",",
"size",
",",
"bbox",
"=",
"None",
")",
":",
"image",
"=",
"Image",
".",
"open",
"(",
"file",
")",
"if",
"bbox",
":",
"thumbnail",
"=",
"crop_thumbnail",
"(",
"image",
",",
"size",
",",
"bbox",
")",
"else",
... | Generate a thumbnail for a given image file.
:param file file: The source image file to thumbnail
:param int size: The thumbnail size in pixels (Thumbnails are squares)
:param tuple bbox: An optionnal Bounding box definition for the thumbnail | [
"Generate",
"a",
"thumbnail",
"for",
"a",
"given",
"image",
"file",
"."
] | 092e9327384b8411c9bb38ca257ecb558584d201 | https://github.com/noirbizarre/flask-fs/blob/092e9327384b8411c9bb38ca257ecb558584d201/flask_fs/images.py#L16-L29 | train |
noirbizarre/flask-fs | setup.py | pip | def pip(filename):
"""Parse pip reqs file and transform it to setuptools requirements."""
requirements = []
for line in open(join(ROOT, 'requirements', filename)):
line = line.strip()
if not line or '://' in line:
continue
match = RE_REQUIREMENT.match(line)
if mat... | python | def pip(filename):
"""Parse pip reqs file and transform it to setuptools requirements."""
requirements = []
for line in open(join(ROOT, 'requirements', filename)):
line = line.strip()
if not line or '://' in line:
continue
match = RE_REQUIREMENT.match(line)
if mat... | [
"def",
"pip",
"(",
"filename",
")",
":",
"requirements",
"=",
"[",
"]",
"for",
"line",
"in",
"open",
"(",
"join",
"(",
"ROOT",
",",
"'requirements'",
",",
"filename",
")",
")",
":",
"line",
"=",
"line",
".",
"strip",
"(",
")",
"if",
"not",
"line",
... | Parse pip reqs file and transform it to setuptools requirements. | [
"Parse",
"pip",
"reqs",
"file",
"and",
"transform",
"it",
"to",
"setuptools",
"requirements",
"."
] | 092e9327384b8411c9bb38ca257ecb558584d201 | https://github.com/noirbizarre/flask-fs/blob/092e9327384b8411c9bb38ca257ecb558584d201/setup.py#L16-L28 | train |
noirbizarre/flask-fs | flask_fs/backends/__init__.py | BaseBackend.move | def move(self, filename, target):
'''
Move a file given its filename to another path in the storage
Default implementation perform a copy then a delete.
Backends should overwrite it if there is a better way.
'''
self.copy(filename, target)
self.delete(filename) | python | def move(self, filename, target):
'''
Move a file given its filename to another path in the storage
Default implementation perform a copy then a delete.
Backends should overwrite it if there is a better way.
'''
self.copy(filename, target)
self.delete(filename) | [
"def",
"move",
"(",
"self",
",",
"filename",
",",
"target",
")",
":",
"self",
".",
"copy",
"(",
"filename",
",",
"target",
")",
"self",
".",
"delete",
"(",
"filename",
")"
] | Move a file given its filename to another path in the storage
Default implementation perform a copy then a delete.
Backends should overwrite it if there is a better way. | [
"Move",
"a",
"file",
"given",
"its",
"filename",
"to",
"another",
"path",
"in",
"the",
"storage"
] | 092e9327384b8411c9bb38ca257ecb558584d201 | https://github.com/noirbizarre/flask-fs/blob/092e9327384b8411c9bb38ca257ecb558584d201/flask_fs/backends/__init__.py#L49-L57 | train |
noirbizarre/flask-fs | flask_fs/backends/__init__.py | BaseBackend.save | def save(self, file_or_wfs, filename, overwrite=False):
'''
Save a file-like object or a `werkzeug.FileStorage` with the specified filename.
:param storage: The file or the storage to be saved.
:param filename: The destination in the storage.
:param overwrite: if `False`, raise ... | python | def save(self, file_or_wfs, filename, overwrite=False):
'''
Save a file-like object or a `werkzeug.FileStorage` with the specified filename.
:param storage: The file or the storage to be saved.
:param filename: The destination in the storage.
:param overwrite: if `False`, raise ... | [
"def",
"save",
"(",
"self",
",",
"file_or_wfs",
",",
"filename",
",",
"overwrite",
"=",
"False",
")",
":",
"self",
".",
"write",
"(",
"filename",
",",
"file_or_wfs",
".",
"read",
"(",
")",
")",
"return",
"filename"
] | Save a file-like object or a `werkzeug.FileStorage` with the specified filename.
:param storage: The file or the storage to be saved.
:param filename: The destination in the storage.
:param overwrite: if `False`, raise an exception if file exists in storage
:raises FileExists: when fil... | [
"Save",
"a",
"file",
"-",
"like",
"object",
"or",
"a",
"werkzeug",
".",
"FileStorage",
"with",
"the",
"specified",
"filename",
"."
] | 092e9327384b8411c9bb38ca257ecb558584d201 | https://github.com/noirbizarre/flask-fs/blob/092e9327384b8411c9bb38ca257ecb558584d201/flask_fs/backends/__init__.py#L59-L70 | train |
noirbizarre/flask-fs | flask_fs/backends/__init__.py | BaseBackend.metadata | def metadata(self, filename):
'''
Fetch all available metadata for a given file
'''
meta = self.get_metadata(filename)
# Fix backend mime misdetection
meta['mime'] = meta.get('mime') or files.mime(filename, self.DEFAULT_MIME)
return meta | python | def metadata(self, filename):
'''
Fetch all available metadata for a given file
'''
meta = self.get_metadata(filename)
# Fix backend mime misdetection
meta['mime'] = meta.get('mime') or files.mime(filename, self.DEFAULT_MIME)
return meta | [
"def",
"metadata",
"(",
"self",
",",
"filename",
")",
":",
"meta",
"=",
"self",
".",
"get_metadata",
"(",
"filename",
")",
"meta",
"[",
"'mime'",
"]",
"=",
"meta",
".",
"get",
"(",
"'mime'",
")",
"or",
"files",
".",
"mime",
"(",
"filename",
",",
"s... | Fetch all available metadata for a given file | [
"Fetch",
"all",
"available",
"metadata",
"for",
"a",
"given",
"file"
] | 092e9327384b8411c9bb38ca257ecb558584d201 | https://github.com/noirbizarre/flask-fs/blob/092e9327384b8411c9bb38ca257ecb558584d201/flask_fs/backends/__init__.py#L72-L79 | train |
noirbizarre/flask-fs | flask_fs/backends/__init__.py | BaseBackend.as_binary | def as_binary(self, content, encoding='utf8'):
'''Perform content encoding for binary write'''
if hasattr(content, 'read'):
return content.read()
elif isinstance(content, six.text_type):
return content.encode(encoding)
else:
return content | python | def as_binary(self, content, encoding='utf8'):
'''Perform content encoding for binary write'''
if hasattr(content, 'read'):
return content.read()
elif isinstance(content, six.text_type):
return content.encode(encoding)
else:
return content | [
"def",
"as_binary",
"(",
"self",
",",
"content",
",",
"encoding",
"=",
"'utf8'",
")",
":",
"if",
"hasattr",
"(",
"content",
",",
"'read'",
")",
":",
"return",
"content",
".",
"read",
"(",
")",
"elif",
"isinstance",
"(",
"content",
",",
"six",
".",
"t... | Perform content encoding for binary write | [
"Perform",
"content",
"encoding",
"for",
"binary",
"write"
] | 092e9327384b8411c9bb38ca257ecb558584d201 | https://github.com/noirbizarre/flask-fs/blob/092e9327384b8411c9bb38ca257ecb558584d201/flask_fs/backends/__init__.py#L91-L98 | train |
noirbizarre/flask-fs | flask_fs/backends/s3.py | S3Backend.get_metadata | def get_metadata(self, filename):
'''Fetch all availabe metadata'''
obj = self.bucket.Object(filename)
checksum = 'md5:{0}'.format(obj.e_tag[1:-1])
mime = obj.content_type.split(';', 1)[0] if obj.content_type else None
return {
'checksum': checksum,
'size'... | python | def get_metadata(self, filename):
'''Fetch all availabe metadata'''
obj = self.bucket.Object(filename)
checksum = 'md5:{0}'.format(obj.e_tag[1:-1])
mime = obj.content_type.split(';', 1)[0] if obj.content_type else None
return {
'checksum': checksum,
'size'... | [
"def",
"get_metadata",
"(",
"self",
",",
"filename",
")",
":",
"obj",
"=",
"self",
".",
"bucket",
".",
"Object",
"(",
"filename",
")",
"checksum",
"=",
"'md5:{0}'",
".",
"format",
"(",
"obj",
".",
"e_tag",
"[",
"1",
":",
"-",
"1",
"]",
")",
"mime",... | Fetch all availabe metadata | [
"Fetch",
"all",
"availabe",
"metadata"
] | 092e9327384b8411c9bb38ca257ecb558584d201 | https://github.com/noirbizarre/flask-fs/blob/092e9327384b8411c9bb38ca257ecb558584d201/flask_fs/backends/s3.py#L89-L99 | train |
noirbizarre/flask-fs | flask_fs/mongo.py | ImageReference.thumbnail | def thumbnail(self, size):
'''Get the thumbnail filename for a given size'''
if size in self.thumbnail_sizes:
return self.thumbnails.get(str(size))
else:
raise ValueError('Unregistered thumbnail size {0}'.format(size)) | python | def thumbnail(self, size):
'''Get the thumbnail filename for a given size'''
if size in self.thumbnail_sizes:
return self.thumbnails.get(str(size))
else:
raise ValueError('Unregistered thumbnail size {0}'.format(size)) | [
"def",
"thumbnail",
"(",
"self",
",",
"size",
")",
":",
"if",
"size",
"in",
"self",
".",
"thumbnail_sizes",
":",
"return",
"self",
".",
"thumbnails",
".",
"get",
"(",
"str",
"(",
"size",
")",
")",
"else",
":",
"raise",
"ValueError",
"(",
"'Unregistered... | Get the thumbnail filename for a given size | [
"Get",
"the",
"thumbnail",
"filename",
"for",
"a",
"given",
"size"
] | 092e9327384b8411c9bb38ca257ecb558584d201 | https://github.com/noirbizarre/flask-fs/blob/092e9327384b8411c9bb38ca257ecb558584d201/flask_fs/mongo.py#L163-L168 | train |
noirbizarre/flask-fs | flask_fs/mongo.py | ImageReference.full | def full(self, external=False):
'''Get the full image URL in respect with ``max_size``'''
return self.fs.url(self.filename, external=external) if self.filename else None | python | def full(self, external=False):
'''Get the full image URL in respect with ``max_size``'''
return self.fs.url(self.filename, external=external) if self.filename else None | [
"def",
"full",
"(",
"self",
",",
"external",
"=",
"False",
")",
":",
"return",
"self",
".",
"fs",
".",
"url",
"(",
"self",
".",
"filename",
",",
"external",
"=",
"external",
")",
"if",
"self",
".",
"filename",
"else",
"None"
] | Get the full image URL in respect with ``max_size`` | [
"Get",
"the",
"full",
"image",
"URL",
"in",
"respect",
"with",
"max_size"
] | 092e9327384b8411c9bb38ca257ecb558584d201 | https://github.com/noirbizarre/flask-fs/blob/092e9327384b8411c9bb38ca257ecb558584d201/flask_fs/mongo.py#L170-L172 | train |
noirbizarre/flask-fs | flask_fs/mongo.py | ImageReference.best_url | def best_url(self, size=None, external=False):
'''
Provide the best thumbnail for downscaling.
If there is no match, provide the bigger if exists or the original
'''
if not self.thumbnail_sizes:
return self.url
elif not size:
self.thumbnail_sizes.... | python | def best_url(self, size=None, external=False):
'''
Provide the best thumbnail for downscaling.
If there is no match, provide the bigger if exists or the original
'''
if not self.thumbnail_sizes:
return self.url
elif not size:
self.thumbnail_sizes.... | [
"def",
"best_url",
"(",
"self",
",",
"size",
"=",
"None",
",",
"external",
"=",
"False",
")",
":",
"if",
"not",
"self",
".",
"thumbnail_sizes",
":",
"return",
"self",
".",
"url",
"elif",
"not",
"size",
":",
"self",
".",
"thumbnail_sizes",
".",
"sort",
... | Provide the best thumbnail for downscaling.
If there is no match, provide the bigger if exists or the original | [
"Provide",
"the",
"best",
"thumbnail",
"for",
"downscaling",
"."
] | 092e9327384b8411c9bb38ca257ecb558584d201 | https://github.com/noirbizarre/flask-fs/blob/092e9327384b8411c9bb38ca257ecb558584d201/flask_fs/mongo.py#L174-L193 | train |
noirbizarre/flask-fs | flask_fs/mongo.py | ImageReference.rerender | def rerender(self):
'''
Rerender all derived images from the original.
If optmization settings or expected sizes changed,
they will be used for the new rendering.
'''
with self.fs.open(self.original, 'rb') as f_img:
img = io.BytesIO(f_img.read()) # Store the ... | python | def rerender(self):
'''
Rerender all derived images from the original.
If optmization settings or expected sizes changed,
they will be used for the new rendering.
'''
with self.fs.open(self.original, 'rb') as f_img:
img = io.BytesIO(f_img.read()) # Store the ... | [
"def",
"rerender",
"(",
"self",
")",
":",
"with",
"self",
".",
"fs",
".",
"open",
"(",
"self",
".",
"original",
",",
"'rb'",
")",
"as",
"f_img",
":",
"img",
"=",
"io",
".",
"BytesIO",
"(",
"f_img",
".",
"read",
"(",
")",
")",
"self",
".",
"save... | Rerender all derived images from the original.
If optmization settings or expected sizes changed,
they will be used for the new rendering. | [
"Rerender",
"all",
"derived",
"images",
"from",
"the",
"original",
".",
"If",
"optmization",
"settings",
"or",
"expected",
"sizes",
"changed",
"they",
"will",
"be",
"used",
"for",
"the",
"new",
"rendering",
"."
] | 092e9327384b8411c9bb38ca257ecb558584d201 | https://github.com/noirbizarre/flask-fs/blob/092e9327384b8411c9bb38ca257ecb558584d201/flask_fs/mongo.py#L195-L203 | train |
noirbizarre/flask-fs | flask_fs/views.py | get_file | def get_file(fs, filename):
'''Serve files for storages with direct file access'''
storage = by_name(fs)
if storage is None:
abort(404)
return storage.serve(filename) | python | def get_file(fs, filename):
'''Serve files for storages with direct file access'''
storage = by_name(fs)
if storage is None:
abort(404)
return storage.serve(filename) | [
"def",
"get_file",
"(",
"fs",
",",
"filename",
")",
":",
"storage",
"=",
"by_name",
"(",
"fs",
")",
"if",
"storage",
"is",
"None",
":",
"abort",
"(",
"404",
")",
"return",
"storage",
".",
"serve",
"(",
"filename",
")"
] | Serve files for storages with direct file access | [
"Serve",
"files",
"for",
"storages",
"with",
"direct",
"file",
"access"
] | 092e9327384b8411c9bb38ca257ecb558584d201 | https://github.com/noirbizarre/flask-fs/blob/092e9327384b8411c9bb38ca257ecb558584d201/flask_fs/views.py#L12-L17 | train |
noirbizarre/flask-fs | flask_fs/__init__.py | init_app | def init_app(app, *storages):
'''
Initialize Storages configuration
Register blueprint if necessary.
:param app: The `~flask.Flask` instance to get the configuration from.
:param storages: A `Storage` instance list to register and configure.
'''
# Set default configuration
app.config.... | python | def init_app(app, *storages):
'''
Initialize Storages configuration
Register blueprint if necessary.
:param app: The `~flask.Flask` instance to get the configuration from.
:param storages: A `Storage` instance list to register and configure.
'''
# Set default configuration
app.config.... | [
"def",
"init_app",
"(",
"app",
",",
"*",
"storages",
")",
":",
"app",
".",
"config",
".",
"setdefault",
"(",
"'FS_SERVE'",
",",
"app",
".",
"config",
".",
"get",
"(",
"'DEBUG'",
",",
"False",
")",
")",
"app",
".",
"config",
".",
"setdefault",
"(",
... | Initialize Storages configuration
Register blueprint if necessary.
:param app: The `~flask.Flask` instance to get the configuration from.
:param storages: A `Storage` instance list to register and configure. | [
"Initialize",
"Storages",
"configuration",
"Register",
"blueprint",
"if",
"necessary",
"."
] | 092e9327384b8411c9bb38ca257ecb558584d201 | https://github.com/noirbizarre/flask-fs/blob/092e9327384b8411c9bb38ca257ecb558584d201/flask_fs/__init__.py#L25-L48 | train |
noirbizarre/flask-fs | flask_fs/backends/local.py | LocalBackend.get_metadata | def get_metadata(self, filename):
'''Fetch all available metadata'''
dest = self.path(filename)
with open(dest, 'rb', buffering=0) as f:
checksum = 'sha1:{0}'.format(sha1(f))
return {
'checksum': checksum,
'size': os.path.getsize(dest),
'mi... | python | def get_metadata(self, filename):
'''Fetch all available metadata'''
dest = self.path(filename)
with open(dest, 'rb', buffering=0) as f:
checksum = 'sha1:{0}'.format(sha1(f))
return {
'checksum': checksum,
'size': os.path.getsize(dest),
'mi... | [
"def",
"get_metadata",
"(",
"self",
",",
"filename",
")",
":",
"dest",
"=",
"self",
".",
"path",
"(",
"filename",
")",
"with",
"open",
"(",
"dest",
",",
"'rb'",
",",
"buffering",
"=",
"0",
")",
"as",
"f",
":",
"checksum",
"=",
"'sha1:{0}'",
".",
"f... | Fetch all available metadata | [
"Fetch",
"all",
"available",
"metadata"
] | 092e9327384b8411c9bb38ca257ecb558584d201 | https://github.com/noirbizarre/flask-fs/blob/092e9327384b8411c9bb38ca257ecb558584d201/flask_fs/backends/local.py#L132-L142 | train |
LogicalDash/LiSE | ELiDE/ELiDE/dummy.py | Dummy.on_touch_move | def on_touch_move(self, touch):
"""Follow the touch"""
if touch is not self._touch:
return False
self.pos = (
touch.x + self.x_down,
touch.y + self.y_down
)
return True | python | def on_touch_move(self, touch):
"""Follow the touch"""
if touch is not self._touch:
return False
self.pos = (
touch.x + self.x_down,
touch.y + self.y_down
)
return True | [
"def",
"on_touch_move",
"(",
"self",
",",
"touch",
")",
":",
"if",
"touch",
"is",
"not",
"self",
".",
"_touch",
":",
"return",
"False",
"self",
".",
"pos",
"=",
"(",
"touch",
".",
"x",
"+",
"self",
".",
"x_down",
",",
"touch",
".",
"y",
"+",
"sel... | Follow the touch | [
"Follow",
"the",
"touch"
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/ELiDE/ELiDE/dummy.py#L75-L83 | train |
LogicalDash/LiSE | LiSE/LiSE/thing.py | Thing.clear | def clear(self):
"""Unset everything."""
for k in list(self.keys()):
if k not in self.extrakeys:
del self[k] | python | def clear(self):
"""Unset everything."""
for k in list(self.keys()):
if k not in self.extrakeys:
del self[k] | [
"def",
"clear",
"(",
"self",
")",
":",
"for",
"k",
"in",
"list",
"(",
"self",
".",
"keys",
"(",
")",
")",
":",
"if",
"k",
"not",
"in",
"self",
".",
"extrakeys",
":",
"del",
"self",
"[",
"k",
"]"
] | Unset everything. | [
"Unset",
"everything",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/LiSE/LiSE/thing.py#L152-L156 | train |
LogicalDash/LiSE | LiSE/LiSE/engine.py | AbstractEngine.loading | def loading(self):
"""Context manager for when you need to instantiate entities upon unpacking"""
if getattr(self, '_initialized', False):
raise ValueError("Already loading")
self._initialized = False
yield
self._initialized = True | python | def loading(self):
"""Context manager for when you need to instantiate entities upon unpacking"""
if getattr(self, '_initialized', False):
raise ValueError("Already loading")
self._initialized = False
yield
self._initialized = True | [
"def",
"loading",
"(",
"self",
")",
":",
"if",
"getattr",
"(",
"self",
",",
"'_initialized'",
",",
"False",
")",
":",
"raise",
"ValueError",
"(",
"\"Already loading\"",
")",
"self",
".",
"_initialized",
"=",
"False",
"yield",
"self",
".",
"_initialized",
"... | Context manager for when you need to instantiate entities upon unpacking | [
"Context",
"manager",
"for",
"when",
"you",
"need",
"to",
"instantiate",
"entities",
"upon",
"unpacking"
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/LiSE/LiSE/engine.py#L164-L170 | train |
LogicalDash/LiSE | LiSE/LiSE/engine.py | AbstractEngine.dice | def dice(self, n, d):
"""Roll ``n`` dice with ``d`` faces, and yield the results.
This is an iterator. You'll get the result of each die in
successon.
"""
for i in range(0, n):
yield self.roll_die(d) | python | def dice(self, n, d):
"""Roll ``n`` dice with ``d`` faces, and yield the results.
This is an iterator. You'll get the result of each die in
successon.
"""
for i in range(0, n):
yield self.roll_die(d) | [
"def",
"dice",
"(",
"self",
",",
"n",
",",
"d",
")",
":",
"for",
"i",
"in",
"range",
"(",
"0",
",",
"n",
")",
":",
"yield",
"self",
".",
"roll_die",
"(",
"d",
")"
] | Roll ``n`` dice with ``d`` faces, and yield the results.
This is an iterator. You'll get the result of each die in
successon. | [
"Roll",
"n",
"dice",
"with",
"d",
"faces",
"and",
"yield",
"the",
"results",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/LiSE/LiSE/engine.py#L413-L421 | train |
LogicalDash/LiSE | LiSE/LiSE/engine.py | AbstractEngine.dice_check | def dice_check(self, n, d, target, comparator='<='):
"""Roll ``n`` dice with ``d`` sides, sum them, and return whether they
are <= ``target``.
If ``comparator`` is provided, use it instead of <=. You may
use a string like '<' or '>='.
"""
from operator import gt, lt, ge... | python | def dice_check(self, n, d, target, comparator='<='):
"""Roll ``n`` dice with ``d`` sides, sum them, and return whether they
are <= ``target``.
If ``comparator`` is provided, use it instead of <=. You may
use a string like '<' or '>='.
"""
from operator import gt, lt, ge... | [
"def",
"dice_check",
"(",
"self",
",",
"n",
",",
"d",
",",
"target",
",",
"comparator",
"=",
"'<='",
")",
":",
"from",
"operator",
"import",
"gt",
",",
"lt",
",",
"ge",
",",
"le",
",",
"eq",
",",
"ne",
"comps",
"=",
"{",
"'>'",
":",
"gt",
",",
... | Roll ``n`` dice with ``d`` sides, sum them, and return whether they
are <= ``target``.
If ``comparator`` is provided, use it instead of <=. You may
use a string like '<' or '>='. | [
"Roll",
"n",
"dice",
"with",
"d",
"sides",
"sum",
"them",
"and",
"return",
"whether",
"they",
"are",
"<",
"=",
"target",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/LiSE/LiSE/engine.py#L423-L446 | train |
LogicalDash/LiSE | LiSE/LiSE/engine.py | AbstractEngine.percent_chance | def percent_chance(self, pct):
"""Given a ``pct``% chance of something happening right now, decide at
random whether it actually happens, and return ``True`` or
``False`` as appropriate.
Values not between 0 and 100 are treated as though they
were 0 or 100, whichever is nearer.
... | python | def percent_chance(self, pct):
"""Given a ``pct``% chance of something happening right now, decide at
random whether it actually happens, and return ``True`` or
``False`` as appropriate.
Values not between 0 and 100 are treated as though they
were 0 or 100, whichever is nearer.
... | [
"def",
"percent_chance",
"(",
"self",
",",
"pct",
")",
":",
"if",
"pct",
"<=",
"0",
":",
"return",
"False",
"if",
"pct",
">=",
"100",
":",
"return",
"True",
"return",
"pct",
"/",
"100",
"<",
"self",
".",
"random",
"(",
")"
] | Given a ``pct``% chance of something happening right now, decide at
random whether it actually happens, and return ``True`` or
``False`` as appropriate.
Values not between 0 and 100 are treated as though they
were 0 or 100, whichever is nearer. | [
"Given",
"a",
"pct",
"%",
"chance",
"of",
"something",
"happening",
"right",
"now",
"decide",
"at",
"random",
"whether",
"it",
"actually",
"happens",
"and",
"return",
"True",
"or",
"False",
"as",
"appropriate",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/LiSE/LiSE/engine.py#L448-L461 | train |
LogicalDash/LiSE | LiSE/LiSE/engine.py | Engine._remember_avatarness | def _remember_avatarness(
self, character, graph, node,
is_avatar=True, branch=None, turn=None,
tick=None
):
"""Use this to record a change in avatarness.
Should be called whenever a node that wasn't an avatar of a
character now is, and whenever a node th... | python | def _remember_avatarness(
self, character, graph, node,
is_avatar=True, branch=None, turn=None,
tick=None
):
"""Use this to record a change in avatarness.
Should be called whenever a node that wasn't an avatar of a
character now is, and whenever a node th... | [
"def",
"_remember_avatarness",
"(",
"self",
",",
"character",
",",
"graph",
",",
"node",
",",
"is_avatar",
"=",
"True",
",",
"branch",
"=",
"None",
",",
"turn",
"=",
"None",
",",
"tick",
"=",
"None",
")",
":",
"branch",
"=",
"branch",
"or",
"self",
"... | Use this to record a change in avatarness.
Should be called whenever a node that wasn't an avatar of a
character now is, and whenever a node that was an avatar of a
character now isn't.
``character`` is the one using the node as an avatar,
``graph`` is the character the node is... | [
"Use",
"this",
"to",
"record",
"a",
"change",
"in",
"avatarness",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/LiSE/LiSE/engine.py#L806-L841 | train |
LogicalDash/LiSE | LiSE/LiSE/engine.py | Engine._init_caches | def _init_caches(self):
from .xcollections import (
StringStore,
FunctionStore,
CharacterMapping,
UniversalMapping
)
from .cache import (
Cache,
NodeContentsCache,
InitializedCache,
EntitylessCache,
... | python | def _init_caches(self):
from .xcollections import (
StringStore,
FunctionStore,
CharacterMapping,
UniversalMapping
)
from .cache import (
Cache,
NodeContentsCache,
InitializedCache,
EntitylessCache,
... | [
"def",
"_init_caches",
"(",
"self",
")",
":",
"from",
".",
"xcollections",
"import",
"(",
"StringStore",
",",
"FunctionStore",
",",
"CharacterMapping",
",",
"UniversalMapping",
")",
"from",
".",
"cache",
"import",
"(",
"Cache",
",",
"NodeContentsCache",
",",
"... | The last turn when the rules engine ran in each branch | [
"The",
"last",
"turn",
"when",
"the",
"rules",
"engine",
"ran",
"in",
"each",
"branch"
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/LiSE/LiSE/engine.py#L843-L919 | train |
LogicalDash/LiSE | LiSE/LiSE/engine.py | Engine.close | def close(self):
"""Commit changes and close the database."""
import sys, os
for store in self.stores:
if hasattr(store, 'save'):
store.save(reimport=False)
path, filename = os.path.split(store._filename)
modname = filename[:-3]
if ... | python | def close(self):
"""Commit changes and close the database."""
import sys, os
for store in self.stores:
if hasattr(store, 'save'):
store.save(reimport=False)
path, filename = os.path.split(store._filename)
modname = filename[:-3]
if ... | [
"def",
"close",
"(",
"self",
")",
":",
"import",
"sys",
",",
"os",
"for",
"store",
"in",
"self",
".",
"stores",
":",
"if",
"hasattr",
"(",
"store",
",",
"'save'",
")",
":",
"store",
".",
"save",
"(",
"reimport",
"=",
"False",
")",
"path",
",",
"f... | Commit changes and close the database. | [
"Commit",
"changes",
"and",
"close",
"the",
"database",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/LiSE/LiSE/engine.py#L1107-L1117 | train |
LogicalDash/LiSE | LiSE/LiSE/engine.py | Engine.advance | def advance(self):
"""Follow the next rule if available.
If we've run out of rules, reset the rules iterator.
"""
try:
return next(self._rules_iter)
except InnerStopIteration:
self._rules_iter = self._follow_rules()
return StopIteration()
... | python | def advance(self):
"""Follow the next rule if available.
If we've run out of rules, reset the rules iterator.
"""
try:
return next(self._rules_iter)
except InnerStopIteration:
self._rules_iter = self._follow_rules()
return StopIteration()
... | [
"def",
"advance",
"(",
"self",
")",
":",
"try",
":",
"return",
"next",
"(",
"self",
".",
"_rules_iter",
")",
"except",
"InnerStopIteration",
":",
"self",
".",
"_rules_iter",
"=",
"self",
".",
"_follow_rules",
"(",
")",
"return",
"StopIteration",
"(",
")",
... | Follow the next rule if available.
If we've run out of rules, reset the rules iterator. | [
"Follow",
"the",
"next",
"rule",
"if",
"available",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/LiSE/LiSE/engine.py#L1395-L1408 | train |
LogicalDash/LiSE | LiSE/LiSE/engine.py | Engine.del_character | def del_character(self, name):
"""Remove the Character from the database entirely.
This also deletes all its history. You'd better be sure.
"""
self.query.del_character(name)
self.del_graph(name)
del self.character[name] | python | def del_character(self, name):
"""Remove the Character from the database entirely.
This also deletes all its history. You'd better be sure.
"""
self.query.del_character(name)
self.del_graph(name)
del self.character[name] | [
"def",
"del_character",
"(",
"self",
",",
"name",
")",
":",
"self",
".",
"query",
".",
"del_character",
"(",
"name",
")",
"self",
".",
"del_graph",
"(",
"name",
")",
"del",
"self",
".",
"character",
"[",
"name",
"]"
] | Remove the Character from the database entirely.
This also deletes all its history. You'd better be sure. | [
"Remove",
"the",
"Character",
"from",
"the",
"database",
"entirely",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/LiSE/LiSE/engine.py#L1433-L1441 | train |
LogicalDash/LiSE | LiSE/LiSE/engine.py | Engine.alias | def alias(self, v, stat='dummy'):
"""Return a representation of a value suitable for use in historical queries.
It will behave much as if you assigned the value to some entity and then used its
``historical`` method to get a reference to the set of its past values, which
happens to cont... | python | def alias(self, v, stat='dummy'):
"""Return a representation of a value suitable for use in historical queries.
It will behave much as if you assigned the value to some entity and then used its
``historical`` method to get a reference to the set of its past values, which
happens to cont... | [
"def",
"alias",
"(",
"self",
",",
"v",
",",
"stat",
"=",
"'dummy'",
")",
":",
"from",
".",
"util",
"import",
"EntityStatAccessor",
"r",
"=",
"DummyEntity",
"(",
"self",
")",
"r",
"[",
"stat",
"]",
"=",
"v",
"return",
"EntityStatAccessor",
"(",
"r",
"... | Return a representation of a value suitable for use in historical queries.
It will behave much as if you assigned the value to some entity and then used its
``historical`` method to get a reference to the set of its past values, which
happens to contain only the value you've provided here, ``v`... | [
"Return",
"a",
"representation",
"of",
"a",
"value",
"suitable",
"for",
"use",
"in",
"historical",
"queries",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/LiSE/LiSE/engine.py#L1460-L1474 | train |
LogicalDash/LiSE | ELiDE/ELiDE/screen.py | MainScreen.on_play_speed | def on_play_speed(self, *args):
"""Change the interval at which ``self.play`` is called to match my
current ``play_speed``.
"""
Clock.unschedule(self.play)
Clock.schedule_interval(self.play, 1.0 / self.play_speed) | python | def on_play_speed(self, *args):
"""Change the interval at which ``self.play`` is called to match my
current ``play_speed``.
"""
Clock.unschedule(self.play)
Clock.schedule_interval(self.play, 1.0 / self.play_speed) | [
"def",
"on_play_speed",
"(",
"self",
",",
"*",
"args",
")",
":",
"Clock",
".",
"unschedule",
"(",
"self",
".",
"play",
")",
"Clock",
".",
"schedule_interval",
"(",
"self",
".",
"play",
",",
"1.0",
"/",
"self",
".",
"play_speed",
")"
] | Change the interval at which ``self.play`` is called to match my
current ``play_speed``. | [
"Change",
"the",
"interval",
"at",
"which",
"self",
".",
"play",
"is",
"called",
"to",
"match",
"my",
"current",
"play_speed",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/ELiDE/ELiDE/screen.py#L210-L216 | train |
LogicalDash/LiSE | ELiDE/ELiDE/screen.py | MainScreen.remake_display | def remake_display(self, *args):
"""Remake any affected widgets after a change in my ``kv``.
"""
Builder.load_string(self.kv)
if hasattr(self, '_kv_layout'):
self.remove_widget(self._kv_layout)
del self._kv_layout
self._kv_layout = KvLayout()
self... | python | def remake_display(self, *args):
"""Remake any affected widgets after a change in my ``kv``.
"""
Builder.load_string(self.kv)
if hasattr(self, '_kv_layout'):
self.remove_widget(self._kv_layout)
del self._kv_layout
self._kv_layout = KvLayout()
self... | [
"def",
"remake_display",
"(",
"self",
",",
"*",
"args",
")",
":",
"Builder",
".",
"load_string",
"(",
"self",
".",
"kv",
")",
"if",
"hasattr",
"(",
"self",
",",
"'_kv_layout'",
")",
":",
"self",
".",
"remove_widget",
"(",
"self",
".",
"_kv_layout",
")"... | Remake any affected widgets after a change in my ``kv``. | [
"Remake",
"any",
"affected",
"widgets",
"after",
"a",
"change",
"in",
"my",
"kv",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/ELiDE/ELiDE/screen.py#L218-L227 | train |
LogicalDash/LiSE | ELiDE/ELiDE/screen.py | MainScreen.next_turn | def next_turn(self, *args):
"""Advance time by one turn, if it's not blocked.
Block time by setting ``engine.universal['block'] = True``"""
if self.tmp_block:
return
eng = self.app.engine
dial = self.dialoglayout
if eng.universal.get('block'):
Log... | python | def next_turn(self, *args):
"""Advance time by one turn, if it's not blocked.
Block time by setting ``engine.universal['block'] = True``"""
if self.tmp_block:
return
eng = self.app.engine
dial = self.dialoglayout
if eng.universal.get('block'):
Log... | [
"def",
"next_turn",
"(",
"self",
",",
"*",
"args",
")",
":",
"if",
"self",
".",
"tmp_block",
":",
"return",
"eng",
"=",
"self",
".",
"app",
".",
"engine",
"dial",
"=",
"self",
".",
"dialoglayout",
"if",
"eng",
".",
"universal",
".",
"get",
"(",
"'b... | Advance time by one turn, if it's not blocked.
Block time by setting ``engine.universal['block'] = True`` | [
"Advance",
"time",
"by",
"one",
"turn",
"if",
"it",
"s",
"not",
"blocked",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/ELiDE/ELiDE/screen.py#L330-L350 | train |
LogicalDash/LiSE | allegedb/allegedb/__init__.py | setgraphval | def setgraphval(delta, graph, key, val):
"""Change a delta to say that a graph stat was set to a certain value"""
delta.setdefault(graph, {})[key] = val | python | def setgraphval(delta, graph, key, val):
"""Change a delta to say that a graph stat was set to a certain value"""
delta.setdefault(graph, {})[key] = val | [
"def",
"setgraphval",
"(",
"delta",
",",
"graph",
",",
"key",
",",
"val",
")",
":",
"delta",
".",
"setdefault",
"(",
"graph",
",",
"{",
"}",
")",
"[",
"key",
"]",
"=",
"val"
] | Change a delta to say that a graph stat was set to a certain value | [
"Change",
"a",
"delta",
"to",
"say",
"that",
"a",
"graph",
"stat",
"was",
"set",
"to",
"a",
"certain",
"value"
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/allegedb/allegedb/__init__.py#L222-L224 | train |
LogicalDash/LiSE | allegedb/allegedb/__init__.py | setnode | def setnode(delta, graph, node, exists):
"""Change a delta to say that a node was created or deleted"""
delta.setdefault(graph, {}).setdefault('nodes', {})[node] = bool(exists) | python | def setnode(delta, graph, node, exists):
"""Change a delta to say that a node was created or deleted"""
delta.setdefault(graph, {}).setdefault('nodes', {})[node] = bool(exists) | [
"def",
"setnode",
"(",
"delta",
",",
"graph",
",",
"node",
",",
"exists",
")",
":",
"delta",
".",
"setdefault",
"(",
"graph",
",",
"{",
"}",
")",
".",
"setdefault",
"(",
"'nodes'",
",",
"{",
"}",
")",
"[",
"node",
"]",
"=",
"bool",
"(",
"exists",... | Change a delta to say that a node was created or deleted | [
"Change",
"a",
"delta",
"to",
"say",
"that",
"a",
"node",
"was",
"created",
"or",
"deleted"
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/allegedb/allegedb/__init__.py#L227-L229 | train |
LogicalDash/LiSE | allegedb/allegedb/__init__.py | setnodeval | def setnodeval(delta, graph, node, key, value):
"""Change a delta to say that a node stat was set to a certain value"""
if (
graph in delta and 'nodes' in delta[graph] and
node in delta[graph]['nodes'] and not delta[graph]['nodes'][node]
):
return
delta.setdefault(graph, {}).setd... | python | def setnodeval(delta, graph, node, key, value):
"""Change a delta to say that a node stat was set to a certain value"""
if (
graph in delta and 'nodes' in delta[graph] and
node in delta[graph]['nodes'] and not delta[graph]['nodes'][node]
):
return
delta.setdefault(graph, {}).setd... | [
"def",
"setnodeval",
"(",
"delta",
",",
"graph",
",",
"node",
",",
"key",
",",
"value",
")",
":",
"if",
"(",
"graph",
"in",
"delta",
"and",
"'nodes'",
"in",
"delta",
"[",
"graph",
"]",
"and",
"node",
"in",
"delta",
"[",
"graph",
"]",
"[",
"'nodes'"... | Change a delta to say that a node stat was set to a certain value | [
"Change",
"a",
"delta",
"to",
"say",
"that",
"a",
"node",
"stat",
"was",
"set",
"to",
"a",
"certain",
"value"
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/allegedb/allegedb/__init__.py#L232-L239 | train |
LogicalDash/LiSE | allegedb/allegedb/__init__.py | setedge | def setedge(delta, is_multigraph, graph, orig, dest, idx, exists):
"""Change a delta to say that an edge was created or deleted"""
if is_multigraph(graph):
delta.setdefault(graph, {}).setdefault('edges', {})\
.setdefault(orig, {}).setdefault(dest, {})[idx] = bool(exists)
else:
de... | python | def setedge(delta, is_multigraph, graph, orig, dest, idx, exists):
"""Change a delta to say that an edge was created or deleted"""
if is_multigraph(graph):
delta.setdefault(graph, {}).setdefault('edges', {})\
.setdefault(orig, {}).setdefault(dest, {})[idx] = bool(exists)
else:
de... | [
"def",
"setedge",
"(",
"delta",
",",
"is_multigraph",
",",
"graph",
",",
"orig",
",",
"dest",
",",
"idx",
",",
"exists",
")",
":",
"if",
"is_multigraph",
"(",
"graph",
")",
":",
"delta",
".",
"setdefault",
"(",
"graph",
",",
"{",
"}",
")",
".",
"se... | Change a delta to say that an edge was created or deleted | [
"Change",
"a",
"delta",
"to",
"say",
"that",
"an",
"edge",
"was",
"created",
"or",
"deleted"
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/allegedb/allegedb/__init__.py#L242-L249 | train |
LogicalDash/LiSE | allegedb/allegedb/__init__.py | setedgeval | def setedgeval(delta, is_multigraph, graph, orig, dest, idx, key, value):
"""Change a delta to say that an edge stat was set to a certain value"""
if is_multigraph(graph):
if (
graph in delta and 'edges' in delta[graph] and
orig in delta[graph]['edges'] and dest in delta[graph]['... | python | def setedgeval(delta, is_multigraph, graph, orig, dest, idx, key, value):
"""Change a delta to say that an edge stat was set to a certain value"""
if is_multigraph(graph):
if (
graph in delta and 'edges' in delta[graph] and
orig in delta[graph]['edges'] and dest in delta[graph]['... | [
"def",
"setedgeval",
"(",
"delta",
",",
"is_multigraph",
",",
"graph",
",",
"orig",
",",
"dest",
",",
"idx",
",",
"key",
",",
"value",
")",
":",
"if",
"is_multigraph",
"(",
"graph",
")",
":",
"if",
"(",
"graph",
"in",
"delta",
"and",
"'edges'",
"in",... | Change a delta to say that an edge stat was set to a certain value | [
"Change",
"a",
"delta",
"to",
"say",
"that",
"an",
"edge",
"stat",
"was",
"set",
"to",
"a",
"certain",
"value"
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/allegedb/allegedb/__init__.py#L252-L273 | train |
LogicalDash/LiSE | allegedb/allegedb/__init__.py | ORM.advancing | def advancing(self):
"""A context manager for when time is moving forward one turn at a time.
When used in LiSE, this means that the game is being simulated.
It changes how the caching works, making it more efficient.
"""
if self._forward:
raise ValueError("Already ... | python | def advancing(self):
"""A context manager for when time is moving forward one turn at a time.
When used in LiSE, this means that the game is being simulated.
It changes how the caching works, making it more efficient.
"""
if self._forward:
raise ValueError("Already ... | [
"def",
"advancing",
"(",
"self",
")",
":",
"if",
"self",
".",
"_forward",
":",
"raise",
"ValueError",
"(",
"\"Already advancing\"",
")",
"self",
".",
"_forward",
"=",
"True",
"yield",
"self",
".",
"_forward",
"=",
"False"
] | A context manager for when time is moving forward one turn at a time.
When used in LiSE, this means that the game is being simulated.
It changes how the caching works, making it more efficient. | [
"A",
"context",
"manager",
"for",
"when",
"time",
"is",
"moving",
"forward",
"one",
"turn",
"at",
"a",
"time",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/allegedb/allegedb/__init__.py#L334-L345 | train |
LogicalDash/LiSE | allegedb/allegedb/__init__.py | ORM.batch | def batch(self):
"""A context manager for when you're creating lots of state.
Reads will be much slower in a batch, but writes will be faster.
You *can* combine this with ``advancing`` but it isn't any faster.
"""
if self._no_kc:
raise ValueError("Already in a batc... | python | def batch(self):
"""A context manager for when you're creating lots of state.
Reads will be much slower in a batch, but writes will be faster.
You *can* combine this with ``advancing`` but it isn't any faster.
"""
if self._no_kc:
raise ValueError("Already in a batc... | [
"def",
"batch",
"(",
"self",
")",
":",
"if",
"self",
".",
"_no_kc",
":",
"raise",
"ValueError",
"(",
"\"Already in a batch\"",
")",
"self",
".",
"_no_kc",
"=",
"True",
"yield",
"self",
".",
"_no_kc",
"=",
"False"
] | A context manager for when you're creating lots of state.
Reads will be much slower in a batch, but writes will be faster.
You *can* combine this with ``advancing`` but it isn't any faster. | [
"A",
"context",
"manager",
"for",
"when",
"you",
"re",
"creating",
"lots",
"of",
"state",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/allegedb/allegedb/__init__.py#L348-L360 | train |
LogicalDash/LiSE | allegedb/allegedb/__init__.py | ORM.get_delta | def get_delta(self, branch, turn_from, tick_from, turn_to, tick_to):
"""Get a dictionary describing changes to all graphs.
The keys are graph names. Their values are dictionaries of the graphs'
attributes' new values, with ``None`` for deleted keys. Also in those graph
dictionaries are ... | python | def get_delta(self, branch, turn_from, tick_from, turn_to, tick_to):
"""Get a dictionary describing changes to all graphs.
The keys are graph names. Their values are dictionaries of the graphs'
attributes' new values, with ``None`` for deleted keys. Also in those graph
dictionaries are ... | [
"def",
"get_delta",
"(",
"self",
",",
"branch",
",",
"turn_from",
",",
"tick_from",
",",
"turn_to",
",",
"tick_to",
")",
":",
"from",
"functools",
"import",
"partial",
"if",
"turn_from",
"==",
"turn_to",
":",
"return",
"self",
".",
"get_turn_delta",
"(",
"... | Get a dictionary describing changes to all graphs.
The keys are graph names. Their values are dictionaries of the graphs'
attributes' new values, with ``None`` for deleted keys. Also in those graph
dictionaries are special keys 'node_val' and 'edge_val' describing changes
to node and ed... | [
"Get",
"a",
"dictionary",
"describing",
"changes",
"to",
"all",
"graphs",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/allegedb/allegedb/__init__.py#L362-L407 | train |
LogicalDash/LiSE | allegedb/allegedb/__init__.py | ORM._init_caches | def _init_caches(self):
from collections import defaultdict
from .cache import Cache, NodesCache, EdgesCache
self._where_cached = defaultdict(list)
self._global_cache = self.query._global_cache = {}
self._node_objs = node_objs = WeakValueDictionary()
self._get_node_stuff ... | python | def _init_caches(self):
from collections import defaultdict
from .cache import Cache, NodesCache, EdgesCache
self._where_cached = defaultdict(list)
self._global_cache = self.query._global_cache = {}
self._node_objs = node_objs = WeakValueDictionary()
self._get_node_stuff ... | [
"def",
"_init_caches",
"(",
"self",
")",
":",
"from",
"collections",
"import",
"defaultdict",
"from",
".",
"cache",
"import",
"Cache",
",",
"NodesCache",
",",
"EdgesCache",
"self",
".",
"_where_cached",
"=",
"defaultdict",
"(",
"list",
")",
"self",
".",
"_gl... | Immediate children of a branch | [
"Immediate",
"children",
"of",
"a",
"branch"
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/allegedb/allegedb/__init__.py#L504-L553 | train |
LogicalDash/LiSE | allegedb/allegedb/__init__.py | ORM.is_parent_of | def is_parent_of(self, parent, child):
"""Return whether ``child`` is a branch descended from ``parent`` at
any remove.
"""
if parent == 'trunk':
return True
if child == 'trunk':
return False
if child not in self._branches:
raise Value... | python | def is_parent_of(self, parent, child):
"""Return whether ``child`` is a branch descended from ``parent`` at
any remove.
"""
if parent == 'trunk':
return True
if child == 'trunk':
return False
if child not in self._branches:
raise Value... | [
"def",
"is_parent_of",
"(",
"self",
",",
"parent",
",",
"child",
")",
":",
"if",
"parent",
"==",
"'trunk'",
":",
"return",
"True",
"if",
"child",
"==",
"'trunk'",
":",
"return",
"False",
"if",
"child",
"not",
"in",
"self",
".",
"_branches",
":",
"raise... | Return whether ``child`` is a branch descended from ``parent`` at
any remove. | [
"Return",
"whether",
"child",
"is",
"a",
"branch",
"descended",
"from",
"parent",
"at",
"any",
"remove",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/allegedb/allegedb/__init__.py#L655-L672 | train |
LogicalDash/LiSE | allegedb/allegedb/__init__.py | ORM._copy_plans | def _copy_plans(self, branch_from, turn_from, tick_from):
"""Collect all plans that are active at the given time and copy them to the current branch"""
plan_ticks = self._plan_ticks
plan_ticks_uncommitted = self._plan_ticks_uncommitted
time_plan = self._time_plan
plans = self._pl... | python | def _copy_plans(self, branch_from, turn_from, tick_from):
"""Collect all plans that are active at the given time and copy them to the current branch"""
plan_ticks = self._plan_ticks
plan_ticks_uncommitted = self._plan_ticks_uncommitted
time_plan = self._time_plan
plans = self._pl... | [
"def",
"_copy_plans",
"(",
"self",
",",
"branch_from",
",",
"turn_from",
",",
"tick_from",
")",
":",
"plan_ticks",
"=",
"self",
".",
"_plan_ticks",
"plan_ticks_uncommitted",
"=",
"self",
".",
"_plan_ticks_uncommitted",
"time_plan",
"=",
"self",
".",
"_time_plan",
... | Collect all plans that are active at the given time and copy them to the current branch | [
"Collect",
"all",
"plans",
"that",
"are",
"active",
"at",
"the",
"given",
"time",
"and",
"copy",
"them",
"to",
"the",
"current",
"branch"
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/allegedb/allegedb/__init__.py#L710-L746 | train |
LogicalDash/LiSE | allegedb/allegedb/__init__.py | ORM.delete_plan | def delete_plan(self, plan):
"""Delete the portion of a plan that has yet to occur.
:arg plan: integer ID of a plan, as given by ``with self.plan() as plan:``
"""
branch, turn, tick = self._btt()
to_delete = []
plan_ticks = self._plan_ticks[plan]
for trn, tcks i... | python | def delete_plan(self, plan):
"""Delete the portion of a plan that has yet to occur.
:arg plan: integer ID of a plan, as given by ``with self.plan() as plan:``
"""
branch, turn, tick = self._btt()
to_delete = []
plan_ticks = self._plan_ticks[plan]
for trn, tcks i... | [
"def",
"delete_plan",
"(",
"self",
",",
"plan",
")",
":",
"branch",
",",
"turn",
",",
"tick",
"=",
"self",
".",
"_btt",
"(",
")",
"to_delete",
"=",
"[",
"]",
"plan_ticks",
"=",
"self",
".",
"_plan_ticks",
"[",
"plan",
"]",
"for",
"trn",
",",
"tcks"... | Delete the portion of a plan that has yet to occur.
:arg plan: integer ID of a plan, as given by ``with self.plan() as plan:`` | [
"Delete",
"the",
"portion",
"of",
"a",
"plan",
"that",
"has",
"yet",
"to",
"occur",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/allegedb/allegedb/__init__.py#L748-L776 | train |
LogicalDash/LiSE | allegedb/allegedb/__init__.py | ORM._nbtt | def _nbtt(self):
"""Increment the tick and return branch, turn, tick
Unless we're viewing the past, in which case raise HistoryError.
Idea is you use this when you want to advance time, which you
can only do once per branch, turn, tick.
"""
from .cache import HistoryEr... | python | def _nbtt(self):
"""Increment the tick and return branch, turn, tick
Unless we're viewing the past, in which case raise HistoryError.
Idea is you use this when you want to advance time, which you
can only do once per branch, turn, tick.
"""
from .cache import HistoryEr... | [
"def",
"_nbtt",
"(",
"self",
")",
":",
"from",
".",
"cache",
"import",
"HistoryError",
"branch",
",",
"turn",
",",
"tick",
"=",
"self",
".",
"_btt",
"(",
")",
"tick",
"+=",
"1",
"if",
"(",
"branch",
",",
"turn",
")",
"in",
"self",
".",
"_turn_end_p... | Increment the tick and return branch, turn, tick
Unless we're viewing the past, in which case raise HistoryError.
Idea is you use this when you want to advance time, which you
can only do once per branch, turn, tick. | [
"Increment",
"the",
"tick",
"and",
"return",
"branch",
"turn",
"tick"
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/allegedb/allegedb/__init__.py#L855-L895 | train |
LogicalDash/LiSE | allegedb/allegedb/__init__.py | ORM.commit | def commit(self):
"""Write the state of all graphs to the database and commit the transaction.
Also saves the current branch, turn, and tick.
"""
self.query.globl['branch'] = self._obranch
self.query.globl['turn'] = self._oturn
self.query.globl['tick'] = self._otick
... | python | def commit(self):
"""Write the state of all graphs to the database and commit the transaction.
Also saves the current branch, turn, and tick.
"""
self.query.globl['branch'] = self._obranch
self.query.globl['turn'] = self._oturn
self.query.globl['tick'] = self._otick
... | [
"def",
"commit",
"(",
"self",
")",
":",
"self",
".",
"query",
".",
"globl",
"[",
"'branch'",
"]",
"=",
"self",
".",
"_obranch",
"self",
".",
"query",
".",
"globl",
"[",
"'turn'",
"]",
"=",
"self",
".",
"_oturn",
"self",
".",
"query",
".",
"globl",
... | Write the state of all graphs to the database and commit the transaction.
Also saves the current branch, turn, and tick. | [
"Write",
"the",
"state",
"of",
"all",
"graphs",
"to",
"the",
"database",
"and",
"commit",
"the",
"transaction",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/allegedb/allegedb/__init__.py#L897-L919 | train |
LogicalDash/LiSE | allegedb/allegedb/__init__.py | ORM.new_graph | def new_graph(self, name, data=None, **attr):
"""Return a new instance of type Graph, initialized with the given
data if provided.
:arg name: a name for the graph
:arg data: dictionary or NetworkX graph object providing initial state
"""
self._init_graph(name, 'Graph')
... | python | def new_graph(self, name, data=None, **attr):
"""Return a new instance of type Graph, initialized with the given
data if provided.
:arg name: a name for the graph
:arg data: dictionary or NetworkX graph object providing initial state
"""
self._init_graph(name, 'Graph')
... | [
"def",
"new_graph",
"(",
"self",
",",
"name",
",",
"data",
"=",
"None",
",",
"**",
"attr",
")",
":",
"self",
".",
"_init_graph",
"(",
"name",
",",
"'Graph'",
")",
"g",
"=",
"Graph",
"(",
"self",
",",
"name",
",",
"data",
",",
"**",
"attr",
")",
... | Return a new instance of type Graph, initialized with the given
data if provided.
:arg name: a name for the graph
:arg data: dictionary or NetworkX graph object providing initial state | [
"Return",
"a",
"new",
"instance",
"of",
"type",
"Graph",
"initialized",
"with",
"the",
"given",
"data",
"if",
"provided",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/allegedb/allegedb/__init__.py#L933-L944 | train |
LogicalDash/LiSE | allegedb/allegedb/__init__.py | ORM.new_digraph | def new_digraph(self, name, data=None, **attr):
"""Return a new instance of type DiGraph, initialized with the given
data if provided.
:arg name: a name for the graph
:arg data: dictionary or NetworkX graph object providing initial state
"""
self._init_graph(name, 'DiGr... | python | def new_digraph(self, name, data=None, **attr):
"""Return a new instance of type DiGraph, initialized with the given
data if provided.
:arg name: a name for the graph
:arg data: dictionary or NetworkX graph object providing initial state
"""
self._init_graph(name, 'DiGr... | [
"def",
"new_digraph",
"(",
"self",
",",
"name",
",",
"data",
"=",
"None",
",",
"**",
"attr",
")",
":",
"self",
".",
"_init_graph",
"(",
"name",
",",
"'DiGraph'",
")",
"dg",
"=",
"DiGraph",
"(",
"self",
",",
"name",
",",
"data",
",",
"**",
"attr",
... | Return a new instance of type DiGraph, initialized with the given
data if provided.
:arg name: a name for the graph
:arg data: dictionary or NetworkX graph object providing initial state | [
"Return",
"a",
"new",
"instance",
"of",
"type",
"DiGraph",
"initialized",
"with",
"the",
"given",
"data",
"if",
"provided",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/allegedb/allegedb/__init__.py#L946-L957 | train |
LogicalDash/LiSE | allegedb/allegedb/__init__.py | ORM.new_multigraph | def new_multigraph(self, name, data=None, **attr):
"""Return a new instance of type MultiGraph, initialized with the given
data if provided.
:arg name: a name for the graph
:arg data: dictionary or NetworkX graph object providing initial state
"""
self._init_graph(name,... | python | def new_multigraph(self, name, data=None, **attr):
"""Return a new instance of type MultiGraph, initialized with the given
data if provided.
:arg name: a name for the graph
:arg data: dictionary or NetworkX graph object providing initial state
"""
self._init_graph(name,... | [
"def",
"new_multigraph",
"(",
"self",
",",
"name",
",",
"data",
"=",
"None",
",",
"**",
"attr",
")",
":",
"self",
".",
"_init_graph",
"(",
"name",
",",
"'MultiGraph'",
")",
"mg",
"=",
"MultiGraph",
"(",
"self",
",",
"name",
",",
"data",
",",
"**",
... | Return a new instance of type MultiGraph, initialized with the given
data if provided.
:arg name: a name for the graph
:arg data: dictionary or NetworkX graph object providing initial state | [
"Return",
"a",
"new",
"instance",
"of",
"type",
"MultiGraph",
"initialized",
"with",
"the",
"given",
"data",
"if",
"provided",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/allegedb/allegedb/__init__.py#L959-L970 | train |
LogicalDash/LiSE | allegedb/allegedb/__init__.py | ORM.new_multidigraph | def new_multidigraph(self, name, data=None, **attr):
"""Return a new instance of type MultiDiGraph, initialized with the given
data if provided.
:arg name: a name for the graph
:arg data: dictionary or NetworkX graph object providing initial state
"""
self._init_graph(n... | python | def new_multidigraph(self, name, data=None, **attr):
"""Return a new instance of type MultiDiGraph, initialized with the given
data if provided.
:arg name: a name for the graph
:arg data: dictionary or NetworkX graph object providing initial state
"""
self._init_graph(n... | [
"def",
"new_multidigraph",
"(",
"self",
",",
"name",
",",
"data",
"=",
"None",
",",
"**",
"attr",
")",
":",
"self",
".",
"_init_graph",
"(",
"name",
",",
"'MultiDiGraph'",
")",
"mdg",
"=",
"MultiDiGraph",
"(",
"self",
",",
"name",
",",
"data",
",",
"... | Return a new instance of type MultiDiGraph, initialized with the given
data if provided.
:arg name: a name for the graph
:arg data: dictionary or NetworkX graph object providing initial state | [
"Return",
"a",
"new",
"instance",
"of",
"type",
"MultiDiGraph",
"initialized",
"with",
"the",
"given",
"data",
"if",
"provided",
"."
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/allegedb/allegedb/__init__.py#L972-L983 | train |
LogicalDash/LiSE | allegedb/allegedb/__init__.py | ORM.get_graph | def get_graph(self, name):
"""Return a graph previously created with ``new_graph``,
``new_digraph``, ``new_multigraph``, or
``new_multidigraph``
:arg name: name of an existing graph
"""
if name in self._graph_objs:
return self._graph_objs[name]
graph... | python | def get_graph(self, name):
"""Return a graph previously created with ``new_graph``,
``new_digraph``, ``new_multigraph``, or
``new_multidigraph``
:arg name: name of an existing graph
"""
if name in self._graph_objs:
return self._graph_objs[name]
graph... | [
"def",
"get_graph",
"(",
"self",
",",
"name",
")",
":",
"if",
"name",
"in",
"self",
".",
"_graph_objs",
":",
"return",
"self",
".",
"_graph_objs",
"[",
"name",
"]",
"graphtypes",
"=",
"{",
"'Graph'",
":",
"Graph",
",",
"'DiGraph'",
":",
"DiGraph",
",",... | Return a graph previously created with ``new_graph``,
``new_digraph``, ``new_multigraph``, or
``new_multidigraph``
:arg name: name of an existing graph | [
"Return",
"a",
"graph",
"previously",
"created",
"with",
"new_graph",
"new_digraph",
"new_multigraph",
"or",
"new_multidigraph"
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/allegedb/allegedb/__init__.py#L985-L1008 | train |
LogicalDash/LiSE | allegedb/allegedb/__init__.py | ORM.del_graph | def del_graph(self, name):
"""Remove all traces of a graph's existence from the database
:arg name: name of an existing graph
"""
# make sure the graph exists before deleting anything
self.get_graph(name)
self.query.del_graph(name)
if name in self._graph_objs:
... | python | def del_graph(self, name):
"""Remove all traces of a graph's existence from the database
:arg name: name of an existing graph
"""
# make sure the graph exists before deleting anything
self.get_graph(name)
self.query.del_graph(name)
if name in self._graph_objs:
... | [
"def",
"del_graph",
"(",
"self",
",",
"name",
")",
":",
"self",
".",
"get_graph",
"(",
"name",
")",
"self",
".",
"query",
".",
"del_graph",
"(",
"name",
")",
"if",
"name",
"in",
"self",
".",
"_graph_objs",
":",
"del",
"self",
".",
"_graph_objs",
"[",... | Remove all traces of a graph's existence from the database
:arg name: name of an existing graph | [
"Remove",
"all",
"traces",
"of",
"a",
"graph",
"s",
"existence",
"from",
"the",
"database"
] | fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84 | https://github.com/LogicalDash/LiSE/blob/fe6fd4f0a7c1780e065f4c9babb9bc443af6bb84/allegedb/allegedb/__init__.py#L1010-L1020 | train |
niemasd/TreeSwift | treeswift/Tree.py | read_tree_dendropy | def read_tree_dendropy(tree):
'''Create a TreeSwift tree from a DendroPy tree
Args:
``tree`` (``dendropy.datamodel.treemodel``): A Dendropy ``Tree`` object
Returns:
``Tree``: A TreeSwift tree created from ``tree``
'''
out = Tree(); d2t = dict()
if not hasattr(tree, 'preorder_no... | python | def read_tree_dendropy(tree):
'''Create a TreeSwift tree from a DendroPy tree
Args:
``tree`` (``dendropy.datamodel.treemodel``): A Dendropy ``Tree`` object
Returns:
``Tree``: A TreeSwift tree created from ``tree``
'''
out = Tree(); d2t = dict()
if not hasattr(tree, 'preorder_no... | [
"def",
"read_tree_dendropy",
"(",
"tree",
")",
":",
"out",
"=",
"Tree",
"(",
")",
"d2t",
"=",
"dict",
"(",
")",
"if",
"not",
"hasattr",
"(",
"tree",
",",
"'preorder_node_iter'",
")",
"or",
"not",
"hasattr",
"(",
"tree",
",",
"'seed_node'",
")",
"or",
... | Create a TreeSwift tree from a DendroPy tree
Args:
``tree`` (``dendropy.datamodel.treemodel``): A Dendropy ``Tree`` object
Returns:
``Tree``: A TreeSwift tree created from ``tree`` | [
"Create",
"a",
"TreeSwift",
"tree",
"from",
"a",
"DendroPy",
"tree"
] | 7e0cbc770fcc2ee1194ef7c2a0ab9fb82f089917 | https://github.com/niemasd/TreeSwift/blob/7e0cbc770fcc2ee1194ef7c2a0ab9fb82f089917/treeswift/Tree.py#L1199-L1223 | train |
niemasd/TreeSwift | treeswift/Tree.py | read_tree_newick | def read_tree_newick(newick):
'''Read a tree from a Newick string or file
Args:
``newick`` (``str``): Either a Newick string or the path to a Newick file (plain-text or gzipped)
Returns:
``Tree``: The tree represented by ``newick``. If the Newick file has multiple trees (one per line), a `... | python | def read_tree_newick(newick):
'''Read a tree from a Newick string or file
Args:
``newick`` (``str``): Either a Newick string or the path to a Newick file (plain-text or gzipped)
Returns:
``Tree``: The tree represented by ``newick``. If the Newick file has multiple trees (one per line), a `... | [
"def",
"read_tree_newick",
"(",
"newick",
")",
":",
"if",
"not",
"isinstance",
"(",
"newick",
",",
"str",
")",
":",
"try",
":",
"newick",
"=",
"str",
"(",
"newick",
")",
"except",
":",
"raise",
"TypeError",
"(",
"\"newick must be a str\"",
")",
"if",
"ne... | Read a tree from a Newick string or file
Args:
``newick`` (``str``): Either a Newick string or the path to a Newick file (plain-text or gzipped)
Returns:
``Tree``: The tree represented by ``newick``. If the Newick file has multiple trees (one per line), a ``list`` of ``Tree`` objects will be r... | [
"Read",
"a",
"tree",
"from",
"a",
"Newick",
"string",
"or",
"file"
] | 7e0cbc770fcc2ee1194ef7c2a0ab9fb82f089917 | https://github.com/niemasd/TreeSwift/blob/7e0cbc770fcc2ee1194ef7c2a0ab9fb82f089917/treeswift/Tree.py#L1225-L1276 | train |
niemasd/TreeSwift | treeswift/Tree.py | read_tree_nexus | def read_tree_nexus(nexus):
'''Read a tree from a Nexus string or file
Args:
``nexus`` (``str``): Either a Nexus string or the path to a Nexus file (plain-text or gzipped)
Returns:
``dict`` of ``Tree``: A dictionary of the trees represented by ``nexus``, where keys are tree names (``str``)... | python | def read_tree_nexus(nexus):
'''Read a tree from a Nexus string or file
Args:
``nexus`` (``str``): Either a Nexus string or the path to a Nexus file (plain-text or gzipped)
Returns:
``dict`` of ``Tree``: A dictionary of the trees represented by ``nexus``, where keys are tree names (``str``)... | [
"def",
"read_tree_nexus",
"(",
"nexus",
")",
":",
"if",
"not",
"isinstance",
"(",
"nexus",
",",
"str",
")",
":",
"raise",
"TypeError",
"(",
"\"nexus must be a str\"",
")",
"if",
"nexus",
".",
"lower",
"(",
")",
".",
"endswith",
"(",
"'.gz'",
")",
":",
... | Read a tree from a Nexus string or file
Args:
``nexus`` (``str``): Either a Nexus string or the path to a Nexus file (plain-text or gzipped)
Returns:
``dict`` of ``Tree``: A dictionary of the trees represented by ``nexus``, where keys are tree names (``str``) and values are ``Tree`` objects | [
"Read",
"a",
"tree",
"from",
"a",
"Nexus",
"string",
"or",
"file"
] | 7e0cbc770fcc2ee1194ef7c2a0ab9fb82f089917 | https://github.com/niemasd/TreeSwift/blob/7e0cbc770fcc2ee1194ef7c2a0ab9fb82f089917/treeswift/Tree.py#L1395-L1424 | train |
niemasd/TreeSwift | treeswift/Tree.py | read_tree | def read_tree(input, schema):
'''Read a tree from a string or file
Args:
``input`` (``str``): Either a tree string, a path to a tree file (plain-text or gzipped), or a DendroPy Tree object
``schema`` (``str``): The schema of ``input`` (DendroPy, Newick, NeXML, or Nexus)
Returns:
*... | python | def read_tree(input, schema):
'''Read a tree from a string or file
Args:
``input`` (``str``): Either a tree string, a path to a tree file (plain-text or gzipped), or a DendroPy Tree object
``schema`` (``str``): The schema of ``input`` (DendroPy, Newick, NeXML, or Nexus)
Returns:
*... | [
"def",
"read_tree",
"(",
"input",
",",
"schema",
")",
":",
"schema_to_function",
"=",
"{",
"'dendropy'",
":",
"read_tree_dendropy",
",",
"'newick'",
":",
"read_tree_newick",
",",
"'nexml'",
":",
"read_tree_nexml",
",",
"'nexus'",
":",
"read_tree_nexus",
"}",
"if... | Read a tree from a string or file
Args:
``input`` (``str``): Either a tree string, a path to a tree file (plain-text or gzipped), or a DendroPy Tree object
``schema`` (``str``): The schema of ``input`` (DendroPy, Newick, NeXML, or Nexus)
Returns:
* If the input is Newick, either a ``T... | [
"Read",
"a",
"tree",
"from",
"a",
"string",
"or",
"file"
] | 7e0cbc770fcc2ee1194ef7c2a0ab9fb82f089917 | https://github.com/niemasd/TreeSwift/blob/7e0cbc770fcc2ee1194ef7c2a0ab9fb82f089917/treeswift/Tree.py#L1426-L1447 | train |
niemasd/TreeSwift | treeswift/Tree.py | Tree.avg_branch_length | def avg_branch_length(self, terminal=True, internal=True):
'''Compute the average length of the selected branches of this ``Tree``. Edges with length ``None`` will be treated as 0-length
Args:
``terminal`` (``bool``): ``True`` to include terminal branches, otherwise ``False``
`... | python | def avg_branch_length(self, terminal=True, internal=True):
'''Compute the average length of the selected branches of this ``Tree``. Edges with length ``None`` will be treated as 0-length
Args:
``terminal`` (``bool``): ``True`` to include terminal branches, otherwise ``False``
`... | [
"def",
"avg_branch_length",
"(",
"self",
",",
"terminal",
"=",
"True",
",",
"internal",
"=",
"True",
")",
":",
"if",
"not",
"isinstance",
"(",
"terminal",
",",
"bool",
")",
":",
"raise",
"TypeError",
"(",
"\"terminal must be a bool\"",
")",
"if",
"not",
"i... | Compute the average length of the selected branches of this ``Tree``. Edges with length ``None`` will be treated as 0-length
Args:
``terminal`` (``bool``): ``True`` to include terminal branches, otherwise ``False``
``internal`` (``bool``): ``True`` to include internal branches, otherwi... | [
"Compute",
"the",
"average",
"length",
"of",
"the",
"selected",
"branches",
"of",
"this",
"Tree",
".",
"Edges",
"with",
"length",
"None",
"will",
"be",
"treated",
"as",
"0",
"-",
"length"
] | 7e0cbc770fcc2ee1194ef7c2a0ab9fb82f089917 | https://github.com/niemasd/TreeSwift/blob/7e0cbc770fcc2ee1194ef7c2a0ab9fb82f089917/treeswift/Tree.py#L40-L61 | train |
niemasd/TreeSwift | treeswift/Tree.py | Tree.branch_lengths | def branch_lengths(self, terminal=True, internal=True):
'''Generator over the lengths of the selected branches of this ``Tree``. Edges with length ``None`` will be output as 0-length
Args:
``terminal`` (``bool``): ``True`` to include terminal branches, otherwise ``False``
``int... | python | def branch_lengths(self, terminal=True, internal=True):
'''Generator over the lengths of the selected branches of this ``Tree``. Edges with length ``None`` will be output as 0-length
Args:
``terminal`` (``bool``): ``True`` to include terminal branches, otherwise ``False``
``int... | [
"def",
"branch_lengths",
"(",
"self",
",",
"terminal",
"=",
"True",
",",
"internal",
"=",
"True",
")",
":",
"if",
"not",
"isinstance",
"(",
"terminal",
",",
"bool",
")",
":",
"raise",
"TypeError",
"(",
"\"terminal must be a bool\"",
")",
"if",
"not",
"isin... | Generator over the lengths of the selected branches of this ``Tree``. Edges with length ``None`` will be output as 0-length
Args:
``terminal`` (``bool``): ``True`` to include terminal branches, otherwise ``False``
``internal`` (``bool``): ``True`` to include internal branches, otherwis... | [
"Generator",
"over",
"the",
"lengths",
"of",
"the",
"selected",
"branches",
"of",
"this",
"Tree",
".",
"Edges",
"with",
"length",
"None",
"will",
"be",
"output",
"as",
"0",
"-",
"length"
] | 7e0cbc770fcc2ee1194ef7c2a0ab9fb82f089917 | https://github.com/niemasd/TreeSwift/blob/7e0cbc770fcc2ee1194ef7c2a0ab9fb82f089917/treeswift/Tree.py#L63-L80 | train |
niemasd/TreeSwift | treeswift/Tree.py | Tree.closest_leaf_to_root | def closest_leaf_to_root(self):
'''Return the leaf that is closest to the root and the corresponding distance. Edges with no length will be considered to have a length of 0
Returns:
``tuple``: First value is the closest leaf to the root, and second value is the corresponding distance
... | python | def closest_leaf_to_root(self):
'''Return the leaf that is closest to the root and the corresponding distance. Edges with no length will be considered to have a length of 0
Returns:
``tuple``: First value is the closest leaf to the root, and second value is the corresponding distance
... | [
"def",
"closest_leaf_to_root",
"(",
"self",
")",
":",
"best",
"=",
"(",
"None",
",",
"float",
"(",
"'inf'",
")",
")",
"d",
"=",
"dict",
"(",
")",
"for",
"node",
"in",
"self",
".",
"traverse_preorder",
"(",
")",
":",
"if",
"node",
".",
"edge_length",
... | Return the leaf that is closest to the root and the corresponding distance. Edges with no length will be considered to have a length of 0
Returns:
``tuple``: First value is the closest leaf to the root, and second value is the corresponding distance | [
"Return",
"the",
"leaf",
"that",
"is",
"closest",
"to",
"the",
"root",
"and",
"the",
"corresponding",
"distance",
".",
"Edges",
"with",
"no",
"length",
"will",
"be",
"considered",
"to",
"have",
"a",
"length",
"of",
"0"
] | 7e0cbc770fcc2ee1194ef7c2a0ab9fb82f089917 | https://github.com/niemasd/TreeSwift/blob/7e0cbc770fcc2ee1194ef7c2a0ab9fb82f089917/treeswift/Tree.py#L82-L98 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.