partition stringclasses 3
values | func_name stringlengths 1 134 | docstring stringlengths 1 46.9k | path stringlengths 4 223 | original_string stringlengths 75 104k | code stringlengths 75 104k | docstring_tokens listlengths 1 1.97k | repo stringlengths 7 55 | language stringclasses 1
value | url stringlengths 87 315 | code_tokens listlengths 19 28.4k | sha stringlengths 40 40 |
|---|---|---|---|---|---|---|---|---|---|---|---|
test | _form_onset_offset_fronts | Takes an array of onsets or offsets (shape = [nfrequencies, nsamples], where a 1 corresponds to an on/offset,
and samples are 0 otherwise), and returns a new array of the same shape, where each 1 has been replaced by
either a 0, if the on/offset has been discarded, or a non-zero positive integer, such that
... | algorithms/asa.py | def _form_onset_offset_fronts(ons_or_offs, sample_rate_hz, threshold_ms=20):
"""
Takes an array of onsets or offsets (shape = [nfrequencies, nsamples], where a 1 corresponds to an on/offset,
and samples are 0 otherwise), and returns a new array of the same shape, where each 1 has been replaced by
either... | def _form_onset_offset_fronts(ons_or_offs, sample_rate_hz, threshold_ms=20):
"""
Takes an array of onsets or offsets (shape = [nfrequencies, nsamples], where a 1 corresponds to an on/offset,
and samples are 0 otherwise), and returns a new array of the same shape, where each 1 has been replaced by
either... | [
"Takes",
"an",
"array",
"of",
"onsets",
"or",
"offsets",
"(",
"shape",
"=",
"[",
"nfrequencies",
"nsamples",
"]",
"where",
"a",
"1",
"corresponds",
"to",
"an",
"on",
"/",
"offset",
"and",
"samples",
"are",
"0",
"otherwise",
")",
"and",
"returns",
"a",
... | MaxStrange/AudioSegment | python | https://github.com/MaxStrange/AudioSegment/blob/1daefb8de626ddff3ff7016697c3ad31d262ecd6/algorithms/asa.py#L197-L261 | [
"def",
"_form_onset_offset_fronts",
"(",
"ons_or_offs",
",",
"sample_rate_hz",
",",
"threshold_ms",
"=",
"20",
")",
":",
"threshold_s",
"=",
"threshold_ms",
"/",
"1000",
"threshold_samples",
"=",
"sample_rate_hz",
"*",
"threshold_s",
"ons_or_offs",
"=",
"np",
".",
... | 1daefb8de626ddff3ff7016697c3ad31d262ecd6 |
test | _lookup_offset_by_onset_idx | Takes an onset index (freq, sample) and returns the offset index (freq, sample)
such that frequency index is the same, and sample index is the minimum of all
offsets ocurring after the given onset. If there are no offsets after the given
onset in that frequency channel, the final sample in that channel is r... | algorithms/asa.py | def _lookup_offset_by_onset_idx(onset_idx, onsets, offsets):
"""
Takes an onset index (freq, sample) and returns the offset index (freq, sample)
such that frequency index is the same, and sample index is the minimum of all
offsets ocurring after the given onset. If there are no offsets after the given
... | def _lookup_offset_by_onset_idx(onset_idx, onsets, offsets):
"""
Takes an onset index (freq, sample) and returns the offset index (freq, sample)
such that frequency index is the same, and sample index is the minimum of all
offsets ocurring after the given onset. If there are no offsets after the given
... | [
"Takes",
"an",
"onset",
"index",
"(",
"freq",
"sample",
")",
"and",
"returns",
"the",
"offset",
"index",
"(",
"freq",
"sample",
")",
"such",
"that",
"frequency",
"index",
"is",
"the",
"same",
"and",
"sample",
"index",
"is",
"the",
"minimum",
"of",
"all",... | MaxStrange/AudioSegment | python | https://github.com/MaxStrange/AudioSegment/blob/1daefb8de626ddff3ff7016697c3ad31d262ecd6/algorithms/asa.py#L263-L283 | [
"def",
"_lookup_offset_by_onset_idx",
"(",
"onset_idx",
",",
"onsets",
",",
"offsets",
")",
":",
"assert",
"len",
"(",
"onset_idx",
")",
"==",
"2",
",",
"\"Onset_idx must be a tuple of the form (freq_idx, sample_idx)\"",
"frequency_idx",
",",
"sample_idx",
"=",
"onset_i... | 1daefb8de626ddff3ff7016697c3ad31d262ecd6 |
test | _get_front_idxs_from_id | Return a list of tuples of the form (frequency_idx, sample_idx),
corresponding to all the indexes of the given front. | algorithms/asa.py | def _get_front_idxs_from_id(fronts, id):
"""
Return a list of tuples of the form (frequency_idx, sample_idx),
corresponding to all the indexes of the given front.
"""
if id == -1:
# This is the only special case.
# -1 is the index of the catch-all final column offset front.
f... | def _get_front_idxs_from_id(fronts, id):
"""
Return a list of tuples of the form (frequency_idx, sample_idx),
corresponding to all the indexes of the given front.
"""
if id == -1:
# This is the only special case.
# -1 is the index of the catch-all final column offset front.
f... | [
"Return",
"a",
"list",
"of",
"tuples",
"of",
"the",
"form",
"(",
"frequency_idx",
"sample_idx",
")",
"corresponding",
"to",
"all",
"the",
"indexes",
"of",
"the",
"given",
"front",
"."
] | MaxStrange/AudioSegment | python | https://github.com/MaxStrange/AudioSegment/blob/1daefb8de626ddff3ff7016697c3ad31d262ecd6/algorithms/asa.py#L285-L297 | [
"def",
"_get_front_idxs_from_id",
"(",
"fronts",
",",
"id",
")",
":",
"if",
"id",
"==",
"-",
"1",
":",
"# This is the only special case.",
"# -1 is the index of the catch-all final column offset front.",
"freq_idxs",
"=",
"np",
".",
"arange",
"(",
"fronts",
".",
"shap... | 1daefb8de626ddff3ff7016697c3ad31d262ecd6 |
test | _choose_front_id_from_candidates | Returns a front ID which is the id of the offset front that contains the most overlap
with offsets that correspond to the given onset front ID. | algorithms/asa.py | def _choose_front_id_from_candidates(candidate_offset_front_ids, offset_fronts, offsets_corresponding_to_onsets):
"""
Returns a front ID which is the id of the offset front that contains the most overlap
with offsets that correspond to the given onset front ID.
"""
noverlaps = [] # will contain tup... | def _choose_front_id_from_candidates(candidate_offset_front_ids, offset_fronts, offsets_corresponding_to_onsets):
"""
Returns a front ID which is the id of the offset front that contains the most overlap
with offsets that correspond to the given onset front ID.
"""
noverlaps = [] # will contain tup... | [
"Returns",
"a",
"front",
"ID",
"which",
"is",
"the",
"id",
"of",
"the",
"offset",
"front",
"that",
"contains",
"the",
"most",
"overlap",
"with",
"offsets",
"that",
"correspond",
"to",
"the",
"given",
"onset",
"front",
"ID",
"."
] | MaxStrange/AudioSegment | python | https://github.com/MaxStrange/AudioSegment/blob/1daefb8de626ddff3ff7016697c3ad31d262ecd6/algorithms/asa.py#L299-L311 | [
"def",
"_choose_front_id_from_candidates",
"(",
"candidate_offset_front_ids",
",",
"offset_fronts",
",",
"offsets_corresponding_to_onsets",
")",
":",
"noverlaps",
"=",
"[",
"]",
"# will contain tuples of the form (number_overlapping, offset_front_id)",
"for",
"offset_front_id",
"in... | 1daefb8de626ddff3ff7016697c3ad31d262ecd6 |
test | _get_offset_front_id_after_onset_sample_idx | Returns the offset_front_id which corresponds to the offset front which occurs
first entirely after the given onset sample_idx. | algorithms/asa.py | def _get_offset_front_id_after_onset_sample_idx(onset_sample_idx, offset_fronts):
"""
Returns the offset_front_id which corresponds to the offset front which occurs
first entirely after the given onset sample_idx.
"""
# get all the offset_front_ids
offset_front_ids = [i for i in np.unique(offset... | def _get_offset_front_id_after_onset_sample_idx(onset_sample_idx, offset_fronts):
"""
Returns the offset_front_id which corresponds to the offset front which occurs
first entirely after the given onset sample_idx.
"""
# get all the offset_front_ids
offset_front_ids = [i for i in np.unique(offset... | [
"Returns",
"the",
"offset_front_id",
"which",
"corresponds",
"to",
"the",
"offset",
"front",
"which",
"occurs",
"first",
"entirely",
"after",
"the",
"given",
"onset",
"sample_idx",
"."
] | MaxStrange/AudioSegment | python | https://github.com/MaxStrange/AudioSegment/blob/1daefb8de626ddff3ff7016697c3ad31d262ecd6/algorithms/asa.py#L313-L337 | [
"def",
"_get_offset_front_id_after_onset_sample_idx",
"(",
"onset_sample_idx",
",",
"offset_fronts",
")",
":",
"# get all the offset_front_ids",
"offset_front_ids",
"=",
"[",
"i",
"for",
"i",
"in",
"np",
".",
"unique",
"(",
"offset_fronts",
")",
"if",
"i",
"!=",
"0"... | 1daefb8de626ddff3ff7016697c3ad31d262ecd6 |
test | _get_offset_front_id_after_onset_front | Get the ID corresponding to the offset which occurs first after the given onset_front_id.
By `first` I mean the front which contains the offset which is closest to the latest point
in the onset front. By `after`, I mean that the offset must contain only offsets which
occur after the latest onset in the onse... | algorithms/asa.py | def _get_offset_front_id_after_onset_front(onset_front_id, onset_fronts, offset_fronts):
"""
Get the ID corresponding to the offset which occurs first after the given onset_front_id.
By `first` I mean the front which contains the offset which is closest to the latest point
in the onset front. By `after`... | def _get_offset_front_id_after_onset_front(onset_front_id, onset_fronts, offset_fronts):
"""
Get the ID corresponding to the offset which occurs first after the given onset_front_id.
By `first` I mean the front which contains the offset which is closest to the latest point
in the onset front. By `after`... | [
"Get",
"the",
"ID",
"corresponding",
"to",
"the",
"offset",
"which",
"occurs",
"first",
"after",
"the",
"given",
"onset_front_id",
".",
"By",
"first",
"I",
"mean",
"the",
"front",
"which",
"contains",
"the",
"offset",
"which",
"is",
"closest",
"to",
"the",
... | MaxStrange/AudioSegment | python | https://github.com/MaxStrange/AudioSegment/blob/1daefb8de626ddff3ff7016697c3ad31d262ecd6/algorithms/asa.py#L339-L359 | [
"def",
"_get_offset_front_id_after_onset_front",
"(",
"onset_front_id",
",",
"onset_fronts",
",",
"offset_fronts",
")",
":",
"# get the onset idxs for this front",
"onset_idxs",
"=",
"_get_front_idxs_from_id",
"(",
"onset_fronts",
",",
"onset_front_id",
")",
"# get the sample i... | 1daefb8de626ddff3ff7016697c3ad31d262ecd6 |
test | _match_offset_front_id_to_onset_front_id | Find all offset fronts which are composed of at least one offset which corresponds to one of the onsets in the
given onset front.
The offset front which contains the most of such offsets is the match.
If there are no such offset fronts, return -1. | algorithms/asa.py | def _match_offset_front_id_to_onset_front_id(onset_front_id, onset_fronts, offset_fronts, onsets, offsets):
"""
Find all offset fronts which are composed of at least one offset which corresponds to one of the onsets in the
given onset front.
The offset front which contains the most of such offsets is th... | def _match_offset_front_id_to_onset_front_id(onset_front_id, onset_fronts, offset_fronts, onsets, offsets):
"""
Find all offset fronts which are composed of at least one offset which corresponds to one of the onsets in the
given onset front.
The offset front which contains the most of such offsets is th... | [
"Find",
"all",
"offset",
"fronts",
"which",
"are",
"composed",
"of",
"at",
"least",
"one",
"offset",
"which",
"corresponds",
"to",
"one",
"of",
"the",
"onsets",
"in",
"the",
"given",
"onset",
"front",
".",
"The",
"offset",
"front",
"which",
"contains",
"th... | MaxStrange/AudioSegment | python | https://github.com/MaxStrange/AudioSegment/blob/1daefb8de626ddff3ff7016697c3ad31d262ecd6/algorithms/asa.py#L361-L389 | [
"def",
"_match_offset_front_id_to_onset_front_id",
"(",
"onset_front_id",
",",
"onset_fronts",
",",
"offset_fronts",
",",
"onsets",
",",
"offsets",
")",
":",
"# find all offset fronts which are composed of at least one offset which corresponds to one of the onsets in the onset front",
... | 1daefb8de626ddff3ff7016697c3ad31d262ecd6 |
test | _get_consecutive_portions_of_front | Yields lists of the form [(f, s), (f, s)], one at a time from the given front (which is a list of the same form),
such that each list yielded is consecutive in frequency. | algorithms/asa.py | def _get_consecutive_portions_of_front(front):
"""
Yields lists of the form [(f, s), (f, s)], one at a time from the given front (which is a list of the same form),
such that each list yielded is consecutive in frequency.
"""
last_f = None
ls = []
for f, s in front:
if last_f is not ... | def _get_consecutive_portions_of_front(front):
"""
Yields lists of the form [(f, s), (f, s)], one at a time from the given front (which is a list of the same form),
such that each list yielded is consecutive in frequency.
"""
last_f = None
ls = []
for f, s in front:
if last_f is not ... | [
"Yields",
"lists",
"of",
"the",
"form",
"[",
"(",
"f",
"s",
")",
"(",
"f",
"s",
")",
"]",
"one",
"at",
"a",
"time",
"from",
"the",
"given",
"front",
"(",
"which",
"is",
"a",
"list",
"of",
"the",
"same",
"form",
")",
"such",
"that",
"each",
"lis... | MaxStrange/AudioSegment | python | https://github.com/MaxStrange/AudioSegment/blob/1daefb8de626ddff3ff7016697c3ad31d262ecd6/algorithms/asa.py#L391-L404 | [
"def",
"_get_consecutive_portions_of_front",
"(",
"front",
")",
":",
"last_f",
"=",
"None",
"ls",
"=",
"[",
"]",
"for",
"f",
",",
"s",
"in",
"front",
":",
"if",
"last_f",
"is",
"not",
"None",
"and",
"f",
"!=",
"last_f",
"+",
"1",
":",
"yield",
"ls",
... | 1daefb8de626ddff3ff7016697c3ad31d262ecd6 |
test | _get_consecutive_and_overlapping_fronts | Gets an onset_front and an offset_front such that they both occupy at least some of the same
frequency channels, then returns the portion of each that overlaps with the other. | algorithms/asa.py | def _get_consecutive_and_overlapping_fronts(onset_fronts, offset_fronts, onset_front_id, offset_front_id):
"""
Gets an onset_front and an offset_front such that they both occupy at least some of the same
frequency channels, then returns the portion of each that overlaps with the other.
"""
# Get the... | def _get_consecutive_and_overlapping_fronts(onset_fronts, offset_fronts, onset_front_id, offset_front_id):
"""
Gets an onset_front and an offset_front such that they both occupy at least some of the same
frequency channels, then returns the portion of each that overlaps with the other.
"""
# Get the... | [
"Gets",
"an",
"onset_front",
"and",
"an",
"offset_front",
"such",
"that",
"they",
"both",
"occupy",
"at",
"least",
"some",
"of",
"the",
"same",
"frequency",
"channels",
"then",
"returns",
"the",
"portion",
"of",
"each",
"that",
"overlaps",
"with",
"the",
"ot... | MaxStrange/AudioSegment | python | https://github.com/MaxStrange/AudioSegment/blob/1daefb8de626ddff3ff7016697c3ad31d262ecd6/algorithms/asa.py#L406-L430 | [
"def",
"_get_consecutive_and_overlapping_fronts",
"(",
"onset_fronts",
",",
"offset_fronts",
",",
"onset_front_id",
",",
"offset_front_id",
")",
":",
"# Get the onset front of interest",
"onset_front",
"=",
"_get_front_idxs_from_id",
"(",
"onset_fronts",
",",
"onset_front_id",
... | 1daefb8de626ddff3ff7016697c3ad31d262ecd6 |
test | _update_segmentation_mask | Returns an updated segmentation mask such that the input `segmentation_mask` has been updated by segmenting between
`onset_front_id` and `offset_front_id`, as found in `onset_fronts` and `offset_fronts`, respectively.
This function also returns the onset_fronts and offset_fronts matrices, updated so that any f... | algorithms/asa.py | def _update_segmentation_mask(segmentation_mask, onset_fronts, offset_fronts, onset_front_id, offset_front_id_most_overlap):
"""
Returns an updated segmentation mask such that the input `segmentation_mask` has been updated by segmenting between
`onset_front_id` and `offset_front_id`, as found in `onset_fron... | def _update_segmentation_mask(segmentation_mask, onset_fronts, offset_fronts, onset_front_id, offset_front_id_most_overlap):
"""
Returns an updated segmentation mask such that the input `segmentation_mask` has been updated by segmenting between
`onset_front_id` and `offset_front_id`, as found in `onset_fron... | [
"Returns",
"an",
"updated",
"segmentation",
"mask",
"such",
"that",
"the",
"input",
"segmentation_mask",
"has",
"been",
"updated",
"by",
"segmenting",
"between",
"onset_front_id",
"and",
"offset_front_id",
"as",
"found",
"in",
"onset_fronts",
"and",
"offset_fronts",
... | MaxStrange/AudioSegment | python | https://github.com/MaxStrange/AudioSegment/blob/1daefb8de626ddff3ff7016697c3ad31d262ecd6/algorithms/asa.py#L433-L575 | [
"def",
"_update_segmentation_mask",
"(",
"segmentation_mask",
",",
"onset_fronts",
",",
"offset_fronts",
",",
"onset_front_id",
",",
"offset_front_id_most_overlap",
")",
":",
"# Get the portions of the onset and offset fronts that overlap and are consecutive",
"onset_front_overlap",
... | 1daefb8de626ddff3ff7016697c3ad31d262ecd6 |
test | _front_id_from_idx | Returns the front ID found in `front` at the given `index`.
:param front: An onset or offset front array of shape [nfrequencies, nsamples]
:index: A tuple of the form (frequency index, sample index)
:returns: The ID of the front or -1 if not found in `fro... | algorithms/asa.py | def _front_id_from_idx(front, index):
"""
Returns the front ID found in `front` at the given `index`.
:param front: An onset or offset front array of shape [nfrequencies, nsamples]
:index: A tuple of the form (frequency index, sample index)
:returns: ... | def _front_id_from_idx(front, index):
"""
Returns the front ID found in `front` at the given `index`.
:param front: An onset or offset front array of shape [nfrequencies, nsamples]
:index: A tuple of the form (frequency index, sample index)
:returns: ... | [
"Returns",
"the",
"front",
"ID",
"found",
"in",
"front",
"at",
"the",
"given",
"index",
"."
] | MaxStrange/AudioSegment | python | https://github.com/MaxStrange/AudioSegment/blob/1daefb8de626ddff3ff7016697c3ad31d262ecd6/algorithms/asa.py#L577-L591 | [
"def",
"_front_id_from_idx",
"(",
"front",
",",
"index",
")",
":",
"fidx",
",",
"sidx",
"=",
"index",
"id",
"=",
"front",
"[",
"fidx",
",",
"sidx",
"]",
"if",
"id",
"==",
"0",
":",
"return",
"-",
"1",
"else",
":",
"return",
"id"
] | 1daefb8de626ddff3ff7016697c3ad31d262ecd6 |
test | _get_front_ids_one_at_a_time | Yields one onset front ID at a time until they are gone. All the onset fronts from a
frequency channel are yielded, then all of the next channel's, etc., though one at a time. | algorithms/asa.py | def _get_front_ids_one_at_a_time(onset_fronts):
"""
Yields one onset front ID at a time until they are gone. All the onset fronts from a
frequency channel are yielded, then all of the next channel's, etc., though one at a time.
"""
yielded_so_far = set()
for row in onset_fronts:
for id i... | def _get_front_ids_one_at_a_time(onset_fronts):
"""
Yields one onset front ID at a time until they are gone. All the onset fronts from a
frequency channel are yielded, then all of the next channel's, etc., though one at a time.
"""
yielded_so_far = set()
for row in onset_fronts:
for id i... | [
"Yields",
"one",
"onset",
"front",
"ID",
"at",
"a",
"time",
"until",
"they",
"are",
"gone",
".",
"All",
"the",
"onset",
"fronts",
"from",
"a",
"frequency",
"channel",
"are",
"yielded",
"then",
"all",
"of",
"the",
"next",
"channel",
"s",
"etc",
".",
"th... | MaxStrange/AudioSegment | python | https://github.com/MaxStrange/AudioSegment/blob/1daefb8de626ddff3ff7016697c3ad31d262ecd6/algorithms/asa.py#L593-L603 | [
"def",
"_get_front_ids_one_at_a_time",
"(",
"onset_fronts",
")",
":",
"yielded_so_far",
"=",
"set",
"(",
")",
"for",
"row",
"in",
"onset_fronts",
":",
"for",
"id",
"in",
"row",
":",
"if",
"id",
"!=",
"0",
"and",
"id",
"not",
"in",
"yielded_so_far",
":",
... | 1daefb8de626ddff3ff7016697c3ad31d262ecd6 |
test | _get_corresponding_offsets | Gets the offsets that occur as close as possible to the onsets in the given onset-front. | algorithms/asa.py | def _get_corresponding_offsets(onset_fronts, onset_front_id, onsets, offsets):
"""
Gets the offsets that occur as close as possible to the onsets in the given onset-front.
"""
corresponding_offsets = []
for index in _get_front_idxs_from_id(onset_fronts, onset_front_id):
offset_fidx, offset_s... | def _get_corresponding_offsets(onset_fronts, onset_front_id, onsets, offsets):
"""
Gets the offsets that occur as close as possible to the onsets in the given onset-front.
"""
corresponding_offsets = []
for index in _get_front_idxs_from_id(onset_fronts, onset_front_id):
offset_fidx, offset_s... | [
"Gets",
"the",
"offsets",
"that",
"occur",
"as",
"close",
"as",
"possible",
"to",
"the",
"onsets",
"in",
"the",
"given",
"onset",
"-",
"front",
"."
] | MaxStrange/AudioSegment | python | https://github.com/MaxStrange/AudioSegment/blob/1daefb8de626ddff3ff7016697c3ad31d262ecd6/algorithms/asa.py#L605-L613 | [
"def",
"_get_corresponding_offsets",
"(",
"onset_fronts",
",",
"onset_front_id",
",",
"onsets",
",",
"offsets",
")",
":",
"corresponding_offsets",
"=",
"[",
"]",
"for",
"index",
"in",
"_get_front_idxs_from_id",
"(",
"onset_fronts",
",",
"onset_front_id",
")",
":",
... | 1daefb8de626ddff3ff7016697c3ad31d262ecd6 |
test | _get_all_offset_fronts_from_offsets | Returns all the offset fronts that are composed of at least one of the given offset indexes.
Also returns a dict of the form {offset_front_id: ntimes saw} | algorithms/asa.py | def _get_all_offset_fronts_from_offsets(offset_fronts, corresponding_offsets):
"""
Returns all the offset fronts that are composed of at least one of the given offset indexes.
Also returns a dict of the form {offset_front_id: ntimes saw}
"""
all_offset_fronts_of_interest = []
ids_ntimes_seen = {... | def _get_all_offset_fronts_from_offsets(offset_fronts, corresponding_offsets):
"""
Returns all the offset fronts that are composed of at least one of the given offset indexes.
Also returns a dict of the form {offset_front_id: ntimes saw}
"""
all_offset_fronts_of_interest = []
ids_ntimes_seen = {... | [
"Returns",
"all",
"the",
"offset",
"fronts",
"that",
"are",
"composed",
"of",
"at",
"least",
"one",
"of",
"the",
"given",
"offset",
"indexes",
".",
"Also",
"returns",
"a",
"dict",
"of",
"the",
"form",
"{",
"offset_front_id",
":",
"ntimes",
"saw",
"}"
] | MaxStrange/AudioSegment | python | https://github.com/MaxStrange/AudioSegment/blob/1daefb8de626ddff3ff7016697c3ad31d262ecd6/algorithms/asa.py#L615-L630 | [
"def",
"_get_all_offset_fronts_from_offsets",
"(",
"offset_fronts",
",",
"corresponding_offsets",
")",
":",
"all_offset_fronts_of_interest",
"=",
"[",
"]",
"ids_ntimes_seen",
"=",
"{",
"}",
"for",
"offset_index",
"in",
"corresponding_offsets",
":",
"offset_id",
"=",
"_f... | 1daefb8de626ddff3ff7016697c3ad31d262ecd6 |
test | _remove_overlaps | Removes all points in the fronts that overlap with the segmentation mask. | algorithms/asa.py | def _remove_overlaps(segmentation_mask, fronts):
"""
Removes all points in the fronts that overlap with the segmentation mask.
"""
fidxs, sidxs = np.where((segmentation_mask != fronts) & (segmentation_mask != 0) & (fronts != 0))
fronts[fidxs, sidxs] = 0 | def _remove_overlaps(segmentation_mask, fronts):
"""
Removes all points in the fronts that overlap with the segmentation mask.
"""
fidxs, sidxs = np.where((segmentation_mask != fronts) & (segmentation_mask != 0) & (fronts != 0))
fronts[fidxs, sidxs] = 0 | [
"Removes",
"all",
"points",
"in",
"the",
"fronts",
"that",
"overlap",
"with",
"the",
"segmentation",
"mask",
"."
] | MaxStrange/AudioSegment | python | https://github.com/MaxStrange/AudioSegment/blob/1daefb8de626ddff3ff7016697c3ad31d262ecd6/algorithms/asa.py#L632-L637 | [
"def",
"_remove_overlaps",
"(",
"segmentation_mask",
",",
"fronts",
")",
":",
"fidxs",
",",
"sidxs",
"=",
"np",
".",
"where",
"(",
"(",
"segmentation_mask",
"!=",
"fronts",
")",
"&",
"(",
"segmentation_mask",
"!=",
"0",
")",
"&",
"(",
"fronts",
"!=",
"0"... | 1daefb8de626ddff3ff7016697c3ad31d262ecd6 |
test | _match_fronts | Returns a segmentation mask, which looks like this:
frequency 1: 0 0 4 4 4 4 4 0 0 5 5 5
frequency 2: 0 4 4 4 4 4 0 0 0 0 5 5
frequency 3: 0 4 4 4 4 4 4 4 5 5 5 5
That is, each item in the array is either a 0 (not part of a segment) or a positive
integer which indicates which segment the sample in ... | algorithms/asa.py | def _match_fronts(onset_fronts, offset_fronts, onsets, offsets, debug=False):
"""
Returns a segmentation mask, which looks like this:
frequency 1: 0 0 4 4 4 4 4 0 0 5 5 5
frequency 2: 0 4 4 4 4 4 0 0 0 0 5 5
frequency 3: 0 4 4 4 4 4 4 4 5 5 5 5
That is, each item in the array is either a 0 (not... | def _match_fronts(onset_fronts, offset_fronts, onsets, offsets, debug=False):
"""
Returns a segmentation mask, which looks like this:
frequency 1: 0 0 4 4 4 4 4 0 0 5 5 5
frequency 2: 0 4 4 4 4 4 0 0 0 0 5 5
frequency 3: 0 4 4 4 4 4 4 4 5 5 5 5
That is, each item in the array is either a 0 (not... | [
"Returns",
"a",
"segmentation",
"mask",
"which",
"looks",
"like",
"this",
":",
"frequency",
"1",
":",
"0",
"0",
"4",
"4",
"4",
"4",
"4",
"0",
"0",
"5",
"5",
"5",
"frequency",
"2",
":",
"0",
"4",
"4",
"4",
"4",
"4",
"0",
"0",
"0",
"0",
"5",
... | MaxStrange/AudioSegment | python | https://github.com/MaxStrange/AudioSegment/blob/1daefb8de626ddff3ff7016697c3ad31d262ecd6/algorithms/asa.py#L639-L773 | [
"def",
"_match_fronts",
"(",
"onset_fronts",
",",
"offset_fronts",
",",
"onsets",
",",
"offsets",
",",
"debug",
"=",
"False",
")",
":",
"def",
"printd",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"debug",
":",
"print",
"(",
"*",
"args... | 1daefb8de626ddff3ff7016697c3ad31d262ecd6 |
test | _remove_fronts_that_are_too_small | Removes all fronts from `fronts` which are strictly smaller than
`size` consecutive frequencies in length. | algorithms/asa.py | def _remove_fronts_that_are_too_small(fronts, size):
"""
Removes all fronts from `fronts` which are strictly smaller than
`size` consecutive frequencies in length.
"""
ids = np.unique(fronts)
for id in ids:
if id == 0 or id == -1:
continue
front = _get_front_idxs_from... | def _remove_fronts_that_are_too_small(fronts, size):
"""
Removes all fronts from `fronts` which are strictly smaller than
`size` consecutive frequencies in length.
"""
ids = np.unique(fronts)
for id in ids:
if id == 0 or id == -1:
continue
front = _get_front_idxs_from... | [
"Removes",
"all",
"fronts",
"from",
"fronts",
"which",
"are",
"strictly",
"smaller",
"than",
"size",
"consecutive",
"frequencies",
"in",
"length",
"."
] | MaxStrange/AudioSegment | python | https://github.com/MaxStrange/AudioSegment/blob/1daefb8de626ddff3ff7016697c3ad31d262ecd6/algorithms/asa.py#L776-L788 | [
"def",
"_remove_fronts_that_are_too_small",
"(",
"fronts",
",",
"size",
")",
":",
"ids",
"=",
"np",
".",
"unique",
"(",
"fronts",
")",
"for",
"id",
"in",
"ids",
":",
"if",
"id",
"==",
"0",
"or",
"id",
"==",
"-",
"1",
":",
"continue",
"front",
"=",
... | 1daefb8de626ddff3ff7016697c3ad31d262ecd6 |
test | _break_poorly_matched_fronts | For each onset front, for each frequency in that front, break the onset front if the signals
between this frequency's onset and the next frequency's onset are not similar enough.
Specifically:
If we have the following two frequency channels, and the two O's are part of the same onset front,
::
... | algorithms/asa.py | def _break_poorly_matched_fronts(fronts, threshold=0.1, threshold_overlap_samples=3):
"""
For each onset front, for each frequency in that front, break the onset front if the signals
between this frequency's onset and the next frequency's onset are not similar enough.
Specifically:
If we have the f... | def _break_poorly_matched_fronts(fronts, threshold=0.1, threshold_overlap_samples=3):
"""
For each onset front, for each frequency in that front, break the onset front if the signals
between this frequency's onset and the next frequency's onset are not similar enough.
Specifically:
If we have the f... | [
"For",
"each",
"onset",
"front",
"for",
"each",
"frequency",
"in",
"that",
"front",
"break",
"the",
"onset",
"front",
"if",
"the",
"signals",
"between",
"this",
"frequency",
"s",
"onset",
"and",
"the",
"next",
"frequency",
"s",
"onset",
"are",
"not",
"simi... | MaxStrange/AudioSegment | python | https://github.com/MaxStrange/AudioSegment/blob/1daefb8de626ddff3ff7016697c3ad31d262ecd6/algorithms/asa.py#L790-L855 | [
"def",
"_break_poorly_matched_fronts",
"(",
"fronts",
",",
"threshold",
"=",
"0.1",
",",
"threshold_overlap_samples",
"=",
"3",
")",
":",
"assert",
"threshold_overlap_samples",
">",
"0",
",",
"\"Number of samples of overlap must be greater than zero\"",
"breaks_after",
"=",... | 1daefb8de626ddff3ff7016697c3ad31d262ecd6 |
test | _update_segmentation_mask_if_overlap | Merges the segments specified by `id` (found in `toupdate`) and `otherid`
(found in `other`) if they overlap at all. Updates `toupdate` accordingly. | algorithms/asa.py | def _update_segmentation_mask_if_overlap(toupdate, other, id, otherid):
"""
Merges the segments specified by `id` (found in `toupdate`) and `otherid`
(found in `other`) if they overlap at all. Updates `toupdate` accordingly.
"""
# If there is any overlap or touching, merge the two, otherwise just re... | def _update_segmentation_mask_if_overlap(toupdate, other, id, otherid):
"""
Merges the segments specified by `id` (found in `toupdate`) and `otherid`
(found in `other`) if they overlap at all. Updates `toupdate` accordingly.
"""
# If there is any overlap or touching, merge the two, otherwise just re... | [
"Merges",
"the",
"segments",
"specified",
"by",
"id",
"(",
"found",
"in",
"toupdate",
")",
"and",
"otherid",
"(",
"found",
"in",
"other",
")",
"if",
"they",
"overlap",
"at",
"all",
".",
"Updates",
"toupdate",
"accordingly",
"."
] | MaxStrange/AudioSegment | python | https://github.com/MaxStrange/AudioSegment/blob/1daefb8de626ddff3ff7016697c3ad31d262ecd6/algorithms/asa.py#L857-L870 | [
"def",
"_update_segmentation_mask_if_overlap",
"(",
"toupdate",
",",
"other",
",",
"id",
",",
"otherid",
")",
":",
"# If there is any overlap or touching, merge the two, otherwise just return",
"yourmask",
"=",
"other",
"==",
"otherid",
"mymask",
"=",
"toupdate",
"==",
"i... | 1daefb8de626ddff3ff7016697c3ad31d262ecd6 |
test | _segments_are_adjacent | Checks if seg1 and seg2 are adjacent at any point. Each is a tuple of the form
(fidxs, sidxs). | algorithms/asa.py | def _segments_are_adjacent(seg1, seg2):
"""
Checks if seg1 and seg2 are adjacent at any point. Each is a tuple of the form
(fidxs, sidxs).
"""
# TODO: This is unnacceptably slow
lsf1, lss1 = seg1
lsf2, lss2 = seg2
for i, f1 in enumerate(lsf1):
for j, f2 in enumerate(lsf2):
... | def _segments_are_adjacent(seg1, seg2):
"""
Checks if seg1 and seg2 are adjacent at any point. Each is a tuple of the form
(fidxs, sidxs).
"""
# TODO: This is unnacceptably slow
lsf1, lss1 = seg1
lsf2, lss2 = seg2
for i, f1 in enumerate(lsf1):
for j, f2 in enumerate(lsf2):
... | [
"Checks",
"if",
"seg1",
"and",
"seg2",
"are",
"adjacent",
"at",
"any",
"point",
".",
"Each",
"is",
"a",
"tuple",
"of",
"the",
"form",
"(",
"fidxs",
"sidxs",
")",
"."
] | MaxStrange/AudioSegment | python | https://github.com/MaxStrange/AudioSegment/blob/1daefb8de626ddff3ff7016697c3ad31d262ecd6/algorithms/asa.py#L872-L886 | [
"def",
"_segments_are_adjacent",
"(",
"seg1",
",",
"seg2",
")",
":",
"# TODO: This is unnacceptably slow",
"lsf1",
",",
"lss1",
"=",
"seg1",
"lsf2",
",",
"lss2",
"=",
"seg2",
"for",
"i",
",",
"f1",
"in",
"enumerate",
"(",
"lsf1",
")",
":",
"for",
"j",
",... | 1daefb8de626ddff3ff7016697c3ad31d262ecd6 |
test | _merge_adjacent_segments | Merges all segments in `mask` which are touching. | algorithms/asa.py | def _merge_adjacent_segments(mask):
"""
Merges all segments in `mask` which are touching.
"""
mask_ids = [id for id in np.unique(mask) if id != 0]
for id in mask_ids:
myfidxs, mysidxs = np.where(mask == id)
for other in mask_ids: # Ugh, brute force O(N^2) algorithm.. gross..
... | def _merge_adjacent_segments(mask):
"""
Merges all segments in `mask` which are touching.
"""
mask_ids = [id for id in np.unique(mask) if id != 0]
for id in mask_ids:
myfidxs, mysidxs = np.where(mask == id)
for other in mask_ids: # Ugh, brute force O(N^2) algorithm.. gross..
... | [
"Merges",
"all",
"segments",
"in",
"mask",
"which",
"are",
"touching",
"."
] | MaxStrange/AudioSegment | python | https://github.com/MaxStrange/AudioSegment/blob/1daefb8de626ddff3ff7016697c3ad31d262ecd6/algorithms/asa.py#L888-L901 | [
"def",
"_merge_adjacent_segments",
"(",
"mask",
")",
":",
"mask_ids",
"=",
"[",
"id",
"for",
"id",
"in",
"np",
".",
"unique",
"(",
"mask",
")",
"if",
"id",
"!=",
"0",
"]",
"for",
"id",
"in",
"mask_ids",
":",
"myfidxs",
",",
"mysidxs",
"=",
"np",
".... | 1daefb8de626ddff3ff7016697c3ad31d262ecd6 |
test | _integrate_segmentation_masks | `segmasks` should be in sorted order of [coarsest, ..., finest].
Integrates the given list of segmentation masks together to form one segmentation mask
by having each segment subsume ones that exist in the finer masks. | algorithms/asa.py | def _integrate_segmentation_masks(segmasks):
"""
`segmasks` should be in sorted order of [coarsest, ..., finest].
Integrates the given list of segmentation masks together to form one segmentation mask
by having each segment subsume ones that exist in the finer masks.
"""
if len(segmasks) == 1:
... | def _integrate_segmentation_masks(segmasks):
"""
`segmasks` should be in sorted order of [coarsest, ..., finest].
Integrates the given list of segmentation masks together to form one segmentation mask
by having each segment subsume ones that exist in the finer masks.
"""
if len(segmasks) == 1:
... | [
"segmasks",
"should",
"be",
"in",
"sorted",
"order",
"of",
"[",
"coarsest",
"...",
"finest",
"]",
"."
] | MaxStrange/AudioSegment | python | https://github.com/MaxStrange/AudioSegment/blob/1daefb8de626ddff3ff7016697c3ad31d262ecd6/algorithms/asa.py#L903-L924 | [
"def",
"_integrate_segmentation_masks",
"(",
"segmasks",
")",
":",
"if",
"len",
"(",
"segmasks",
")",
"==",
"1",
":",
"return",
"segmasks",
"assert",
"len",
"(",
"segmasks",
")",
">",
"0",
",",
"\"Passed in empty list of segmentation masks\"",
"coarse_mask",
"=",
... | 1daefb8de626ddff3ff7016697c3ad31d262ecd6 |
test | _separate_masks | Returns a list of segmentation masks each of the same dimension as the input one,
but where they each have exactly one segment in them and all other samples in them
are zeroed.
Only bothers to return segments that are larger in total area than `threshold * mask.size`. | algorithms/asa.py | def _separate_masks(mask, threshold=0.025):
"""
Returns a list of segmentation masks each of the same dimension as the input one,
but where they each have exactly one segment in them and all other samples in them
are zeroed.
Only bothers to return segments that are larger in total area than `thresh... | def _separate_masks(mask, threshold=0.025):
"""
Returns a list of segmentation masks each of the same dimension as the input one,
but where they each have exactly one segment in them and all other samples in them
are zeroed.
Only bothers to return segments that are larger in total area than `thresh... | [
"Returns",
"a",
"list",
"of",
"segmentation",
"masks",
"each",
"of",
"the",
"same",
"dimension",
"as",
"the",
"input",
"one",
"but",
"where",
"they",
"each",
"have",
"exactly",
"one",
"segment",
"in",
"them",
"and",
"all",
"other",
"samples",
"in",
"them",... | MaxStrange/AudioSegment | python | https://github.com/MaxStrange/AudioSegment/blob/1daefb8de626ddff3ff7016697c3ad31d262ecd6/algorithms/asa.py#L935-L953 | [
"def",
"_separate_masks",
"(",
"mask",
",",
"threshold",
"=",
"0.025",
")",
":",
"try",
":",
"ncpus",
"=",
"multiprocessing",
".",
"cpu_count",
"(",
")",
"except",
"NotImplementedError",
":",
"ncpus",
"=",
"2",
"with",
"multiprocessing",
".",
"Pool",
"(",
... | 1daefb8de626ddff3ff7016697c3ad31d262ecd6 |
test | _downsample_one_or_the_other | Takes the given `mask` and `stft`, which must be matrices of shape `frequencies, times`
and downsamples one of them into the other one's times, so that the time dimensions
are equal. Leaves the frequency dimension untouched. | algorithms/asa.py | def _downsample_one_or_the_other(mask, mask_indexes, stft, stft_indexes):
"""
Takes the given `mask` and `stft`, which must be matrices of shape `frequencies, times`
and downsamples one of them into the other one's times, so that the time dimensions
are equal. Leaves the frequency dimension untouched.
... | def _downsample_one_or_the_other(mask, mask_indexes, stft, stft_indexes):
"""
Takes the given `mask` and `stft`, which must be matrices of shape `frequencies, times`
and downsamples one of them into the other one's times, so that the time dimensions
are equal. Leaves the frequency dimension untouched.
... | [
"Takes",
"the",
"given",
"mask",
"and",
"stft",
"which",
"must",
"be",
"matrices",
"of",
"shape",
"frequencies",
"times",
"and",
"downsamples",
"one",
"of",
"them",
"into",
"the",
"other",
"one",
"s",
"times",
"so",
"that",
"the",
"time",
"dimensions",
"ar... | MaxStrange/AudioSegment | python | https://github.com/MaxStrange/AudioSegment/blob/1daefb8de626ddff3ff7016697c3ad31d262ecd6/algorithms/asa.py#L976-L996 | [
"def",
"_downsample_one_or_the_other",
"(",
"mask",
",",
"mask_indexes",
",",
"stft",
",",
"stft_indexes",
")",
":",
"assert",
"len",
"(",
"mask",
".",
"shape",
")",
"==",
"2",
",",
"\"Expected a two-dimensional `mask`, but got one of {} dimensions.\"",
".",
"format",... | 1daefb8de626ddff3ff7016697c3ad31d262ecd6 |
test | _map_segmentation_mask_to_stft_domain | Maps the given `mask`, which is in domain (`frequencies`, `times`) to the new domain (`stft_frequencies`, `stft_times`)
and returns the result. | algorithms/asa.py | def _map_segmentation_mask_to_stft_domain(mask, times, frequencies, stft_times, stft_frequencies):
"""
Maps the given `mask`, which is in domain (`frequencies`, `times`) to the new domain (`stft_frequencies`, `stft_times`)
and returns the result.
"""
assert mask.shape == (frequencies.shape[0], times... | def _map_segmentation_mask_to_stft_domain(mask, times, frequencies, stft_times, stft_frequencies):
"""
Maps the given `mask`, which is in domain (`frequencies`, `times`) to the new domain (`stft_frequencies`, `stft_times`)
and returns the result.
"""
assert mask.shape == (frequencies.shape[0], times... | [
"Maps",
"the",
"given",
"mask",
"which",
"is",
"in",
"domain",
"(",
"frequencies",
"times",
")",
"to",
"the",
"new",
"domain",
"(",
"stft_frequencies",
"stft_times",
")",
"and",
"returns",
"the",
"result",
"."
] | MaxStrange/AudioSegment | python | https://github.com/MaxStrange/AudioSegment/blob/1daefb8de626ddff3ff7016697c3ad31d262ecd6/algorithms/asa.py#L998-L1020 | [
"def",
"_map_segmentation_mask_to_stft_domain",
"(",
"mask",
",",
"times",
",",
"frequencies",
",",
"stft_times",
",",
"stft_frequencies",
")",
":",
"assert",
"mask",
".",
"shape",
"==",
"(",
"frequencies",
".",
"shape",
"[",
"0",
"]",
",",
"times",
".",
"sh... | 1daefb8de626ddff3ff7016697c3ad31d262ecd6 |
test | _asa_task | Worker for the ASA algorithm's multiprocessing step. | algorithms/asa.py | def _asa_task(q, masks, stft, sample_width, frame_rate, nsamples_for_each_fft):
"""
Worker for the ASA algorithm's multiprocessing step.
"""
# Convert each mask to (1 or 0) rather than (ID or 0)
for mask in masks:
mask = np.where(mask > 0, 1, 0)
# Multiply the masks against STFTs
ma... | def _asa_task(q, masks, stft, sample_width, frame_rate, nsamples_for_each_fft):
"""
Worker for the ASA algorithm's multiprocessing step.
"""
# Convert each mask to (1 or 0) rather than (ID or 0)
for mask in masks:
mask = np.where(mask > 0, 1, 0)
# Multiply the masks against STFTs
ma... | [
"Worker",
"for",
"the",
"ASA",
"algorithm",
"s",
"multiprocessing",
"step",
"."
] | MaxStrange/AudioSegment | python | https://github.com/MaxStrange/AudioSegment/blob/1daefb8de626ddff3ff7016697c3ad31d262ecd6/algorithms/asa.py#L1022-L1043 | [
"def",
"_asa_task",
"(",
"q",
",",
"masks",
",",
"stft",
",",
"sample_width",
",",
"frame_rate",
",",
"nsamples_for_each_fft",
")",
":",
"# Convert each mask to (1 or 0) rather than (ID or 0)",
"for",
"mask",
"in",
"masks",
":",
"mask",
"=",
"np",
".",
"where",
... | 1daefb8de626ddff3ff7016697c3ad31d262ecd6 |
test | _get_filter_indices | Runs a Markov Decision Process over the given `seg` in chunks of `ms_per_input`, yielding `True` if
this `ms_per_input` chunk has been classified as positive (1) and `False` if this chunk has been
classified as negative (0).
:param seg: The AudioSegment to apply this algorithm to.
:para... | algorithms/eventdetection.py | def _get_filter_indices(seg, start_as_yes, prob_raw_yes, ms_per_input, model, transition_matrix, model_stats):
"""
Runs a Markov Decision Process over the given `seg` in chunks of `ms_per_input`, yielding `True` if
this `ms_per_input` chunk has been classified as positive (1) and `False` if this chunk has b... | def _get_filter_indices(seg, start_as_yes, prob_raw_yes, ms_per_input, model, transition_matrix, model_stats):
"""
Runs a Markov Decision Process over the given `seg` in chunks of `ms_per_input`, yielding `True` if
this `ms_per_input` chunk has been classified as positive (1) and `False` if this chunk has b... | [
"Runs",
"a",
"Markov",
"Decision",
"Process",
"over",
"the",
"given",
"seg",
"in",
"chunks",
"of",
"ms_per_input",
"yielding",
"True",
"if",
"this",
"ms_per_input",
"chunk",
"has",
"been",
"classified",
"as",
"positive",
"(",
"1",
")",
"and",
"False",
"if",
... | MaxStrange/AudioSegment | python | https://github.com/MaxStrange/AudioSegment/blob/1daefb8de626ddff3ff7016697c3ad31d262ecd6/algorithms/eventdetection.py#L9-L44 | [
"def",
"_get_filter_indices",
"(",
"seg",
",",
"start_as_yes",
",",
"prob_raw_yes",
",",
"ms_per_input",
",",
"model",
",",
"transition_matrix",
",",
"model_stats",
")",
":",
"filter_triggered",
"=",
"1",
"if",
"start_as_yes",
"else",
"0",
"prob_raw_no",
"=",
"1... | 1daefb8de626ddff3ff7016697c3ad31d262ecd6 |
test | _group_filter_values | Takes a list of 1s and 0s and returns a list of tuples of the form:
['y/n', timestamp]. | algorithms/eventdetection.py | def _group_filter_values(seg, filter_indices, ms_per_input):
"""
Takes a list of 1s and 0s and returns a list of tuples of the form:
['y/n', timestamp].
"""
ret = []
for filter_value, (_segment, timestamp) in zip(filter_indices, seg.generate_frames_as_segments(ms_per_input)):
if filter_v... | def _group_filter_values(seg, filter_indices, ms_per_input):
"""
Takes a list of 1s and 0s and returns a list of tuples of the form:
['y/n', timestamp].
"""
ret = []
for filter_value, (_segment, timestamp) in zip(filter_indices, seg.generate_frames_as_segments(ms_per_input)):
if filter_v... | [
"Takes",
"a",
"list",
"of",
"1s",
"and",
"0s",
"and",
"returns",
"a",
"list",
"of",
"tuples",
"of",
"the",
"form",
":",
"[",
"y",
"/",
"n",
"timestamp",
"]",
"."
] | MaxStrange/AudioSegment | python | https://github.com/MaxStrange/AudioSegment/blob/1daefb8de626ddff3ff7016697c3ad31d262ecd6/algorithms/eventdetection.py#L46-L67 | [
"def",
"_group_filter_values",
"(",
"seg",
",",
"filter_indices",
",",
"ms_per_input",
")",
":",
"ret",
"=",
"[",
"]",
"for",
"filter_value",
",",
"(",
"_segment",
",",
"timestamp",
")",
"in",
"zip",
"(",
"filter_indices",
",",
"seg",
".",
"generate_frames_a... | 1daefb8de626ddff3ff7016697c3ad31d262ecd6 |
test | _homogeneity_filter | Takes `ls` (a list of 1s and 0s) and smoothes it so that adjacent values are more likely
to be the same.
:param ls: A list of 1s and 0s to smooth.
:param window_size: How large the smoothing kernel is.
:returns: A list of 1s and 0s, but smoother. | algorithms/eventdetection.py | def _homogeneity_filter(ls, window_size):
"""
Takes `ls` (a list of 1s and 0s) and smoothes it so that adjacent values are more likely
to be the same.
:param ls: A list of 1s and 0s to smooth.
:param window_size: How large the smoothing kernel is.
:returns: A list of 1s and 0... | def _homogeneity_filter(ls, window_size):
"""
Takes `ls` (a list of 1s and 0s) and smoothes it so that adjacent values are more likely
to be the same.
:param ls: A list of 1s and 0s to smooth.
:param window_size: How large the smoothing kernel is.
:returns: A list of 1s and 0... | [
"Takes",
"ls",
"(",
"a",
"list",
"of",
"1s",
"and",
"0s",
")",
"and",
"smoothes",
"it",
"so",
"that",
"adjacent",
"values",
"are",
"more",
"likely",
"to",
"be",
"the",
"same",
"."
] | MaxStrange/AudioSegment | python | https://github.com/MaxStrange/AudioSegment/blob/1daefb8de626ddff3ff7016697c3ad31d262ecd6/algorithms/eventdetection.py#L69-L89 | [
"def",
"_homogeneity_filter",
"(",
"ls",
",",
"window_size",
")",
":",
"# TODO: This is fine way to do this, but it seems like it might be faster and better to do a Gaussian convolution followed by rounding",
"k",
"=",
"window_size",
"i",
"=",
"k",
"while",
"i",
"<=",
"len",
"(... | 1daefb8de626ddff3ff7016697c3ad31d262ecd6 |
test | bandpass_filter | Does a bandpass filter over the given data.
:param data: The data (numpy array) to be filtered.
:param low: The low cutoff in Hz.
:param high: The high cutoff in Hz.
:param fs: The sample rate (in Hz) of the data.
:param order: The order of the filter. The higher the order, the tighter the roll-off... | algorithms/filters.py | def bandpass_filter(data, low, high, fs, order=5):
"""
Does a bandpass filter over the given data.
:param data: The data (numpy array) to be filtered.
:param low: The low cutoff in Hz.
:param high: The high cutoff in Hz.
:param fs: The sample rate (in Hz) of the data.
:param order: The orde... | def bandpass_filter(data, low, high, fs, order=5):
"""
Does a bandpass filter over the given data.
:param data: The data (numpy array) to be filtered.
:param low: The low cutoff in Hz.
:param high: The high cutoff in Hz.
:param fs: The sample rate (in Hz) of the data.
:param order: The orde... | [
"Does",
"a",
"bandpass",
"filter",
"over",
"the",
"given",
"data",
"."
] | MaxStrange/AudioSegment | python | https://github.com/MaxStrange/AudioSegment/blob/1daefb8de626ddff3ff7016697c3ad31d262ecd6/algorithms/filters.py#L7-L23 | [
"def",
"bandpass_filter",
"(",
"data",
",",
"low",
",",
"high",
",",
"fs",
",",
"order",
"=",
"5",
")",
":",
"nyq",
"=",
"0.5",
"*",
"fs",
"low",
"=",
"low",
"/",
"nyq",
"high",
"=",
"high",
"/",
"nyq",
"b",
",",
"a",
"=",
"signal",
".",
"but... | 1daefb8de626ddff3ff7016697c3ad31d262ecd6 |
test | lowpass_filter | Does a lowpass filter over the given data.
:param data: The data (numpy array) to be filtered.
:param cutoff: The high cutoff in Hz.
:param fs: The sample rate in Hz of the data.
:param order: The order of the filter. The higher the order, the tighter the roll-off.
:returns: Filtered data (numpy ar... | algorithms/filters.py | def lowpass_filter(data, cutoff, fs, order=5):
"""
Does a lowpass filter over the given data.
:param data: The data (numpy array) to be filtered.
:param cutoff: The high cutoff in Hz.
:param fs: The sample rate in Hz of the data.
:param order: The order of the filter. The higher the order, the ... | def lowpass_filter(data, cutoff, fs, order=5):
"""
Does a lowpass filter over the given data.
:param data: The data (numpy array) to be filtered.
:param cutoff: The high cutoff in Hz.
:param fs: The sample rate in Hz of the data.
:param order: The order of the filter. The higher the order, the ... | [
"Does",
"a",
"lowpass",
"filter",
"over",
"the",
"given",
"data",
"."
] | MaxStrange/AudioSegment | python | https://github.com/MaxStrange/AudioSegment/blob/1daefb8de626ddff3ff7016697c3ad31d262ecd6/algorithms/filters.py#L25-L39 | [
"def",
"lowpass_filter",
"(",
"data",
",",
"cutoff",
",",
"fs",
",",
"order",
"=",
"5",
")",
":",
"nyq",
"=",
"0.5",
"*",
"fs",
"normal_cutoff",
"=",
"cutoff",
"/",
"nyq",
"b",
",",
"a",
"=",
"signal",
".",
"butter",
"(",
"order",
",",
"normal_cuto... | 1daefb8de626ddff3ff7016697c3ad31d262ecd6 |
test | list_to_tf_input | Separates the outcome feature from the data and creates the onehot vector for each row. | BlackBoxAuditing/model_factories/DecisionTree.py | def list_to_tf_input(data, response_index, num_outcomes):
"""
Separates the outcome feature from the data and creates the onehot vector for each row.
"""
matrix = np.matrix([row[:response_index] + row[response_index+1:] for row in data])
outcomes = np.asarray([row[response_index] for row in data], dtype=np.ui... | def list_to_tf_input(data, response_index, num_outcomes):
"""
Separates the outcome feature from the data and creates the onehot vector for each row.
"""
matrix = np.matrix([row[:response_index] + row[response_index+1:] for row in data])
outcomes = np.asarray([row[response_index] for row in data], dtype=np.ui... | [
"Separates",
"the",
"outcome",
"feature",
"from",
"the",
"data",
"and",
"creates",
"the",
"onehot",
"vector",
"for",
"each",
"row",
"."
] | algofairness/BlackBoxAuditing | python | https://github.com/algofairness/BlackBoxAuditing/blob/b06c4faed5591cd7088475b2a203127bc5820483/BlackBoxAuditing/model_factories/DecisionTree.py#L132-L140 | [
"def",
"list_to_tf_input",
"(",
"data",
",",
"response_index",
",",
"num_outcomes",
")",
":",
"matrix",
"=",
"np",
".",
"matrix",
"(",
"[",
"row",
"[",
":",
"response_index",
"]",
"+",
"row",
"[",
"response_index",
"+",
"1",
":",
"]",
"for",
"row",
"in... | b06c4faed5591cd7088475b2a203127bc5820483 |
test | expand_and_standardize_dataset | Standardizes continuous features and expands categorical features. | BlackBoxAuditing/model_factories/DecisionTree.py | def expand_and_standardize_dataset(response_index, response_header, data_set, col_vals, headers, standardizers, feats_to_ignore, columns_to_expand, outcome_trans_dict):
"""
Standardizes continuous features and expands categorical features.
"""
# expand and standardize
modified_set = []
for row_index, row in... | def expand_and_standardize_dataset(response_index, response_header, data_set, col_vals, headers, standardizers, feats_to_ignore, columns_to_expand, outcome_trans_dict):
"""
Standardizes continuous features and expands categorical features.
"""
# expand and standardize
modified_set = []
for row_index, row in... | [
"Standardizes",
"continuous",
"features",
"and",
"expands",
"categorical",
"features",
"."
] | algofairness/BlackBoxAuditing | python | https://github.com/algofairness/BlackBoxAuditing/blob/b06c4faed5591cd7088475b2a203127bc5820483/BlackBoxAuditing/model_factories/DecisionTree.py#L142-L190 | [
"def",
"expand_and_standardize_dataset",
"(",
"response_index",
",",
"response_header",
",",
"data_set",
",",
"col_vals",
",",
"headers",
",",
"standardizers",
",",
"feats_to_ignore",
",",
"columns_to_expand",
",",
"outcome_trans_dict",
")",
":",
"# expand and standardize... | b06c4faed5591cd7088475b2a203127bc5820483 |
test | equal_ignore_order | Used to check whether the two edge lists have the same edges
when elements are neither hashable nor sortable. | BlackBoxAuditing/repairers/CategoricalFeature.py | def equal_ignore_order(a, b):
"""
Used to check whether the two edge lists have the same edges
when elements are neither hashable nor sortable.
"""
unmatched = list(b)
for element in a:
try:
unmatched.remove(element)
except ValueError:
return False
return not unmatched | def equal_ignore_order(a, b):
"""
Used to check whether the two edge lists have the same edges
when elements are neither hashable nor sortable.
"""
unmatched = list(b)
for element in a:
try:
unmatched.remove(element)
except ValueError:
return False
return not unmatched | [
"Used",
"to",
"check",
"whether",
"the",
"two",
"edge",
"lists",
"have",
"the",
"same",
"edges",
"when",
"elements",
"are",
"neither",
"hashable",
"nor",
"sortable",
"."
] | algofairness/BlackBoxAuditing | python | https://github.com/algofairness/BlackBoxAuditing/blob/b06c4faed5591cd7088475b2a203127bc5820483/BlackBoxAuditing/repairers/CategoricalFeature.py#L111-L122 | [
"def",
"equal_ignore_order",
"(",
"a",
",",
"b",
")",
":",
"unmatched",
"=",
"list",
"(",
"b",
")",
"for",
"element",
"in",
"a",
":",
"try",
":",
"unmatched",
".",
"remove",
"(",
"element",
")",
"except",
"ValueError",
":",
"return",
"False",
"return",... | b06c4faed5591cd7088475b2a203127bc5820483 |
test | Repairer.repair | Create unique value structures: When performing repairs, we choose median values. If repair is partial, then values will be modified to some intermediate value between the original and the median value. However, the partially repaired value will only be chosen out of values that exist in the data set. This prevents ch... | python2_source/BlackBoxAuditing/repairers/CategoricRepairer.py | def repair(self, data_to_repair):
num_cols = len(data_to_repair[0])
col_ids = range(num_cols)
# Get column type information
col_types = ["Y"]*len(col_ids)
for i, col in enumerate(col_ids):
if i in self.features_to_ignore:
col_types[i] = "I"
elif i == self.feature_to_repair:
... | def repair(self, data_to_repair):
num_cols = len(data_to_repair[0])
col_ids = range(num_cols)
# Get column type information
col_types = ["Y"]*len(col_ids)
for i, col in enumerate(col_ids):
if i in self.features_to_ignore:
col_types[i] = "I"
elif i == self.feature_to_repair:
... | [
"Create",
"unique",
"value",
"structures",
":",
"When",
"performing",
"repairs",
"we",
"choose",
"median",
"values",
".",
"If",
"repair",
"is",
"partial",
"then",
"values",
"will",
"be",
"modified",
"to",
"some",
"intermediate",
"value",
"between",
"the",
"ori... | algofairness/BlackBoxAuditing | python | https://github.com/algofairness/BlackBoxAuditing/blob/b06c4faed5591cd7088475b2a203127bc5820483/python2_source/BlackBoxAuditing/repairers/CategoricRepairer.py#L15-L197 | [
"def",
"repair",
"(",
"self",
",",
"data_to_repair",
")",
":",
"num_cols",
"=",
"len",
"(",
"data_to_repair",
"[",
"0",
"]",
")",
"col_ids",
"=",
"range",
"(",
"num_cols",
")",
"# Get column type information",
"col_types",
"=",
"[",
"\"Y\"",
"]",
"*",
"len... | b06c4faed5591cd7088475b2a203127bc5820483 |
test | group_audit_ranks | Given a list of audit files, rank them using the `measurer` and
return the features that never deviate more than `similarity_bound`
across repairs. | BlackBoxAuditing/audit_reading.py | def group_audit_ranks(filenames, measurer, similarity_bound=0.05):
"""
Given a list of audit files, rank them using the `measurer` and
return the features that never deviate more than `similarity_bound`
across repairs.
"""
def _partition_groups(feature_scores):
groups = []
for feature, score in fea... | def group_audit_ranks(filenames, measurer, similarity_bound=0.05):
"""
Given a list of audit files, rank them using the `measurer` and
return the features that never deviate more than `similarity_bound`
across repairs.
"""
def _partition_groups(feature_scores):
groups = []
for feature, score in fea... | [
"Given",
"a",
"list",
"of",
"audit",
"files",
"rank",
"them",
"using",
"the",
"measurer",
"and",
"return",
"the",
"features",
"that",
"never",
"deviate",
"more",
"than",
"similarity_bound",
"across",
"repairs",
"."
] | algofairness/BlackBoxAuditing | python | https://github.com/algofairness/BlackBoxAuditing/blob/b06c4faed5591cd7088475b2a203127bc5820483/BlackBoxAuditing/audit_reading.py#L124-L183 | [
"def",
"group_audit_ranks",
"(",
"filenames",
",",
"measurer",
",",
"similarity_bound",
"=",
"0.05",
")",
":",
"def",
"_partition_groups",
"(",
"feature_scores",
")",
":",
"groups",
"=",
"[",
"]",
"for",
"feature",
",",
"score",
"in",
"feature_scores",
":",
... | b06c4faed5591cd7088475b2a203127bc5820483 |
test | accuracy | Given a confusion matrix, returns the accuracy.
Accuracy Definition: http://research.ics.aalto.fi/events/eyechallenge2005/evaluation.shtml | python2_source/BlackBoxAuditing/measurements.py | def accuracy(conf_matrix):
"""
Given a confusion matrix, returns the accuracy.
Accuracy Definition: http://research.ics.aalto.fi/events/eyechallenge2005/evaluation.shtml
"""
total, correct = 0.0, 0.0
for true_response, guess_dict in conf_matrix.items():
for guess, count in guess_dict.items():
if t... | def accuracy(conf_matrix):
"""
Given a confusion matrix, returns the accuracy.
Accuracy Definition: http://research.ics.aalto.fi/events/eyechallenge2005/evaluation.shtml
"""
total, correct = 0.0, 0.0
for true_response, guess_dict in conf_matrix.items():
for guess, count in guess_dict.items():
if t... | [
"Given",
"a",
"confusion",
"matrix",
"returns",
"the",
"accuracy",
".",
"Accuracy",
"Definition",
":",
"http",
":",
"//",
"research",
".",
"ics",
".",
"aalto",
".",
"fi",
"/",
"events",
"/",
"eyechallenge2005",
"/",
"evaluation",
".",
"shtml"
] | algofairness/BlackBoxAuditing | python | https://github.com/algofairness/BlackBoxAuditing/blob/b06c4faed5591cd7088475b2a203127bc5820483/python2_source/BlackBoxAuditing/measurements.py#L1-L12 | [
"def",
"accuracy",
"(",
"conf_matrix",
")",
":",
"total",
",",
"correct",
"=",
"0.0",
",",
"0.0",
"for",
"true_response",
",",
"guess_dict",
"in",
"conf_matrix",
".",
"items",
"(",
")",
":",
"for",
"guess",
",",
"count",
"in",
"guess_dict",
".",
"items",... | b06c4faed5591cd7088475b2a203127bc5820483 |
test | BCR | Given a confusion matrix, returns Balanced Classification Rate.
BCR is (1 - Balanced Error Rate).
BER Definition: http://research.ics.aalto.fi/events/eyechallenge2005/evaluation.shtml | python2_source/BlackBoxAuditing/measurements.py | def BCR(conf_matrix):
"""
Given a confusion matrix, returns Balanced Classification Rate.
BCR is (1 - Balanced Error Rate).
BER Definition: http://research.ics.aalto.fi/events/eyechallenge2005/evaluation.shtml
"""
parts = []
for true_response, guess_dict in conf_matrix.items():
error = 0.0
total =... | def BCR(conf_matrix):
"""
Given a confusion matrix, returns Balanced Classification Rate.
BCR is (1 - Balanced Error Rate).
BER Definition: http://research.ics.aalto.fi/events/eyechallenge2005/evaluation.shtml
"""
parts = []
for true_response, guess_dict in conf_matrix.items():
error = 0.0
total =... | [
"Given",
"a",
"confusion",
"matrix",
"returns",
"Balanced",
"Classification",
"Rate",
".",
"BCR",
"is",
"(",
"1",
"-",
"Balanced",
"Error",
"Rate",
")",
".",
"BER",
"Definition",
":",
"http",
":",
"//",
"research",
".",
"ics",
".",
"aalto",
".",
"fi",
... | algofairness/BlackBoxAuditing | python | https://github.com/algofairness/BlackBoxAuditing/blob/b06c4faed5591cd7088475b2a203127bc5820483/python2_source/BlackBoxAuditing/measurements.py#L14-L30 | [
"def",
"BCR",
"(",
"conf_matrix",
")",
":",
"parts",
"=",
"[",
"]",
"for",
"true_response",
",",
"guess_dict",
"in",
"conf_matrix",
".",
"items",
"(",
")",
":",
"error",
"=",
"0.0",
"total",
"=",
"0.0",
"for",
"guess",
",",
"count",
"in",
"guess_dict",... | b06c4faed5591cd7088475b2a203127bc5820483 |
test | get_median | Given an unsorted list of numeric values, return median value (as a float).
Note that in the case of even-length lists of values, we apply the value to
the left of the center to be the median (such that the median can only be
a value from the list of values).
Eg: get_median([1,2,3,4]) == 2, not 2.5. | BlackBoxAuditing/repairers/calculators.py | def get_median(values, kdd):
"""
Given an unsorted list of numeric values, return median value (as a float).
Note that in the case of even-length lists of values, we apply the value to
the left of the center to be the median (such that the median can only be
a value from the list of values).
Eg: get_median(... | def get_median(values, kdd):
"""
Given an unsorted list of numeric values, return median value (as a float).
Note that in the case of even-length lists of values, we apply the value to
the left of the center to be the median (such that the median can only be
a value from the list of values).
Eg: get_median(... | [
"Given",
"an",
"unsorted",
"list",
"of",
"numeric",
"values",
"return",
"median",
"value",
"(",
"as",
"a",
"float",
")",
".",
"Note",
"that",
"in",
"the",
"case",
"of",
"even",
"-",
"length",
"lists",
"of",
"values",
"we",
"apply",
"the",
"value",
"to"... | algofairness/BlackBoxAuditing | python | https://github.com/algofairness/BlackBoxAuditing/blob/b06c4faed5591cd7088475b2a203127bc5820483/BlackBoxAuditing/repairers/calculators.py#L3-L24 | [
"def",
"get_median",
"(",
"values",
",",
"kdd",
")",
":",
"if",
"not",
"values",
":",
"raise",
"Exception",
"(",
"\"Cannot calculate median of list with no values!\"",
")",
"sorted_values",
"=",
"deepcopy",
"(",
"values",
")",
"sorted_values",
".",
"sort",
"(",
... | b06c4faed5591cd7088475b2a203127bc5820483 |
test | expand_to_one_hot | with open("brandon_testing/test_"+str(time.clock())+".csv","w") as f:
writer = csv.writer(f,delimiter=",")
for row in fin:
writer.writerow(row) | python2_source/BlackBoxAuditing/model_factories/RecidivismTensorFlowModelFactory.py | def expand_to_one_hot(data,expand = True,use_alternative=False):
header_dict = {'ALCABUS':0,'PRIRCAT':1,'TMSRVC':2,'SEX1':3,'RACE':4,'RELTYP':5,'age_1st_arrest':6,'DRUGAB':7,'Class':8,'RLAGE':9,'NFRCTNS':10}
new_data = []
for entry in data:
temp = {}
if expand == True:
if entry[header_dict["SEX1"]] ... | def expand_to_one_hot(data,expand = True,use_alternative=False):
header_dict = {'ALCABUS':0,'PRIRCAT':1,'TMSRVC':2,'SEX1':3,'RACE':4,'RELTYP':5,'age_1st_arrest':6,'DRUGAB':7,'Class':8,'RLAGE':9,'NFRCTNS':10}
new_data = []
for entry in data:
temp = {}
if expand == True:
if entry[header_dict["SEX1"]] ... | [
"with",
"open",
"(",
"brandon_testing",
"/",
"test_",
"+",
"str",
"(",
"time",
".",
"clock",
"()",
")",
"+",
".",
"csv",
"w",
")",
"as",
"f",
":",
"writer",
"=",
"csv",
".",
"writer",
"(",
"f",
"delimiter",
"=",
")",
"for",
"row",
"in",
"fin",
... | algofairness/BlackBoxAuditing | python | https://github.com/algofairness/BlackBoxAuditing/blob/b06c4faed5591cd7088475b2a203127bc5820483/python2_source/BlackBoxAuditing/model_factories/RecidivismTensorFlowModelFactory.py#L139-L253 | [
"def",
"expand_to_one_hot",
"(",
"data",
",",
"expand",
"=",
"True",
",",
"use_alternative",
"=",
"False",
")",
":",
"header_dict",
"=",
"{",
"'ALCABUS'",
":",
"0",
",",
"'PRIRCAT'",
":",
"1",
",",
"'TMSRVC'",
":",
"2",
",",
"'SEX1'",
":",
"3",
",",
... | b06c4faed5591cd7088475b2a203127bc5820483 |
test | load_audit_confusion_matrices | Loads a confusion matrix in a two-level dictionary format.
For example, the confusion matrix of a 75%-accurate model
that predicted 15 values (and mis-classified 5) may look like:
{"A": {"A":10, "B": 5}, "B": {"B":5}}
Note that raw boolean values are translated into strings, such that
a value that was the b... | python2_source/BlackBoxAuditing/audit_reading.py | def load_audit_confusion_matrices(filename):
"""
Loads a confusion matrix in a two-level dictionary format.
For example, the confusion matrix of a 75%-accurate model
that predicted 15 values (and mis-classified 5) may look like:
{"A": {"A":10, "B": 5}, "B": {"B":5}}
Note that raw boolean values are transl... | def load_audit_confusion_matrices(filename):
"""
Loads a confusion matrix in a two-level dictionary format.
For example, the confusion matrix of a 75%-accurate model
that predicted 15 values (and mis-classified 5) may look like:
{"A": {"A":10, "B": 5}, "B": {"B":5}}
Note that raw boolean values are transl... | [
"Loads",
"a",
"confusion",
"matrix",
"in",
"a",
"two",
"-",
"level",
"dictionary",
"format",
"."
] | algofairness/BlackBoxAuditing | python | https://github.com/algofairness/BlackBoxAuditing/blob/b06c4faed5591cd7088475b2a203127bc5820483/python2_source/BlackBoxAuditing/audit_reading.py#L11-L40 | [
"def",
"load_audit_confusion_matrices",
"(",
"filename",
")",
":",
"with",
"open",
"(",
"filename",
")",
"as",
"audit_file",
":",
"audit_file",
".",
"next",
"(",
")",
"# Skip the first line.",
"# Extract the confusion matrices and repair levels from the audit file.",
"confu... | b06c4faed5591cd7088475b2a203127bc5820483 |
test | list_to_tf_input | Separates the outcome feature from the data. | BlackBoxAuditing/model_factories/SVM.py | def list_to_tf_input(data, response_index, num_outcomes):
"""
Separates the outcome feature from the data.
"""
matrix = np.matrix([row[:response_index] + row[response_index+1:] for row in data])
outcomes = np.asarray([row[response_index] for row in data], dtype=np.uint8)
return matrix, outcomes | def list_to_tf_input(data, response_index, num_outcomes):
"""
Separates the outcome feature from the data.
"""
matrix = np.matrix([row[:response_index] + row[response_index+1:] for row in data])
outcomes = np.asarray([row[response_index] for row in data], dtype=np.uint8)
return matrix, outcomes | [
"Separates",
"the",
"outcome",
"feature",
"from",
"the",
"data",
"."
] | algofairness/BlackBoxAuditing | python | https://github.com/algofairness/BlackBoxAuditing/blob/b06c4faed5591cd7088475b2a203127bc5820483/BlackBoxAuditing/model_factories/SVM.py#L138-L145 | [
"def",
"list_to_tf_input",
"(",
"data",
",",
"response_index",
",",
"num_outcomes",
")",
":",
"matrix",
"=",
"np",
".",
"matrix",
"(",
"[",
"row",
"[",
":",
"response_index",
"]",
"+",
"row",
"[",
"response_index",
"+",
"1",
":",
"]",
"for",
"row",
"in... | b06c4faed5591cd7088475b2a203127bc5820483 |
test | FreedmanDiaconisBinSize | The bin size in FD-binning is given by size = 2 * IQR(x) * n^(-1/3)
More Info: https://en.wikipedia.org/wiki/Freedman%E2%80%93Diaconis_rule
If the BinSize ends up being 0 (in the case that all values are the same),
return a BinSize of 1. | python2_source/BlackBoxAuditing/repairers/binning/BinSizes.py | def FreedmanDiaconisBinSize(feature_values):
"""
The bin size in FD-binning is given by size = 2 * IQR(x) * n^(-1/3)
More Info: https://en.wikipedia.org/wiki/Freedman%E2%80%93Diaconis_rule
If the BinSize ends up being 0 (in the case that all values are the same),
return a BinSize of 1.
"""
q75, q25 = nu... | def FreedmanDiaconisBinSize(feature_values):
"""
The bin size in FD-binning is given by size = 2 * IQR(x) * n^(-1/3)
More Info: https://en.wikipedia.org/wiki/Freedman%E2%80%93Diaconis_rule
If the BinSize ends up being 0 (in the case that all values are the same),
return a BinSize of 1.
"""
q75, q25 = nu... | [
"The",
"bin",
"size",
"in",
"FD",
"-",
"binning",
"is",
"given",
"by",
"size",
"=",
"2",
"*",
"IQR",
"(",
"x",
")",
"*",
"n^",
"(",
"-",
"1",
"/",
"3",
")",
"More",
"Info",
":",
"https",
":",
"//",
"en",
".",
"wikipedia",
".",
"org",
"/",
"... | algofairness/BlackBoxAuditing | python | https://github.com/algofairness/BlackBoxAuditing/blob/b06c4faed5591cd7088475b2a203127bc5820483/python2_source/BlackBoxAuditing/repairers/binning/BinSizes.py#L3-L15 | [
"def",
"FreedmanDiaconisBinSize",
"(",
"feature_values",
")",
":",
"q75",
",",
"q25",
"=",
"numpy",
".",
"percentile",
"(",
"feature_values",
",",
"[",
"75",
",",
"25",
"]",
")",
"IQR",
"=",
"q75",
"-",
"q25",
"return",
"2.0",
"*",
"IQR",
"*",
"len",
... | b06c4faed5591cd7088475b2a203127bc5820483 |
test | PackagesStatusDetector._update_index_url_from_configs | Checks for alternative index-url in pip.conf | pip_upgrader/packages_status_detector.py | def _update_index_url_from_configs(self):
""" Checks for alternative index-url in pip.conf """
if 'VIRTUAL_ENV' in os.environ:
self.pip_config_locations.append(os.path.join(os.environ['VIRTUAL_ENV'], 'pip.conf'))
self.pip_config_locations.append(os.path.join(os.environ['VIRTUAL_... | def _update_index_url_from_configs(self):
""" Checks for alternative index-url in pip.conf """
if 'VIRTUAL_ENV' in os.environ:
self.pip_config_locations.append(os.path.join(os.environ['VIRTUAL_ENV'], 'pip.conf'))
self.pip_config_locations.append(os.path.join(os.environ['VIRTUAL_... | [
"Checks",
"for",
"alternative",
"index",
"-",
"url",
"in",
"pip",
".",
"conf"
] | simion/pip-upgrader | python | https://github.com/simion/pip-upgrader/blob/716adca65d9ed56d4d416f94ede8a8e4fa8d640a/pip_upgrader/packages_status_detector.py#L55-L90 | [
"def",
"_update_index_url_from_configs",
"(",
"self",
")",
":",
"if",
"'VIRTUAL_ENV'",
"in",
"os",
".",
"environ",
":",
"self",
".",
"pip_config_locations",
".",
"append",
"(",
"os",
".",
"path",
".",
"join",
"(",
"os",
".",
"environ",
"[",
"'VIRTUAL_ENV'",
... | 716adca65d9ed56d4d416f94ede8a8e4fa8d640a |
test | PackagesStatusDetector._fetch_index_package_info | :type package_name: str
:type current_version: version.Version | pip_upgrader/packages_status_detector.py | def _fetch_index_package_info(self, package_name, current_version):
"""
:type package_name: str
:type current_version: version.Version
"""
try:
package_canonical_name = package_name
if self.PYPI_API_TYPE == 'simple_html':
package_canonical... | def _fetch_index_package_info(self, package_name, current_version):
"""
:type package_name: str
:type current_version: version.Version
"""
try:
package_canonical_name = package_name
if self.PYPI_API_TYPE == 'simple_html':
package_canonical... | [
":",
"type",
"package_name",
":",
"str",
":",
"type",
"current_version",
":",
"version",
".",
"Version"
] | simion/pip-upgrader | python | https://github.com/simion/pip-upgrader/blob/716adca65d9ed56d4d416f94ede8a8e4fa8d640a/pip_upgrader/packages_status_detector.py#L153-L175 | [
"def",
"_fetch_index_package_info",
"(",
"self",
",",
"package_name",
",",
"current_version",
")",
":",
"try",
":",
"package_canonical_name",
"=",
"package_name",
"if",
"self",
".",
"PYPI_API_TYPE",
"==",
"'simple_html'",
":",
"package_canonical_name",
"=",
"canonical... | 716adca65d9ed56d4d416f94ede8a8e4fa8d640a |
test | PackagesStatusDetector._parse_pypi_json_package_info | :type package_name: str
:type current_version: version.Version
:type response: requests.models.Response | pip_upgrader/packages_status_detector.py | def _parse_pypi_json_package_info(self, package_name, current_version, response):
"""
:type package_name: str
:type current_version: version.Version
:type response: requests.models.Response
"""
data = response.json()
all_versions = [version.parse(vers) for vers i... | def _parse_pypi_json_package_info(self, package_name, current_version, response):
"""
:type package_name: str
:type current_version: version.Version
:type response: requests.models.Response
"""
data = response.json()
all_versions = [version.parse(vers) for vers i... | [
":",
"type",
"package_name",
":",
"str",
":",
"type",
"current_version",
":",
"version",
".",
"Version",
":",
"type",
"response",
":",
"requests",
".",
"models",
".",
"Response"
] | simion/pip-upgrader | python | https://github.com/simion/pip-upgrader/blob/716adca65d9ed56d4d416f94ede8a8e4fa8d640a/pip_upgrader/packages_status_detector.py#L188-L227 | [
"def",
"_parse_pypi_json_package_info",
"(",
"self",
",",
"package_name",
",",
"current_version",
",",
"response",
")",
":",
"data",
"=",
"response",
".",
"json",
"(",
")",
"all_versions",
"=",
"[",
"version",
".",
"parse",
"(",
"vers",
")",
"for",
"vers",
... | 716adca65d9ed56d4d416f94ede8a8e4fa8d640a |
test | PackagesStatusDetector._parse_simple_html_package_info | :type package_name: str
:type current_version: version.Version
:type response: requests.models.Response | pip_upgrader/packages_status_detector.py | def _parse_simple_html_package_info(self, package_name, current_version, response):
"""
:type package_name: str
:type current_version: version.Version
:type response: requests.models.Response
"""
pattern = r'<a.*>.*{name}-([A-z0-9\.-]*)(?:-py|\.tar).*<\/a>'.format(name=re... | def _parse_simple_html_package_info(self, package_name, current_version, response):
"""
:type package_name: str
:type current_version: version.Version
:type response: requests.models.Response
"""
pattern = r'<a.*>.*{name}-([A-z0-9\.-]*)(?:-py|\.tar).*<\/a>'.format(name=re... | [
":",
"type",
"package_name",
":",
"str",
":",
"type",
"current_version",
":",
"version",
".",
"Version",
":",
"type",
"response",
":",
"requests",
".",
"models",
".",
"Response"
] | simion/pip-upgrader | python | https://github.com/simion/pip-upgrader/blob/716adca65d9ed56d4d416f94ede8a8e4fa8d640a/pip_upgrader/packages_status_detector.py#L229-L258 | [
"def",
"_parse_simple_html_package_info",
"(",
"self",
",",
"package_name",
",",
"current_version",
",",
"response",
")",
":",
"pattern",
"=",
"r'<a.*>.*{name}-([A-z0-9\\.-]*)(?:-py|\\.tar).*<\\/a>'",
".",
"format",
"(",
"name",
"=",
"re",
".",
"escape",
"(",
"package... | 716adca65d9ed56d4d416f94ede8a8e4fa8d640a |
test | main | Main CLI entrypoint. | pip_upgrader/cli.py | def main():
""" Main CLI entrypoint. """
options = get_options()
Windows.enable(auto_colors=True, reset_atexit=True)
try:
# maybe check if virtualenv is not activated
check_for_virtualenv(options)
# 1. detect requirements files
filenames = RequirementsDetector(options.g... | def main():
""" Main CLI entrypoint. """
options = get_options()
Windows.enable(auto_colors=True, reset_atexit=True)
try:
# maybe check if virtualenv is not activated
check_for_virtualenv(options)
# 1. detect requirements files
filenames = RequirementsDetector(options.g... | [
"Main",
"CLI",
"entrypoint",
"."
] | simion/pip-upgrader | python | https://github.com/simion/pip-upgrader/blob/716adca65d9ed56d4d416f94ede8a8e4fa8d640a/pip_upgrader/cli.py#L47-L84 | [
"def",
"main",
"(",
")",
":",
"options",
"=",
"get_options",
"(",
")",
"Windows",
".",
"enable",
"(",
"auto_colors",
"=",
"True",
",",
"reset_atexit",
"=",
"True",
")",
"try",
":",
"# maybe check if virtualenv is not activated",
"check_for_virtualenv",
"(",
"opt... | 716adca65d9ed56d4d416f94ede8a8e4fa8d640a |
test | PackagesUpgrader._update_package | Update (install) the package in current environment, and if success, also replace version in file | pip_upgrader/packages_upgrader.py | def _update_package(self, package):
""" Update (install) the package in current environment, and if success, also replace version in file """
try:
if not self.dry_run and not self.skip_package_installation: # pragma: nocover
subprocess.check_call(['pip', 'install', '{}=={}'.... | def _update_package(self, package):
""" Update (install) the package in current environment, and if success, also replace version in file """
try:
if not self.dry_run and not self.skip_package_installation: # pragma: nocover
subprocess.check_call(['pip', 'install', '{}=={}'.... | [
"Update",
"(",
"install",
")",
"the",
"package",
"in",
"current",
"environment",
"and",
"if",
"success",
"also",
"replace",
"version",
"in",
"file"
] | simion/pip-upgrader | python | https://github.com/simion/pip-upgrader/blob/716adca65d9ed56d4d416f94ede8a8e4fa8d640a/pip_upgrader/packages_upgrader.py#L30-L41 | [
"def",
"_update_package",
"(",
"self",
",",
"package",
")",
":",
"try",
":",
"if",
"not",
"self",
".",
"dry_run",
"and",
"not",
"self",
".",
"skip_package_installation",
":",
"# pragma: nocover",
"subprocess",
".",
"check_call",
"(",
"[",
"'pip'",
",",
"'ins... | 716adca65d9ed56d4d416f94ede8a8e4fa8d640a |
test | RequirementsDetector.autodetect_files | Attempt to detect requirements files in the current working directory | pip_upgrader/requirements_detector.py | def autodetect_files(self):
""" Attempt to detect requirements files in the current working directory """
if self._is_valid_requirements_file('requirements.txt'):
self.filenames.append('requirements.txt')
if self._is_valid_requirements_file('requirements.pip'): # pragma: nocover
... | def autodetect_files(self):
""" Attempt to detect requirements files in the current working directory """
if self._is_valid_requirements_file('requirements.txt'):
self.filenames.append('requirements.txt')
if self._is_valid_requirements_file('requirements.pip'): # pragma: nocover
... | [
"Attempt",
"to",
"detect",
"requirements",
"files",
"in",
"the",
"current",
"working",
"directory"
] | simion/pip-upgrader | python | https://github.com/simion/pip-upgrader/blob/716adca65d9ed56d4d416f94ede8a8e4fa8d640a/pip_upgrader/requirements_detector.py#L32-L45 | [
"def",
"autodetect_files",
"(",
"self",
")",
":",
"if",
"self",
".",
"_is_valid_requirements_file",
"(",
"'requirements.txt'",
")",
":",
"self",
".",
"filenames",
".",
"append",
"(",
"'requirements.txt'",
")",
"if",
"self",
".",
"_is_valid_requirements_file",
"(",... | 716adca65d9ed56d4d416f94ede8a8e4fa8d640a |
test | resolve_streams | Resolve all streams on the network.
This function returns all currently available streams from any outlet on
the network. The network is usually the subnet specified at the local
router, but may also include a group of machines visible to each other via
multicast packets (given that the network supp... | pylsl/pylsl.py | def resolve_streams(wait_time=1.0):
"""Resolve all streams on the network.
This function returns all currently available streams from any outlet on
the network. The network is usually the subnet specified at the local
router, but may also include a group of machines visible to each other via
mul... | def resolve_streams(wait_time=1.0):
"""Resolve all streams on the network.
This function returns all currently available streams from any outlet on
the network. The network is usually the subnet specified at the local
router, but may also include a group of machines visible to each other via
mul... | [
"Resolve",
"all",
"streams",
"on",
"the",
"network",
"."
] | labstreaminglayer/liblsl-Python | python | https://github.com/labstreaminglayer/liblsl-Python/blob/1ff6fe2794f8dba286b7491d1f7a4c915b8a0605/pylsl/pylsl.py#L519-L543 | [
"def",
"resolve_streams",
"(",
"wait_time",
"=",
"1.0",
")",
":",
"# noinspection PyCallingNonCallable",
"buffer",
"=",
"(",
"c_void_p",
"*",
"1024",
")",
"(",
")",
"num_found",
"=",
"lib",
".",
"lsl_resolve_all",
"(",
"byref",
"(",
"buffer",
")",
",",
"1024... | 1ff6fe2794f8dba286b7491d1f7a4c915b8a0605 |
test | resolve_byprop | Resolve all streams with a specific value for a given property.
If the goal is to resolve a specific stream, this method is preferred over
resolving all streams and then selecting the desired one.
Keyword arguments:
prop -- The StreamInfo property that should have a specific value (e.g.,
... | pylsl/pylsl.py | def resolve_byprop(prop, value, minimum=1, timeout=FOREVER):
"""Resolve all streams with a specific value for a given property.
If the goal is to resolve a specific stream, this method is preferred over
resolving all streams and then selecting the desired one.
Keyword arguments:
prop -- The S... | def resolve_byprop(prop, value, minimum=1, timeout=FOREVER):
"""Resolve all streams with a specific value for a given property.
If the goal is to resolve a specific stream, this method is preferred over
resolving all streams and then selecting the desired one.
Keyword arguments:
prop -- The S... | [
"Resolve",
"all",
"streams",
"with",
"a",
"specific",
"value",
"for",
"a",
"given",
"property",
"."
] | labstreaminglayer/liblsl-Python | python | https://github.com/labstreaminglayer/liblsl-Python/blob/1ff6fe2794f8dba286b7491d1f7a4c915b8a0605/pylsl/pylsl.py#L546-L575 | [
"def",
"resolve_byprop",
"(",
"prop",
",",
"value",
",",
"minimum",
"=",
"1",
",",
"timeout",
"=",
"FOREVER",
")",
":",
"# noinspection PyCallingNonCallable",
"buffer",
"=",
"(",
"c_void_p",
"*",
"1024",
")",
"(",
")",
"num_found",
"=",
"lib",
".",
"lsl_re... | 1ff6fe2794f8dba286b7491d1f7a4c915b8a0605 |
test | resolve_bypred | Resolve all streams that match a given predicate.
Advanced query that allows to impose more conditions on the retrieved
streams; the given string is an XPath 1.0 predicate for the <description>
node (omitting the surrounding []'s), see also
http://en.wikipedia.org/w/index.php?title=XPath_1.0&oldid=474... | pylsl/pylsl.py | def resolve_bypred(predicate, minimum=1, timeout=FOREVER):
"""Resolve all streams that match a given predicate.
Advanced query that allows to impose more conditions on the retrieved
streams; the given string is an XPath 1.0 predicate for the <description>
node (omitting the surrounding []'s), see also... | def resolve_bypred(predicate, minimum=1, timeout=FOREVER):
"""Resolve all streams that match a given predicate.
Advanced query that allows to impose more conditions on the retrieved
streams; the given string is an XPath 1.0 predicate for the <description>
node (omitting the surrounding []'s), see also... | [
"Resolve",
"all",
"streams",
"that",
"match",
"a",
"given",
"predicate",
"."
] | labstreaminglayer/liblsl-Python | python | https://github.com/labstreaminglayer/liblsl-Python/blob/1ff6fe2794f8dba286b7491d1f7a4c915b8a0605/pylsl/pylsl.py#L578-L605 | [
"def",
"resolve_bypred",
"(",
"predicate",
",",
"minimum",
"=",
"1",
",",
"timeout",
"=",
"FOREVER",
")",
":",
"# noinspection PyCallingNonCallable",
"buffer",
"=",
"(",
"c_void_p",
"*",
"1024",
")",
"(",
")",
"num_found",
"=",
"lib",
".",
"lsl_resolve_bypred"... | 1ff6fe2794f8dba286b7491d1f7a4c915b8a0605 |
test | handle_error | Error handler function. Translates an error code into an exception. | pylsl/pylsl.py | def handle_error(errcode):
"""Error handler function. Translates an error code into an exception."""
if type(errcode) is c_int:
errcode = errcode.value
if errcode == 0:
pass # no error
elif errcode == -1:
raise TimeoutError("the operation failed due to a timeout.")
elif errc... | def handle_error(errcode):
"""Error handler function. Translates an error code into an exception."""
if type(errcode) is c_int:
errcode = errcode.value
if errcode == 0:
pass # no error
elif errcode == -1:
raise TimeoutError("the operation failed due to a timeout.")
elif errc... | [
"Error",
"handler",
"function",
".",
"Translates",
"an",
"error",
"code",
"into",
"an",
"exception",
"."
] | labstreaminglayer/liblsl-Python | python | https://github.com/labstreaminglayer/liblsl-Python/blob/1ff6fe2794f8dba286b7491d1f7a4c915b8a0605/pylsl/pylsl.py#L1129-L1144 | [
"def",
"handle_error",
"(",
"errcode",
")",
":",
"if",
"type",
"(",
"errcode",
")",
"is",
"c_int",
":",
"errcode",
"=",
"errcode",
".",
"value",
"if",
"errcode",
"==",
"0",
":",
"pass",
"# no error",
"elif",
"errcode",
"==",
"-",
"1",
":",
"raise",
"... | 1ff6fe2794f8dba286b7491d1f7a4c915b8a0605 |
test | StreamOutlet.push_sample | Push a sample into the outlet.
Each entry in the list corresponds to one channel.
Keyword arguments:
x -- A list of values to push (one per channel).
timestamp -- Optionally the capture time of the sample, in agreement
with local_clock(); if omitted, the current
... | pylsl/pylsl.py | def push_sample(self, x, timestamp=0.0, pushthrough=True):
"""Push a sample into the outlet.
Each entry in the list corresponds to one channel.
Keyword arguments:
x -- A list of values to push (one per channel).
timestamp -- Optionally the capture time of the sample, in agreeme... | def push_sample(self, x, timestamp=0.0, pushthrough=True):
"""Push a sample into the outlet.
Each entry in the list corresponds to one channel.
Keyword arguments:
x -- A list of values to push (one per channel).
timestamp -- Optionally the capture time of the sample, in agreeme... | [
"Push",
"a",
"sample",
"into",
"the",
"outlet",
"."
] | labstreaminglayer/liblsl-Python | python | https://github.com/labstreaminglayer/liblsl-Python/blob/1ff6fe2794f8dba286b7491d1f7a4c915b8a0605/pylsl/pylsl.py#L430-L455 | [
"def",
"push_sample",
"(",
"self",
",",
"x",
",",
"timestamp",
"=",
"0.0",
",",
"pushthrough",
"=",
"True",
")",
":",
"if",
"len",
"(",
"x",
")",
"==",
"self",
".",
"channel_count",
":",
"if",
"self",
".",
"channel_format",
"==",
"cf_string",
":",
"x... | 1ff6fe2794f8dba286b7491d1f7a4c915b8a0605 |
test | StreamOutlet.push_chunk | Push a list of samples into the outlet.
samples -- A list of samples, either as a list of lists or a list of
multiplexed values.
timestamp -- Optionally the capture time of the most recent sample, in
agreement with local_clock(); if omitted, the current
... | pylsl/pylsl.py | def push_chunk(self, x, timestamp=0.0, pushthrough=True):
"""Push a list of samples into the outlet.
samples -- A list of samples, either as a list of lists or a list of
multiplexed values.
timestamp -- Optionally the capture time of the most recent sample, in
... | def push_chunk(self, x, timestamp=0.0, pushthrough=True):
"""Push a list of samples into the outlet.
samples -- A list of samples, either as a list of lists or a list of
multiplexed values.
timestamp -- Optionally the capture time of the most recent sample, in
... | [
"Push",
"a",
"list",
"of",
"samples",
"into",
"the",
"outlet",
"."
] | labstreaminglayer/liblsl-Python | python | https://github.com/labstreaminglayer/liblsl-Python/blob/1ff6fe2794f8dba286b7491d1f7a4c915b8a0605/pylsl/pylsl.py#L457-L495 | [
"def",
"push_chunk",
"(",
"self",
",",
"x",
",",
"timestamp",
"=",
"0.0",
",",
"pushthrough",
"=",
"True",
")",
":",
"try",
":",
"n_values",
"=",
"self",
".",
"channel_count",
"*",
"len",
"(",
"x",
")",
"data_buff",
"=",
"(",
"self",
".",
"value_type... | 1ff6fe2794f8dba286b7491d1f7a4c915b8a0605 |
test | StreamOutlet.wait_for_consumers | Wait until some consumer shows up (without wasting resources).
Returns True if the wait was successful, False if the timeout expired. | pylsl/pylsl.py | def wait_for_consumers(self, timeout):
"""Wait until some consumer shows up (without wasting resources).
Returns True if the wait was successful, False if the timeout expired.
"""
return bool(lib.lsl_wait_for_consumers(self.obj, c_double(timeout))) | def wait_for_consumers(self, timeout):
"""Wait until some consumer shows up (without wasting resources).
Returns True if the wait was successful, False if the timeout expired.
"""
return bool(lib.lsl_wait_for_consumers(self.obj, c_double(timeout))) | [
"Wait",
"until",
"some",
"consumer",
"shows",
"up",
"(",
"without",
"wasting",
"resources",
")",
"."
] | labstreaminglayer/liblsl-Python | python | https://github.com/labstreaminglayer/liblsl-Python/blob/1ff6fe2794f8dba286b7491d1f7a4c915b8a0605/pylsl/pylsl.py#L506-L512 | [
"def",
"wait_for_consumers",
"(",
"self",
",",
"timeout",
")",
":",
"return",
"bool",
"(",
"lib",
".",
"lsl_wait_for_consumers",
"(",
"self",
".",
"obj",
",",
"c_double",
"(",
"timeout",
")",
")",
")"
] | 1ff6fe2794f8dba286b7491d1f7a4c915b8a0605 |
test | StreamInlet.info | Retrieve the complete information of the given stream.
This includes the extended description. Can be invoked at any time of
the stream's lifetime.
Keyword arguments:
timeout -- Timeout of the operation. (default FOREVER)
Throws a TimeoutError (if the timeout e... | pylsl/pylsl.py | def info(self, timeout=FOREVER):
"""Retrieve the complete information of the given stream.
This includes the extended description. Can be invoked at any time of
the stream's lifetime.
Keyword arguments:
timeout -- Timeout of the operation. (default FOREVER)
... | def info(self, timeout=FOREVER):
"""Retrieve the complete information of the given stream.
This includes the extended description. Can be invoked at any time of
the stream's lifetime.
Keyword arguments:
timeout -- Timeout of the operation. (default FOREVER)
... | [
"Retrieve",
"the",
"complete",
"information",
"of",
"the",
"given",
"stream",
"."
] | labstreaminglayer/liblsl-Python | python | https://github.com/labstreaminglayer/liblsl-Python/blob/1ff6fe2794f8dba286b7491d1f7a4c915b8a0605/pylsl/pylsl.py#L688-L705 | [
"def",
"info",
"(",
"self",
",",
"timeout",
"=",
"FOREVER",
")",
":",
"errcode",
"=",
"c_int",
"(",
")",
"result",
"=",
"lib",
".",
"lsl_get_fullinfo",
"(",
"self",
".",
"obj",
",",
"c_double",
"(",
"timeout",
")",
",",
"byref",
"(",
"errcode",
")",
... | 1ff6fe2794f8dba286b7491d1f7a4c915b8a0605 |
test | StreamInlet.open_stream | Subscribe to the data stream.
All samples pushed in at the other end from this moment onwards will be
queued and eventually be delivered in response to pull_sample() or
pull_chunk() calls. Pulling a sample without some preceding open_stream
is permitted (the stream will then be opene... | pylsl/pylsl.py | def open_stream(self, timeout=FOREVER):
"""Subscribe to the data stream.
All samples pushed in at the other end from this moment onwards will be
queued and eventually be delivered in response to pull_sample() or
pull_chunk() calls. Pulling a sample without some preceding open_stream
... | def open_stream(self, timeout=FOREVER):
"""Subscribe to the data stream.
All samples pushed in at the other end from this moment onwards will be
queued and eventually be delivered in response to pull_sample() or
pull_chunk() calls. Pulling a sample without some preceding open_stream
... | [
"Subscribe",
"to",
"the",
"data",
"stream",
"."
] | labstreaminglayer/liblsl-Python | python | https://github.com/labstreaminglayer/liblsl-Python/blob/1ff6fe2794f8dba286b7491d1f7a4c915b8a0605/pylsl/pylsl.py#L707-L724 | [
"def",
"open_stream",
"(",
"self",
",",
"timeout",
"=",
"FOREVER",
")",
":",
"errcode",
"=",
"c_int",
"(",
")",
"lib",
".",
"lsl_open_stream",
"(",
"self",
".",
"obj",
",",
"c_double",
"(",
"timeout",
")",
",",
"byref",
"(",
"errcode",
")",
")",
"han... | 1ff6fe2794f8dba286b7491d1f7a4c915b8a0605 |
test | StreamInlet.time_correction | Retrieve an estimated time correction offset for the given stream.
The first call to this function takes several miliseconds until a
reliable first estimate is obtained. Subsequent calls are instantaneous
(and rely on periodic background updates). The precision of these
estimates sho... | pylsl/pylsl.py | def time_correction(self, timeout=FOREVER):
"""Retrieve an estimated time correction offset for the given stream.
The first call to this function takes several miliseconds until a
reliable first estimate is obtained. Subsequent calls are instantaneous
(and rely on periodic background ... | def time_correction(self, timeout=FOREVER):
"""Retrieve an estimated time correction offset for the given stream.
The first call to this function takes several miliseconds until a
reliable first estimate is obtained. Subsequent calls are instantaneous
(and rely on periodic background ... | [
"Retrieve",
"an",
"estimated",
"time",
"correction",
"offset",
"for",
"the",
"given",
"stream",
"."
] | labstreaminglayer/liblsl-Python | python | https://github.com/labstreaminglayer/liblsl-Python/blob/1ff6fe2794f8dba286b7491d1f7a4c915b8a0605/pylsl/pylsl.py#L739-L764 | [
"def",
"time_correction",
"(",
"self",
",",
"timeout",
"=",
"FOREVER",
")",
":",
"errcode",
"=",
"c_int",
"(",
")",
"result",
"=",
"lib",
".",
"lsl_time_correction",
"(",
"self",
".",
"obj",
",",
"c_double",
"(",
"timeout",
")",
",",
"byref",
"(",
"err... | 1ff6fe2794f8dba286b7491d1f7a4c915b8a0605 |
test | StreamInlet.pull_sample | Pull a sample from the inlet and return it.
Keyword arguments:
timeout -- The timeout for this operation, if any. (default FOREVER)
If this is passed as 0.0, then the function returns only a
sample if one is buffered for immediate pickup.
... | pylsl/pylsl.py | def pull_sample(self, timeout=FOREVER, sample=None):
"""Pull a sample from the inlet and return it.
Keyword arguments:
timeout -- The timeout for this operation, if any. (default FOREVER)
If this is passed as 0.0, then the function returns only a
s... | def pull_sample(self, timeout=FOREVER, sample=None):
"""Pull a sample from the inlet and return it.
Keyword arguments:
timeout -- The timeout for this operation, if any. (default FOREVER)
If this is passed as 0.0, then the function returns only a
s... | [
"Pull",
"a",
"sample",
"from",
"the",
"inlet",
"and",
"return",
"it",
".",
"Keyword",
"arguments",
":",
"timeout",
"--",
"The",
"timeout",
"for",
"this",
"operation",
"if",
"any",
".",
"(",
"default",
"FOREVER",
")",
"If",
"this",
"is",
"passed",
"as",
... | labstreaminglayer/liblsl-Python | python | https://github.com/labstreaminglayer/liblsl-Python/blob/1ff6fe2794f8dba286b7491d1f7a4c915b8a0605/pylsl/pylsl.py#L766-L806 | [
"def",
"pull_sample",
"(",
"self",
",",
"timeout",
"=",
"FOREVER",
",",
"sample",
"=",
"None",
")",
":",
"# support for the legacy API",
"if",
"type",
"(",
"timeout",
")",
"is",
"list",
":",
"assign_to",
"=",
"timeout",
"timeout",
"=",
"sample",
"if",
"typ... | 1ff6fe2794f8dba286b7491d1f7a4c915b8a0605 |
test | StreamInlet.pull_chunk | Pull a chunk of samples from the inlet.
Keyword arguments:
timeout -- The timeout of the operation; if passed as 0.0, then only
samples available for immediate pickup will be returned.
(default 0.0)
max_samples -- Maximum number of samples to retu... | pylsl/pylsl.py | def pull_chunk(self, timeout=0.0, max_samples=1024, dest_obj=None):
"""Pull a chunk of samples from the inlet.
Keyword arguments:
timeout -- The timeout of the operation; if passed as 0.0, then only
samples available for immediate pickup will be returned.
... | def pull_chunk(self, timeout=0.0, max_samples=1024, dest_obj=None):
"""Pull a chunk of samples from the inlet.
Keyword arguments:
timeout -- The timeout of the operation; if passed as 0.0, then only
samples available for immediate pickup will be returned.
... | [
"Pull",
"a",
"chunk",
"of",
"samples",
"from",
"the",
"inlet",
".",
"Keyword",
"arguments",
":",
"timeout",
"--",
"The",
"timeout",
"of",
"the",
"operation",
";",
"if",
"passed",
"as",
"0",
".",
"0",
"then",
"only",
"samples",
"available",
"for",
"immedi... | labstreaminglayer/liblsl-Python | python | https://github.com/labstreaminglayer/liblsl-Python/blob/1ff6fe2794f8dba286b7491d1f7a4c915b8a0605/pylsl/pylsl.py#L808-L865 | [
"def",
"pull_chunk",
"(",
"self",
",",
"timeout",
"=",
"0.0",
",",
"max_samples",
"=",
"1024",
",",
"dest_obj",
"=",
"None",
")",
":",
"# look up a pre-allocated buffer of appropriate length ",
"num_channels",
"=",
"self",
".",
"channel_count",
"max_values",
... | 1ff6fe2794f8dba286b7491d1f7a4c915b8a0605 |
test | XMLElement.child | Get a child with a specified name. | pylsl/pylsl.py | def child(self, name):
"""Get a child with a specified name."""
return XMLElement(lib.lsl_child(self.e, str.encode(name))) | def child(self, name):
"""Get a child with a specified name."""
return XMLElement(lib.lsl_child(self.e, str.encode(name))) | [
"Get",
"a",
"child",
"with",
"a",
"specified",
"name",
"."
] | labstreaminglayer/liblsl-Python | python | https://github.com/labstreaminglayer/liblsl-Python/blob/1ff6fe2794f8dba286b7491d1f7a4c915b8a0605/pylsl/pylsl.py#L920-L922 | [
"def",
"child",
"(",
"self",
",",
"name",
")",
":",
"return",
"XMLElement",
"(",
"lib",
".",
"lsl_child",
"(",
"self",
".",
"e",
",",
"str",
".",
"encode",
"(",
"name",
")",
")",
")"
] | 1ff6fe2794f8dba286b7491d1f7a4c915b8a0605 |
test | XMLElement.next_sibling | Get the next sibling in the children list of the parent node.
If a name is provided, the next sibling with the given name is returned. | pylsl/pylsl.py | def next_sibling(self, name=None):
"""Get the next sibling in the children list of the parent node.
If a name is provided, the next sibling with the given name is returned.
"""
if name is None:
return XMLElement(lib.lsl_next_sibling(self.e))
else:
return... | def next_sibling(self, name=None):
"""Get the next sibling in the children list of the parent node.
If a name is provided, the next sibling with the given name is returned.
"""
if name is None:
return XMLElement(lib.lsl_next_sibling(self.e))
else:
return... | [
"Get",
"the",
"next",
"sibling",
"in",
"the",
"children",
"list",
"of",
"the",
"parent",
"node",
"."
] | labstreaminglayer/liblsl-Python | python | https://github.com/labstreaminglayer/liblsl-Python/blob/1ff6fe2794f8dba286b7491d1f7a4c915b8a0605/pylsl/pylsl.py#L924-L933 | [
"def",
"next_sibling",
"(",
"self",
",",
"name",
"=",
"None",
")",
":",
"if",
"name",
"is",
"None",
":",
"return",
"XMLElement",
"(",
"lib",
".",
"lsl_next_sibling",
"(",
"self",
".",
"e",
")",
")",
"else",
":",
"return",
"XMLElement",
"(",
"lib",
".... | 1ff6fe2794f8dba286b7491d1f7a4c915b8a0605 |
test | XMLElement.previous_sibling | Get the previous sibling in the children list of the parent node.
If a name is provided, the previous sibling with the given name is
returned. | pylsl/pylsl.py | def previous_sibling(self, name=None):
"""Get the previous sibling in the children list of the parent node.
If a name is provided, the previous sibling with the given name is
returned.
"""
if name is None:
return XMLElement(lib.lsl_previous_sibling(self.e))
... | def previous_sibling(self, name=None):
"""Get the previous sibling in the children list of the parent node.
If a name is provided, the previous sibling with the given name is
returned.
"""
if name is None:
return XMLElement(lib.lsl_previous_sibling(self.e))
... | [
"Get",
"the",
"previous",
"sibling",
"in",
"the",
"children",
"list",
"of",
"the",
"parent",
"node",
"."
] | labstreaminglayer/liblsl-Python | python | https://github.com/labstreaminglayer/liblsl-Python/blob/1ff6fe2794f8dba286b7491d1f7a4c915b8a0605/pylsl/pylsl.py#L935-L946 | [
"def",
"previous_sibling",
"(",
"self",
",",
"name",
"=",
"None",
")",
":",
"if",
"name",
"is",
"None",
":",
"return",
"XMLElement",
"(",
"lib",
".",
"lsl_previous_sibling",
"(",
"self",
".",
"e",
")",
")",
"else",
":",
"return",
"XMLElement",
"(",
"li... | 1ff6fe2794f8dba286b7491d1f7a4c915b8a0605 |
test | XMLElement.child_value | Get child value (value of the first child that is text).
If a name is provided, then the value of the first child with the
given name is returned. | pylsl/pylsl.py | def child_value(self, name=None):
"""Get child value (value of the first child that is text).
If a name is provided, then the value of the first child with the
given name is returned.
"""
if name is None:
res = lib.lsl_child_value(self.e)
else:
r... | def child_value(self, name=None):
"""Get child value (value of the first child that is text).
If a name is provided, then the value of the first child with the
given name is returned.
"""
if name is None:
res = lib.lsl_child_value(self.e)
else:
r... | [
"Get",
"child",
"value",
"(",
"value",
"of",
"the",
"first",
"child",
"that",
"is",
"text",
")",
"."
] | labstreaminglayer/liblsl-Python | python | https://github.com/labstreaminglayer/liblsl-Python/blob/1ff6fe2794f8dba286b7491d1f7a4c915b8a0605/pylsl/pylsl.py#L974-L985 | [
"def",
"child_value",
"(",
"self",
",",
"name",
"=",
"None",
")",
":",
"if",
"name",
"is",
"None",
":",
"res",
"=",
"lib",
".",
"lsl_child_value",
"(",
"self",
".",
"e",
")",
"else",
":",
"res",
"=",
"lib",
".",
"lsl_child_value_n",
"(",
"self",
".... | 1ff6fe2794f8dba286b7491d1f7a4c915b8a0605 |
test | XMLElement.append_child_value | Append a child node with a given name, which has a (nameless)
plain-text child with the given text value. | pylsl/pylsl.py | def append_child_value(self, name, value):
"""Append a child node with a given name, which has a (nameless)
plain-text child with the given text value."""
return XMLElement(lib.lsl_append_child_value(self.e,
str.encode(name),
... | def append_child_value(self, name, value):
"""Append a child node with a given name, which has a (nameless)
plain-text child with the given text value."""
return XMLElement(lib.lsl_append_child_value(self.e,
str.encode(name),
... | [
"Append",
"a",
"child",
"node",
"with",
"a",
"given",
"name",
"which",
"has",
"a",
"(",
"nameless",
")",
"plain",
"-",
"text",
"child",
"with",
"the",
"given",
"text",
"value",
"."
] | labstreaminglayer/liblsl-Python | python | https://github.com/labstreaminglayer/liblsl-Python/blob/1ff6fe2794f8dba286b7491d1f7a4c915b8a0605/pylsl/pylsl.py#L989-L994 | [
"def",
"append_child_value",
"(",
"self",
",",
"name",
",",
"value",
")",
":",
"return",
"XMLElement",
"(",
"lib",
".",
"lsl_append_child_value",
"(",
"self",
".",
"e",
",",
"str",
".",
"encode",
"(",
"name",
")",
",",
"str",
".",
"encode",
"(",
"value... | 1ff6fe2794f8dba286b7491d1f7a4c915b8a0605 |
test | XMLElement.prepend_child_value | Prepend a child node with a given name, which has a (nameless)
plain-text child with the given text value. | pylsl/pylsl.py | def prepend_child_value(self, name, value):
"""Prepend a child node with a given name, which has a (nameless)
plain-text child with the given text value."""
return XMLElement(lib.lsl_prepend_child_value(self.e,
str.encode(name),
... | def prepend_child_value(self, name, value):
"""Prepend a child node with a given name, which has a (nameless)
plain-text child with the given text value."""
return XMLElement(lib.lsl_prepend_child_value(self.e,
str.encode(name),
... | [
"Prepend",
"a",
"child",
"node",
"with",
"a",
"given",
"name",
"which",
"has",
"a",
"(",
"nameless",
")",
"plain",
"-",
"text",
"child",
"with",
"the",
"given",
"text",
"value",
"."
] | labstreaminglayer/liblsl-Python | python | https://github.com/labstreaminglayer/liblsl-Python/blob/1ff6fe2794f8dba286b7491d1f7a4c915b8a0605/pylsl/pylsl.py#L996-L1001 | [
"def",
"prepend_child_value",
"(",
"self",
",",
"name",
",",
"value",
")",
":",
"return",
"XMLElement",
"(",
"lib",
".",
"lsl_prepend_child_value",
"(",
"self",
".",
"e",
",",
"str",
".",
"encode",
"(",
"name",
")",
",",
"str",
".",
"encode",
"(",
"val... | 1ff6fe2794f8dba286b7491d1f7a4c915b8a0605 |
test | XMLElement.set_child_value | Set the text value of the (nameless) plain-text child of a named
child node. | pylsl/pylsl.py | def set_child_value(self, name, value):
"""Set the text value of the (nameless) plain-text child of a named
child node."""
return XMLElement(lib.lsl_set_child_value(self.e,
str.encode(name),
str.... | def set_child_value(self, name, value):
"""Set the text value of the (nameless) plain-text child of a named
child node."""
return XMLElement(lib.lsl_set_child_value(self.e,
str.encode(name),
str.... | [
"Set",
"the",
"text",
"value",
"of",
"the",
"(",
"nameless",
")",
"plain",
"-",
"text",
"child",
"of",
"a",
"named",
"child",
"node",
"."
] | labstreaminglayer/liblsl-Python | python | https://github.com/labstreaminglayer/liblsl-Python/blob/1ff6fe2794f8dba286b7491d1f7a4c915b8a0605/pylsl/pylsl.py#L1003-L1008 | [
"def",
"set_child_value",
"(",
"self",
",",
"name",
",",
"value",
")",
":",
"return",
"XMLElement",
"(",
"lib",
".",
"lsl_set_child_value",
"(",
"self",
".",
"e",
",",
"str",
".",
"encode",
"(",
"name",
")",
",",
"str",
".",
"encode",
"(",
"value",
"... | 1ff6fe2794f8dba286b7491d1f7a4c915b8a0605 |
test | XMLElement.set_name | Set the element's name. Returns False if the node is empty. | pylsl/pylsl.py | def set_name(self, name):
"""Set the element's name. Returns False if the node is empty."""
return bool(lib.lsl_set_name(self.e, str.encode(name))) | def set_name(self, name):
"""Set the element's name. Returns False if the node is empty."""
return bool(lib.lsl_set_name(self.e, str.encode(name))) | [
"Set",
"the",
"element",
"s",
"name",
".",
"Returns",
"False",
"if",
"the",
"node",
"is",
"empty",
"."
] | labstreaminglayer/liblsl-Python | python | https://github.com/labstreaminglayer/liblsl-Python/blob/1ff6fe2794f8dba286b7491d1f7a4c915b8a0605/pylsl/pylsl.py#L1010-L1012 | [
"def",
"set_name",
"(",
"self",
",",
"name",
")",
":",
"return",
"bool",
"(",
"lib",
".",
"lsl_set_name",
"(",
"self",
".",
"e",
",",
"str",
".",
"encode",
"(",
"name",
")",
")",
")"
] | 1ff6fe2794f8dba286b7491d1f7a4c915b8a0605 |
test | XMLElement.set_value | Set the element's value. Returns False if the node is empty. | pylsl/pylsl.py | def set_value(self, value):
"""Set the element's value. Returns False if the node is empty."""
return bool(lib.lsl_set_value(self.e, str.encode(value))) | def set_value(self, value):
"""Set the element's value. Returns False if the node is empty."""
return bool(lib.lsl_set_value(self.e, str.encode(value))) | [
"Set",
"the",
"element",
"s",
"value",
".",
"Returns",
"False",
"if",
"the",
"node",
"is",
"empty",
"."
] | labstreaminglayer/liblsl-Python | python | https://github.com/labstreaminglayer/liblsl-Python/blob/1ff6fe2794f8dba286b7491d1f7a4c915b8a0605/pylsl/pylsl.py#L1014-L1016 | [
"def",
"set_value",
"(",
"self",
",",
"value",
")",
":",
"return",
"bool",
"(",
"lib",
".",
"lsl_set_value",
"(",
"self",
".",
"e",
",",
"str",
".",
"encode",
"(",
"value",
")",
")",
")"
] | 1ff6fe2794f8dba286b7491d1f7a4c915b8a0605 |
test | XMLElement.append_child | Append a child element with the specified name. | pylsl/pylsl.py | def append_child(self, name):
"""Append a child element with the specified name."""
return XMLElement(lib.lsl_append_child(self.e, str.encode(name))) | def append_child(self, name):
"""Append a child element with the specified name."""
return XMLElement(lib.lsl_append_child(self.e, str.encode(name))) | [
"Append",
"a",
"child",
"element",
"with",
"the",
"specified",
"name",
"."
] | labstreaminglayer/liblsl-Python | python | https://github.com/labstreaminglayer/liblsl-Python/blob/1ff6fe2794f8dba286b7491d1f7a4c915b8a0605/pylsl/pylsl.py#L1018-L1020 | [
"def",
"append_child",
"(",
"self",
",",
"name",
")",
":",
"return",
"XMLElement",
"(",
"lib",
".",
"lsl_append_child",
"(",
"self",
".",
"e",
",",
"str",
".",
"encode",
"(",
"name",
")",
")",
")"
] | 1ff6fe2794f8dba286b7491d1f7a4c915b8a0605 |
test | XMLElement.prepend_child | Prepend a child element with the specified name. | pylsl/pylsl.py | def prepend_child(self, name):
"""Prepend a child element with the specified name."""
return XMLElement(lib.lsl_prepend_child(self.e, str.encode(name))) | def prepend_child(self, name):
"""Prepend a child element with the specified name."""
return XMLElement(lib.lsl_prepend_child(self.e, str.encode(name))) | [
"Prepend",
"a",
"child",
"element",
"with",
"the",
"specified",
"name",
"."
] | labstreaminglayer/liblsl-Python | python | https://github.com/labstreaminglayer/liblsl-Python/blob/1ff6fe2794f8dba286b7491d1f7a4c915b8a0605/pylsl/pylsl.py#L1022-L1024 | [
"def",
"prepend_child",
"(",
"self",
",",
"name",
")",
":",
"return",
"XMLElement",
"(",
"lib",
".",
"lsl_prepend_child",
"(",
"self",
".",
"e",
",",
"str",
".",
"encode",
"(",
"name",
")",
")",
")"
] | 1ff6fe2794f8dba286b7491d1f7a4c915b8a0605 |
test | XMLElement.append_copy | Append a copy of the specified element as a child. | pylsl/pylsl.py | def append_copy(self, elem):
"""Append a copy of the specified element as a child."""
return XMLElement(lib.lsl_append_copy(self.e, elem.e)) | def append_copy(self, elem):
"""Append a copy of the specified element as a child."""
return XMLElement(lib.lsl_append_copy(self.e, elem.e)) | [
"Append",
"a",
"copy",
"of",
"the",
"specified",
"element",
"as",
"a",
"child",
"."
] | labstreaminglayer/liblsl-Python | python | https://github.com/labstreaminglayer/liblsl-Python/blob/1ff6fe2794f8dba286b7491d1f7a4c915b8a0605/pylsl/pylsl.py#L1026-L1028 | [
"def",
"append_copy",
"(",
"self",
",",
"elem",
")",
":",
"return",
"XMLElement",
"(",
"lib",
".",
"lsl_append_copy",
"(",
"self",
".",
"e",
",",
"elem",
".",
"e",
")",
")"
] | 1ff6fe2794f8dba286b7491d1f7a4c915b8a0605 |
test | XMLElement.prepend_copy | Prepend a copy of the specified element as a child. | pylsl/pylsl.py | def prepend_copy(self, elem):
"""Prepend a copy of the specified element as a child."""
return XMLElement(lib.lsl_prepend_copy(self.e, elem.e)) | def prepend_copy(self, elem):
"""Prepend a copy of the specified element as a child."""
return XMLElement(lib.lsl_prepend_copy(self.e, elem.e)) | [
"Prepend",
"a",
"copy",
"of",
"the",
"specified",
"element",
"as",
"a",
"child",
"."
] | labstreaminglayer/liblsl-Python | python | https://github.com/labstreaminglayer/liblsl-Python/blob/1ff6fe2794f8dba286b7491d1f7a4c915b8a0605/pylsl/pylsl.py#L1030-L1032 | [
"def",
"prepend_copy",
"(",
"self",
",",
"elem",
")",
":",
"return",
"XMLElement",
"(",
"lib",
".",
"lsl_prepend_copy",
"(",
"self",
".",
"e",
",",
"elem",
".",
"e",
")",
")"
] | 1ff6fe2794f8dba286b7491d1f7a4c915b8a0605 |
test | XMLElement.remove_child | Remove a given child element, specified by name or as element. | pylsl/pylsl.py | def remove_child(self, rhs):
"""Remove a given child element, specified by name or as element."""
if type(rhs) is XMLElement:
lib.lsl_remove_child(self.e, rhs.e)
else:
lib.lsl_remove_child_n(self.e, rhs) | def remove_child(self, rhs):
"""Remove a given child element, specified by name or as element."""
if type(rhs) is XMLElement:
lib.lsl_remove_child(self.e, rhs.e)
else:
lib.lsl_remove_child_n(self.e, rhs) | [
"Remove",
"a",
"given",
"child",
"element",
"specified",
"by",
"name",
"or",
"as",
"element",
"."
] | labstreaminglayer/liblsl-Python | python | https://github.com/labstreaminglayer/liblsl-Python/blob/1ff6fe2794f8dba286b7491d1f7a4c915b8a0605/pylsl/pylsl.py#L1034-L1039 | [
"def",
"remove_child",
"(",
"self",
",",
"rhs",
")",
":",
"if",
"type",
"(",
"rhs",
")",
"is",
"XMLElement",
":",
"lib",
".",
"lsl_remove_child",
"(",
"self",
".",
"e",
",",
"rhs",
".",
"e",
")",
"else",
":",
"lib",
".",
"lsl_remove_child_n",
"(",
... | 1ff6fe2794f8dba286b7491d1f7a4c915b8a0605 |
test | ContinuousResolver.results | Obtain the set of currently present streams on the network.
Returns a list of matching StreamInfo objects (with empty desc
field), any of which can subsequently be used to open an inlet. | pylsl/pylsl.py | def results(self):
"""Obtain the set of currently present streams on the network.
Returns a list of matching StreamInfo objects (with empty desc
field), any of which can subsequently be used to open an inlet.
"""
# noinspection PyCallingNonCallable
buffer = (c_void_p*10... | def results(self):
"""Obtain the set of currently present streams on the network.
Returns a list of matching StreamInfo objects (with empty desc
field), any of which can subsequently be used to open an inlet.
"""
# noinspection PyCallingNonCallable
buffer = (c_void_p*10... | [
"Obtain",
"the",
"set",
"of",
"currently",
"present",
"streams",
"on",
"the",
"network",
"."
] | labstreaminglayer/liblsl-Python | python | https://github.com/labstreaminglayer/liblsl-Python/blob/1ff6fe2794f8dba286b7491d1f7a4c915b8a0605/pylsl/pylsl.py#L1092-L1102 | [
"def",
"results",
"(",
"self",
")",
":",
"# noinspection PyCallingNonCallable",
"buffer",
"=",
"(",
"c_void_p",
"*",
"1024",
")",
"(",
")",
"num_found",
"=",
"lib",
".",
"lsl_resolver_results",
"(",
"self",
".",
"obj",
",",
"byref",
"(",
"buffer",
")",
","... | 1ff6fe2794f8dba286b7491d1f7a4c915b8a0605 |
test | pair | See all token associated with a given token.
PAIR lilas | addok/pairs.py | def pair(cmd, word):
"""See all token associated with a given token.
PAIR lilas"""
word = list(preprocess_query(word))[0]
key = pair_key(word)
tokens = [t.decode() for t in DB.smembers(key)]
tokens.sort()
print(white(tokens))
print(magenta('(Total: {})'.format(len(tokens)))) | def pair(cmd, word):
"""See all token associated with a given token.
PAIR lilas"""
word = list(preprocess_query(word))[0]
key = pair_key(word)
tokens = [t.decode() for t in DB.smembers(key)]
tokens.sort()
print(white(tokens))
print(magenta('(Total: {})'.format(len(tokens)))) | [
"See",
"all",
"token",
"associated",
"with",
"a",
"given",
"token",
".",
"PAIR",
"lilas"
] | addok/addok | python | https://github.com/addok/addok/blob/46a270d76ec778d2b445c2be753e5c6ba070a9b2/addok/pairs.py#L35-L43 | [
"def",
"pair",
"(",
"cmd",
",",
"word",
")",
":",
"word",
"=",
"list",
"(",
"preprocess_query",
"(",
"word",
")",
")",
"[",
"0",
"]",
"key",
"=",
"pair_key",
"(",
"word",
")",
"tokens",
"=",
"[",
"t",
".",
"decode",
"(",
")",
"for",
"t",
"in",
... | 46a270d76ec778d2b445c2be753e5c6ba070a9b2 |
test | do_AUTOCOMPLETE | Shows autocomplete results for a given token. | addok/autocomplete.py | def do_AUTOCOMPLETE(cmd, s):
"""Shows autocomplete results for a given token."""
s = list(preprocess_query(s))[0]
keys = [k.decode() for k in DB.smembers(edge_ngram_key(s))]
print(white(keys))
print(magenta('({} elements)'.format(len(keys)))) | def do_AUTOCOMPLETE(cmd, s):
"""Shows autocomplete results for a given token."""
s = list(preprocess_query(s))[0]
keys = [k.decode() for k in DB.smembers(edge_ngram_key(s))]
print(white(keys))
print(magenta('({} elements)'.format(len(keys)))) | [
"Shows",
"autocomplete",
"results",
"for",
"a",
"given",
"token",
"."
] | addok/addok | python | https://github.com/addok/addok/blob/46a270d76ec778d2b445c2be753e5c6ba070a9b2/addok/autocomplete.py#L128-L133 | [
"def",
"do_AUTOCOMPLETE",
"(",
"cmd",
",",
"s",
")",
":",
"s",
"=",
"list",
"(",
"preprocess_query",
"(",
"s",
")",
")",
"[",
"0",
"]",
"keys",
"=",
"[",
"k",
".",
"decode",
"(",
")",
"for",
"k",
"in",
"DB",
".",
"smembers",
"(",
"edge_ngram_key"... | 46a270d76ec778d2b445c2be753e5c6ba070a9b2 |
test | compute_edge_ngrams | Compute edge ngram of token from min. Does not include token itself. | addok/helpers/text.py | def compute_edge_ngrams(token, min=None):
"""Compute edge ngram of token from min. Does not include token itself."""
if min is None:
min = config.MIN_EDGE_NGRAMS
token = token[:config.MAX_EDGE_NGRAMS + 1]
return [token[:i] for i in range(min, len(token))] | def compute_edge_ngrams(token, min=None):
"""Compute edge ngram of token from min. Does not include token itself."""
if min is None:
min = config.MIN_EDGE_NGRAMS
token = token[:config.MAX_EDGE_NGRAMS + 1]
return [token[:i] for i in range(min, len(token))] | [
"Compute",
"edge",
"ngram",
"of",
"token",
"from",
"min",
".",
"Does",
"not",
"include",
"token",
"itself",
"."
] | addok/addok | python | https://github.com/addok/addok/blob/46a270d76ec778d2b445c2be753e5c6ba070a9b2/addok/helpers/text.py#L187-L192 | [
"def",
"compute_edge_ngrams",
"(",
"token",
",",
"min",
"=",
"None",
")",
":",
"if",
"min",
"is",
"None",
":",
"min",
"=",
"config",
".",
"MIN_EDGE_NGRAMS",
"token",
"=",
"token",
"[",
":",
"config",
".",
"MAX_EDGE_NGRAMS",
"+",
"1",
"]",
"return",
"["... | 46a270d76ec778d2b445c2be753e5c6ba070a9b2 |
test | iter_pipe | Allow for iterators to return either an item or an iterator of items. | addok/helpers/__init__.py | def iter_pipe(pipe, processors):
"""Allow for iterators to return either an item or an iterator of items."""
if isinstance(pipe, str):
pipe = [pipe]
for it in processors:
pipe = it(pipe)
yield from pipe | def iter_pipe(pipe, processors):
"""Allow for iterators to return either an item or an iterator of items."""
if isinstance(pipe, str):
pipe = [pipe]
for it in processors:
pipe = it(pipe)
yield from pipe | [
"Allow",
"for",
"iterators",
"to",
"return",
"either",
"an",
"item",
"or",
"an",
"iterator",
"of",
"items",
"."
] | addok/addok | python | https://github.com/addok/addok/blob/46a270d76ec778d2b445c2be753e5c6ba070a9b2/addok/helpers/__init__.py#L33-L39 | [
"def",
"iter_pipe",
"(",
"pipe",
",",
"processors",
")",
":",
"if",
"isinstance",
"(",
"pipe",
",",
"str",
")",
":",
"pipe",
"=",
"[",
"pipe",
"]",
"for",
"it",
"in",
"processors",
":",
"pipe",
"=",
"it",
"(",
"pipe",
")",
"yield",
"from",
"pipe"
] | 46a270d76ec778d2b445c2be753e5c6ba070a9b2 |
test | import_by_path | Import functions or class by their path. Should be of the form:
path.to.module.func | addok/helpers/__init__.py | def import_by_path(path):
"""
Import functions or class by their path. Should be of the form:
path.to.module.func
"""
if not isinstance(path, str):
return path
module_path, *name = path.rsplit('.', 1)
func = import_module(module_path)
if name:
func = getattr(func, name[0]... | def import_by_path(path):
"""
Import functions or class by their path. Should be of the form:
path.to.module.func
"""
if not isinstance(path, str):
return path
module_path, *name = path.rsplit('.', 1)
func = import_module(module_path)
if name:
func = getattr(func, name[0]... | [
"Import",
"functions",
"or",
"class",
"by",
"their",
"path",
".",
"Should",
"be",
"of",
"the",
"form",
":",
"path",
".",
"to",
".",
"module",
".",
"func"
] | addok/addok | python | https://github.com/addok/addok/blob/46a270d76ec778d2b445c2be753e5c6ba070a9b2/addok/helpers/__init__.py#L42-L53 | [
"def",
"import_by_path",
"(",
"path",
")",
":",
"if",
"not",
"isinstance",
"(",
"path",
",",
"str",
")",
":",
"return",
"path",
"module_path",
",",
"",
"*",
"name",
"=",
"path",
".",
"rsplit",
"(",
"'.'",
",",
"1",
")",
"func",
"=",
"import_module",
... | 46a270d76ec778d2b445c2be753e5c6ba070a9b2 |
test | haversine_distance | Calculate the great circle distance between two points
on the earth (specified in decimal degrees). | addok/helpers/__init__.py | def haversine_distance(point1, point2):
"""
Calculate the great circle distance between two points
on the earth (specified in decimal degrees).
"""
lat1, lon1 = point1
lat2, lon2 = point2
# Convert decimal degrees to radians.
lon1, lat1, lon2, lat2 = map(radians, [lon1, lat1, lon2, lat2... | def haversine_distance(point1, point2):
"""
Calculate the great circle distance between two points
on the earth (specified in decimal degrees).
"""
lat1, lon1 = point1
lat2, lon2 = point2
# Convert decimal degrees to radians.
lon1, lat1, lon2, lat2 = map(radians, [lon1, lat1, lon2, lat2... | [
"Calculate",
"the",
"great",
"circle",
"distance",
"between",
"two",
"points",
"on",
"the",
"earth",
"(",
"specified",
"in",
"decimal",
"degrees",
")",
"."
] | addok/addok | python | https://github.com/addok/addok/blob/46a270d76ec778d2b445c2be753e5c6ba070a9b2/addok/helpers/__init__.py#L64-L83 | [
"def",
"haversine_distance",
"(",
"point1",
",",
"point2",
")",
":",
"lat1",
",",
"lon1",
"=",
"point1",
"lat2",
",",
"lon2",
"=",
"point2",
"# Convert decimal degrees to radians.",
"lon1",
",",
"lat1",
",",
"lon2",
",",
"lat2",
"=",
"map",
"(",
"radians",
... | 46a270d76ec778d2b445c2be753e5c6ba070a9b2 |
test | ChunkedPool.imap_unordered | Customized version of imap_unordered.
Directly send chunks to func, instead of iterating in each process and
sending one by one.
Original:
https://hg.python.org/cpython/file/tip/Lib/multiprocessing/pool.py#l271
Other tried options:
- map_async: makes a list(iterable), ... | addok/helpers/__init__.py | def imap_unordered(self, func, iterable, chunksize):
"""Customized version of imap_unordered.
Directly send chunks to func, instead of iterating in each process and
sending one by one.
Original:
https://hg.python.org/cpython/file/tip/Lib/multiprocessing/pool.py#l271
Ot... | def imap_unordered(self, func, iterable, chunksize):
"""Customized version of imap_unordered.
Directly send chunks to func, instead of iterating in each process and
sending one by one.
Original:
https://hg.python.org/cpython/file/tip/Lib/multiprocessing/pool.py#l271
Ot... | [
"Customized",
"version",
"of",
"imap_unordered",
"."
] | addok/addok | python | https://github.com/addok/addok/blob/46a270d76ec778d2b445c2be753e5c6ba070a9b2/addok/helpers/__init__.py#L144-L164 | [
"def",
"imap_unordered",
"(",
"self",
",",
"func",
",",
"iterable",
",",
"chunksize",
")",
":",
"assert",
"self",
".",
"_state",
"==",
"RUN",
"task_batches",
"=",
"Pool",
".",
"_get_tasks",
"(",
"func",
",",
"iterable",
",",
"chunksize",
")",
"result",
"... | 46a270d76ec778d2b445c2be753e5c6ba070a9b2 |
test | make_fuzzy | Naive neighborhoods algo. | addok/fuzzy.py | def make_fuzzy(word, max=1):
"""Naive neighborhoods algo."""
# inversions
neighbors = []
for i in range(0, len(word) - 1):
neighbor = list(word)
neighbor[i], neighbor[i+1] = neighbor[i+1], neighbor[i]
neighbors.append(''.join(neighbor))
# substitutions
for letter in strin... | def make_fuzzy(word, max=1):
"""Naive neighborhoods algo."""
# inversions
neighbors = []
for i in range(0, len(word) - 1):
neighbor = list(word)
neighbor[i], neighbor[i+1] = neighbor[i+1], neighbor[i]
neighbors.append(''.join(neighbor))
# substitutions
for letter in strin... | [
"Naive",
"neighborhoods",
"algo",
"."
] | addok/addok | python | https://github.com/addok/addok/blob/46a270d76ec778d2b445c2be753e5c6ba070a9b2/addok/fuzzy.py#L11-L38 | [
"def",
"make_fuzzy",
"(",
"word",
",",
"max",
"=",
"1",
")",
":",
"# inversions",
"neighbors",
"=",
"[",
"]",
"for",
"i",
"in",
"range",
"(",
"0",
",",
"len",
"(",
"word",
")",
"-",
"1",
")",
":",
"neighbor",
"=",
"list",
"(",
"word",
")",
"nei... | 46a270d76ec778d2b445c2be753e5c6ba070a9b2 |
test | do_fuzzy | Compute fuzzy extensions of word.
FUZZY lilas | addok/fuzzy.py | def do_fuzzy(self, word):
"""Compute fuzzy extensions of word.
FUZZY lilas"""
word = list(preprocess_query(word))[0]
print(white(make_fuzzy(word))) | def do_fuzzy(self, word):
"""Compute fuzzy extensions of word.
FUZZY lilas"""
word = list(preprocess_query(word))[0]
print(white(make_fuzzy(word))) | [
"Compute",
"fuzzy",
"extensions",
"of",
"word",
".",
"FUZZY",
"lilas"
] | addok/addok | python | https://github.com/addok/addok/blob/46a270d76ec778d2b445c2be753e5c6ba070a9b2/addok/fuzzy.py#L100-L104 | [
"def",
"do_fuzzy",
"(",
"self",
",",
"word",
")",
":",
"word",
"=",
"list",
"(",
"preprocess_query",
"(",
"word",
")",
")",
"[",
"0",
"]",
"print",
"(",
"white",
"(",
"make_fuzzy",
"(",
"word",
")",
")",
")"
] | 46a270d76ec778d2b445c2be753e5c6ba070a9b2 |
test | do_fuzzyindex | Compute fuzzy extensions of word that exist in index.
FUZZYINDEX lilas | addok/fuzzy.py | def do_fuzzyindex(self, word):
"""Compute fuzzy extensions of word that exist in index.
FUZZYINDEX lilas"""
word = list(preprocess_query(word))[0]
token = Token(word)
neighbors = make_fuzzy(token)
neighbors = [(n, DB.zcard(dbkeys.token_key(n))) for n in neighbors]
neighbors.sort(key=lambda n... | def do_fuzzyindex(self, word):
"""Compute fuzzy extensions of word that exist in index.
FUZZYINDEX lilas"""
word = list(preprocess_query(word))[0]
token = Token(word)
neighbors = make_fuzzy(token)
neighbors = [(n, DB.zcard(dbkeys.token_key(n))) for n in neighbors]
neighbors.sort(key=lambda n... | [
"Compute",
"fuzzy",
"extensions",
"of",
"word",
"that",
"exist",
"in",
"index",
".",
"FUZZYINDEX",
"lilas"
] | addok/addok | python | https://github.com/addok/addok/blob/46a270d76ec778d2b445c2be753e5c6ba070a9b2/addok/fuzzy.py#L107-L118 | [
"def",
"do_fuzzyindex",
"(",
"self",
",",
"word",
")",
":",
"word",
"=",
"list",
"(",
"preprocess_query",
"(",
"word",
")",
")",
"[",
"0",
"]",
"token",
"=",
"Token",
"(",
"word",
")",
"neighbors",
"=",
"make_fuzzy",
"(",
"token",
")",
"neighbors",
"... | 46a270d76ec778d2b445c2be753e5c6ba070a9b2 |
test | extend_results_extrapoling_relations | Try to extract the bigger group of interlinked tokens.
Should generally be used at last in the collectors chain. | addok/helpers/collectors.py | def extend_results_extrapoling_relations(helper):
"""Try to extract the bigger group of interlinked tokens.
Should generally be used at last in the collectors chain.
"""
if not helper.bucket_dry:
return # No need.
tokens = set(helper.meaningful + helper.common)
for relation in _extract... | def extend_results_extrapoling_relations(helper):
"""Try to extract the bigger group of interlinked tokens.
Should generally be used at last in the collectors chain.
"""
if not helper.bucket_dry:
return # No need.
tokens = set(helper.meaningful + helper.common)
for relation in _extract... | [
"Try",
"to",
"extract",
"the",
"bigger",
"group",
"of",
"interlinked",
"tokens",
"."
] | addok/addok | python | https://github.com/addok/addok/blob/46a270d76ec778d2b445c2be753e5c6ba070a9b2/addok/helpers/collectors.py#L133-L146 | [
"def",
"extend_results_extrapoling_relations",
"(",
"helper",
")",
":",
"if",
"not",
"helper",
".",
"bucket_dry",
":",
"return",
"# No need.",
"tokens",
"=",
"set",
"(",
"helper",
".",
"meaningful",
"+",
"helper",
".",
"common",
")",
"for",
"relation",
"in",
... | 46a270d76ec778d2b445c2be753e5c6ba070a9b2 |
test | Cmd.do_help | Display this help message. | addok/shell.py | def do_help(self, command):
"""Display this help message."""
if command:
doc = getattr(self, 'do_' + command).__doc__
print(cyan(doc.replace(' ' * 8, '')))
else:
print(magenta('Available commands:'))
print(magenta('Type "HELP <command>" to get more... | def do_help(self, command):
"""Display this help message."""
if command:
doc = getattr(self, 'do_' + command).__doc__
print(cyan(doc.replace(' ' * 8, '')))
else:
print(magenta('Available commands:'))
print(magenta('Type "HELP <command>" to get more... | [
"Display",
"this",
"help",
"message",
"."
] | addok/addok | python | https://github.com/addok/addok/blob/46a270d76ec778d2b445c2be753e5c6ba070a9b2/addok/shell.py#L110-L127 | [
"def",
"do_help",
"(",
"self",
",",
"command",
")",
":",
"if",
"command",
":",
"doc",
"=",
"getattr",
"(",
"self",
",",
"'do_'",
"+",
"command",
")",
".",
"__doc__",
"print",
"(",
"cyan",
"(",
"doc",
".",
"replace",
"(",
"' '",
"*",
"8",
",",
"''... | 46a270d76ec778d2b445c2be753e5c6ba070a9b2 |
test | Cmd.do_BENCH | Run a search many times to benchmark it.
BENCH [100] rue des Lilas | addok/shell.py | def do_BENCH(self, query):
"""Run a search many times to benchmark it.
BENCH [100] rue des Lilas"""
try:
count = int(re.match(r'^(\d+).*', query).group(1))
except AttributeError:
count = 100
self._search(query, count=count) | def do_BENCH(self, query):
"""Run a search many times to benchmark it.
BENCH [100] rue des Lilas"""
try:
count = int(re.match(r'^(\d+).*', query).group(1))
except AttributeError:
count = 100
self._search(query, count=count) | [
"Run",
"a",
"search",
"many",
"times",
"to",
"benchmark",
"it",
".",
"BENCH",
"[",
"100",
"]",
"rue",
"des",
"Lilas"
] | addok/addok | python | https://github.com/addok/addok/blob/46a270d76ec778d2b445c2be753e5c6ba070a9b2/addok/shell.py#L209-L216 | [
"def",
"do_BENCH",
"(",
"self",
",",
"query",
")",
":",
"try",
":",
"count",
"=",
"int",
"(",
"re",
".",
"match",
"(",
"r'^(\\d+).*'",
",",
"query",
")",
".",
"group",
"(",
"1",
")",
")",
"except",
"AttributeError",
":",
"count",
"=",
"100",
"self"... | 46a270d76ec778d2b445c2be753e5c6ba070a9b2 |
test | Cmd.do_INTERSECT | Do a raw intersect between tokens (default limit 100).
INTERSECT rue des lilas [LIMIT 100] | addok/shell.py | def do_INTERSECT(self, words):
"""Do a raw intersect between tokens (default limit 100).
INTERSECT rue des lilas [LIMIT 100]"""
start = time.time()
limit = 100
if 'LIMIT' in words:
words, limit = words.split('LIMIT')
limit = int(limit)
tokens = [ke... | def do_INTERSECT(self, words):
"""Do a raw intersect between tokens (default limit 100).
INTERSECT rue des lilas [LIMIT 100]"""
start = time.time()
limit = 100
if 'LIMIT' in words:
words, limit = words.split('LIMIT')
limit = int(limit)
tokens = [ke... | [
"Do",
"a",
"raw",
"intersect",
"between",
"tokens",
"(",
"default",
"limit",
"100",
")",
".",
"INTERSECT",
"rue",
"des",
"lilas",
"[",
"LIMIT",
"100",
"]"
] | addok/addok | python | https://github.com/addok/addok/blob/46a270d76ec778d2b445c2be753e5c6ba070a9b2/addok/shell.py#L218-L234 | [
"def",
"do_INTERSECT",
"(",
"self",
",",
"words",
")",
":",
"start",
"=",
"time",
".",
"time",
"(",
")",
"limit",
"=",
"100",
"if",
"'LIMIT'",
"in",
"words",
":",
"words",
",",
"limit",
"=",
"words",
".",
"split",
"(",
"'LIMIT'",
")",
"limit",
"=",... | 46a270d76ec778d2b445c2be753e5c6ba070a9b2 |
test | Cmd.do_DBINFO | Print some useful infos from Redis DB. | addok/shell.py | def do_DBINFO(self, *args):
"""Print some useful infos from Redis DB."""
info = DB.info()
keys = [
'keyspace_misses', 'keyspace_hits', 'used_memory_human',
'total_commands_processed', 'total_connections_received',
'connected_clients']
for key in keys:
... | def do_DBINFO(self, *args):
"""Print some useful infos from Redis DB."""
info = DB.info()
keys = [
'keyspace_misses', 'keyspace_hits', 'used_memory_human',
'total_commands_processed', 'total_connections_received',
'connected_clients']
for key in keys:
... | [
"Print",
"some",
"useful",
"infos",
"from",
"Redis",
"DB",
"."
] | addok/addok | python | https://github.com/addok/addok/blob/46a270d76ec778d2b445c2be753e5c6ba070a9b2/addok/shell.py#L236-L250 | [
"def",
"do_DBINFO",
"(",
"self",
",",
"*",
"args",
")",
":",
"info",
"=",
"DB",
".",
"info",
"(",
")",
"keys",
"=",
"[",
"'keyspace_misses'",
",",
"'keyspace_hits'",
",",
"'used_memory_human'",
",",
"'total_commands_processed'",
",",
"'total_connections_received... | 46a270d76ec778d2b445c2be753e5c6ba070a9b2 |
test | Cmd.do_DBKEY | Print raw content of a DB key.
DBKEY g|u09tyzfe | addok/shell.py | def do_DBKEY(self, key):
"""Print raw content of a DB key.
DBKEY g|u09tyzfe"""
type_ = DB.type(key).decode()
if type_ == 'set':
out = DB.smembers(key)
elif type_ == 'string':
out = DB.get(key)
else:
out = 'Unsupported type {}'.format(ty... | def do_DBKEY(self, key):
"""Print raw content of a DB key.
DBKEY g|u09tyzfe"""
type_ = DB.type(key).decode()
if type_ == 'set':
out = DB.smembers(key)
elif type_ == 'string':
out = DB.get(key)
else:
out = 'Unsupported type {}'.format(ty... | [
"Print",
"raw",
"content",
"of",
"a",
"DB",
"key",
".",
"DBKEY",
"g|u09tyzfe"
] | addok/addok | python | https://github.com/addok/addok/blob/46a270d76ec778d2b445c2be753e5c6ba070a9b2/addok/shell.py#L252-L263 | [
"def",
"do_DBKEY",
"(",
"self",
",",
"key",
")",
":",
"type_",
"=",
"DB",
".",
"type",
"(",
"key",
")",
".",
"decode",
"(",
")",
"if",
"type_",
"==",
"'set'",
":",
"out",
"=",
"DB",
".",
"smembers",
"(",
"key",
")",
"elif",
"type_",
"==",
"'str... | 46a270d76ec778d2b445c2be753e5c6ba070a9b2 |
test | Cmd.do_GEODISTANCE | Compute geodistance from a result to a point.
GEODISTANCE 772210180J 48.1234 2.9876 | addok/shell.py | def do_GEODISTANCE(self, s):
"""Compute geodistance from a result to a point.
GEODISTANCE 772210180J 48.1234 2.9876"""
try:
_id, lat, lon = s.split()
except:
return self.error('Malformed query. Use: ID lat lon')
try:
result = Result(keys.docume... | def do_GEODISTANCE(self, s):
"""Compute geodistance from a result to a point.
GEODISTANCE 772210180J 48.1234 2.9876"""
try:
_id, lat, lon = s.split()
except:
return self.error('Malformed query. Use: ID lat lon')
try:
result = Result(keys.docume... | [
"Compute",
"geodistance",
"from",
"a",
"result",
"to",
"a",
"point",
".",
"GEODISTANCE",
"772210180J",
"48",
".",
"1234",
"2",
".",
"9876"
] | addok/addok | python | https://github.com/addok/addok/blob/46a270d76ec778d2b445c2be753e5c6ba070a9b2/addok/shell.py#L265-L279 | [
"def",
"do_GEODISTANCE",
"(",
"self",
",",
"s",
")",
":",
"try",
":",
"_id",
",",
"lat",
",",
"lon",
"=",
"s",
".",
"split",
"(",
")",
"except",
":",
"return",
"self",
".",
"error",
"(",
"'Malformed query. Use: ID lat lon'",
")",
"try",
":",
"result",
... | 46a270d76ec778d2b445c2be753e5c6ba070a9b2 |
test | Cmd.do_GEOHASHTOGEOJSON | Build GeoJSON corresponding to geohash given as parameter.
GEOHASHTOGEOJSON u09vej04 [NEIGHBORS 0|1|2] | addok/shell.py | def do_GEOHASHTOGEOJSON(self, geoh):
"""Build GeoJSON corresponding to geohash given as parameter.
GEOHASHTOGEOJSON u09vej04 [NEIGHBORS 0|1|2]"""
geoh, with_neighbors = self._match_option('NEIGHBORS', geoh)
bbox = geohash.bbox(geoh)
try:
with_neighbors = int(with_neig... | def do_GEOHASHTOGEOJSON(self, geoh):
"""Build GeoJSON corresponding to geohash given as parameter.
GEOHASHTOGEOJSON u09vej04 [NEIGHBORS 0|1|2]"""
geoh, with_neighbors = self._match_option('NEIGHBORS', geoh)
bbox = geohash.bbox(geoh)
try:
with_neighbors = int(with_neig... | [
"Build",
"GeoJSON",
"corresponding",
"to",
"geohash",
"given",
"as",
"parameter",
".",
"GEOHASHTOGEOJSON",
"u09vej04",
"[",
"NEIGHBORS",
"0|1|2",
"]"
] | addok/addok | python | https://github.com/addok/addok/blob/46a270d76ec778d2b445c2be753e5c6ba070a9b2/addok/shell.py#L281-L320 | [
"def",
"do_GEOHASHTOGEOJSON",
"(",
"self",
",",
"geoh",
")",
":",
"geoh",
",",
"with_neighbors",
"=",
"self",
".",
"_match_option",
"(",
"'NEIGHBORS'",
",",
"geoh",
")",
"bbox",
"=",
"geohash",
".",
"bbox",
"(",
"geoh",
")",
"try",
":",
"with_neighbors",
... | 46a270d76ec778d2b445c2be753e5c6ba070a9b2 |
test | Cmd.do_GEOHASH | Compute a geohash from latitude and longitude.
GEOHASH 48.1234 2.9876 | addok/shell.py | def do_GEOHASH(self, latlon):
"""Compute a geohash from latitude and longitude.
GEOHASH 48.1234 2.9876"""
try:
lat, lon = map(float, latlon.split())
except ValueError:
print(red('Invalid lat and lon {}'.format(latlon)))
else:
print(white(geohas... | def do_GEOHASH(self, latlon):
"""Compute a geohash from latitude and longitude.
GEOHASH 48.1234 2.9876"""
try:
lat, lon = map(float, latlon.split())
except ValueError:
print(red('Invalid lat and lon {}'.format(latlon)))
else:
print(white(geohas... | [
"Compute",
"a",
"geohash",
"from",
"latitude",
"and",
"longitude",
".",
"GEOHASH",
"48",
".",
"1234",
"2",
".",
"9876"
] | addok/addok | python | https://github.com/addok/addok/blob/46a270d76ec778d2b445c2be753e5c6ba070a9b2/addok/shell.py#L322-L330 | [
"def",
"do_GEOHASH",
"(",
"self",
",",
"latlon",
")",
":",
"try",
":",
"lat",
",",
"lon",
"=",
"map",
"(",
"float",
",",
"latlon",
".",
"split",
"(",
")",
")",
"except",
"ValueError",
":",
"print",
"(",
"red",
"(",
"'Invalid lat and lon {}'",
".",
"f... | 46a270d76ec778d2b445c2be753e5c6ba070a9b2 |
test | Cmd.do_GEOHASHMEMBERS | Return members of a geohash and its neighbors.
GEOHASHMEMBERS u09vej04 [NEIGHBORS 0] | addok/shell.py | def do_GEOHASHMEMBERS(self, geoh):
"""Return members of a geohash and its neighbors.
GEOHASHMEMBERS u09vej04 [NEIGHBORS 0]"""
geoh, with_neighbors = self._match_option('NEIGHBORS', geoh)
key = compute_geohash_key(geoh, with_neighbors != '0')
if key:
for id_ in DB.smem... | def do_GEOHASHMEMBERS(self, geoh):
"""Return members of a geohash and its neighbors.
GEOHASHMEMBERS u09vej04 [NEIGHBORS 0]"""
geoh, with_neighbors = self._match_option('NEIGHBORS', geoh)
key = compute_geohash_key(geoh, with_neighbors != '0')
if key:
for id_ in DB.smem... | [
"Return",
"members",
"of",
"a",
"geohash",
"and",
"its",
"neighbors",
".",
"GEOHASHMEMBERS",
"u09vej04",
"[",
"NEIGHBORS",
"0",
"]"
] | addok/addok | python | https://github.com/addok/addok/blob/46a270d76ec778d2b445c2be753e5c6ba070a9b2/addok/shell.py#L332-L340 | [
"def",
"do_GEOHASHMEMBERS",
"(",
"self",
",",
"geoh",
")",
":",
"geoh",
",",
"with_neighbors",
"=",
"self",
".",
"_match_option",
"(",
"'NEIGHBORS'",
",",
"geoh",
")",
"key",
"=",
"compute_geohash_key",
"(",
"geoh",
",",
"with_neighbors",
"!=",
"'0'",
")",
... | 46a270d76ec778d2b445c2be753e5c6ba070a9b2 |
test | Cmd.do_GET | Get document from index with its id.
GET 772210180J | addok/shell.py | def do_GET(self, _id):
"""Get document from index with its id.
GET 772210180J"""
doc = doc_by_id(_id)
if not doc:
return self.error('id "{}" not found'.format(_id))
for key, value in doc.items():
if key == config.HOUSENUMBERS_FIELD:
continu... | def do_GET(self, _id):
"""Get document from index with its id.
GET 772210180J"""
doc = doc_by_id(_id)
if not doc:
return self.error('id "{}" not found'.format(_id))
for key, value in doc.items():
if key == config.HOUSENUMBERS_FIELD:
continu... | [
"Get",
"document",
"from",
"index",
"with",
"its",
"id",
".",
"GET",
"772210180J"
] | addok/addok | python | https://github.com/addok/addok/blob/46a270d76ec778d2b445c2be753e5c6ba070a9b2/addok/shell.py#L342-L360 | [
"def",
"do_GET",
"(",
"self",
",",
"_id",
")",
":",
"doc",
"=",
"doc_by_id",
"(",
"_id",
")",
"if",
"not",
"doc",
":",
"return",
"self",
".",
"error",
"(",
"'id \"{}\" not found'",
".",
"format",
"(",
"_id",
")",
")",
"for",
"key",
",",
"value",
"i... | 46a270d76ec778d2b445c2be753e5c6ba070a9b2 |
test | Cmd.do_INDEX | Get index details for a document by its id.
INDEX 772210180J | addok/shell.py | def do_INDEX(self, _id):
"""Get index details for a document by its id.
INDEX 772210180J"""
doc = doc_by_id(_id)
if not doc:
return self.error('id "{}" not found'.format(_id))
for field in config.FIELDS:
key = field['key']
if key in doc:
... | def do_INDEX(self, _id):
"""Get index details for a document by its id.
INDEX 772210180J"""
doc = doc_by_id(_id)
if not doc:
return self.error('id "{}" not found'.format(_id))
for field in config.FIELDS:
key = field['key']
if key in doc:
... | [
"Get",
"index",
"details",
"for",
"a",
"document",
"by",
"its",
"id",
".",
"INDEX",
"772210180J"
] | addok/addok | python | https://github.com/addok/addok/blob/46a270d76ec778d2b445c2be753e5c6ba070a9b2/addok/shell.py#L375-L384 | [
"def",
"do_INDEX",
"(",
"self",
",",
"_id",
")",
":",
"doc",
"=",
"doc_by_id",
"(",
"_id",
")",
"if",
"not",
"doc",
":",
"return",
"self",
".",
"error",
"(",
"'id \"{}\" not found'",
".",
"format",
"(",
"_id",
")",
")",
"for",
"field",
"in",
"config"... | 46a270d76ec778d2b445c2be753e5c6ba070a9b2 |
test | Cmd.do_BESTSCORE | Return document linked to word with higher score.
BESTSCORE lilas | addok/shell.py | def do_BESTSCORE(self, word):
"""Return document linked to word with higher score.
BESTSCORE lilas"""
key = keys.token_key(indexed_string(word)[0])
for _id, score in DB.zrevrange(key, 0, 20, withscores=True):
result = Result(_id)
print(white(result), blue(score), ... | def do_BESTSCORE(self, word):
"""Return document linked to word with higher score.
BESTSCORE lilas"""
key = keys.token_key(indexed_string(word)[0])
for _id, score in DB.zrevrange(key, 0, 20, withscores=True):
result = Result(_id)
print(white(result), blue(score), ... | [
"Return",
"document",
"linked",
"to",
"word",
"with",
"higher",
"score",
".",
"BESTSCORE",
"lilas"
] | addok/addok | python | https://github.com/addok/addok/blob/46a270d76ec778d2b445c2be753e5c6ba070a9b2/addok/shell.py#L386-L392 | [
"def",
"do_BESTSCORE",
"(",
"self",
",",
"word",
")",
":",
"key",
"=",
"keys",
".",
"token_key",
"(",
"indexed_string",
"(",
"word",
")",
"[",
"0",
"]",
")",
"for",
"_id",
",",
"score",
"in",
"DB",
".",
"zrevrange",
"(",
"key",
",",
"0",
",",
"20... | 46a270d76ec778d2b445c2be753e5c6ba070a9b2 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.