id int32 0 252k | repo stringlengths 7 55 | path stringlengths 4 127 | func_name stringlengths 1 88 | original_string stringlengths 75 19.8k | language stringclasses 1
value | code stringlengths 75 19.8k | code_tokens list | docstring stringlengths 3 17.3k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 87 242 |
|---|---|---|---|---|---|---|---|---|---|---|---|
42,300 | jciskey/pygraph | pygraph/functions/planarity/kocay_algorithm.py | __embed_branch_recursive | def __embed_branch_recursive(u, dfs_data):
"""A recursive implementation of the EmbedBranch function, as defined on pages 8 and 22 of the paper."""
#print "\nu: {}\nadj: {}".format(u, dfs_data['adj'][u])
#print 'Pre-inserts'
#print "FG: {}".format(dfs_data['FG'])
#print "LF: {}".format(dfs_data['LF... | python | def __embed_branch_recursive(u, dfs_data):
"""A recursive implementation of the EmbedBranch function, as defined on pages 8 and 22 of the paper."""
#print "\nu: {}\nadj: {}".format(u, dfs_data['adj'][u])
#print 'Pre-inserts'
#print "FG: {}".format(dfs_data['FG'])
#print "LF: {}".format(dfs_data['LF... | [
"def",
"__embed_branch_recursive",
"(",
"u",
",",
"dfs_data",
")",
":",
"#print \"\\nu: {}\\nadj: {}\".format(u, dfs_data['adj'][u])",
"#print 'Pre-inserts'",
"#print \"FG: {}\".format(dfs_data['FG'])",
"#print \"LF: {}\".format(dfs_data['LF'])",
"#print \"RF: {}\".format(dfs_data['RF'])",
... | A recursive implementation of the EmbedBranch function, as defined on pages 8 and 22 of the paper. | [
"A",
"recursive",
"implementation",
"of",
"the",
"EmbedBranch",
"function",
"as",
"defined",
"on",
"pages",
"8",
"and",
"22",
"of",
"the",
"paper",
"."
] | 037bb2f32503fecb60d62921f9766d54109f15e2 | https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/functions/planarity/kocay_algorithm.py#L212-L262 |
42,301 | jciskey/pygraph | pygraph/functions/planarity/kocay_algorithm.py | __embed_frond | def __embed_frond(node_u, node_w, dfs_data, as_branch_marker=False):
"""Embeds a frond uw into either LF or RF. Returns whether the embedding was successful."""
d_u = D(node_u, dfs_data)
d_w = D(node_w, dfs_data)
comp_d_w = abs(d_w)
if as_branch_marker:
d_w *= -1
if dfs_data['last_i... | python | def __embed_frond(node_u, node_w, dfs_data, as_branch_marker=False):
"""Embeds a frond uw into either LF or RF. Returns whether the embedding was successful."""
d_u = D(node_u, dfs_data)
d_w = D(node_w, dfs_data)
comp_d_w = abs(d_w)
if as_branch_marker:
d_w *= -1
if dfs_data['last_i... | [
"def",
"__embed_frond",
"(",
"node_u",
",",
"node_w",
",",
"dfs_data",
",",
"as_branch_marker",
"=",
"False",
")",
":",
"d_u",
"=",
"D",
"(",
"node_u",
",",
"dfs_data",
")",
"d_w",
"=",
"D",
"(",
"node_w",
",",
"dfs_data",
")",
"comp_d_w",
"=",
"abs",
... | Embeds a frond uw into either LF or RF. Returns whether the embedding was successful. | [
"Embeds",
"a",
"frond",
"uw",
"into",
"either",
"LF",
"or",
"RF",
".",
"Returns",
"whether",
"the",
"embedding",
"was",
"successful",
"."
] | 037bb2f32503fecb60d62921f9766d54109f15e2 | https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/functions/planarity/kocay_algorithm.py#L285-L400 |
42,302 | jciskey/pygraph | pygraph/functions/planarity/kocay_algorithm.py | __insert_frond_RF | def __insert_frond_RF(d_w, d_u, dfs_data):
"""Encapsulates the process of inserting a frond uw into the right side frond group."""
# --Add the frond to the right side
dfs_data['RF'].append( (d_w, d_u) )
dfs_data['FG']['r'] += 1
dfs_data['last_inserted_side'] = 'RF' | python | def __insert_frond_RF(d_w, d_u, dfs_data):
"""Encapsulates the process of inserting a frond uw into the right side frond group."""
# --Add the frond to the right side
dfs_data['RF'].append( (d_w, d_u) )
dfs_data['FG']['r'] += 1
dfs_data['last_inserted_side'] = 'RF' | [
"def",
"__insert_frond_RF",
"(",
"d_w",
",",
"d_u",
",",
"dfs_data",
")",
":",
"# --Add the frond to the right side",
"dfs_data",
"[",
"'RF'",
"]",
".",
"append",
"(",
"(",
"d_w",
",",
"d_u",
")",
")",
"dfs_data",
"[",
"'FG'",
"]",
"[",
"'r'",
"]",
"+=",... | Encapsulates the process of inserting a frond uw into the right side frond group. | [
"Encapsulates",
"the",
"process",
"of",
"inserting",
"a",
"frond",
"uw",
"into",
"the",
"right",
"side",
"frond",
"group",
"."
] | 037bb2f32503fecb60d62921f9766d54109f15e2 | https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/functions/planarity/kocay_algorithm.py#L473-L479 |
42,303 | jciskey/pygraph | pygraph/functions/planarity/kocay_algorithm.py | __insert_frond_LF | def __insert_frond_LF(d_w, d_u, dfs_data):
"""Encapsulates the process of inserting a frond uw into the left side frond group."""
# --Add the frond to the left side
dfs_data['LF'].append( (d_w, d_u) )
dfs_data['FG']['l'] += 1
dfs_data['last_inserted_side'] = 'LF' | python | def __insert_frond_LF(d_w, d_u, dfs_data):
"""Encapsulates the process of inserting a frond uw into the left side frond group."""
# --Add the frond to the left side
dfs_data['LF'].append( (d_w, d_u) )
dfs_data['FG']['l'] += 1
dfs_data['last_inserted_side'] = 'LF' | [
"def",
"__insert_frond_LF",
"(",
"d_w",
",",
"d_u",
",",
"dfs_data",
")",
":",
"# --Add the frond to the left side",
"dfs_data",
"[",
"'LF'",
"]",
".",
"append",
"(",
"(",
"d_w",
",",
"d_u",
")",
")",
"dfs_data",
"[",
"'FG'",
"]",
"[",
"'l'",
"]",
"+=",
... | Encapsulates the process of inserting a frond uw into the left side frond group. | [
"Encapsulates",
"the",
"process",
"of",
"inserting",
"a",
"frond",
"uw",
"into",
"the",
"left",
"side",
"frond",
"group",
"."
] | 037bb2f32503fecb60d62921f9766d54109f15e2 | https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/functions/planarity/kocay_algorithm.py#L481-L487 |
42,304 | jciskey/pygraph | pygraph/functions/planarity/kocay_algorithm.py | merge_Fm | def merge_Fm(dfs_data):
"""Merges Fm-1 and Fm, as defined on page 19 of the paper."""
FG = dfs_data['FG']
m = FG['m']
FGm = FG[m]
FGm1 = FG[m-1]
if FGm[0]['u'] < FGm1[0]['u']:
FGm1[0]['u'] = FGm[0]['u']
if FGm[0]['v'] > FGm1[0]['v']:
FGm1[0]['v'] = FGm[0]['v']
if FGm[1... | python | def merge_Fm(dfs_data):
"""Merges Fm-1 and Fm, as defined on page 19 of the paper."""
FG = dfs_data['FG']
m = FG['m']
FGm = FG[m]
FGm1 = FG[m-1]
if FGm[0]['u'] < FGm1[0]['u']:
FGm1[0]['u'] = FGm[0]['u']
if FGm[0]['v'] > FGm1[0]['v']:
FGm1[0]['v'] = FGm[0]['v']
if FGm[1... | [
"def",
"merge_Fm",
"(",
"dfs_data",
")",
":",
"FG",
"=",
"dfs_data",
"[",
"'FG'",
"]",
"m",
"=",
"FG",
"[",
"'m'",
"]",
"FGm",
"=",
"FG",
"[",
"m",
"]",
"FGm1",
"=",
"FG",
"[",
"m",
"-",
"1",
"]",
"if",
"FGm",
"[",
"0",
"]",
"[",
"'u'",
"... | Merges Fm-1 and Fm, as defined on page 19 of the paper. | [
"Merges",
"Fm",
"-",
"1",
"and",
"Fm",
"as",
"defined",
"on",
"page",
"19",
"of",
"the",
"paper",
"."
] | 037bb2f32503fecb60d62921f9766d54109f15e2 | https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/functions/planarity/kocay_algorithm.py#L490-L510 |
42,305 | jciskey/pygraph | pygraph/functions/planarity/kocay_algorithm.py | __check_left_side_conflict | def __check_left_side_conflict(x, y, dfs_data):
"""Checks to see if the frond xy will conflict with a frond on the left side of the embedding."""
l = dfs_data['FG']['l']
w, z = dfs_data['LF'][l]
return __check_conflict_fronds(x, y, w, z, dfs_data) | python | def __check_left_side_conflict(x, y, dfs_data):
"""Checks to see if the frond xy will conflict with a frond on the left side of the embedding."""
l = dfs_data['FG']['l']
w, z = dfs_data['LF'][l]
return __check_conflict_fronds(x, y, w, z, dfs_data) | [
"def",
"__check_left_side_conflict",
"(",
"x",
",",
"y",
",",
"dfs_data",
")",
":",
"l",
"=",
"dfs_data",
"[",
"'FG'",
"]",
"[",
"'l'",
"]",
"w",
",",
"z",
"=",
"dfs_data",
"[",
"'LF'",
"]",
"[",
"l",
"]",
"return",
"__check_conflict_fronds",
"(",
"x... | Checks to see if the frond xy will conflict with a frond on the left side of the embedding. | [
"Checks",
"to",
"see",
"if",
"the",
"frond",
"xy",
"will",
"conflict",
"with",
"a",
"frond",
"on",
"the",
"left",
"side",
"of",
"the",
"embedding",
"."
] | 037bb2f32503fecb60d62921f9766d54109f15e2 | https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/functions/planarity/kocay_algorithm.py#L671-L675 |
42,306 | jciskey/pygraph | pygraph/functions/planarity/kocay_algorithm.py | __check_right_side_conflict | def __check_right_side_conflict(x, y, dfs_data):
"""Checks to see if the frond xy will conflict with a frond on the right side of the embedding."""
r = dfs_data['FG']['r']
w, z = dfs_data['RF'][r]
return __check_conflict_fronds(x, y, w, z, dfs_data) | python | def __check_right_side_conflict(x, y, dfs_data):
"""Checks to see if the frond xy will conflict with a frond on the right side of the embedding."""
r = dfs_data['FG']['r']
w, z = dfs_data['RF'][r]
return __check_conflict_fronds(x, y, w, z, dfs_data) | [
"def",
"__check_right_side_conflict",
"(",
"x",
",",
"y",
",",
"dfs_data",
")",
":",
"r",
"=",
"dfs_data",
"[",
"'FG'",
"]",
"[",
"'r'",
"]",
"w",
",",
"z",
"=",
"dfs_data",
"[",
"'RF'",
"]",
"[",
"r",
"]",
"return",
"__check_conflict_fronds",
"(",
"... | Checks to see if the frond xy will conflict with a frond on the right side of the embedding. | [
"Checks",
"to",
"see",
"if",
"the",
"frond",
"xy",
"will",
"conflict",
"with",
"a",
"frond",
"on",
"the",
"right",
"side",
"of",
"the",
"embedding",
"."
] | 037bb2f32503fecb60d62921f9766d54109f15e2 | https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/functions/planarity/kocay_algorithm.py#L678-L682 |
42,307 | jciskey/pygraph | pygraph/functions/planarity/kocay_algorithm.py | __check_conflict_fronds | def __check_conflict_fronds(x, y, w, z, dfs_data):
"""Checks a pair of fronds to see if they conflict. Returns True if a conflict was found, False otherwise."""
# Case 1: False frond and corresponding branch marker
# --x and w should both be negative, and either xy or wz should be the same value uu
if ... | python | def __check_conflict_fronds(x, y, w, z, dfs_data):
"""Checks a pair of fronds to see if they conflict. Returns True if a conflict was found, False otherwise."""
# Case 1: False frond and corresponding branch marker
# --x and w should both be negative, and either xy or wz should be the same value uu
if ... | [
"def",
"__check_conflict_fronds",
"(",
"x",
",",
"y",
",",
"w",
",",
"z",
",",
"dfs_data",
")",
":",
"# Case 1: False frond and corresponding branch marker",
"# --x and w should both be negative, and either xy or wz should be the same value uu",
"if",
"x",
"<",
"0",
"and",
... | Checks a pair of fronds to see if they conflict. Returns True if a conflict was found, False otherwise. | [
"Checks",
"a",
"pair",
"of",
"fronds",
"to",
"see",
"if",
"they",
"conflict",
".",
"Returns",
"True",
"if",
"a",
"conflict",
"was",
"found",
"False",
"otherwise",
"."
] | 037bb2f32503fecb60d62921f9766d54109f15e2 | https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/functions/planarity/kocay_algorithm.py#L685-L718 |
42,308 | jciskey/pygraph | pygraph/functions/planarity/kocay_algorithm.py | __calculate_adjacency_lists | def __calculate_adjacency_lists(graph):
"""Builds an adjacency list representation for the graph, since we can't guarantee that the
internal representation of the graph is stored that way."""
adj = {}
for node in graph.get_all_node_ids():
neighbors = graph.neighbors(node)
adj[node] =... | python | def __calculate_adjacency_lists(graph):
"""Builds an adjacency list representation for the graph, since we can't guarantee that the
internal representation of the graph is stored that way."""
adj = {}
for node in graph.get_all_node_ids():
neighbors = graph.neighbors(node)
adj[node] =... | [
"def",
"__calculate_adjacency_lists",
"(",
"graph",
")",
":",
"adj",
"=",
"{",
"}",
"for",
"node",
"in",
"graph",
".",
"get_all_node_ids",
"(",
")",
":",
"neighbors",
"=",
"graph",
".",
"neighbors",
"(",
"node",
")",
"adj",
"[",
"node",
"]",
"=",
"neig... | Builds an adjacency list representation for the graph, since we can't guarantee that the
internal representation of the graph is stored that way. | [
"Builds",
"an",
"adjacency",
"list",
"representation",
"for",
"the",
"graph",
"since",
"we",
"can",
"t",
"guarantee",
"that",
"the",
"internal",
"representation",
"of",
"the",
"graph",
"is",
"stored",
"that",
"way",
"."
] | 037bb2f32503fecb60d62921f9766d54109f15e2 | https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/functions/planarity/kocay_algorithm.py#L779-L786 |
42,309 | jciskey/pygraph | pygraph/functions/planarity/kocay_algorithm.py | __get_all_lowpoints | def __get_all_lowpoints(dfs_data):
"""Calculates the lowpoints for each node in a graph."""
lowpoint_1_lookup = {}
lowpoint_2_lookup = {}
ordering = dfs_data['ordering']
for node in ordering:
low_1, low_2 = __get_lowpoints(node, dfs_data)
lowpoint_1_lookup[node] = low_1
low... | python | def __get_all_lowpoints(dfs_data):
"""Calculates the lowpoints for each node in a graph."""
lowpoint_1_lookup = {}
lowpoint_2_lookup = {}
ordering = dfs_data['ordering']
for node in ordering:
low_1, low_2 = __get_lowpoints(node, dfs_data)
lowpoint_1_lookup[node] = low_1
low... | [
"def",
"__get_all_lowpoints",
"(",
"dfs_data",
")",
":",
"lowpoint_1_lookup",
"=",
"{",
"}",
"lowpoint_2_lookup",
"=",
"{",
"}",
"ordering",
"=",
"dfs_data",
"[",
"'ordering'",
"]",
"for",
"node",
"in",
"ordering",
":",
"low_1",
",",
"low_2",
"=",
"__get_low... | Calculates the lowpoints for each node in a graph. | [
"Calculates",
"the",
"lowpoints",
"for",
"each",
"node",
"in",
"a",
"graph",
"."
] | 037bb2f32503fecb60d62921f9766d54109f15e2 | https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/functions/planarity/kocay_algorithm.py#L789-L801 |
42,310 | jciskey/pygraph | pygraph/functions/planarity/kocay_algorithm.py | __get_lowpoints | def __get_lowpoints(node, dfs_data):
"""Calculates the lowpoints for a single node in a graph."""
ordering_lookup = dfs_data['ordering_lookup']
t_u = T(node, dfs_data)
sorted_t_u = sorted(t_u, key=lambda a: ordering_lookup[a])
lowpoint_1 = sorted_t_u[0]
lowpoint_2 = sorted_t_u[1]
return l... | python | def __get_lowpoints(node, dfs_data):
"""Calculates the lowpoints for a single node in a graph."""
ordering_lookup = dfs_data['ordering_lookup']
t_u = T(node, dfs_data)
sorted_t_u = sorted(t_u, key=lambda a: ordering_lookup[a])
lowpoint_1 = sorted_t_u[0]
lowpoint_2 = sorted_t_u[1]
return l... | [
"def",
"__get_lowpoints",
"(",
"node",
",",
"dfs_data",
")",
":",
"ordering_lookup",
"=",
"dfs_data",
"[",
"'ordering_lookup'",
"]",
"t_u",
"=",
"T",
"(",
"node",
",",
"dfs_data",
")",
"sorted_t_u",
"=",
"sorted",
"(",
"t_u",
",",
"key",
"=",
"lambda",
"... | Calculates the lowpoints for a single node in a graph. | [
"Calculates",
"the",
"lowpoints",
"for",
"a",
"single",
"node",
"in",
"a",
"graph",
"."
] | 037bb2f32503fecb60d62921f9766d54109f15e2 | https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/functions/planarity/kocay_algorithm.py#L804-L814 |
42,311 | jciskey/pygraph | pygraph/functions/planarity/kocay_algorithm.py | __edge_weight | def __edge_weight(edge_id, dfs_data):
"""Calculates the edge weight used to sort edges."""
graph = dfs_data['graph']
edge_lookup = dfs_data['edge_lookup']
edge = graph.get_edge(edge_id)
u, v = edge['vertices']
d_u = D(u, dfs_data)
d_v = D(v, dfs_data)
lp_1 = L1(v, dfs_data)
d_lp_1 =... | python | def __edge_weight(edge_id, dfs_data):
"""Calculates the edge weight used to sort edges."""
graph = dfs_data['graph']
edge_lookup = dfs_data['edge_lookup']
edge = graph.get_edge(edge_id)
u, v = edge['vertices']
d_u = D(u, dfs_data)
d_v = D(v, dfs_data)
lp_1 = L1(v, dfs_data)
d_lp_1 =... | [
"def",
"__edge_weight",
"(",
"edge_id",
",",
"dfs_data",
")",
":",
"graph",
"=",
"dfs_data",
"[",
"'graph'",
"]",
"edge_lookup",
"=",
"dfs_data",
"[",
"'edge_lookup'",
"]",
"edge",
"=",
"graph",
".",
"get_edge",
"(",
"edge_id",
")",
"u",
",",
"v",
"=",
... | Calculates the edge weight used to sort edges. | [
"Calculates",
"the",
"edge",
"weight",
"used",
"to",
"sort",
"edges",
"."
] | 037bb2f32503fecb60d62921f9766d54109f15e2 | https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/functions/planarity/kocay_algorithm.py#L817-L836 |
42,312 | jciskey/pygraph | pygraph/functions/planarity/kocay_algorithm.py | is_type_I_branch | def is_type_I_branch(u, v, dfs_data):
"""Determines whether a branch uv is a type I branch."""
if u != a(v, dfs_data):
return False
if u == L2(v, dfs_data):
return True
return False | python | def is_type_I_branch(u, v, dfs_data):
"""Determines whether a branch uv is a type I branch."""
if u != a(v, dfs_data):
return False
if u == L2(v, dfs_data):
return True
return False | [
"def",
"is_type_I_branch",
"(",
"u",
",",
"v",
",",
"dfs_data",
")",
":",
"if",
"u",
"!=",
"a",
"(",
"v",
",",
"dfs_data",
")",
":",
"return",
"False",
"if",
"u",
"==",
"L2",
"(",
"v",
",",
"dfs_data",
")",
":",
"return",
"True",
"return",
"False... | Determines whether a branch uv is a type I branch. | [
"Determines",
"whether",
"a",
"branch",
"uv",
"is",
"a",
"type",
"I",
"branch",
"."
] | 037bb2f32503fecb60d62921f9766d54109f15e2 | https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/functions/planarity/kocay_algorithm.py#L861-L867 |
42,313 | jciskey/pygraph | pygraph/functions/planarity/kocay_algorithm.py | is_type_II_branch | def is_type_II_branch(u, v, dfs_data):
"""Determines whether a branch uv is a type II branch."""
if u != a(v, dfs_data):
return False
if u < L2(v, dfs_data):
return True
return False | python | def is_type_II_branch(u, v, dfs_data):
"""Determines whether a branch uv is a type II branch."""
if u != a(v, dfs_data):
return False
if u < L2(v, dfs_data):
return True
return False | [
"def",
"is_type_II_branch",
"(",
"u",
",",
"v",
",",
"dfs_data",
")",
":",
"if",
"u",
"!=",
"a",
"(",
"v",
",",
"dfs_data",
")",
":",
"return",
"False",
"if",
"u",
"<",
"L2",
"(",
"v",
",",
"dfs_data",
")",
":",
"return",
"True",
"return",
"False... | Determines whether a branch uv is a type II branch. | [
"Determines",
"whether",
"a",
"branch",
"uv",
"is",
"a",
"type",
"II",
"branch",
"."
] | 037bb2f32503fecb60d62921f9766d54109f15e2 | https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/functions/planarity/kocay_algorithm.py#L870-L876 |
42,314 | jciskey/pygraph | pygraph/functions/planarity/kocay_algorithm.py | __get_descendants | def __get_descendants(node, dfs_data):
"""Gets the descendants of a node."""
list_of_descendants = []
stack = deque()
children_lookup = dfs_data['children_lookup']
current_node = node
children = children_lookup[current_node]
dfs_current_node = D(current_node, dfs_data)
for n in childr... | python | def __get_descendants(node, dfs_data):
"""Gets the descendants of a node."""
list_of_descendants = []
stack = deque()
children_lookup = dfs_data['children_lookup']
current_node = node
children = children_lookup[current_node]
dfs_current_node = D(current_node, dfs_data)
for n in childr... | [
"def",
"__get_descendants",
"(",
"node",
",",
"dfs_data",
")",
":",
"list_of_descendants",
"=",
"[",
"]",
"stack",
"=",
"deque",
"(",
")",
"children_lookup",
"=",
"dfs_data",
"[",
"'children_lookup'",
"]",
"current_node",
"=",
"node",
"children",
"=",
"childre... | Gets the descendants of a node. | [
"Gets",
"the",
"descendants",
"of",
"a",
"node",
"."
] | 037bb2f32503fecb60d62921f9766d54109f15e2 | https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/functions/planarity/kocay_algorithm.py#L892-L920 |
42,315 | jciskey/pygraph | pygraph/functions/planarity/kocay_algorithm.py | S_star | def S_star(u, dfs_data):
"""The set of all descendants of u, with u added."""
s_u = S(u, dfs_data)
if u not in s_u:
s_u.append(u)
return s_u | python | def S_star(u, dfs_data):
"""The set of all descendants of u, with u added."""
s_u = S(u, dfs_data)
if u not in s_u:
s_u.append(u)
return s_u | [
"def",
"S_star",
"(",
"u",
",",
"dfs_data",
")",
":",
"s_u",
"=",
"S",
"(",
"u",
",",
"dfs_data",
")",
"if",
"u",
"not",
"in",
"s_u",
":",
"s_u",
".",
"append",
"(",
"u",
")",
"return",
"s_u"
] | The set of all descendants of u, with u added. | [
"The",
"set",
"of",
"all",
"descendants",
"of",
"u",
"with",
"u",
"added",
"."
] | 037bb2f32503fecb60d62921f9766d54109f15e2 | https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/functions/planarity/kocay_algorithm.py#L955-L960 |
42,316 | MartinThoma/hwrt | hwrt/classify.py | classify_segmented_recording | def classify_segmented_recording(recording, result_format=None):
"""Use this function if you are sure you have a single symbol.
Parameters
----------
recording : string
The recording in JSON format
Returns
-------
list of dictionaries
Each dictionary contains the keys 'symb... | python | def classify_segmented_recording(recording, result_format=None):
"""Use this function if you are sure you have a single symbol.
Parameters
----------
recording : string
The recording in JSON format
Returns
-------
list of dictionaries
Each dictionary contains the keys 'symb... | [
"def",
"classify_segmented_recording",
"(",
"recording",
",",
"result_format",
"=",
"None",
")",
":",
"global",
"single_symbol_classifier",
"if",
"single_symbol_classifier",
"is",
"None",
":",
"single_symbol_classifier",
"=",
"SingleClassificer",
"(",
")",
"return",
"si... | Use this function if you are sure you have a single symbol.
Parameters
----------
recording : string
The recording in JSON format
Returns
-------
list of dictionaries
Each dictionary contains the keys 'symbol' and 'probability'. The list
is sorted descending by probabil... | [
"Use",
"this",
"function",
"if",
"you",
"are",
"sure",
"you",
"have",
"a",
"single",
"symbol",
"."
] | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/classify.py#L65-L82 |
42,317 | MartinThoma/hwrt | hwrt/classify.py | SingleClassificer.predict | def predict(self, recording, result_format=None):
"""Predict the class of the given recording.
Parameters
----------
recording : string
Recording of a single handwritten dataset in JSON format.
result_format : string, optional
If it is 'LaTeX', then only ... | python | def predict(self, recording, result_format=None):
"""Predict the class of the given recording.
Parameters
----------
recording : string
Recording of a single handwritten dataset in JSON format.
result_format : string, optional
If it is 'LaTeX', then only ... | [
"def",
"predict",
"(",
"self",
",",
"recording",
",",
"result_format",
"=",
"None",
")",
":",
"evaluate",
"=",
"utils",
".",
"evaluate_model_single_recording_preloaded",
"results",
"=",
"evaluate",
"(",
"self",
".",
"preprocessing_queue",
",",
"self",
".",
"feat... | Predict the class of the given recording.
Parameters
----------
recording : string
Recording of a single handwritten dataset in JSON format.
result_format : string, optional
If it is 'LaTeX', then only the latex code will be returned
Returns
----... | [
"Predict",
"the",
"class",
"of",
"the",
"given",
"recording",
"."
] | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/classify.py#L36-L62 |
42,318 | MartinThoma/hwrt | hwrt/filter_dataset.py | get_symbol_ids | def get_symbol_ids(symbol_yml_file, metadata):
"""
Get a list of ids which describe which class they get mapped to.
Parameters
----------
symbol_yml_file : string
Path to a YAML file.
metadata : dict
Metainformation of symbols, like the id on write-math.com.
Has keys 'sy... | python | def get_symbol_ids(symbol_yml_file, metadata):
"""
Get a list of ids which describe which class they get mapped to.
Parameters
----------
symbol_yml_file : string
Path to a YAML file.
metadata : dict
Metainformation of symbols, like the id on write-math.com.
Has keys 'sy... | [
"def",
"get_symbol_ids",
"(",
"symbol_yml_file",
",",
"metadata",
")",
":",
"with",
"open",
"(",
"symbol_yml_file",
",",
"'r'",
")",
"as",
"stream",
":",
"symbol_cfg",
"=",
"yaml",
".",
"load",
"(",
"stream",
")",
"symbol_ids",
"=",
"[",
"]",
"symbol_ids_s... | Get a list of ids which describe which class they get mapped to.
Parameters
----------
symbol_yml_file : string
Path to a YAML file.
metadata : dict
Metainformation of symbols, like the id on write-math.com.
Has keys 'symbols', 'tags', 'tags2symbols'.
Returns
-------
... | [
"Get",
"a",
"list",
"of",
"ids",
"which",
"describe",
"which",
"class",
"they",
"get",
"mapped",
"to",
"."
] | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/filter_dataset.py#L47-L150 |
42,319 | MartinThoma/hwrt | hwrt/filter_dataset.py | read_csv | def read_csv(filepath):
"""
Read a CSV into a list of dictionarys. The first line of the CSV determines
the keys of the dictionary.
Parameters
----------
filepath : string
Returns
-------
list of dictionaries
"""
symbols = []
with open(filepath, 'rb') as csvfile:
... | python | def read_csv(filepath):
"""
Read a CSV into a list of dictionarys. The first line of the CSV determines
the keys of the dictionary.
Parameters
----------
filepath : string
Returns
-------
list of dictionaries
"""
symbols = []
with open(filepath, 'rb') as csvfile:
... | [
"def",
"read_csv",
"(",
"filepath",
")",
":",
"symbols",
"=",
"[",
"]",
"with",
"open",
"(",
"filepath",
",",
"'rb'",
")",
"as",
"csvfile",
":",
"spamreader",
"=",
"csv",
".",
"DictReader",
"(",
"csvfile",
",",
"delimiter",
"=",
"','",
",",
"quotechar"... | Read a CSV into a list of dictionarys. The first line of the CSV determines
the keys of the dictionary.
Parameters
----------
filepath : string
Returns
-------
list of dictionaries | [
"Read",
"a",
"CSV",
"into",
"a",
"list",
"of",
"dictionarys",
".",
"The",
"first",
"line",
"of",
"the",
"CSV",
"determines",
"the",
"keys",
"of",
"the",
"dictionary",
"."
] | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/filter_dataset.py#L179-L197 |
42,320 | MartinThoma/hwrt | hwrt/filter_dataset.py | load_raw | def load_raw(raw_pickle_file):
"""
Load a pickle file of raw recordings.
Parameters
----------
raw_pickle_file : str
Path to a pickle file which contains raw recordings.
Returns
-------
dict
The loaded pickle file.
"""
with open(raw_pickle_file, 'rb') as f:
... | python | def load_raw(raw_pickle_file):
"""
Load a pickle file of raw recordings.
Parameters
----------
raw_pickle_file : str
Path to a pickle file which contains raw recordings.
Returns
-------
dict
The loaded pickle file.
"""
with open(raw_pickle_file, 'rb') as f:
... | [
"def",
"load_raw",
"(",
"raw_pickle_file",
")",
":",
"with",
"open",
"(",
"raw_pickle_file",
",",
"'rb'",
")",
"as",
"f",
":",
"raw",
"=",
"pickle",
".",
"load",
"(",
"f",
")",
"logging",
".",
"info",
"(",
"\"Loaded %i recordings.\"",
",",
"len",
"(",
... | Load a pickle file of raw recordings.
Parameters
----------
raw_pickle_file : str
Path to a pickle file which contains raw recordings.
Returns
-------
dict
The loaded pickle file. | [
"Load",
"a",
"pickle",
"file",
"of",
"raw",
"recordings",
"."
] | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/filter_dataset.py#L200-L217 |
42,321 | MartinThoma/hwrt | hwrt/data_analyzation_metrics.py | get_metrics | def get_metrics(metrics_description):
"""Get metrics from a list of dictionaries. """
return utils.get_objectlist(metrics_description,
config_key='data_analyzation_plugins',
module=sys.modules[__name__]) | python | def get_metrics(metrics_description):
"""Get metrics from a list of dictionaries. """
return utils.get_objectlist(metrics_description,
config_key='data_analyzation_plugins',
module=sys.modules[__name__]) | [
"def",
"get_metrics",
"(",
"metrics_description",
")",
":",
"return",
"utils",
".",
"get_objectlist",
"(",
"metrics_description",
",",
"config_key",
"=",
"'data_analyzation_plugins'",
",",
"module",
"=",
"sys",
".",
"modules",
"[",
"__name__",
"]",
")"
] | Get metrics from a list of dictionaries. | [
"Get",
"metrics",
"from",
"a",
"list",
"of",
"dictionaries",
"."
] | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/data_analyzation_metrics.py#L44-L48 |
42,322 | MartinThoma/hwrt | hwrt/data_analyzation_metrics.py | prepare_file | def prepare_file(filename):
"""Truncate the file and return the filename."""
directory = os.path.join(utils.get_project_root(), "analyzation/")
if not os.path.exists(directory):
os.makedirs(directory)
workfilename = os.path.join(directory, filename)
open(workfilename, 'w').close() # Truncat... | python | def prepare_file(filename):
"""Truncate the file and return the filename."""
directory = os.path.join(utils.get_project_root(), "analyzation/")
if not os.path.exists(directory):
os.makedirs(directory)
workfilename = os.path.join(directory, filename)
open(workfilename, 'w').close() # Truncat... | [
"def",
"prepare_file",
"(",
"filename",
")",
":",
"directory",
"=",
"os",
".",
"path",
".",
"join",
"(",
"utils",
".",
"get_project_root",
"(",
")",
",",
"\"analyzation/\"",
")",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"directory",
")",
":"... | Truncate the file and return the filename. | [
"Truncate",
"the",
"file",
"and",
"return",
"the",
"filename",
"."
] | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/data_analyzation_metrics.py#L53-L60 |
42,323 | MartinThoma/hwrt | hwrt/data_analyzation_metrics.py | sort_by_formula_id | def sort_by_formula_id(raw_datasets):
"""
Sort a list of formulas by `id`, where `id` represents the accepted
formula id.
Parameters
----------
raw_datasets : list of dictionaries
A list of raw datasets.
Examples
--------
The parameter `raw_datasets` has to be of the format... | python | def sort_by_formula_id(raw_datasets):
"""
Sort a list of formulas by `id`, where `id` represents the accepted
formula id.
Parameters
----------
raw_datasets : list of dictionaries
A list of raw datasets.
Examples
--------
The parameter `raw_datasets` has to be of the format... | [
"def",
"sort_by_formula_id",
"(",
"raw_datasets",
")",
":",
"by_formula_id",
"=",
"defaultdict",
"(",
"list",
")",
"for",
"el",
"in",
"raw_datasets",
":",
"by_formula_id",
"[",
"el",
"[",
"'handwriting'",
"]",
".",
"formula_id",
"]",
".",
"append",
"(",
"el"... | Sort a list of formulas by `id`, where `id` represents the accepted
formula id.
Parameters
----------
raw_datasets : list of dictionaries
A list of raw datasets.
Examples
--------
The parameter `raw_datasets` has to be of the format
>>> rd = [{'is_in_testset': 0,
... ... | [
"Sort",
"a",
"list",
"of",
"formulas",
"by",
"id",
"where",
"id",
"represents",
"the",
"accepted",
"formula",
"id",
"."
] | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/data_analyzation_metrics.py#L63-L97 |
42,324 | MartinThoma/hwrt | hwrt/data_analyzation_metrics.py | AnalyzeErrors._write_data | def _write_data(self, symbols, err_recs, nr_recordings,
total_error_count, percentages, time_max_list):
"""Write all obtained data to a file.
Parameters
----------
symbols : list of tuples (String, non-negative int)
List of all symbols with the count of r... | python | def _write_data(self, symbols, err_recs, nr_recordings,
total_error_count, percentages, time_max_list):
"""Write all obtained data to a file.
Parameters
----------
symbols : list of tuples (String, non-negative int)
List of all symbols with the count of r... | [
"def",
"_write_data",
"(",
"self",
",",
"symbols",
",",
"err_recs",
",",
"nr_recordings",
",",
"total_error_count",
",",
"percentages",
",",
"time_max_list",
")",
":",
"write_file",
"=",
"open",
"(",
"self",
".",
"filename",
",",
"\"a\"",
")",
"s",
"=",
"\... | Write all obtained data to a file.
Parameters
----------
symbols : list of tuples (String, non-negative int)
List of all symbols with the count of recordings
err_recs : dictionary
count of recordings by error type
nr_recordings : non-negative int
... | [
"Write",
"all",
"obtained",
"data",
"to",
"a",
"file",
"."
] | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/data_analyzation_metrics.py#L297-L367 |
42,325 | MartinThoma/hwrt | hwrt/features.py | print_featurelist | def print_featurelist(feature_list):
"""
Print the feature_list in a human-readable form.
Parameters
----------
feature_list : list
feature objects
"""
input_features = sum(map(lambda n: n.get_dimension(), feature_list))
print("## Features (%i)" % input_features)
print("```"... | python | def print_featurelist(feature_list):
"""
Print the feature_list in a human-readable form.
Parameters
----------
feature_list : list
feature objects
"""
input_features = sum(map(lambda n: n.get_dimension(), feature_list))
print("## Features (%i)" % input_features)
print("```"... | [
"def",
"print_featurelist",
"(",
"feature_list",
")",
":",
"input_features",
"=",
"sum",
"(",
"map",
"(",
"lambda",
"n",
":",
"n",
".",
"get_dimension",
"(",
")",
",",
"feature_list",
")",
")",
"print",
"(",
"\"## Features (%i)\"",
"%",
"input_features",
")"... | Print the feature_list in a human-readable form.
Parameters
----------
feature_list : list
feature objects | [
"Print",
"the",
"feature_list",
"in",
"a",
"human",
"-",
"readable",
"form",
"."
] | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/features.py#L64-L78 |
42,326 | MartinThoma/hwrt | hwrt/features.py | DouglasPeuckerPoints._stroke_simplification | def _stroke_simplification(self, pointlist):
"""The Douglas-Peucker line simplification takes a list of points as an
argument. It tries to simplifiy this list by removing as many points
as possible while still maintaining the overall shape of the stroke.
It does so by taking the... | python | def _stroke_simplification(self, pointlist):
"""The Douglas-Peucker line simplification takes a list of points as an
argument. It tries to simplifiy this list by removing as many points
as possible while still maintaining the overall shape of the stroke.
It does so by taking the... | [
"def",
"_stroke_simplification",
"(",
"self",
",",
"pointlist",
")",
":",
"# Find the point with the biggest distance",
"dmax",
"=",
"0",
"index",
"=",
"0",
"for",
"i",
"in",
"range",
"(",
"1",
",",
"len",
"(",
"pointlist",
")",
")",
":",
"d",
"=",
"geomet... | The Douglas-Peucker line simplification takes a list of points as an
argument. It tries to simplifiy this list by removing as many points
as possible while still maintaining the overall shape of the stroke.
It does so by taking the first and the last point, connecting them
by... | [
"The",
"Douglas",
"-",
"Peucker",
"line",
"simplification",
"takes",
"a",
"list",
"of",
"points",
"as",
"an",
"argument",
".",
"It",
"tries",
"to",
"simplifiy",
"this",
"list",
"by",
"removing",
"as",
"many",
"points",
"as",
"possible",
"while",
"still",
"... | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/features.py#L598-L628 |
42,327 | MartinThoma/hwrt | hwrt/preprocessing.py | get_preprocessing_queue | def get_preprocessing_queue(preprocessing_list):
"""Get preprocessing queue from a list of dictionaries
>>> l = [{'RemoveDuplicateTime': None},
{'ScaleAndShift': [{'center': True}]}
]
>>> get_preprocessing_queue(l)
[RemoveDuplicateTime, ScaleAndShift
- center: True
- ... | python | def get_preprocessing_queue(preprocessing_list):
"""Get preprocessing queue from a list of dictionaries
>>> l = [{'RemoveDuplicateTime': None},
{'ScaleAndShift': [{'center': True}]}
]
>>> get_preprocessing_queue(l)
[RemoveDuplicateTime, ScaleAndShift
- center: True
- ... | [
"def",
"get_preprocessing_queue",
"(",
"preprocessing_list",
")",
":",
"return",
"utils",
".",
"get_objectlist",
"(",
"preprocessing_list",
",",
"config_key",
"=",
"'preprocessing'",
",",
"module",
"=",
"sys",
".",
"modules",
"[",
"__name__",
"]",
")"
] | Get preprocessing queue from a list of dictionaries
>>> l = [{'RemoveDuplicateTime': None},
{'ScaleAndShift': [{'center': True}]}
]
>>> get_preprocessing_queue(l)
[RemoveDuplicateTime, ScaleAndShift
- center: True
- max_width: 1
- max_height: 1
] | [
"Get",
"preprocessing",
"queue",
"from",
"a",
"list",
"of",
"dictionaries"
] | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/preprocessing.py#L43-L58 |
42,328 | MartinThoma/hwrt | hwrt/preprocessing.py | print_preprocessing_list | def print_preprocessing_list(preprocessing_queue):
"""
Print the ``preproc_list`` in a human-readable form.
Parameters
----------
preprocessing_queue : list of preprocessing objects
Algorithms that get applied for preprocessing.
"""
print("## Preprocessing")
print("```")
for... | python | def print_preprocessing_list(preprocessing_queue):
"""
Print the ``preproc_list`` in a human-readable form.
Parameters
----------
preprocessing_queue : list of preprocessing objects
Algorithms that get applied for preprocessing.
"""
print("## Preprocessing")
print("```")
for... | [
"def",
"print_preprocessing_list",
"(",
"preprocessing_queue",
")",
":",
"print",
"(",
"\"## Preprocessing\"",
")",
"print",
"(",
"\"```\"",
")",
"for",
"algorithm",
"in",
"preprocessing_queue",
":",
"print",
"(",
"\"* \"",
"+",
"str",
"(",
"algorithm",
")",
")"... | Print the ``preproc_list`` in a human-readable form.
Parameters
----------
preprocessing_queue : list of preprocessing objects
Algorithms that get applied for preprocessing. | [
"Print",
"the",
"preproc_list",
"in",
"a",
"human",
"-",
"readable",
"form",
"."
] | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/preprocessing.py#L61-L74 |
42,329 | MartinThoma/hwrt | hwrt/preprocessing.py | ScaleAndShift._get_parameters | def _get_parameters(self, hwr_obj):
""" Take a list of points and calculate the factors for scaling and
moving it so that it's in the unit square. Keept the aspect
ratio.
Optionally center the points inside of the unit square.
"""
a = hwr_obj.get_bounding_box(... | python | def _get_parameters(self, hwr_obj):
""" Take a list of points and calculate the factors for scaling and
moving it so that it's in the unit square. Keept the aspect
ratio.
Optionally center the points inside of the unit square.
"""
a = hwr_obj.get_bounding_box(... | [
"def",
"_get_parameters",
"(",
"self",
",",
"hwr_obj",
")",
":",
"a",
"=",
"hwr_obj",
".",
"get_bounding_box",
"(",
")",
"width",
"=",
"a",
"[",
"'maxx'",
"]",
"-",
"a",
"[",
"'minx'",
"]",
"+",
"self",
".",
"width_add",
"height",
"=",
"a",
"[",
"'... | Take a list of points and calculate the factors for scaling and
moving it so that it's in the unit square. Keept the aspect
ratio.
Optionally center the points inside of the unit square. | [
"Take",
"a",
"list",
"of",
"points",
"and",
"calculate",
"the",
"factors",
"for",
"scaling",
"and",
"moving",
"it",
"so",
"that",
"it",
"s",
"in",
"the",
"unit",
"square",
".",
"Keept",
"the",
"aspect",
"ratio",
".",
"Optionally",
"center",
"the",
"point... | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/preprocessing.py#L175-L215 |
42,330 | MartinThoma/hwrt | hwrt/preprocessing.py | SpaceEvenly._calculate_pen_down_strokes | def _calculate_pen_down_strokes(self, pointlist, times=None):
"""Calculate the intervall borders 'times' that contain the information
when a stroke started, when it ended and how it should be
interpolated."""
if times is None:
times = []
for stroke in pointlist:... | python | def _calculate_pen_down_strokes(self, pointlist, times=None):
"""Calculate the intervall borders 'times' that contain the information
when a stroke started, when it ended and how it should be
interpolated."""
if times is None:
times = []
for stroke in pointlist:... | [
"def",
"_calculate_pen_down_strokes",
"(",
"self",
",",
"pointlist",
",",
"times",
"=",
"None",
")",
":",
"if",
"times",
"is",
"None",
":",
"times",
"=",
"[",
"]",
"for",
"stroke",
"in",
"pointlist",
":",
"stroke_info",
"=",
"{",
"\"start\"",
":",
"strok... | Calculate the intervall borders 'times' that contain the information
when a stroke started, when it ended and how it should be
interpolated. | [
"Calculate",
"the",
"intervall",
"borders",
"times",
"that",
"contain",
"the",
"information",
"when",
"a",
"stroke",
"started",
"when",
"it",
"ended",
"and",
"how",
"it",
"should",
"be",
"interpolated",
"."
] | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/preprocessing.py#L263-L296 |
42,331 | MartinThoma/hwrt | hwrt/preprocessing.py | SpaceEvenly._calculate_pen_up_strokes | def _calculate_pen_up_strokes(self, pointlist, times=None):
""" 'Pen-up' strokes are virtual strokes that were not drawn. It
models the time when the user moved from one stroke to the next.
"""
if times is None:
times = []
for i in range(len(pointlist) - 1):
... | python | def _calculate_pen_up_strokes(self, pointlist, times=None):
""" 'Pen-up' strokes are virtual strokes that were not drawn. It
models the time when the user moved from one stroke to the next.
"""
if times is None:
times = []
for i in range(len(pointlist) - 1):
... | [
"def",
"_calculate_pen_up_strokes",
"(",
"self",
",",
"pointlist",
",",
"times",
"=",
"None",
")",
":",
"if",
"times",
"is",
"None",
":",
"times",
"=",
"[",
"]",
"for",
"i",
"in",
"range",
"(",
"len",
"(",
"pointlist",
")",
"-",
"1",
")",
":",
"str... | 'Pen-up' strokes are virtual strokes that were not drawn. It
models the time when the user moved from one stroke to the next. | [
"Pen",
"-",
"up",
"strokes",
"are",
"virtual",
"strokes",
"that",
"were",
"not",
"drawn",
".",
"It",
"models",
"the",
"time",
"when",
"the",
"user",
"moved",
"from",
"one",
"stroke",
"to",
"the",
"next",
"."
] | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/preprocessing.py#L298-L325 |
42,332 | MartinThoma/hwrt | hwrt/preprocessing.py | SpaceEvenlyPerStroke._space | def _space(self, hwr_obj, stroke, kind):
"""Do the interpolation of 'kind' for 'stroke'"""
new_stroke = []
stroke = sorted(stroke, key=lambda p: p['time'])
x, y, t = [], [], []
for point in stroke:
x.append(point['x'])
y.append(point['y'])
t.... | python | def _space(self, hwr_obj, stroke, kind):
"""Do the interpolation of 'kind' for 'stroke'"""
new_stroke = []
stroke = sorted(stroke, key=lambda p: p['time'])
x, y, t = [], [], []
for point in stroke:
x.append(point['x'])
y.append(point['y'])
t.... | [
"def",
"_space",
"(",
"self",
",",
"hwr_obj",
",",
"stroke",
",",
"kind",
")",
":",
"new_stroke",
"=",
"[",
"]",
"stroke",
"=",
"sorted",
"(",
"stroke",
",",
"key",
"=",
"lambda",
"p",
":",
"p",
"[",
"'time'",
"]",
")",
"x",
",",
"y",
",",
"t",... | Do the interpolation of 'kind' for 'stroke | [
"Do",
"the",
"interpolation",
"of",
"kind",
"for",
"stroke"
] | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/preprocessing.py#L382-L426 |
42,333 | MartinThoma/hwrt | hwrt/preprocessing.py | WeightedAverageSmoothing._calculate_average | def _calculate_average(self, points):
"""Calculate the arithmetic mean of the points x and y coordinates
seperately.
"""
assert len(self.theta) == len(points), \
"points has length %i, but should have length %i" % \
(len(points), len(self.theta))
new_po... | python | def _calculate_average(self, points):
"""Calculate the arithmetic mean of the points x and y coordinates
seperately.
"""
assert len(self.theta) == len(points), \
"points has length %i, but should have length %i" % \
(len(points), len(self.theta))
new_po... | [
"def",
"_calculate_average",
"(",
"self",
",",
"points",
")",
":",
"assert",
"len",
"(",
"self",
".",
"theta",
")",
"==",
"len",
"(",
"points",
")",
",",
"\"points has length %i, but should have length %i\"",
"%",
"(",
"len",
"(",
"points",
")",
",",
"len",
... | Calculate the arithmetic mean of the points x and y coordinates
seperately. | [
"Calculate",
"the",
"arithmetic",
"mean",
"of",
"the",
"points",
"x",
"and",
"y",
"coordinates",
"seperately",
"."
] | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/preprocessing.py#L700-L712 |
42,334 | MartinThoma/hwrt | hwrt/create_model.py | create_model | def create_model(model_folder, model_type, topology, override):
"""
Create a model if it doesn't exist already.
Parameters
----------
model_folder :
The path to the folder where the model is described with an `info.yml`
model_type :
MLP
topology :
Something like 160:... | python | def create_model(model_folder, model_type, topology, override):
"""
Create a model if it doesn't exist already.
Parameters
----------
model_folder :
The path to the folder where the model is described with an `info.yml`
model_type :
MLP
topology :
Something like 160:... | [
"def",
"create_model",
"(",
"model_folder",
",",
"model_type",
",",
"topology",
",",
"override",
")",
":",
"latest_model",
"=",
"utils",
".",
"get_latest_in_folder",
"(",
"model_folder",
",",
"\".json\"",
")",
"if",
"(",
"latest_model",
"==",
"\"\"",
")",
"or"... | Create a model if it doesn't exist already.
Parameters
----------
model_folder :
The path to the folder where the model is described with an `info.yml`
model_type :
MLP
topology :
Something like 160:500:369 - that means the first layer has 160
neurons, the second lay... | [
"Create",
"a",
"model",
"if",
"it",
"doesn",
"t",
"exist",
"already",
"."
] | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/create_model.py#L14-L42 |
42,335 | MartinThoma/hwrt | hwrt/create_model.py | main | def main(model_folder, override=False):
"""Parse the info.yml from ``model_folder`` and create the model file."""
model_description_file = os.path.join(model_folder, "info.yml")
# Read the model description file
with open(model_description_file, 'r') as ymlfile:
model_description = yaml.load(yml... | python | def main(model_folder, override=False):
"""Parse the info.yml from ``model_folder`` and create the model file."""
model_description_file = os.path.join(model_folder, "info.yml")
# Read the model description file
with open(model_description_file, 'r') as ymlfile:
model_description = yaml.load(yml... | [
"def",
"main",
"(",
"model_folder",
",",
"override",
"=",
"False",
")",
":",
"model_description_file",
"=",
"os",
".",
"path",
".",
"join",
"(",
"model_folder",
",",
"\"info.yml\"",
")",
"# Read the model description file",
"with",
"open",
"(",
"model_description_... | Parse the info.yml from ``model_folder`` and create the model file. | [
"Parse",
"the",
"info",
".",
"yml",
"from",
"model_folder",
"and",
"create",
"the",
"model",
"file",
"."
] | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/create_model.py#L45-L72 |
42,336 | MartinThoma/hwrt | hwrt/serve.py | interactive | def interactive():
"""Interactive classifier."""
global n
if request.method == 'GET' and request.args.get('heartbeat', '') != "":
return request.args.get('heartbeat', '')
if request.method == 'POST':
logging.warning('POST to /interactive is deprecated. '
'Use /wor... | python | def interactive():
"""Interactive classifier."""
global n
if request.method == 'GET' and request.args.get('heartbeat', '') != "":
return request.args.get('heartbeat', '')
if request.method == 'POST':
logging.warning('POST to /interactive is deprecated. '
'Use /wor... | [
"def",
"interactive",
"(",
")",
":",
"global",
"n",
"if",
"request",
".",
"method",
"==",
"'GET'",
"and",
"request",
".",
"args",
".",
"get",
"(",
"'heartbeat'",
",",
"''",
")",
"!=",
"\"\"",
":",
"return",
"request",
".",
"args",
".",
"get",
"(",
... | Interactive classifier. | [
"Interactive",
"classifier",
"."
] | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/serve.py#L85-L95 |
42,337 | MartinThoma/hwrt | hwrt/serve.py | _get_part | def _get_part(pointlist, strokes):
"""Get some strokes of pointlist
Parameters
----------
pointlist : list of lists of dicts
strokes : list of integers
Returns
-------
list of lists of dicts
"""
result = []
strokes = sorted(strokes)
for stroke_index in strokes:
... | python | def _get_part(pointlist, strokes):
"""Get some strokes of pointlist
Parameters
----------
pointlist : list of lists of dicts
strokes : list of integers
Returns
-------
list of lists of dicts
"""
result = []
strokes = sorted(strokes)
for stroke_index in strokes:
... | [
"def",
"_get_part",
"(",
"pointlist",
",",
"strokes",
")",
":",
"result",
"=",
"[",
"]",
"strokes",
"=",
"sorted",
"(",
"strokes",
")",
"for",
"stroke_index",
"in",
"strokes",
":",
"result",
".",
"append",
"(",
"pointlist",
"[",
"stroke_index",
"]",
")",... | Get some strokes of pointlist
Parameters
----------
pointlist : list of lists of dicts
strokes : list of integers
Returns
-------
list of lists of dicts | [
"Get",
"some",
"strokes",
"of",
"pointlist"
] | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/serve.py#L164-L180 |
42,338 | MartinThoma/hwrt | hwrt/serve.py | _get_translate | def _get_translate():
"""
Get a dictionary which translates from a neural network output to
semantics.
"""
translate = {}
model_path = pkg_resources.resource_filename('hwrt', 'misc/')
translation_csv = os.path.join(model_path, 'latex2writemathindex.csv')
arguments = {'newline': '', 'enco... | python | def _get_translate():
"""
Get a dictionary which translates from a neural network output to
semantics.
"""
translate = {}
model_path = pkg_resources.resource_filename('hwrt', 'misc/')
translation_csv = os.path.join(model_path, 'latex2writemathindex.csv')
arguments = {'newline': '', 'enco... | [
"def",
"_get_translate",
"(",
")",
":",
"translate",
"=",
"{",
"}",
"model_path",
"=",
"pkg_resources",
".",
"resource_filename",
"(",
"'hwrt'",
",",
"'misc/'",
")",
"translation_csv",
"=",
"os",
".",
"path",
".",
"join",
"(",
"model_path",
",",
"'latex2writ... | Get a dictionary which translates from a neural network output to
semantics. | [
"Get",
"a",
"dictionary",
"which",
"translates",
"from",
"a",
"neural",
"network",
"output",
"to",
"semantics",
"."
] | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/serve.py#L183-L204 |
42,339 | MartinThoma/hwrt | hwrt/serve.py | main | def main(port=8000, n_output=10, use_segmenter=False):
"""Main function starting the webserver."""
global n
global use_segmenter_flag
n = n_output
use_segmenter_flag = use_segmenter
logging.info("Start webserver...")
app.run(port=port) | python | def main(port=8000, n_output=10, use_segmenter=False):
"""Main function starting the webserver."""
global n
global use_segmenter_flag
n = n_output
use_segmenter_flag = use_segmenter
logging.info("Start webserver...")
app.run(port=port) | [
"def",
"main",
"(",
"port",
"=",
"8000",
",",
"n_output",
"=",
"10",
",",
"use_segmenter",
"=",
"False",
")",
":",
"global",
"n",
"global",
"use_segmenter_flag",
"n",
"=",
"n_output",
"use_segmenter_flag",
"=",
"use_segmenter",
"logging",
".",
"info",
"(",
... | Main function starting the webserver. | [
"Main",
"function",
"starting",
"the",
"webserver",
"."
] | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/serve.py#L355-L362 |
42,340 | MartinThoma/hwrt | hwrt/train.py | generate_training_command | def generate_training_command(model_folder):
"""Generate a string that contains a command with all necessary
parameters to train the model."""
update_if_outdated(model_folder)
model_description_file = os.path.join(model_folder, "info.yml")
# Read the model description file
with open(model_des... | python | def generate_training_command(model_folder):
"""Generate a string that contains a command with all necessary
parameters to train the model."""
update_if_outdated(model_folder)
model_description_file = os.path.join(model_folder, "info.yml")
# Read the model description file
with open(model_des... | [
"def",
"generate_training_command",
"(",
"model_folder",
")",
":",
"update_if_outdated",
"(",
"model_folder",
")",
"model_description_file",
"=",
"os",
".",
"path",
".",
"join",
"(",
"model_folder",
",",
"\"info.yml\"",
")",
"# Read the model description file",
"with",
... | Generate a string that contains a command with all necessary
parameters to train the model. | [
"Generate",
"a",
"string",
"that",
"contains",
"a",
"command",
"with",
"all",
"necessary",
"parameters",
"to",
"train",
"the",
"model",
"."
] | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/train.py#L64-L108 |
42,341 | MartinThoma/hwrt | hwrt/train.py | train_model | def train_model(model_folder):
"""Train the model in ``model_folder``."""
os.chdir(model_folder)
training = generate_training_command(model_folder)
if training is None:
return -1
logging.info(training)
os.chdir(model_folder)
os.system(training) | python | def train_model(model_folder):
"""Train the model in ``model_folder``."""
os.chdir(model_folder)
training = generate_training_command(model_folder)
if training is None:
return -1
logging.info(training)
os.chdir(model_folder)
os.system(training) | [
"def",
"train_model",
"(",
"model_folder",
")",
":",
"os",
".",
"chdir",
"(",
"model_folder",
")",
"training",
"=",
"generate_training_command",
"(",
"model_folder",
")",
"if",
"training",
"is",
"None",
":",
"return",
"-",
"1",
"logging",
".",
"info",
"(",
... | Train the model in ``model_folder``. | [
"Train",
"the",
"model",
"in",
"model_folder",
"."
] | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/train.py#L111-L119 |
42,342 | MartinThoma/hwrt | hwrt/train.py | main | def main(model_folder):
"""Main part of the training script."""
model_description_file = os.path.join(model_folder, "info.yml")
# Read the model description file
with open(model_description_file, 'r') as ymlfile:
model_description = yaml.load(ymlfile)
# Analyze model
logging.info(model... | python | def main(model_folder):
"""Main part of the training script."""
model_description_file = os.path.join(model_folder, "info.yml")
# Read the model description file
with open(model_description_file, 'r') as ymlfile:
model_description = yaml.load(ymlfile)
# Analyze model
logging.info(model... | [
"def",
"main",
"(",
"model_folder",
")",
":",
"model_description_file",
"=",
"os",
".",
"path",
".",
"join",
"(",
"model_folder",
",",
"\"info.yml\"",
")",
"# Read the model description file",
"with",
"open",
"(",
"model_description_file",
",",
"'r'",
")",
"as",
... | Main part of the training script. | [
"Main",
"part",
"of",
"the",
"training",
"script",
"."
] | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/train.py#L122-L136 |
42,343 | MartinThoma/hwrt | hwrt/geometry.py | get_bounding_box | def get_bounding_box(points):
"""Get the bounding box of a list of points.
Parameters
----------
points : list of points
Returns
-------
BoundingBox
"""
assert len(points) > 0, "At least one point has to be given."
min_x, max_x = points[0]['x'], points[0]['x']
min_y, max_y ... | python | def get_bounding_box(points):
"""Get the bounding box of a list of points.
Parameters
----------
points : list of points
Returns
-------
BoundingBox
"""
assert len(points) > 0, "At least one point has to be given."
min_x, max_x = points[0]['x'], points[0]['x']
min_y, max_y ... | [
"def",
"get_bounding_box",
"(",
"points",
")",
":",
"assert",
"len",
"(",
"points",
")",
">",
"0",
",",
"\"At least one point has to be given.\"",
"min_x",
",",
"max_x",
"=",
"points",
"[",
"0",
"]",
"[",
"'x'",
"]",
",",
"points",
"[",
"0",
"]",
"[",
... | Get the bounding box of a list of points.
Parameters
----------
points : list of points
Returns
-------
BoundingBox | [
"Get",
"the",
"bounding",
"box",
"of",
"a",
"list",
"of",
"points",
"."
] | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/geometry.py#L181-L200 |
42,344 | MartinThoma/hwrt | hwrt/geometry.py | do_bb_intersect | def do_bb_intersect(a, b):
"""Check if BoundingBox a intersects with BoundingBox b."""
return a.p1.x <= b.p2.x \
and a.p2.x >= b.p1.x \
and a.p1.y <= b.p2.y \
and a.p2.y >= b.p1.y | python | def do_bb_intersect(a, b):
"""Check if BoundingBox a intersects with BoundingBox b."""
return a.p1.x <= b.p2.x \
and a.p2.x >= b.p1.x \
and a.p1.y <= b.p2.y \
and a.p2.y >= b.p1.y | [
"def",
"do_bb_intersect",
"(",
"a",
",",
"b",
")",
":",
"return",
"a",
".",
"p1",
".",
"x",
"<=",
"b",
".",
"p2",
".",
"x",
"and",
"a",
".",
"p2",
".",
"x",
">=",
"b",
".",
"p1",
".",
"x",
"and",
"a",
".",
"p1",
".",
"y",
"<=",
"b",
"."... | Check if BoundingBox a intersects with BoundingBox b. | [
"Check",
"if",
"BoundingBox",
"a",
"intersects",
"with",
"BoundingBox",
"b",
"."
] | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/geometry.py#L203-L208 |
42,345 | MartinThoma/hwrt | hwrt/geometry.py | segments_distance | def segments_distance(segment1, segment2):
"""Calculate the distance between two line segments in the plane.
>>> a = LineSegment(Point(1,0), Point(2,0))
>>> b = LineSegment(Point(0,1), Point(0,2))
>>> "%0.2f" % segments_distance(a, b)
'1.41'
>>> c = LineSegment(Point(0,0), Point(5,5))
>>> d... | python | def segments_distance(segment1, segment2):
"""Calculate the distance between two line segments in the plane.
>>> a = LineSegment(Point(1,0), Point(2,0))
>>> b = LineSegment(Point(0,1), Point(0,2))
>>> "%0.2f" % segments_distance(a, b)
'1.41'
>>> c = LineSegment(Point(0,0), Point(5,5))
>>> d... | [
"def",
"segments_distance",
"(",
"segment1",
",",
"segment2",
")",
":",
"assert",
"isinstance",
"(",
"segment1",
",",
"LineSegment",
")",
",",
"\"segment1 is not a LineSegment, but a %s\"",
"%",
"type",
"(",
"segment1",
")",
"assert",
"isinstance",
"(",
"segment2",
... | Calculate the distance between two line segments in the plane.
>>> a = LineSegment(Point(1,0), Point(2,0))
>>> b = LineSegment(Point(0,1), Point(0,2))
>>> "%0.2f" % segments_distance(a, b)
'1.41'
>>> c = LineSegment(Point(0,0), Point(5,5))
>>> d = LineSegment(Point(2,2), Point(4,4))
>>> e =... | [
"Calculate",
"the",
"distance",
"between",
"two",
"line",
"segments",
"in",
"the",
"plane",
"."
] | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/geometry.py#L211-L238 |
42,346 | MartinThoma/hwrt | hwrt/geometry.py | perpendicular_distance | def perpendicular_distance(p3, p1, p2):
"""
Calculate the distance from p3 to the stroke defined by p1 and p2.
The distance is the length of the perpendicular from p3 on p1.
Parameters
----------
p1 : dictionary with "x" and "y"
start of stroke
p2 : dictionary with "x" and "y"
... | python | def perpendicular_distance(p3, p1, p2):
"""
Calculate the distance from p3 to the stroke defined by p1 and p2.
The distance is the length of the perpendicular from p3 on p1.
Parameters
----------
p1 : dictionary with "x" and "y"
start of stroke
p2 : dictionary with "x" and "y"
... | [
"def",
"perpendicular_distance",
"(",
"p3",
",",
"p1",
",",
"p2",
")",
":",
"px",
"=",
"p2",
"[",
"'x'",
"]",
"-",
"p1",
"[",
"'x'",
"]",
"py",
"=",
"p2",
"[",
"'y'",
"]",
"-",
"p1",
"[",
"'y'",
"]",
"squared_distance",
"=",
"px",
"*",
"px",
... | Calculate the distance from p3 to the stroke defined by p1 and p2.
The distance is the length of the perpendicular from p3 on p1.
Parameters
----------
p1 : dictionary with "x" and "y"
start of stroke
p2 : dictionary with "x" and "y"
end of stroke
p3 : dictionary with "x" and "y... | [
"Calculate",
"the",
"distance",
"from",
"p3",
"to",
"the",
"stroke",
"defined",
"by",
"p1",
"and",
"p2",
".",
"The",
"distance",
"is",
"the",
"length",
"of",
"the",
"perpendicular",
"from",
"p3",
"on",
"p1",
"."
] | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/geometry.py#L393-L439 |
42,347 | MartinThoma/hwrt | hwrt/geometry.py | Point.dist_to | def dist_to(self, p2):
"""Measure the distance to another point."""
return math.hypot(self.x - p2.x, self.y - p2.y) | python | def dist_to(self, p2):
"""Measure the distance to another point."""
return math.hypot(self.x - p2.x, self.y - p2.y) | [
"def",
"dist_to",
"(",
"self",
",",
"p2",
")",
":",
"return",
"math",
".",
"hypot",
"(",
"self",
".",
"x",
"-",
"p2",
".",
"x",
",",
"self",
".",
"y",
"-",
"p2",
".",
"y",
")"
] | Measure the distance to another point. | [
"Measure",
"the",
"distance",
"to",
"another",
"point",
"."
] | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/geometry.py#L16-L18 |
42,348 | MartinThoma/hwrt | hwrt/geometry.py | LineSegment.get_slope | def get_slope(self):
"""Return the slope m of this line segment."""
# y1 = m*x1 + t
# y2 = m*x2 + t => y1-y2 = m*(x1-x2) <=> m = (y1-y2)/(x1-x2)
return ((self.p1.y-self.p2.y) / (self.p1.x-self.p2.x)) | python | def get_slope(self):
"""Return the slope m of this line segment."""
# y1 = m*x1 + t
# y2 = m*x2 + t => y1-y2 = m*(x1-x2) <=> m = (y1-y2)/(x1-x2)
return ((self.p1.y-self.p2.y) / (self.p1.x-self.p2.x)) | [
"def",
"get_slope",
"(",
"self",
")",
":",
"# y1 = m*x1 + t",
"# y2 = m*x2 + t => y1-y2 = m*(x1-x2) <=> m = (y1-y2)/(x1-x2)",
"return",
"(",
"(",
"self",
".",
"p1",
".",
"y",
"-",
"self",
".",
"p2",
".",
"y",
")",
"/",
"(",
"self",
".",
"p1",
".",
"x",
"-"... | Return the slope m of this line segment. | [
"Return",
"the",
"slope",
"m",
"of",
"this",
"line",
"segment",
"."
] | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/geometry.py#L47-L51 |
42,349 | MartinThoma/hwrt | hwrt/geometry.py | LineSegment.get_offset | def get_offset(self):
"""Get the offset t of this line segment."""
return self.p1.y-self.get_slope()*self.p1.x | python | def get_offset(self):
"""Get the offset t of this line segment."""
return self.p1.y-self.get_slope()*self.p1.x | [
"def",
"get_offset",
"(",
"self",
")",
":",
"return",
"self",
".",
"p1",
".",
"y",
"-",
"self",
".",
"get_slope",
"(",
")",
"*",
"self",
".",
"p1",
".",
"x"
] | Get the offset t of this line segment. | [
"Get",
"the",
"offset",
"t",
"of",
"this",
"line",
"segment",
"."
] | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/geometry.py#L53-L55 |
42,350 | MartinThoma/hwrt | hwrt/geometry.py | PolygonalChain.count_selfintersections | def count_selfintersections(self):
""" Get the number of self-intersections of this polygonal chain."""
# This can be solved more efficiently with sweep line
counter = 0
for i, j in itertools.combinations(range(len(self.lineSegments)), 2):
inters = get_segments_intersections(... | python | def count_selfintersections(self):
""" Get the number of self-intersections of this polygonal chain."""
# This can be solved more efficiently with sweep line
counter = 0
for i, j in itertools.combinations(range(len(self.lineSegments)), 2):
inters = get_segments_intersections(... | [
"def",
"count_selfintersections",
"(",
"self",
")",
":",
"# This can be solved more efficiently with sweep line",
"counter",
"=",
"0",
"for",
"i",
",",
"j",
"in",
"itertools",
".",
"combinations",
"(",
"range",
"(",
"len",
"(",
"self",
".",
"lineSegments",
")",
... | Get the number of self-intersections of this polygonal chain. | [
"Get",
"the",
"number",
"of",
"self",
"-",
"intersections",
"of",
"this",
"polygonal",
"chain",
"."
] | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/geometry.py#L90-L99 |
42,351 | MartinThoma/hwrt | hwrt/geometry.py | PolygonalChain.count_intersections | def count_intersections(self, line_segments_b):
"""
Count the intersections of two strokes with each other.
Parameters
----------
line_segments_b : list
A list of line segemnts
Returns
-------
int
The number of intersections betwe... | python | def count_intersections(self, line_segments_b):
"""
Count the intersections of two strokes with each other.
Parameters
----------
line_segments_b : list
A list of line segemnts
Returns
-------
int
The number of intersections betwe... | [
"def",
"count_intersections",
"(",
"self",
",",
"line_segments_b",
")",
":",
"line_segments_a",
"=",
"self",
".",
"lineSegments",
"# Calculate intersections",
"intersection_points",
"=",
"[",
"]",
"for",
"line1",
",",
"line2",
"in",
"itertools",
".",
"product",
"(... | Count the intersections of two strokes with each other.
Parameters
----------
line_segments_b : list
A list of line segemnts
Returns
-------
int
The number of intersections between A and B. | [
"Count",
"the",
"intersections",
"of",
"two",
"strokes",
"with",
"each",
"other",
"."
] | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/geometry.py#L101-L122 |
42,352 | MartinThoma/hwrt | hwrt/geometry.py | BoundingBox.get_area | def get_area(self):
"""Calculate area of bounding box."""
return (self.p2.x-self.p1.x)*(self.p2.y-self.p1.y) | python | def get_area(self):
"""Calculate area of bounding box."""
return (self.p2.x-self.p1.x)*(self.p2.y-self.p1.y) | [
"def",
"get_area",
"(",
"self",
")",
":",
"return",
"(",
"self",
".",
"p2",
".",
"x",
"-",
"self",
".",
"p1",
".",
"x",
")",
"*",
"(",
"self",
".",
"p2",
".",
"y",
"-",
"self",
".",
"p1",
".",
"y",
")"
] | Calculate area of bounding box. | [
"Calculate",
"area",
"of",
"bounding",
"box",
"."
] | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/geometry.py#L143-L145 |
42,353 | MartinThoma/hwrt | hwrt/geometry.py | BoundingBox.get_center | def get_center(self):
"""
Get the center point of this bounding box.
"""
return Point((self.p1.x+self.p2.x)/2.0, (self.p1.y+self.p2.y)/2.0) | python | def get_center(self):
"""
Get the center point of this bounding box.
"""
return Point((self.p1.x+self.p2.x)/2.0, (self.p1.y+self.p2.y)/2.0) | [
"def",
"get_center",
"(",
"self",
")",
":",
"return",
"Point",
"(",
"(",
"self",
".",
"p1",
".",
"x",
"+",
"self",
".",
"p2",
".",
"x",
")",
"/",
"2.0",
",",
"(",
"self",
".",
"p1",
".",
"y",
"+",
"self",
".",
"p2",
".",
"y",
")",
"/",
"2... | Get the center point of this bounding box. | [
"Get",
"the",
"center",
"point",
"of",
"this",
"bounding",
"box",
"."
] | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/geometry.py#L161-L165 |
42,354 | MartinThoma/hwrt | hwrt/view.py | _list_ids | def _list_ids(path_to_data):
"""List raw data IDs grouped by symbol ID from a pickle file
``path_to_data``."""
loaded = pickle.load(open(path_to_data, "rb"))
raw_datasets = loaded['handwriting_datasets']
raw_ids = {}
for raw_dataset in raw_datasets:
raw_data_id = raw_dataset['handwrit... | python | def _list_ids(path_to_data):
"""List raw data IDs grouped by symbol ID from a pickle file
``path_to_data``."""
loaded = pickle.load(open(path_to_data, "rb"))
raw_datasets = loaded['handwriting_datasets']
raw_ids = {}
for raw_dataset in raw_datasets:
raw_data_id = raw_dataset['handwrit... | [
"def",
"_list_ids",
"(",
"path_to_data",
")",
":",
"loaded",
"=",
"pickle",
".",
"load",
"(",
"open",
"(",
"path_to_data",
",",
"\"rb\"",
")",
")",
"raw_datasets",
"=",
"loaded",
"[",
"'handwriting_datasets'",
"]",
"raw_ids",
"=",
"{",
"}",
"for",
"raw_dat... | List raw data IDs grouped by symbol ID from a pickle file
``path_to_data``. | [
"List",
"raw",
"data",
"IDs",
"grouped",
"by",
"symbol",
"ID",
"from",
"a",
"pickle",
"file",
"path_to_data",
"."
] | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/view.py#L68-L81 |
42,355 | MartinThoma/hwrt | hwrt/view.py | _get_system | def _get_system(model_folder):
"""Return the preprocessing description, the feature description and the
model description."""
# Get model description
model_description_file = os.path.join(model_folder, "info.yml")
if not os.path.isfile(model_description_file):
logging.error("You are prob... | python | def _get_system(model_folder):
"""Return the preprocessing description, the feature description and the
model description."""
# Get model description
model_description_file = os.path.join(model_folder, "info.yml")
if not os.path.isfile(model_description_file):
logging.error("You are prob... | [
"def",
"_get_system",
"(",
"model_folder",
")",
":",
"# Get model description",
"model_description_file",
"=",
"os",
".",
"path",
".",
"join",
"(",
"model_folder",
",",
"\"info.yml\"",
")",
"if",
"not",
"os",
".",
"path",
".",
"isfile",
"(",
"model_description_f... | Return the preprocessing description, the feature description and the
model description. | [
"Return",
"the",
"preprocessing",
"description",
"the",
"feature",
"description",
"and",
"the",
"model",
"description",
"."
] | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/view.py#L99-L117 |
42,356 | MartinThoma/hwrt | hwrt/view.py | display_data | def display_data(raw_data_string, raw_data_id, model_folder, show_raw):
"""Print ``raw_data_id`` with the content ``raw_data_string`` after
applying the preprocessing of ``model_folder`` to it."""
print("## Raw Data (ID: %i)" % raw_data_id)
print("```")
print(raw_data_string)
print("```")
... | python | def display_data(raw_data_string, raw_data_id, model_folder, show_raw):
"""Print ``raw_data_id`` with the content ``raw_data_string`` after
applying the preprocessing of ``model_folder`` to it."""
print("## Raw Data (ID: %i)" % raw_data_id)
print("```")
print(raw_data_string)
print("```")
... | [
"def",
"display_data",
"(",
"raw_data_string",
",",
"raw_data_id",
",",
"model_folder",
",",
"show_raw",
")",
":",
"print",
"(",
"\"## Raw Data (ID: %i)\"",
"%",
"raw_data_id",
")",
"print",
"(",
"\"```\"",
")",
"print",
"(",
"raw_data_string",
")",
"print",
"("... | Print ``raw_data_id`` with the content ``raw_data_string`` after
applying the preprocessing of ``model_folder`` to it. | [
"Print",
"raw_data_id",
"with",
"the",
"content",
"raw_data_string",
"after",
"applying",
"the",
"preprocessing",
"of",
"model_folder",
"to",
"it",
"."
] | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/view.py#L120-L174 |
42,357 | MartinThoma/hwrt | hwrt/view.py | main | def main(list_ids, model, contact_server, raw_data_id, show_raw,
mysql_cfg='mysql_online'):
"""Main function of view.py."""
if list_ids:
preprocessing_desc, _, _ = _get_system(model)
raw_datapath = os.path.join(utils.get_project_root(),
preprocessing_... | python | def main(list_ids, model, contact_server, raw_data_id, show_raw,
mysql_cfg='mysql_online'):
"""Main function of view.py."""
if list_ids:
preprocessing_desc, _, _ = _get_system(model)
raw_datapath = os.path.join(utils.get_project_root(),
preprocessing_... | [
"def",
"main",
"(",
"list_ids",
",",
"model",
",",
"contact_server",
",",
"raw_data_id",
",",
"show_raw",
",",
"mysql_cfg",
"=",
"'mysql_online'",
")",
":",
"if",
"list_ids",
":",
"preprocessing_desc",
",",
"_",
",",
"_",
"=",
"_get_system",
"(",
"model",
... | Main function of view.py. | [
"Main",
"function",
"of",
"view",
".",
"py",
"."
] | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/view.py#L211-L243 |
42,358 | MartinThoma/hwrt | hwrt/preprocess_dataset.py | get_parameters | def get_parameters(folder):
"""Get the parameters of the preprocessing done within `folder`.
Parameters
----------
folder : string
Returns
-------
tuple : (path of raw data,
path where preprocessed data gets stored,
list of preprocessing algorithms)
"""
#... | python | def get_parameters(folder):
"""Get the parameters of the preprocessing done within `folder`.
Parameters
----------
folder : string
Returns
-------
tuple : (path of raw data,
path where preprocessed data gets stored,
list of preprocessing algorithms)
"""
#... | [
"def",
"get_parameters",
"(",
"folder",
")",
":",
"# Read the model description file",
"with",
"open",
"(",
"os",
".",
"path",
".",
"join",
"(",
"folder",
",",
"\"info.yml\"",
")",
",",
"'r'",
")",
"as",
"ymlfile",
":",
"preprocessing_description",
"=",
"yaml"... | Get the parameters of the preprocessing done within `folder`.
Parameters
----------
folder : string
Returns
-------
tuple : (path of raw data,
path where preprocessed data gets stored,
list of preprocessing algorithms) | [
"Get",
"the",
"parameters",
"of",
"the",
"preprocessing",
"done",
"within",
"folder",
"."
] | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/preprocess_dataset.py#L26-L53 |
42,359 | MartinThoma/hwrt | hwrt/preprocess_dataset.py | create_preprocessed_dataset | def create_preprocessed_dataset(path_to_data, outputpath, preprocessing_queue):
"""Create a preprocessed dataset file by applying `preprocessing_queue`
to `path_to_data`. The result will be stored in `outputpath`."""
# Log everything
logging.info("Data soure %s", path_to_data)
logging.info("Outpu... | python | def create_preprocessed_dataset(path_to_data, outputpath, preprocessing_queue):
"""Create a preprocessed dataset file by applying `preprocessing_queue`
to `path_to_data`. The result will be stored in `outputpath`."""
# Log everything
logging.info("Data soure %s", path_to_data)
logging.info("Outpu... | [
"def",
"create_preprocessed_dataset",
"(",
"path_to_data",
",",
"outputpath",
",",
"preprocessing_queue",
")",
":",
"# Log everything",
"logging",
".",
"info",
"(",
"\"Data soure %s\"",
",",
"path_to_data",
")",
"logging",
".",
"info",
"(",
"\"Output will be stored in %... | Create a preprocessed dataset file by applying `preprocessing_queue`
to `path_to_data`. The result will be stored in `outputpath`. | [
"Create",
"a",
"preprocessed",
"dataset",
"file",
"by",
"applying",
"preprocessing_queue",
"to",
"path_to_data",
".",
"The",
"result",
"will",
"be",
"stored",
"in",
"outputpath",
"."
] | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/preprocess_dataset.py#L56-L92 |
42,360 | MartinThoma/hwrt | hwrt/preprocess_dataset.py | main | def main(folder):
"""Main part of preprocess_dataset that glues things togeter."""
raw_datapath, outputpath, p_queue = get_parameters(folder)
create_preprocessed_dataset(raw_datapath, outputpath, p_queue)
utils.create_run_logfile(folder) | python | def main(folder):
"""Main part of preprocess_dataset that glues things togeter."""
raw_datapath, outputpath, p_queue = get_parameters(folder)
create_preprocessed_dataset(raw_datapath, outputpath, p_queue)
utils.create_run_logfile(folder) | [
"def",
"main",
"(",
"folder",
")",
":",
"raw_datapath",
",",
"outputpath",
",",
"p_queue",
"=",
"get_parameters",
"(",
"folder",
")",
"create_preprocessed_dataset",
"(",
"raw_datapath",
",",
"outputpath",
",",
"p_queue",
")",
"utils",
".",
"create_run_logfile",
... | Main part of preprocess_dataset that glues things togeter. | [
"Main",
"part",
"of",
"preprocess_dataset",
"that",
"glues",
"things",
"togeter",
"."
] | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/preprocess_dataset.py#L95-L99 |
42,361 | MartinThoma/hwrt | hwrt/create_ffiles.py | _create_index_formula_lookup | def _create_index_formula_lookup(formula_id2index,
feature_folder,
index2latex):
"""
Create a lookup file where the index is mapped to the formula id and the
LaTeX command.
Parameters
----------
formula_id2index : dict
featur... | python | def _create_index_formula_lookup(formula_id2index,
feature_folder,
index2latex):
"""
Create a lookup file where the index is mapped to the formula id and the
LaTeX command.
Parameters
----------
formula_id2index : dict
featur... | [
"def",
"_create_index_formula_lookup",
"(",
"formula_id2index",
",",
"feature_folder",
",",
"index2latex",
")",
":",
"index2formula_id",
"=",
"sorted",
"(",
"formula_id2index",
".",
"items",
"(",
")",
",",
"key",
"=",
"lambda",
"n",
":",
"n",
"[",
"1",
"]",
... | Create a lookup file where the index is mapped to the formula id and the
LaTeX command.
Parameters
----------
formula_id2index : dict
feature_folder : str
Path to a folder in which a feature file as well as an
index2formula_id.csv is.
index2latex : dict
Maps an integer i... | [
"Create",
"a",
"lookup",
"file",
"where",
"the",
"index",
"is",
"mapped",
"to",
"the",
"formula",
"id",
"and",
"the",
"LaTeX",
"command",
"."
] | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/create_ffiles.py#L38-L59 |
42,362 | MartinThoma/hwrt | hwrt/create_ffiles.py | main | def main(feature_folder, create_learning_curve=False):
"""main function of create_ffiles.py"""
# Read the feature description file
with open(os.path.join(feature_folder, "info.yml"), 'r') as ymlfile:
feature_description = yaml.load(ymlfile)
# Get preprocessed .pickle file from model descriptio... | python | def main(feature_folder, create_learning_curve=False):
"""main function of create_ffiles.py"""
# Read the feature description file
with open(os.path.join(feature_folder, "info.yml"), 'r') as ymlfile:
feature_description = yaml.load(ymlfile)
# Get preprocessed .pickle file from model descriptio... | [
"def",
"main",
"(",
"feature_folder",
",",
"create_learning_curve",
"=",
"False",
")",
":",
"# Read the feature description file",
"with",
"open",
"(",
"os",
".",
"path",
".",
"join",
"(",
"feature_folder",
",",
"\"info.yml\"",
")",
",",
"'r'",
")",
"as",
"yml... | main function of create_ffiles.py | [
"main",
"function",
"of",
"create_ffiles",
".",
"py"
] | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/create_ffiles.py#L88-L160 |
42,363 | MartinThoma/hwrt | hwrt/create_ffiles.py | training_set_multiplication | def training_set_multiplication(training_set, mult_queue):
"""
Multiply the training set by all methods listed in mult_queue.
Parameters
----------
training_set :
set of all recordings that will be used for training
mult_queue :
list of all algorithms that will take one recordin... | python | def training_set_multiplication(training_set, mult_queue):
"""
Multiply the training set by all methods listed in mult_queue.
Parameters
----------
training_set :
set of all recordings that will be used for training
mult_queue :
list of all algorithms that will take one recordin... | [
"def",
"training_set_multiplication",
"(",
"training_set",
",",
"mult_queue",
")",
":",
"logging",
".",
"info",
"(",
"\"Multiply data...\"",
")",
"for",
"algorithm",
"in",
"mult_queue",
":",
"new_trning_set",
"=",
"[",
"]",
"for",
"recording",
"in",
"training_set"... | Multiply the training set by all methods listed in mult_queue.
Parameters
----------
training_set :
set of all recordings that will be used for training
mult_queue :
list of all algorithms that will take one recording and generate more
than one.
Returns
-------
mutl... | [
"Multiply",
"the",
"training",
"set",
"by",
"all",
"methods",
"listed",
"in",
"mult_queue",
"."
] | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/create_ffiles.py#L163-L192 |
42,364 | MartinThoma/hwrt | hwrt/create_ffiles.py | _calculate_feature_stats | def _calculate_feature_stats(feature_list, prepared, serialization_file): # pylint: disable=R0914
"""Calculate min, max and mean for each feature. Store it in object."""
# Create feature only list
feats = [x for x, _ in prepared] # Label is not necessary
# Calculate all means / mins / maxs
means ... | python | def _calculate_feature_stats(feature_list, prepared, serialization_file): # pylint: disable=R0914
"""Calculate min, max and mean for each feature. Store it in object."""
# Create feature only list
feats = [x for x, _ in prepared] # Label is not necessary
# Calculate all means / mins / maxs
means ... | [
"def",
"_calculate_feature_stats",
"(",
"feature_list",
",",
"prepared",
",",
"serialization_file",
")",
":",
"# pylint: disable=R0914",
"# Create feature only list",
"feats",
"=",
"[",
"x",
"for",
"x",
",",
"_",
"in",
"prepared",
"]",
"# Label is not necessary",
"# C... | Calculate min, max and mean for each feature. Store it in object. | [
"Calculate",
"min",
"max",
"and",
"mean",
"for",
"each",
"feature",
".",
"Store",
"it",
"in",
"object",
"."
] | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/create_ffiles.py#L267-L299 |
42,365 | MartinThoma/hwrt | hwrt/create_ffiles.py | make_hdf5 | def make_hdf5(dataset_name, feature_count, data,
output_filename, create_learning_curve):
"""
Create the hdf5 file.
Parameters
----------
filename :
name of the file that hdf5_create will use to create the hdf5 file.
feature_count : integer
number of features
d... | python | def make_hdf5(dataset_name, feature_count, data,
output_filename, create_learning_curve):
"""
Create the hdf5 file.
Parameters
----------
filename :
name of the file that hdf5_create will use to create the hdf5 file.
feature_count : integer
number of features
d... | [
"def",
"make_hdf5",
"(",
"dataset_name",
",",
"feature_count",
",",
"data",
",",
"output_filename",
",",
"create_learning_curve",
")",
":",
"# create raw data file for hdf5_create",
"if",
"dataset_name",
"==",
"\"traindata\"",
"and",
"create_learning_curve",
":",
"max_tra... | Create the hdf5 file.
Parameters
----------
filename :
name of the file that hdf5_create will use to create the hdf5 file.
feature_count : integer
number of features
data : list of tuples
data format ('feature_string', 'label') | [
"Create",
"the",
"hdf5",
"file",
"."
] | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/create_ffiles.py#L354-L390 |
42,366 | MartinThoma/hwrt | hwrt/segmentation/segmentation.py | get_dataset | def get_dataset():
"""Create a dataset for machine learning of segmentations.
Returns
-------
tuple :
(X, y) where X is a list of tuples. Each tuple is a feature. y
is a list of labels (0 for 'not in one symbol' and 1 for 'in symbol')
"""
seg_data = "segmentation-X.npy"
seg_... | python | def get_dataset():
"""Create a dataset for machine learning of segmentations.
Returns
-------
tuple :
(X, y) where X is a list of tuples. Each tuple is a feature. y
is a list of labels (0 for 'not in one symbol' and 1 for 'in symbol')
"""
seg_data = "segmentation-X.npy"
seg_... | [
"def",
"get_dataset",
"(",
")",
":",
"seg_data",
"=",
"\"segmentation-X.npy\"",
"seg_labels",
"=",
"\"segmentation-y.npy\"",
"# seg_ids = \"segmentation-ids.npy\"",
"if",
"os",
".",
"path",
".",
"isfile",
"(",
"seg_data",
")",
"and",
"os",
".",
"path",
".",
"isfil... | Create a dataset for machine learning of segmentations.
Returns
-------
tuple :
(X, y) where X is a list of tuples. Each tuple is a feature. y
is a list of labels (0 for 'not in one symbol' and 1 for 'in symbol') | [
"Create",
"a",
"dataset",
"for",
"machine",
"learning",
"of",
"segmentations",
"."
] | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/segmentation/segmentation.py#L169-L217 |
42,367 | MartinThoma/hwrt | hwrt/segmentation/segmentation.py | get_segmented_raw_data | def get_segmented_raw_data(top_n=10000):
"""Fetch data from the server.
Parameters
----------
top_n : int
Number of data sets which get fetched from the server.
"""
cfg = utils.get_database_configuration()
mysql = cfg['mysql_online']
connection = pymysql.connect(host=mysql['host... | python | def get_segmented_raw_data(top_n=10000):
"""Fetch data from the server.
Parameters
----------
top_n : int
Number of data sets which get fetched from the server.
"""
cfg = utils.get_database_configuration()
mysql = cfg['mysql_online']
connection = pymysql.connect(host=mysql['host... | [
"def",
"get_segmented_raw_data",
"(",
"top_n",
"=",
"10000",
")",
":",
"cfg",
"=",
"utils",
".",
"get_database_configuration",
"(",
")",
"mysql",
"=",
"cfg",
"[",
"'mysql_online'",
"]",
"connection",
"=",
"pymysql",
".",
"connect",
"(",
"host",
"=",
"mysql",... | Fetch data from the server.
Parameters
----------
top_n : int
Number of data sets which get fetched from the server. | [
"Fetch",
"data",
"from",
"the",
"server",
"."
] | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/segmentation/segmentation.py#L248-L282 |
42,368 | MartinThoma/hwrt | hwrt/segmentation/segmentation.py | get_stroke_features | def get_stroke_features(recording, strokeid1, strokeid2):
"""Get the features used to decide if two strokes belong to the same symbol
or not.
Parameters
----------
recording : list
A list of strokes
strokeid1 : int
strokeid2 : int
Returns
-------
list :
A list o... | python | def get_stroke_features(recording, strokeid1, strokeid2):
"""Get the features used to decide if two strokes belong to the same symbol
or not.
Parameters
----------
recording : list
A list of strokes
strokeid1 : int
strokeid2 : int
Returns
-------
list :
A list o... | [
"def",
"get_stroke_features",
"(",
"recording",
",",
"strokeid1",
",",
"strokeid2",
")",
":",
"stroke1",
"=",
"recording",
"[",
"strokeid1",
"]",
"stroke2",
"=",
"recording",
"[",
"strokeid2",
"]",
"assert",
"isinstance",
"(",
"stroke1",
",",
"list",
")",
",... | Get the features used to decide if two strokes belong to the same symbol
or not.
Parameters
----------
recording : list
A list of strokes
strokeid1 : int
strokeid2 : int
Returns
-------
list :
A list of features which could be useful to decide if stroke1 and
... | [
"Get",
"the",
"features",
"used",
"to",
"decide",
"if",
"two",
"strokes",
"belong",
"to",
"the",
"same",
"symbol",
"or",
"not",
"."
] | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/segmentation/segmentation.py#L472-L505 |
42,369 | MartinThoma/hwrt | hwrt/segmentation/segmentation.py | get_segmentation | def get_segmentation(recording,
single_clf,
single_stroke_clf,
stroke_segmented_classifier):
"""
Get a list of segmentations of recording with the probability of the
segmentation being correct.
Parameters
----------
recording : A li... | python | def get_segmentation(recording,
single_clf,
single_stroke_clf,
stroke_segmented_classifier):
"""
Get a list of segmentations of recording with the probability of the
segmentation being correct.
Parameters
----------
recording : A li... | [
"def",
"get_segmentation",
"(",
"recording",
",",
"single_clf",
",",
"single_stroke_clf",
",",
"stroke_segmented_classifier",
")",
":",
"mst_wood",
"=",
"get_mst_wood",
"(",
"recording",
",",
"single_clf",
")",
"return",
"[",
"(",
"normalize_segmentation",
"(",
"[",... | Get a list of segmentations of recording with the probability of the
segmentation being correct.
Parameters
----------
recording : A list of lists
Each sublist represents a stroke
single_clf : object
A classifier for single symbols
single_stroke_clf : object
A classifier... | [
"Get",
"a",
"list",
"of",
"segmentations",
"of",
"recording",
"with",
"the",
"probability",
"of",
"the",
"segmentation",
"being",
"correct",
"."
] | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/segmentation/segmentation.py#L574-L667 |
42,370 | MartinThoma/hwrt | hwrt/segmentation/segmentation.py | break_mst | def break_mst(mst, i):
"""
Break mst into multiple MSTs by removing one node i.
Parameters
----------
mst : symmetrical square matrix
i : index of the mst where to break
Returns
-------
list of dictionarys ('mst' and 'strokes' are the keys)
"""
for j in range(len(mst['mst']... | python | def break_mst(mst, i):
"""
Break mst into multiple MSTs by removing one node i.
Parameters
----------
mst : symmetrical square matrix
i : index of the mst where to break
Returns
-------
list of dictionarys ('mst' and 'strokes' are the keys)
"""
for j in range(len(mst['mst']... | [
"def",
"break_mst",
"(",
"mst",
",",
"i",
")",
":",
"for",
"j",
"in",
"range",
"(",
"len",
"(",
"mst",
"[",
"'mst'",
"]",
")",
")",
":",
"mst",
"[",
"'mst'",
"]",
"[",
"i",
"]",
"[",
"j",
"]",
"=",
"0",
"mst",
"[",
"'mst'",
"]",
"[",
"j",... | Break mst into multiple MSTs by removing one node i.
Parameters
----------
mst : symmetrical square matrix
i : index of the mst where to break
Returns
-------
list of dictionarys ('mst' and 'strokes' are the keys) | [
"Break",
"mst",
"into",
"multiple",
"MSTs",
"by",
"removing",
"one",
"node",
"i",
"."
] | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/segmentation/segmentation.py#L784-L832 |
42,371 | MartinThoma/hwrt | hwrt/segmentation/segmentation.py | _is_out_of_order | def _is_out_of_order(segmentation):
"""
Check if a given segmentation is out of order.
Examples
--------
>>> _is_out_of_order([[0, 1, 2, 3]])
False
>>> _is_out_of_order([[0, 1], [2, 3]])
False
>>> _is_out_of_order([[0, 1, 3], [2]])
True
"""
last_stroke = -1
for symbo... | python | def _is_out_of_order(segmentation):
"""
Check if a given segmentation is out of order.
Examples
--------
>>> _is_out_of_order([[0, 1, 2, 3]])
False
>>> _is_out_of_order([[0, 1], [2, 3]])
False
>>> _is_out_of_order([[0, 1, 3], [2]])
True
"""
last_stroke = -1
for symbo... | [
"def",
"_is_out_of_order",
"(",
"segmentation",
")",
":",
"last_stroke",
"=",
"-",
"1",
"for",
"symbol",
"in",
"segmentation",
":",
"for",
"stroke",
"in",
"symbol",
":",
"if",
"last_stroke",
">",
"stroke",
":",
"return",
"True",
"last_stroke",
"=",
"stroke",... | Check if a given segmentation is out of order.
Examples
--------
>>> _is_out_of_order([[0, 1, 2, 3]])
False
>>> _is_out_of_order([[0, 1], [2, 3]])
False
>>> _is_out_of_order([[0, 1, 3], [2]])
True | [
"Check",
"if",
"a",
"given",
"segmentation",
"is",
"out",
"of",
"order",
"."
] | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/segmentation/segmentation.py#L835-L854 |
42,372 | MartinThoma/hwrt | hwrt/segmentation/segmentation.py | get_bb_intersections | def get_bb_intersections(recording):
"""
Get all intersections of the bounding boxes of strokes.
Parameters
----------
recording : list of lists of integers
Returns
-------
A symmetrical matrix which indicates if two bounding boxes intersect.
"""
intersections = numpy.zeros((le... | python | def get_bb_intersections(recording):
"""
Get all intersections of the bounding boxes of strokes.
Parameters
----------
recording : list of lists of integers
Returns
-------
A symmetrical matrix which indicates if two bounding boxes intersect.
"""
intersections = numpy.zeros((le... | [
"def",
"get_bb_intersections",
"(",
"recording",
")",
":",
"intersections",
"=",
"numpy",
".",
"zeros",
"(",
"(",
"len",
"(",
"recording",
")",
",",
"len",
"(",
"recording",
")",
")",
",",
"dtype",
"=",
"bool",
")",
"for",
"i",
"in",
"range",
"(",
"l... | Get all intersections of the bounding boxes of strokes.
Parameters
----------
recording : list of lists of integers
Returns
-------
A symmetrical matrix which indicates if two bounding boxes intersect. | [
"Get",
"all",
"intersections",
"of",
"the",
"bounding",
"boxes",
"of",
"strokes",
"."
] | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/segmentation/segmentation.py#L1006-L1026 |
42,373 | MartinThoma/hwrt | hwrt/segmentation/beam.py | p_strokes | def p_strokes(symbol, count):
"""
Get the probability of a written `symbol` having `count` strokes.
Parameters
----------
symbol : str
LaTeX command
count : int, >= 1
Returns
-------
float
In [0.0, 1.0]
"""
global stroke_prob
assert count >= 1
epsilo... | python | def p_strokes(symbol, count):
"""
Get the probability of a written `symbol` having `count` strokes.
Parameters
----------
symbol : str
LaTeX command
count : int, >= 1
Returns
-------
float
In [0.0, 1.0]
"""
global stroke_prob
assert count >= 1
epsilo... | [
"def",
"p_strokes",
"(",
"symbol",
",",
"count",
")",
":",
"global",
"stroke_prob",
"assert",
"count",
">=",
"1",
"epsilon",
"=",
"0.00000001",
"if",
"stroke_prob",
"is",
"None",
":",
"misc_path",
"=",
"pkg_resources",
".",
"resource_filename",
"(",
"'hwrt'",
... | Get the probability of a written `symbol` having `count` strokes.
Parameters
----------
symbol : str
LaTeX command
count : int, >= 1
Returns
-------
float
In [0.0, 1.0] | [
"Get",
"the",
"probability",
"of",
"a",
"written",
"symbol",
"having",
"count",
"strokes",
"."
] | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/segmentation/beam.py#L32-L61 |
42,374 | MartinThoma/hwrt | hwrt/segmentation/beam.py | Beam._add_hypotheses_assuming_new_stroke | def _add_hypotheses_assuming_new_stroke(self,
new_stroke,
stroke_nr,
new_beam):
"""
Get new guesses by assuming new_stroke is a new symbol.
Parameters
----... | python | def _add_hypotheses_assuming_new_stroke(self,
new_stroke,
stroke_nr,
new_beam):
"""
Get new guesses by assuming new_stroke is a new symbol.
Parameters
----... | [
"def",
"_add_hypotheses_assuming_new_stroke",
"(",
"self",
",",
"new_stroke",
",",
"stroke_nr",
",",
"new_beam",
")",
":",
"guesses",
"=",
"single_clf",
".",
"predict",
"(",
"{",
"'data'",
":",
"[",
"new_stroke",
"]",
",",
"'id'",
":",
"None",
"}",
")",
"[... | Get new guesses by assuming new_stroke is a new symbol.
Parameters
----------
new_stroke : list of dicts
A list of dicts [{'x': 12, 'y': 34, 'time': 56}, ...] which
represent a point.
stroke_nr : int
Number of the stroke for segmentation
new_b... | [
"Get",
"new",
"guesses",
"by",
"assuming",
"new_stroke",
"is",
"a",
"new",
"symbol",
"."
] | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/segmentation/beam.py#L137-L189 |
42,375 | MartinThoma/hwrt | hwrt/segmentation/beam.py | Beam.add_stroke | def add_stroke(self, new_stroke):
"""
Update the beam so that it considers `new_stroke`.
When a `new_stroke` comes, it can either belong to a symbol for which
at least one other stroke was already made or belong to a symbol for
which `new_stroke` is the first stroke.
Th... | python | def add_stroke(self, new_stroke):
"""
Update the beam so that it considers `new_stroke`.
When a `new_stroke` comes, it can either belong to a symbol for which
at least one other stroke was already made or belong to a symbol for
which `new_stroke` is the first stroke.
Th... | [
"def",
"add_stroke",
"(",
"self",
",",
"new_stroke",
")",
":",
"global",
"single_clf",
"if",
"len",
"(",
"self",
".",
"hypotheses",
")",
"==",
"0",
":",
"# Don't put this in the constructor!",
"self",
".",
"hypotheses",
"=",
"[",
"{",
"'segmentation'",
":",
... | Update the beam so that it considers `new_stroke`.
When a `new_stroke` comes, it can either belong to a symbol for which
at least one other stroke was already made or belong to a symbol for
which `new_stroke` is the first stroke.
The number of hypotheses after q strokes without pruning... | [
"Update",
"the",
"beam",
"so",
"that",
"it",
"considers",
"new_stroke",
"."
] | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/segmentation/beam.py#L191-L295 |
42,376 | MartinThoma/hwrt | hwrt/segmentation/beam.py | Beam._prune | def _prune(self):
"""Shorten hypotheses to the best k ones."""
self.hypotheses = sorted(self.hypotheses,
key=lambda e: e['probability'],
reverse=True)[:self.k] | python | def _prune(self):
"""Shorten hypotheses to the best k ones."""
self.hypotheses = sorted(self.hypotheses,
key=lambda e: e['probability'],
reverse=True)[:self.k] | [
"def",
"_prune",
"(",
"self",
")",
":",
"self",
".",
"hypotheses",
"=",
"sorted",
"(",
"self",
".",
"hypotheses",
",",
"key",
"=",
"lambda",
"e",
":",
"e",
"[",
"'probability'",
"]",
",",
"reverse",
"=",
"True",
")",
"[",
":",
"self",
".",
"k",
"... | Shorten hypotheses to the best k ones. | [
"Shorten",
"hypotheses",
"to",
"the",
"best",
"k",
"ones",
"."
] | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/segmentation/beam.py#L297-L301 |
42,377 | MartinThoma/hwrt | bin/convert_cuda2numpy.py | get_matrices | def get_matrices():
"""
Get the matrices from a pickled files.
Returns
-------
list
List of all matrices.
"""
with open('hwrt/misc/is_one_symbol_classifier.pickle', 'rb') as f:
a = pickle.load(f)
arrays = []
for el1 in a.input_storage:
for el2 in el1.__dict_... | python | def get_matrices():
"""
Get the matrices from a pickled files.
Returns
-------
list
List of all matrices.
"""
with open('hwrt/misc/is_one_symbol_classifier.pickle', 'rb') as f:
a = pickle.load(f)
arrays = []
for el1 in a.input_storage:
for el2 in el1.__dict_... | [
"def",
"get_matrices",
"(",
")",
":",
"with",
"open",
"(",
"'hwrt/misc/is_one_symbol_classifier.pickle'",
",",
"'rb'",
")",
"as",
"f",
":",
"a",
"=",
"pickle",
".",
"load",
"(",
"f",
")",
"arrays",
"=",
"[",
"]",
"for",
"el1",
"in",
"a",
".",
"input_st... | Get the matrices from a pickled files.
Returns
-------
list
List of all matrices. | [
"Get",
"the",
"matrices",
"from",
"a",
"pickled",
"files",
"."
] | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/bin/convert_cuda2numpy.py#L32-L53 |
42,378 | MartinThoma/hwrt | bin/convert_cuda2numpy.py | create_model_tar | def create_model_tar(matrices, tarname="model-cuda-converted.tar"):
"""
Create a tar file which contains the model.
Parameters
----------
matrices : list
tarname : str
Target file which will be created.
"""
# Write layers
filenames = []
for layer in range(len(matrices)):... | python | def create_model_tar(matrices, tarname="model-cuda-converted.tar"):
"""
Create a tar file which contains the model.
Parameters
----------
matrices : list
tarname : str
Target file which will be created.
"""
# Write layers
filenames = []
for layer in range(len(matrices)):... | [
"def",
"create_model_tar",
"(",
"matrices",
",",
"tarname",
"=",
"\"model-cuda-converted.tar\"",
")",
":",
"# Write layers",
"filenames",
"=",
"[",
"]",
"for",
"layer",
"in",
"range",
"(",
"len",
"(",
"matrices",
")",
")",
":",
"if",
"matrices",
"[",
"layer"... | Create a tar file which contains the model.
Parameters
----------
matrices : list
tarname : str
Target file which will be created. | [
"Create",
"a",
"tar",
"file",
"which",
"contains",
"the",
"model",
"."
] | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/bin/convert_cuda2numpy.py#L56-L96 |
42,379 | MartinThoma/hwrt | hwrt/selfcheck.py | check_python_version | def check_python_version():
"""Check if the currently running Python version is new enough."""
# Required due to multiple with statements on one line
req_version = (2, 7)
cur_version = sys.version_info
if cur_version >= req_version:
print("Python version... %sOK%s (found %s, requires %s)" %
... | python | def check_python_version():
"""Check if the currently running Python version is new enough."""
# Required due to multiple with statements on one line
req_version = (2, 7)
cur_version = sys.version_info
if cur_version >= req_version:
print("Python version... %sOK%s (found %s, requires %s)" %
... | [
"def",
"check_python_version",
"(",
")",
":",
"# Required due to multiple with statements on one line",
"req_version",
"=",
"(",
"2",
",",
"7",
")",
"cur_version",
"=",
"sys",
".",
"version_info",
"if",
"cur_version",
">=",
"req_version",
":",
"print",
"(",
"\"Pytho... | Check if the currently running Python version is new enough. | [
"Check",
"if",
"the",
"currently",
"running",
"Python",
"version",
"is",
"new",
"enough",
"."
] | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/selfcheck.py#L48-L60 |
42,380 | MartinThoma/hwrt | hwrt/selfcheck.py | main | def main():
"""Execute all checks."""
check_python_version()
check_python_modules()
check_executables()
home = os.path.expanduser("~")
print("\033[1mCheck files\033[0m")
rcfile = os.path.join(home, ".hwrtrc")
if os.path.isfile(rcfile):
print("~/.hwrtrc... %sFOUND%s" %
... | python | def main():
"""Execute all checks."""
check_python_version()
check_python_modules()
check_executables()
home = os.path.expanduser("~")
print("\033[1mCheck files\033[0m")
rcfile = os.path.join(home, ".hwrtrc")
if os.path.isfile(rcfile):
print("~/.hwrtrc... %sFOUND%s" %
... | [
"def",
"main",
"(",
")",
":",
"check_python_version",
"(",
")",
"check_python_modules",
"(",
")",
"check_executables",
"(",
")",
"home",
"=",
"os",
".",
"path",
".",
"expanduser",
"(",
"\"~\"",
")",
"print",
"(",
"\"\\033[1mCheck files\\033[0m\"",
")",
"rcfile... | Execute all checks. | [
"Execute",
"all",
"checks",
"."
] | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/selfcheck.py#L136-L151 |
42,381 | MartinThoma/hwrt | bin/merge.py | merge | def merge(d1, d2):
"""Merge two raw datasets into one.
Parameters
----------
d1 : dict
d2 : dict
Returns
-------
dict
"""
if d1['formula_id2latex'] is None:
formula_id2latex = {}
else:
formula_id2latex = d1['formula_id2latex'].copy()
formula_id2latex.upd... | python | def merge(d1, d2):
"""Merge two raw datasets into one.
Parameters
----------
d1 : dict
d2 : dict
Returns
-------
dict
"""
if d1['formula_id2latex'] is None:
formula_id2latex = {}
else:
formula_id2latex = d1['formula_id2latex'].copy()
formula_id2latex.upd... | [
"def",
"merge",
"(",
"d1",
",",
"d2",
")",
":",
"if",
"d1",
"[",
"'formula_id2latex'",
"]",
"is",
"None",
":",
"formula_id2latex",
"=",
"{",
"}",
"else",
":",
"formula_id2latex",
"=",
"d1",
"[",
"'formula_id2latex'",
"]",
".",
"copy",
"(",
")",
"formul... | Merge two raw datasets into one.
Parameters
----------
d1 : dict
d2 : dict
Returns
-------
dict | [
"Merge",
"two",
"raw",
"datasets",
"into",
"one",
"."
] | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/bin/merge.py#L37-L58 |
42,382 | MartinThoma/hwrt | hwrt/download.py | is_file_consistent | def is_file_consistent(local_path_file, md5_hash):
"""Check if file is there and if the md5_hash is correct."""
return os.path.isfile(local_path_file) and \
hashlib.md5(open(local_path_file, 'rb').read()).hexdigest() == md5_hash | python | def is_file_consistent(local_path_file, md5_hash):
"""Check if file is there and if the md5_hash is correct."""
return os.path.isfile(local_path_file) and \
hashlib.md5(open(local_path_file, 'rb').read()).hexdigest() == md5_hash | [
"def",
"is_file_consistent",
"(",
"local_path_file",
",",
"md5_hash",
")",
":",
"return",
"os",
".",
"path",
".",
"isfile",
"(",
"local_path_file",
")",
"and",
"hashlib",
".",
"md5",
"(",
"open",
"(",
"local_path_file",
",",
"'rb'",
")",
".",
"read",
"(",
... | Check if file is there and if the md5_hash is correct. | [
"Check",
"if",
"file",
"is",
"there",
"and",
"if",
"the",
"md5_hash",
"is",
"correct",
"."
] | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/download.py#L18-L21 |
42,383 | MartinThoma/hwrt | hwrt/download.py | main | def main():
"""Main part of the download script."""
# Read config file. This has to get updated via git
project_root = utils.get_project_root()
infofile = os.path.join(project_root, "raw-datasets/info.yml")
logging.info("Read '%s'...", infofile)
with open(infofile, 'r') as ymlfile:
datas... | python | def main():
"""Main part of the download script."""
# Read config file. This has to get updated via git
project_root = utils.get_project_root()
infofile = os.path.join(project_root, "raw-datasets/info.yml")
logging.info("Read '%s'...", infofile)
with open(infofile, 'r') as ymlfile:
datas... | [
"def",
"main",
"(",
")",
":",
"# Read config file. This has to get updated via git",
"project_root",
"=",
"utils",
".",
"get_project_root",
"(",
")",
"infofile",
"=",
"os",
".",
"path",
".",
"join",
"(",
"project_root",
",",
"\"raw-datasets/info.yml\"",
")",
"loggin... | Main part of the download script. | [
"Main",
"part",
"of",
"the",
"download",
"script",
"."
] | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/download.py#L32-L53 |
42,384 | MartinThoma/hwrt | hwrt/language_model/language_model.py | load_model | def load_model():
"""
Load a n-gram language model for mathematics in ARPA format which gets
shipped with hwrt.
Returns
-------
A NgramLanguageModel object
"""
logging.info("Load language model...")
ngram_arpa_t = pkg_resources.resource_filename('hwrt',
... | python | def load_model():
"""
Load a n-gram language model for mathematics in ARPA format which gets
shipped with hwrt.
Returns
-------
A NgramLanguageModel object
"""
logging.info("Load language model...")
ngram_arpa_t = pkg_resources.resource_filename('hwrt',
... | [
"def",
"load_model",
"(",
")",
":",
"logging",
".",
"info",
"(",
"\"Load language model...\"",
")",
"ngram_arpa_t",
"=",
"pkg_resources",
".",
"resource_filename",
"(",
"'hwrt'",
",",
"'misc/ngram.arpa.tar.bz2'",
")",
"with",
"tarfile",
".",
"open",
"(",
"ngram_ar... | Load a n-gram language model for mathematics in ARPA format which gets
shipped with hwrt.
Returns
-------
A NgramLanguageModel object | [
"Load",
"a",
"n",
"-",
"gram",
"language",
"model",
"for",
"mathematics",
"in",
"ARPA",
"format",
"which",
"gets",
"shipped",
"with",
"hwrt",
"."
] | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/language_model/language_model.py#L157-L177 |
42,385 | MartinThoma/hwrt | hwrt/language_model/language_model.py | NgramLanguageModel.load_from_arpa_str | def load_from_arpa_str(self, arpa_str):
"""
Initialize N-gram model by reading an ARPA language model string.
Parameters
----------
arpa_str : str
A string in ARPA language model file format
"""
data_found = False
end_found = False
in_... | python | def load_from_arpa_str(self, arpa_str):
"""
Initialize N-gram model by reading an ARPA language model string.
Parameters
----------
arpa_str : str
A string in ARPA language model file format
"""
data_found = False
end_found = False
in_... | [
"def",
"load_from_arpa_str",
"(",
"self",
",",
"arpa_str",
")",
":",
"data_found",
"=",
"False",
"end_found",
"=",
"False",
"in_ngram_block",
"=",
"0",
"for",
"i",
",",
"line",
"in",
"enumerate",
"(",
"arpa_str",
".",
"split",
"(",
"\"\\n\"",
")",
")",
"... | Initialize N-gram model by reading an ARPA language model string.
Parameters
----------
arpa_str : str
A string in ARPA language model file format | [
"Initialize",
"N",
"-",
"gram",
"model",
"by",
"reading",
"an",
"ARPA",
"language",
"model",
"string",
"."
] | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/language_model/language_model.py#L23-L84 |
42,386 | MartinThoma/hwrt | hwrt/language_model/language_model.py | NgramLanguageModel.get_probability | def get_probability(self, sentence):
"""
Calculate the probability of a sentence, given this language model.
Get P(sentence) = P(w1, w2, w3, ..., wn)
= P(w1, w2, w3) * P(w2, w3, w4) *...* P(wn-2, wn-1, wn)
Parameters
----------
sentence : list
... | python | def get_probability(self, sentence):
"""
Calculate the probability of a sentence, given this language model.
Get P(sentence) = P(w1, w2, w3, ..., wn)
= P(w1, w2, w3) * P(w2, w3, w4) *...* P(wn-2, wn-1, wn)
Parameters
----------
sentence : list
... | [
"def",
"get_probability",
"(",
"self",
",",
"sentence",
")",
":",
"if",
"len",
"(",
"sentence",
")",
"==",
"1",
":",
"return",
"Decimal",
"(",
"10",
")",
"**",
"self",
".",
"get_unigram_log_prob",
"(",
"sentence",
")",
"elif",
"len",
"(",
"sentence",
"... | Calculate the probability of a sentence, given this language model.
Get P(sentence) = P(w1, w2, w3, ..., wn)
= P(w1, w2, w3) * P(w2, w3, w4) *...* P(wn-2, wn-1, wn)
Parameters
----------
sentence : list
A list of strings / tokens. | [
"Calculate",
"the",
"probability",
"of",
"a",
"sentence",
"given",
"this",
"language",
"model",
"."
] | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/language_model/language_model.py#L128-L148 |
42,387 | MartinThoma/hwrt | hwrt/datasets/crohme_eval.py | evaluate_dir | def evaluate_dir(sample_dir):
"""Evaluate all recordings in `sample_dir`.
Parameters
----------
sample_dir : string
The path to a directory with *.inkml files.
Returns
-------
list of dictionaries
Each dictionary contains the keys 'filename' and 'results', where
're... | python | def evaluate_dir(sample_dir):
"""Evaluate all recordings in `sample_dir`.
Parameters
----------
sample_dir : string
The path to a directory with *.inkml files.
Returns
-------
list of dictionaries
Each dictionary contains the keys 'filename' and 'results', where
're... | [
"def",
"evaluate_dir",
"(",
"sample_dir",
")",
":",
"results",
"=",
"[",
"]",
"if",
"sample_dir",
"[",
"-",
"1",
"]",
"==",
"\"/\"",
":",
"sample_dir",
"=",
"sample_dir",
"[",
":",
"-",
"1",
"]",
"for",
"filename",
"in",
"glob",
".",
"glob",
"(",
"... | Evaluate all recordings in `sample_dir`.
Parameters
----------
sample_dir : string
The path to a directory with *.inkml files.
Returns
-------
list of dictionaries
Each dictionary contains the keys 'filename' and 'results', where
'results' itself is a list of dictionari... | [
"Evaluate",
"all",
"recordings",
"in",
"sample_dir",
"."
] | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/datasets/crohme_eval.py#L21-L41 |
42,388 | MartinThoma/hwrt | hwrt/datasets/crohme_eval.py | evaluate_inkml | def evaluate_inkml(inkml_file_path):
"""Evaluate an InkML file.
Parameters
----------
inkml_file_path : string
path to an InkML file
Returns
-------
dictionary
The dictionary contains the keys 'filename' and 'results', where
'results' itself is a list of dictionarie... | python | def evaluate_inkml(inkml_file_path):
"""Evaluate an InkML file.
Parameters
----------
inkml_file_path : string
path to an InkML file
Returns
-------
dictionary
The dictionary contains the keys 'filename' and 'results', where
'results' itself is a list of dictionarie... | [
"def",
"evaluate_inkml",
"(",
"inkml_file_path",
")",
":",
"logging",
".",
"info",
"(",
"\"Start evaluating '%s'...\"",
",",
"inkml_file_path",
")",
"ret",
"=",
"{",
"'filename'",
":",
"inkml_file_path",
"}",
"recording",
"=",
"inkml",
".",
"read",
"(",
"inkml_f... | Evaluate an InkML file.
Parameters
----------
inkml_file_path : string
path to an InkML file
Returns
-------
dictionary
The dictionary contains the keys 'filename' and 'results', where
'results' itself is a list of dictionaries. Each of the results has the
keys ... | [
"Evaluate",
"an",
"InkML",
"file",
"."
] | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/datasets/crohme_eval.py#L44-L65 |
42,389 | MartinThoma/hwrt | hwrt/datasets/crohme_eval.py | generate_output_csv | def generate_output_csv(evaluation_results, filename='results.csv'):
"""Generate the evaluation results in the format
Parameters
----------
evaluation_results : list of dictionaries
Each dictionary contains the keys 'filename' and 'results', where
'results' itself is a list of dictionar... | python | def generate_output_csv(evaluation_results, filename='results.csv'):
"""Generate the evaluation results in the format
Parameters
----------
evaluation_results : list of dictionaries
Each dictionary contains the keys 'filename' and 'results', where
'results' itself is a list of dictionar... | [
"def",
"generate_output_csv",
"(",
"evaluation_results",
",",
"filename",
"=",
"'results.csv'",
")",
":",
"with",
"open",
"(",
"filename",
",",
"'w'",
")",
"as",
"f",
":",
"for",
"result",
"in",
"evaluation_results",
":",
"for",
"i",
",",
"entry",
"in",
"e... | Generate the evaluation results in the format
Parameters
----------
evaluation_results : list of dictionaries
Each dictionary contains the keys 'filename' and 'results', where
'results' itself is a list of dictionaries. Each of the results has
the keys 'latex' and 'probability'
... | [
"Generate",
"the",
"evaluation",
"results",
"in",
"the",
"format"
] | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/datasets/crohme_eval.py#L68-L95 |
42,390 | MartinThoma/hwrt | hwrt/utils.py | get_project_configuration | def get_project_configuration():
"""Get project configuration as dictionary."""
home = os.path.expanduser("~")
rcfile = os.path.join(home, ".hwrtrc")
if not os.path.isfile(rcfile):
create_project_configuration(rcfile)
with open(rcfile, 'r') as ymlfile:
cfg = yaml.load(ymlfile)
re... | python | def get_project_configuration():
"""Get project configuration as dictionary."""
home = os.path.expanduser("~")
rcfile = os.path.join(home, ".hwrtrc")
if not os.path.isfile(rcfile):
create_project_configuration(rcfile)
with open(rcfile, 'r') as ymlfile:
cfg = yaml.load(ymlfile)
re... | [
"def",
"get_project_configuration",
"(",
")",
":",
"home",
"=",
"os",
".",
"path",
".",
"expanduser",
"(",
"\"~\"",
")",
"rcfile",
"=",
"os",
".",
"path",
".",
"join",
"(",
"home",
",",
"\".hwrtrc\"",
")",
"if",
"not",
"os",
".",
"path",
".",
"isfile... | Get project configuration as dictionary. | [
"Get",
"project",
"configuration",
"as",
"dictionary",
"."
] | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/utils.py#L73-L81 |
42,391 | MartinThoma/hwrt | hwrt/utils.py | create_project_configuration | def create_project_configuration(filename):
"""Create a project configuration file which contains a configuration
that might make sense."""
home = os.path.expanduser("~")
project_root_folder = os.path.join(home, "hwr-experiments")
config = {'root': project_root_folder,
'nntoolkit': ... | python | def create_project_configuration(filename):
"""Create a project configuration file which contains a configuration
that might make sense."""
home = os.path.expanduser("~")
project_root_folder = os.path.join(home, "hwr-experiments")
config = {'root': project_root_folder,
'nntoolkit': ... | [
"def",
"create_project_configuration",
"(",
"filename",
")",
":",
"home",
"=",
"os",
".",
"path",
".",
"expanduser",
"(",
"\"~\"",
")",
"project_root_folder",
"=",
"os",
".",
"path",
".",
"join",
"(",
"home",
",",
"\"hwr-experiments\"",
")",
"config",
"=",
... | Create a project configuration file which contains a configuration
that might make sense. | [
"Create",
"a",
"project",
"configuration",
"file",
"which",
"contains",
"a",
"configuration",
"that",
"might",
"make",
"sense",
"."
] | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/utils.py#L84-L98 |
42,392 | MartinThoma/hwrt | hwrt/utils.py | get_project_root | def get_project_root():
"""Get the project root folder as a string."""
cfg = get_project_configuration()
# At this point it can be sure that the configuration file exists
# Now make sure the project structure exists
for dirname in ["raw-datasets",
"preprocessed",
... | python | def get_project_root():
"""Get the project root folder as a string."""
cfg = get_project_configuration()
# At this point it can be sure that the configuration file exists
# Now make sure the project structure exists
for dirname in ["raw-datasets",
"preprocessed",
... | [
"def",
"get_project_root",
"(",
")",
":",
"cfg",
"=",
"get_project_configuration",
"(",
")",
"# At this point it can be sure that the configuration file exists",
"# Now make sure the project structure exists",
"for",
"dirname",
"in",
"[",
"\"raw-datasets\"",
",",
"\"preprocessed\... | Get the project root folder as a string. | [
"Get",
"the",
"project",
"root",
"folder",
"as",
"a",
"string",
"."
] | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/utils.py#L101-L140 |
42,393 | MartinThoma/hwrt | hwrt/utils.py | get_template_folder | def get_template_folder():
"""Get path to the folder where th HTML templates are."""
cfg = get_project_configuration()
if 'templates' not in cfg:
home = os.path.expanduser("~")
rcfile = os.path.join(home, ".hwrtrc")
cfg['templates'] = pkg_resources.resource_filename('hwrt',
... | python | def get_template_folder():
"""Get path to the folder where th HTML templates are."""
cfg = get_project_configuration()
if 'templates' not in cfg:
home = os.path.expanduser("~")
rcfile = os.path.join(home, ".hwrtrc")
cfg['templates'] = pkg_resources.resource_filename('hwrt',
... | [
"def",
"get_template_folder",
"(",
")",
":",
"cfg",
"=",
"get_project_configuration",
"(",
")",
"if",
"'templates'",
"not",
"in",
"cfg",
":",
"home",
"=",
"os",
".",
"path",
".",
"expanduser",
"(",
"\"~\"",
")",
"rcfile",
"=",
"os",
".",
"path",
".",
"... | Get path to the folder where th HTML templates are. | [
"Get",
"path",
"to",
"the",
"folder",
"where",
"th",
"HTML",
"templates",
"are",
"."
] | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/utils.py#L143-L153 |
42,394 | MartinThoma/hwrt | hwrt/utils.py | get_database_config_file | def get_database_config_file():
"""Get the absolute path to the database configuration file."""
cfg = get_project_configuration()
if 'dbconfig' in cfg:
if os.path.isfile(cfg['dbconfig']):
return cfg['dbconfig']
else:
logging.info("File '%s' was not found. Adjust 'dbco... | python | def get_database_config_file():
"""Get the absolute path to the database configuration file."""
cfg = get_project_configuration()
if 'dbconfig' in cfg:
if os.path.isfile(cfg['dbconfig']):
return cfg['dbconfig']
else:
logging.info("File '%s' was not found. Adjust 'dbco... | [
"def",
"get_database_config_file",
"(",
")",
":",
"cfg",
"=",
"get_project_configuration",
"(",
")",
"if",
"'dbconfig'",
"in",
"cfg",
":",
"if",
"os",
".",
"path",
".",
"isfile",
"(",
"cfg",
"[",
"'dbconfig'",
"]",
")",
":",
"return",
"cfg",
"[",
"'dbcon... | Get the absolute path to the database configuration file. | [
"Get",
"the",
"absolute",
"path",
"to",
"the",
"database",
"configuration",
"file",
"."
] | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/utils.py#L192-L205 |
42,395 | MartinThoma/hwrt | hwrt/utils.py | get_database_configuration | def get_database_configuration():
"""Get database configuration as dictionary."""
db_config = get_database_config_file()
if db_config is None:
return None
with open(db_config, 'r') as ymlfile:
cfg = yaml.load(ymlfile)
return cfg | python | def get_database_configuration():
"""Get database configuration as dictionary."""
db_config = get_database_config_file()
if db_config is None:
return None
with open(db_config, 'r') as ymlfile:
cfg = yaml.load(ymlfile)
return cfg | [
"def",
"get_database_configuration",
"(",
")",
":",
"db_config",
"=",
"get_database_config_file",
"(",
")",
"if",
"db_config",
"is",
"None",
":",
"return",
"None",
"with",
"open",
"(",
"db_config",
",",
"'r'",
")",
"as",
"ymlfile",
":",
"cfg",
"=",
"yaml",
... | Get database configuration as dictionary. | [
"Get",
"database",
"configuration",
"as",
"dictionary",
"."
] | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/utils.py#L208-L215 |
42,396 | MartinThoma/hwrt | hwrt/utils.py | input_int_default | def input_int_default(question="", default=0):
"""A function that works for both, Python 2.x and Python 3.x.
It asks the user for input and returns it as a string.
"""
answer = input_string(question)
if answer == "" or answer == "yes":
return default
else:
return int(answer) | python | def input_int_default(question="", default=0):
"""A function that works for both, Python 2.x and Python 3.x.
It asks the user for input and returns it as a string.
"""
answer = input_string(question)
if answer == "" or answer == "yes":
return default
else:
return int(answer) | [
"def",
"input_int_default",
"(",
"question",
"=",
"\"\"",
",",
"default",
"=",
"0",
")",
":",
"answer",
"=",
"input_string",
"(",
"question",
")",
"if",
"answer",
"==",
"\"\"",
"or",
"answer",
"==",
"\"yes\"",
":",
"return",
"default",
"else",
":",
"retu... | A function that works for both, Python 2.x and Python 3.x.
It asks the user for input and returns it as a string. | [
"A",
"function",
"that",
"works",
"for",
"both",
"Python",
"2",
".",
"x",
"and",
"Python",
"3",
".",
"x",
".",
"It",
"asks",
"the",
"user",
"for",
"input",
"and",
"returns",
"it",
"as",
"a",
"string",
"."
] | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/utils.py#L236-L244 |
42,397 | MartinThoma/hwrt | hwrt/utils.py | create_run_logfile | def create_run_logfile(folder):
"""Create a 'run.log' within folder. This file contains the time of the
latest successful run.
"""
with open(os.path.join(folder, "run.log"), "w") as f:
datestring = datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S")
f.write("timestamp: '%s'" % da... | python | def create_run_logfile(folder):
"""Create a 'run.log' within folder. This file contains the time of the
latest successful run.
"""
with open(os.path.join(folder, "run.log"), "w") as f:
datestring = datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S")
f.write("timestamp: '%s'" % da... | [
"def",
"create_run_logfile",
"(",
"folder",
")",
":",
"with",
"open",
"(",
"os",
".",
"path",
".",
"join",
"(",
"folder",
",",
"\"run.log\"",
")",
",",
"\"w\"",
")",
"as",
"f",
":",
"datestring",
"=",
"datetime",
".",
"datetime",
".",
"utcnow",
"(",
... | Create a 'run.log' within folder. This file contains the time of the
latest successful run. | [
"Create",
"a",
"run",
".",
"log",
"within",
"folder",
".",
"This",
"file",
"contains",
"the",
"time",
"of",
"the",
"latest",
"successful",
"run",
"."
] | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/utils.py#L317-L323 |
42,398 | MartinThoma/hwrt | hwrt/utils.py | choose_raw_dataset | def choose_raw_dataset(currently=""):
"""Let the user choose a raw dataset. Return the absolute path."""
folder = os.path.join(get_project_root(), "raw-datasets")
files = [os.path.join(folder, name) for name in os.listdir(folder)
if name.endswith(".pickle")]
default = -1
for i, filename... | python | def choose_raw_dataset(currently=""):
"""Let the user choose a raw dataset. Return the absolute path."""
folder = os.path.join(get_project_root(), "raw-datasets")
files = [os.path.join(folder, name) for name in os.listdir(folder)
if name.endswith(".pickle")]
default = -1
for i, filename... | [
"def",
"choose_raw_dataset",
"(",
"currently",
"=",
"\"\"",
")",
":",
"folder",
"=",
"os",
".",
"path",
".",
"join",
"(",
"get_project_root",
"(",
")",
",",
"\"raw-datasets\"",
")",
"files",
"=",
"[",
"os",
".",
"path",
".",
"join",
"(",
"folder",
",",... | Let the user choose a raw dataset. Return the absolute path. | [
"Let",
"the",
"user",
"choose",
"a",
"raw",
"dataset",
".",
"Return",
"the",
"absolute",
"path",
"."
] | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/utils.py#L326-L340 |
42,399 | MartinThoma/hwrt | hwrt/utils.py | get_readable_time | def get_readable_time(t):
"""
Format the time to a readable format.
Parameters
----------
t : int
Time in ms
Returns
-------
string
The time splitted to highest used time (minutes, hours, ...)
"""
ms = t % 1000
t -= ms
t /= 1000
s = t % 60
t -= ... | python | def get_readable_time(t):
"""
Format the time to a readable format.
Parameters
----------
t : int
Time in ms
Returns
-------
string
The time splitted to highest used time (minutes, hours, ...)
"""
ms = t % 1000
t -= ms
t /= 1000
s = t % 60
t -= ... | [
"def",
"get_readable_time",
"(",
"t",
")",
":",
"ms",
"=",
"t",
"%",
"1000",
"t",
"-=",
"ms",
"t",
"/=",
"1000",
"s",
"=",
"t",
"%",
"60",
"t",
"-=",
"s",
"t",
"/=",
"60",
"minutes",
"=",
"t",
"%",
"60",
"t",
"-=",
"minutes",
"t",
"/=",
"60... | Format the time to a readable format.
Parameters
----------
t : int
Time in ms
Returns
-------
string
The time splitted to highest used time (minutes, hours, ...) | [
"Format",
"the",
"time",
"to",
"a",
"readable",
"format",
"."
] | 725c21a3d0f5a30b8492cbc184b3688ceb364e1c | https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/utils.py#L343-L376 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.