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 listlengths 20 707 | docstring stringlengths 3 17.3k | docstring_tokens listlengths 3 222 | sha stringlengths 40 40 | url stringlengths 87 242 | partition stringclasses 1
value | idx int64 0 252k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
jciskey/pygraph | pygraph/functions/biconnected_components.py | find_biconnected_components | def find_biconnected_components(graph):
"""Finds all the biconnected components in a graph.
Returns a list of lists, each containing the edges that form a biconnected component.
Returns an empty list for an empty graph.
"""
list_of_components = []
# Run the algorithm on each of the connected c... | python | def find_biconnected_components(graph):
"""Finds all the biconnected components in a graph.
Returns a list of lists, each containing the edges that form a biconnected component.
Returns an empty list for an empty graph.
"""
list_of_components = []
# Run the algorithm on each of the connected c... | [
"def",
"find_biconnected_components",
"(",
"graph",
")",
":",
"list_of_components",
"=",
"[",
"]",
"# Run the algorithm on each of the connected components of the graph",
"components",
"=",
"get_connected_components_as_subgraphs",
"(",
"graph",
")",
"for",
"component",
"in",
... | Finds all the biconnected components in a graph.
Returns a list of lists, each containing the edges that form a biconnected component.
Returns an empty list for an empty graph. | [
"Finds",
"all",
"the",
"biconnected",
"components",
"in",
"a",
"graph",
".",
"Returns",
"a",
"list",
"of",
"lists",
"each",
"containing",
"the",
"edges",
"that",
"form",
"a",
"biconnected",
"component",
".",
"Returns",
"an",
"empty",
"list",
"for",
"an",
"... | 037bb2f32503fecb60d62921f9766d54109f15e2 | https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/functions/biconnected_components.py#L9-L25 | train | 59,200 |
jciskey/pygraph | pygraph/functions/biconnected_components.py | find_biconnected_components_as_subgraphs | def find_biconnected_components_as_subgraphs(graph):
"""Finds the biconnected components and returns them as subgraphs."""
list_of_graphs = []
list_of_components = find_biconnected_components(graph)
for edge_list in list_of_components:
subgraph = get_subgraph_from_edge_list(graph, edge_list)
... | python | def find_biconnected_components_as_subgraphs(graph):
"""Finds the biconnected components and returns them as subgraphs."""
list_of_graphs = []
list_of_components = find_biconnected_components(graph)
for edge_list in list_of_components:
subgraph = get_subgraph_from_edge_list(graph, edge_list)
... | [
"def",
"find_biconnected_components_as_subgraphs",
"(",
"graph",
")",
":",
"list_of_graphs",
"=",
"[",
"]",
"list_of_components",
"=",
"find_biconnected_components",
"(",
"graph",
")",
"for",
"edge_list",
"in",
"list_of_components",
":",
"subgraph",
"=",
"get_subgraph_f... | Finds the biconnected components and returns them as subgraphs. | [
"Finds",
"the",
"biconnected",
"components",
"and",
"returns",
"them",
"as",
"subgraphs",
"."
] | 037bb2f32503fecb60d62921f9766d54109f15e2 | https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/functions/biconnected_components.py#L28-L37 | train | 59,201 |
jciskey/pygraph | pygraph/functions/biconnected_components.py | find_articulation_vertices | def find_articulation_vertices(graph):
"""Finds all of the articulation vertices within a graph.
Returns a list of all articulation vertices within the graph.
Returns an empty list for an empty graph.
"""
articulation_vertices = []
all_nodes = graph.get_all_node_ids()
if len(all_nodes) == ... | python | def find_articulation_vertices(graph):
"""Finds all of the articulation vertices within a graph.
Returns a list of all articulation vertices within the graph.
Returns an empty list for an empty graph.
"""
articulation_vertices = []
all_nodes = graph.get_all_node_ids()
if len(all_nodes) == ... | [
"def",
"find_articulation_vertices",
"(",
"graph",
")",
":",
"articulation_vertices",
"=",
"[",
"]",
"all_nodes",
"=",
"graph",
".",
"get_all_node_ids",
"(",
")",
"if",
"len",
"(",
"all_nodes",
")",
"==",
"0",
":",
"return",
"articulation_vertices",
"# Run the a... | Finds all of the articulation vertices within a graph.
Returns a list of all articulation vertices within the graph.
Returns an empty list for an empty graph. | [
"Finds",
"all",
"of",
"the",
"articulation",
"vertices",
"within",
"a",
"graph",
".",
"Returns",
"a",
"list",
"of",
"all",
"articulation",
"vertices",
"within",
"the",
"graph",
".",
"Returns",
"an",
"empty",
"list",
"for",
"an",
"empty",
"graph",
"."
] | 037bb2f32503fecb60d62921f9766d54109f15e2 | https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/functions/biconnected_components.py#L40-L60 | train | 59,202 |
jciskey/pygraph | pygraph/functions/biconnected_components.py | output_component | def output_component(graph, edge_stack, u, v):
"""Helper function to pop edges off the stack and produce a list of them."""
edge_list = []
while len(edge_stack) > 0:
edge_id = edge_stack.popleft()
edge_list.append(edge_id)
edge = graph.get_edge(edge_id)
tpl_a = (u, v)
... | python | def output_component(graph, edge_stack, u, v):
"""Helper function to pop edges off the stack and produce a list of them."""
edge_list = []
while len(edge_stack) > 0:
edge_id = edge_stack.popleft()
edge_list.append(edge_id)
edge = graph.get_edge(edge_id)
tpl_a = (u, v)
... | [
"def",
"output_component",
"(",
"graph",
",",
"edge_stack",
",",
"u",
",",
"v",
")",
":",
"edge_list",
"=",
"[",
"]",
"while",
"len",
"(",
"edge_stack",
")",
">",
"0",
":",
"edge_id",
"=",
"edge_stack",
".",
"popleft",
"(",
")",
"edge_list",
".",
"ap... | Helper function to pop edges off the stack and produce a list of them. | [
"Helper",
"function",
"to",
"pop",
"edges",
"off",
"the",
"stack",
"and",
"produce",
"a",
"list",
"of",
"them",
"."
] | 037bb2f32503fecb60d62921f9766d54109f15e2 | https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/functions/biconnected_components.py#L179-L192 | train | 59,203 |
jciskey/pygraph | pygraph/functions/searching/depth_first_search.py | depth_first_search_with_parent_data | def depth_first_search_with_parent_data(graph, root_node = None, adjacency_lists = None):
"""Performs a depth-first search with visiting order of nodes determined by provided adjacency lists,
and also returns a parent lookup dict and a children lookup dict."""
ordering = []
parent_lookup = {}
child... | python | def depth_first_search_with_parent_data(graph, root_node = None, adjacency_lists = None):
"""Performs a depth-first search with visiting order of nodes determined by provided adjacency lists,
and also returns a parent lookup dict and a children lookup dict."""
ordering = []
parent_lookup = {}
child... | [
"def",
"depth_first_search_with_parent_data",
"(",
"graph",
",",
"root_node",
"=",
"None",
",",
"adjacency_lists",
"=",
"None",
")",
":",
"ordering",
"=",
"[",
"]",
"parent_lookup",
"=",
"{",
"}",
"children_lookup",
"=",
"defaultdict",
"(",
"lambda",
":",
"[",... | Performs a depth-first search with visiting order of nodes determined by provided adjacency lists,
and also returns a parent lookup dict and a children lookup dict. | [
"Performs",
"a",
"depth",
"-",
"first",
"search",
"with",
"visiting",
"order",
"of",
"nodes",
"determined",
"by",
"provided",
"adjacency",
"lists",
"and",
"also",
"returns",
"a",
"parent",
"lookup",
"dict",
"and",
"a",
"children",
"lookup",
"dict",
"."
] | 037bb2f32503fecb60d62921f9766d54109f15e2 | https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/functions/searching/depth_first_search.py#L15-L72 | train | 59,204 |
jciskey/pygraph | pygraph/render.py | graph_to_dot | def graph_to_dot(graph, node_renderer=None, edge_renderer=None):
"""Produces a DOT specification string from the provided graph."""
node_pairs = list(graph.nodes.items())
edge_pairs = list(graph.edges.items())
if node_renderer is None:
node_renderer_wrapper = lambda nid: ''
else:
no... | python | def graph_to_dot(graph, node_renderer=None, edge_renderer=None):
"""Produces a DOT specification string from the provided graph."""
node_pairs = list(graph.nodes.items())
edge_pairs = list(graph.edges.items())
if node_renderer is None:
node_renderer_wrapper = lambda nid: ''
else:
no... | [
"def",
"graph_to_dot",
"(",
"graph",
",",
"node_renderer",
"=",
"None",
",",
"edge_renderer",
"=",
"None",
")",
":",
"node_pairs",
"=",
"list",
"(",
"graph",
".",
"nodes",
".",
"items",
"(",
")",
")",
"edge_pairs",
"=",
"list",
"(",
"graph",
".",
"edge... | Produces a DOT specification string from the provided graph. | [
"Produces",
"a",
"DOT",
"specification",
"string",
"from",
"the",
"provided",
"graph",
"."
] | 037bb2f32503fecb60d62921f9766d54109f15e2 | https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/render.py#L4-L32 | train | 59,205 |
jciskey/pygraph | pygraph/functions/connected_components.py | get_connected_components | def get_connected_components(graph):
"""Finds all connected components of the graph.
Returns a list of lists, each containing the nodes that form a connected component.
Returns an empty list for an empty graph.
"""
list_of_components = []
component = [] # Not strictly necessary due to the whil... | python | def get_connected_components(graph):
"""Finds all connected components of the graph.
Returns a list of lists, each containing the nodes that form a connected component.
Returns an empty list for an empty graph.
"""
list_of_components = []
component = [] # Not strictly necessary due to the whil... | [
"def",
"get_connected_components",
"(",
"graph",
")",
":",
"list_of_components",
"=",
"[",
"]",
"component",
"=",
"[",
"]",
"# Not strictly necessary due to the while loop structure, but it helps the automated analysis tools",
"# Store a list of all unreached vertices",
"unreached",
... | Finds all connected components of the graph.
Returns a list of lists, each containing the nodes that form a connected component.
Returns an empty list for an empty graph. | [
"Finds",
"all",
"connected",
"components",
"of",
"the",
"graph",
".",
"Returns",
"a",
"list",
"of",
"lists",
"each",
"containing",
"the",
"nodes",
"that",
"form",
"a",
"connected",
"component",
".",
"Returns",
"an",
"empty",
"list",
"for",
"an",
"empty",
"... | 037bb2f32503fecb60d62921f9766d54109f15e2 | https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/functions/connected_components.py#L8-L41 | train | 59,206 |
jciskey/pygraph | pygraph/functions/connected_components.py | get_connected_components_as_subgraphs | def get_connected_components_as_subgraphs(graph):
"""Finds all connected components of the graph.
Returns a list of graph objects, each representing a connected component.
Returns an empty list for an empty graph.
"""
components = get_connected_components(graph)
list_of_graphs = []
for c i... | python | def get_connected_components_as_subgraphs(graph):
"""Finds all connected components of the graph.
Returns a list of graph objects, each representing a connected component.
Returns an empty list for an empty graph.
"""
components = get_connected_components(graph)
list_of_graphs = []
for c i... | [
"def",
"get_connected_components_as_subgraphs",
"(",
"graph",
")",
":",
"components",
"=",
"get_connected_components",
"(",
"graph",
")",
"list_of_graphs",
"=",
"[",
"]",
"for",
"c",
"in",
"components",
":",
"edge_ids",
"=",
"set",
"(",
")",
"nodes",
"=",
"[",... | Finds all connected components of the graph.
Returns a list of graph objects, each representing a connected component.
Returns an empty list for an empty graph. | [
"Finds",
"all",
"connected",
"components",
"of",
"the",
"graph",
".",
"Returns",
"a",
"list",
"of",
"graph",
"objects",
"each",
"representing",
"a",
"connected",
"component",
".",
"Returns",
"an",
"empty",
"list",
"for",
"an",
"empty",
"graph",
"."
] | 037bb2f32503fecb60d62921f9766d54109f15e2 | https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/functions/connected_components.py#L44-L69 | train | 59,207 |
jciskey/pygraph | pygraph/classes/undirected_graph.py | UndirectedGraph.new_edge | def new_edge(self, node_a, node_b, cost=1):
"""Adds a new, undirected edge between node_a and node_b with a cost.
Returns the edge id of the new edge."""
edge_id = super(UndirectedGraph, self).new_edge(node_a, node_b, cost)
self.nodes[node_b]['edges'].append(edge_id)
return edge_... | python | def new_edge(self, node_a, node_b, cost=1):
"""Adds a new, undirected edge between node_a and node_b with a cost.
Returns the edge id of the new edge."""
edge_id = super(UndirectedGraph, self).new_edge(node_a, node_b, cost)
self.nodes[node_b]['edges'].append(edge_id)
return edge_... | [
"def",
"new_edge",
"(",
"self",
",",
"node_a",
",",
"node_b",
",",
"cost",
"=",
"1",
")",
":",
"edge_id",
"=",
"super",
"(",
"UndirectedGraph",
",",
"self",
")",
".",
"new_edge",
"(",
"node_a",
",",
"node_b",
",",
"cost",
")",
"self",
".",
"nodes",
... | Adds a new, undirected edge between node_a and node_b with a cost.
Returns the edge id of the new edge. | [
"Adds",
"a",
"new",
"undirected",
"edge",
"between",
"node_a",
"and",
"node_b",
"with",
"a",
"cost",
".",
"Returns",
"the",
"edge",
"id",
"of",
"the",
"new",
"edge",
"."
] | 037bb2f32503fecb60d62921f9766d54109f15e2 | https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/classes/undirected_graph.py#L20-L25 | train | 59,208 |
jciskey/pygraph | pygraph/classes/undirected_graph.py | UndirectedGraph.delete_edge_by_id | def delete_edge_by_id(self, edge_id):
"""Removes the edge identified by "edge_id" from the graph."""
edge = self.get_edge(edge_id)
# Remove the edge from the "from node"
# --Determine the from node
from_node_id = edge['vertices'][0]
from_node = self.get_node(from_node_id... | python | def delete_edge_by_id(self, edge_id):
"""Removes the edge identified by "edge_id" from the graph."""
edge = self.get_edge(edge_id)
# Remove the edge from the "from node"
# --Determine the from node
from_node_id = edge['vertices'][0]
from_node = self.get_node(from_node_id... | [
"def",
"delete_edge_by_id",
"(",
"self",
",",
"edge_id",
")",
":",
"edge",
"=",
"self",
".",
"get_edge",
"(",
"edge_id",
")",
"# Remove the edge from the \"from node\"",
"# --Determine the from node",
"from_node_id",
"=",
"edge",
"[",
"'vertices'",
"]",
"[",
"0",
... | Removes the edge identified by "edge_id" from the graph. | [
"Removes",
"the",
"edge",
"identified",
"by",
"edge_id",
"from",
"the",
"graph",
"."
] | 037bb2f32503fecb60d62921f9766d54109f15e2 | https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/classes/undirected_graph.py#L40-L62 | train | 59,209 |
jciskey/pygraph | pygraph/functions/spanning_tree.py | find_minimum_spanning_tree | def find_minimum_spanning_tree(graph):
"""Calculates a minimum spanning tree for a graph.
Returns a list of edges that define the tree.
Returns an empty list for an empty graph.
"""
mst = []
if graph.num_nodes() == 0:
return mst
if graph.num_edges() == 0:
return mst
con... | python | def find_minimum_spanning_tree(graph):
"""Calculates a minimum spanning tree for a graph.
Returns a list of edges that define the tree.
Returns an empty list for an empty graph.
"""
mst = []
if graph.num_nodes() == 0:
return mst
if graph.num_edges() == 0:
return mst
con... | [
"def",
"find_minimum_spanning_tree",
"(",
"graph",
")",
":",
"mst",
"=",
"[",
"]",
"if",
"graph",
".",
"num_nodes",
"(",
")",
"==",
"0",
":",
"return",
"mst",
"if",
"graph",
".",
"num_edges",
"(",
")",
"==",
"0",
":",
"return",
"mst",
"connected_compon... | Calculates a minimum spanning tree for a graph.
Returns a list of edges that define the tree.
Returns an empty list for an empty graph. | [
"Calculates",
"a",
"minimum",
"spanning",
"tree",
"for",
"a",
"graph",
".",
"Returns",
"a",
"list",
"of",
"edges",
"that",
"define",
"the",
"tree",
".",
"Returns",
"an",
"empty",
"list",
"for",
"an",
"empty",
"graph",
"."
] | 037bb2f32503fecb60d62921f9766d54109f15e2 | https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/functions/spanning_tree.py#L8-L26 | train | 59,210 |
jciskey/pygraph | pygraph/functions/spanning_tree.py | find_minimum_spanning_tree_as_subgraph | def find_minimum_spanning_tree_as_subgraph(graph):
"""Calculates a minimum spanning tree and returns a graph representation."""
edge_list = find_minimum_spanning_tree(graph)
subgraph = get_subgraph_from_edge_list(graph, edge_list)
return subgraph | python | def find_minimum_spanning_tree_as_subgraph(graph):
"""Calculates a minimum spanning tree and returns a graph representation."""
edge_list = find_minimum_spanning_tree(graph)
subgraph = get_subgraph_from_edge_list(graph, edge_list)
return subgraph | [
"def",
"find_minimum_spanning_tree_as_subgraph",
"(",
"graph",
")",
":",
"edge_list",
"=",
"find_minimum_spanning_tree",
"(",
"graph",
")",
"subgraph",
"=",
"get_subgraph_from_edge_list",
"(",
"graph",
",",
"edge_list",
")",
"return",
"subgraph"
] | Calculates a minimum spanning tree and returns a graph representation. | [
"Calculates",
"a",
"minimum",
"spanning",
"tree",
"and",
"returns",
"a",
"graph",
"representation",
"."
] | 037bb2f32503fecb60d62921f9766d54109f15e2 | https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/functions/spanning_tree.py#L29-L34 | train | 59,211 |
jciskey/pygraph | pygraph/functions/spanning_tree.py | find_minimum_spanning_forest | def find_minimum_spanning_forest(graph):
"""Calculates the minimum spanning forest of a disconnected graph.
Returns a list of lists, each containing the edges that define that tree.
Returns an empty list for an empty graph.
"""
msf = []
if graph.num_nodes() == 0:
return msf
if graph... | python | def find_minimum_spanning_forest(graph):
"""Calculates the minimum spanning forest of a disconnected graph.
Returns a list of lists, each containing the edges that define that tree.
Returns an empty list for an empty graph.
"""
msf = []
if graph.num_nodes() == 0:
return msf
if graph... | [
"def",
"find_minimum_spanning_forest",
"(",
"graph",
")",
":",
"msf",
"=",
"[",
"]",
"if",
"graph",
".",
"num_nodes",
"(",
")",
"==",
"0",
":",
"return",
"msf",
"if",
"graph",
".",
"num_edges",
"(",
")",
"==",
"0",
":",
"return",
"msf",
"connected_comp... | Calculates the minimum spanning forest of a disconnected graph.
Returns a list of lists, each containing the edges that define that tree.
Returns an empty list for an empty graph. | [
"Calculates",
"the",
"minimum",
"spanning",
"forest",
"of",
"a",
"disconnected",
"graph",
".",
"Returns",
"a",
"list",
"of",
"lists",
"each",
"containing",
"the",
"edges",
"that",
"define",
"that",
"tree",
".",
"Returns",
"an",
"empty",
"list",
"for",
"an",
... | 037bb2f32503fecb60d62921f9766d54109f15e2 | https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/functions/spanning_tree.py#L37-L54 | train | 59,212 |
jciskey/pygraph | pygraph/functions/spanning_tree.py | find_minimum_spanning_forest_as_subgraphs | def find_minimum_spanning_forest_as_subgraphs(graph):
"""Calculates the minimum spanning forest and returns a list of trees as subgraphs."""
forest = find_minimum_spanning_forest(graph)
list_of_subgraphs = [get_subgraph_from_edge_list(graph, edge_list) for edge_list in forest]
return list_of_subgraphs | python | def find_minimum_spanning_forest_as_subgraphs(graph):
"""Calculates the minimum spanning forest and returns a list of trees as subgraphs."""
forest = find_minimum_spanning_forest(graph)
list_of_subgraphs = [get_subgraph_from_edge_list(graph, edge_list) for edge_list in forest]
return list_of_subgraphs | [
"def",
"find_minimum_spanning_forest_as_subgraphs",
"(",
"graph",
")",
":",
"forest",
"=",
"find_minimum_spanning_forest",
"(",
"graph",
")",
"list_of_subgraphs",
"=",
"[",
"get_subgraph_from_edge_list",
"(",
"graph",
",",
"edge_list",
")",
"for",
"edge_list",
"in",
"... | Calculates the minimum spanning forest and returns a list of trees as subgraphs. | [
"Calculates",
"the",
"minimum",
"spanning",
"forest",
"and",
"returns",
"a",
"list",
"of",
"trees",
"as",
"subgraphs",
"."
] | 037bb2f32503fecb60d62921f9766d54109f15e2 | https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/functions/spanning_tree.py#L57-L62 | train | 59,213 |
jciskey/pygraph | pygraph/functions/spanning_tree.py | kruskal_mst | def kruskal_mst(graph):
"""Implements Kruskal's Algorithm for finding minimum spanning trees.
Assumes a non-empty, connected graph.
"""
edges_accepted = 0
ds = DisjointSet()
pq = PriorityQueue()
accepted_edges = []
label_lookup = {}
nodes = graph.get_all_node_ids()
num_vertices ... | python | def kruskal_mst(graph):
"""Implements Kruskal's Algorithm for finding minimum spanning trees.
Assumes a non-empty, connected graph.
"""
edges_accepted = 0
ds = DisjointSet()
pq = PriorityQueue()
accepted_edges = []
label_lookup = {}
nodes = graph.get_all_node_ids()
num_vertices ... | [
"def",
"kruskal_mst",
"(",
"graph",
")",
":",
"edges_accepted",
"=",
"0",
"ds",
"=",
"DisjointSet",
"(",
")",
"pq",
"=",
"PriorityQueue",
"(",
")",
"accepted_edges",
"=",
"[",
"]",
"label_lookup",
"=",
"{",
"}",
"nodes",
"=",
"graph",
".",
"get_all_node_... | Implements Kruskal's Algorithm for finding minimum spanning trees.
Assumes a non-empty, connected graph. | [
"Implements",
"Kruskal",
"s",
"Algorithm",
"for",
"finding",
"minimum",
"spanning",
"trees",
".",
"Assumes",
"a",
"non",
"-",
"empty",
"connected",
"graph",
"."
] | 037bb2f32503fecb60d62921f9766d54109f15e2 | https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/functions/spanning_tree.py#L65-L101 | train | 59,214 |
jciskey/pygraph | pygraph/functions/planarity/lipton-tarjan_algorithm.py | __get_cycle | def __get_cycle(graph, ordering, parent_lookup):
"""Gets the main cycle of the dfs tree."""
root_node = ordering[0]
for i in range(2, len(ordering)):
current_node = ordering[i]
if graph.adjacent(current_node, root_node):
path = []
while current_node != root_node:
... | python | def __get_cycle(graph, ordering, parent_lookup):
"""Gets the main cycle of the dfs tree."""
root_node = ordering[0]
for i in range(2, len(ordering)):
current_node = ordering[i]
if graph.adjacent(current_node, root_node):
path = []
while current_node != root_node:
... | [
"def",
"__get_cycle",
"(",
"graph",
",",
"ordering",
",",
"parent_lookup",
")",
":",
"root_node",
"=",
"ordering",
"[",
"0",
"]",
"for",
"i",
"in",
"range",
"(",
"2",
",",
"len",
"(",
"ordering",
")",
")",
":",
"current_node",
"=",
"ordering",
"[",
"... | Gets the main cycle of the dfs tree. | [
"Gets",
"the",
"main",
"cycle",
"of",
"the",
"dfs",
"tree",
"."
] | 037bb2f32503fecb60d62921f9766d54109f15e2 | https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/functions/planarity/lipton-tarjan_algorithm.py#L3-L15 | train | 59,215 |
jciskey/pygraph | pygraph/functions/planarity/lipton-tarjan_algorithm.py | __get_segments_from_node | def __get_segments_from_node(node, graph):
"""Calculates the segments that can emanate from a particular node on the main cycle."""
list_of_segments = []
node_object = graph.get_node(node)
for e in node_object['edges']:
list_of_segments.append(e)
return list_of_segments | python | def __get_segments_from_node(node, graph):
"""Calculates the segments that can emanate from a particular node on the main cycle."""
list_of_segments = []
node_object = graph.get_node(node)
for e in node_object['edges']:
list_of_segments.append(e)
return list_of_segments | [
"def",
"__get_segments_from_node",
"(",
"node",
",",
"graph",
")",
":",
"list_of_segments",
"=",
"[",
"]",
"node_object",
"=",
"graph",
".",
"get_node",
"(",
"node",
")",
"for",
"e",
"in",
"node_object",
"[",
"'edges'",
"]",
":",
"list_of_segments",
".",
"... | Calculates the segments that can emanate from a particular node on the main cycle. | [
"Calculates",
"the",
"segments",
"that",
"can",
"emanate",
"from",
"a",
"particular",
"node",
"on",
"the",
"main",
"cycle",
"."
] | 037bb2f32503fecb60d62921f9766d54109f15e2 | https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/functions/planarity/lipton-tarjan_algorithm.py#L18-L24 | train | 59,216 |
jciskey/pygraph | pygraph/functions/planarity/lipton-tarjan_algorithm.py | __get_segments_from_cycle | def __get_segments_from_cycle(graph, cycle_path):
"""Calculates the segments that emanate from the main cycle."""
list_of_segments = []
# We work through the cycle in a bottom-up fashion
for n in cycle_path[::-1]:
segments = __get_segments_from_node(n, graph)
if segments:
lis... | python | def __get_segments_from_cycle(graph, cycle_path):
"""Calculates the segments that emanate from the main cycle."""
list_of_segments = []
# We work through the cycle in a bottom-up fashion
for n in cycle_path[::-1]:
segments = __get_segments_from_node(n, graph)
if segments:
lis... | [
"def",
"__get_segments_from_cycle",
"(",
"graph",
",",
"cycle_path",
")",
":",
"list_of_segments",
"=",
"[",
"]",
"# We work through the cycle in a bottom-up fashion",
"for",
"n",
"in",
"cycle_path",
"[",
":",
":",
"-",
"1",
"]",
":",
"segments",
"=",
"__get_segme... | Calculates the segments that emanate from the main cycle. | [
"Calculates",
"the",
"segments",
"that",
"emanate",
"from",
"the",
"main",
"cycle",
"."
] | 037bb2f32503fecb60d62921f9766d54109f15e2 | https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/functions/planarity/lipton-tarjan_algorithm.py#L27-L36 | train | 59,217 |
jciskey/pygraph | pygraph/helpers/functions.py | make_subgraph | def make_subgraph(graph, vertices, edges):
"""Converts a subgraph given by a list of vertices and edges into a graph object."""
# Copy the entire graph
local_graph = copy.deepcopy(graph)
# Remove all the edges that aren't in the list
edges_to_delete = [x for x in local_graph.get_all_edge_ids() if x... | python | def make_subgraph(graph, vertices, edges):
"""Converts a subgraph given by a list of vertices and edges into a graph object."""
# Copy the entire graph
local_graph = copy.deepcopy(graph)
# Remove all the edges that aren't in the list
edges_to_delete = [x for x in local_graph.get_all_edge_ids() if x... | [
"def",
"make_subgraph",
"(",
"graph",
",",
"vertices",
",",
"edges",
")",
":",
"# Copy the entire graph",
"local_graph",
"=",
"copy",
".",
"deepcopy",
"(",
"graph",
")",
"# Remove all the edges that aren't in the list",
"edges_to_delete",
"=",
"[",
"x",
"for",
"x",
... | Converts a subgraph given by a list of vertices and edges into a graph object. | [
"Converts",
"a",
"subgraph",
"given",
"by",
"a",
"list",
"of",
"vertices",
"and",
"edges",
"into",
"a",
"graph",
"object",
"."
] | 037bb2f32503fecb60d62921f9766d54109f15e2 | https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/helpers/functions.py#L11-L26 | train | 59,218 |
jciskey/pygraph | pygraph/helpers/functions.py | convert_graph_directed_to_undirected | def convert_graph_directed_to_undirected(dg):
"""Converts a directed graph into an undirected graph. Directed edges are made undirected."""
udg = UndirectedGraph()
# Copy the graph
# --Copy nodes
# --Copy edges
udg.nodes = copy.deepcopy(dg.nodes)
udg.edges = copy.deepcopy(dg.edges)
udg... | python | def convert_graph_directed_to_undirected(dg):
"""Converts a directed graph into an undirected graph. Directed edges are made undirected."""
udg = UndirectedGraph()
# Copy the graph
# --Copy nodes
# --Copy edges
udg.nodes = copy.deepcopy(dg.nodes)
udg.edges = copy.deepcopy(dg.edges)
udg... | [
"def",
"convert_graph_directed_to_undirected",
"(",
"dg",
")",
":",
"udg",
"=",
"UndirectedGraph",
"(",
")",
"# Copy the graph",
"# --Copy nodes",
"# --Copy edges",
"udg",
".",
"nodes",
"=",
"copy",
".",
"deepcopy",
"(",
"dg",
".",
"nodes",
")",
"udg",
".",
"e... | Converts a directed graph into an undirected graph. Directed edges are made undirected. | [
"Converts",
"a",
"directed",
"graph",
"into",
"an",
"undirected",
"graph",
".",
"Directed",
"edges",
"are",
"made",
"undirected",
"."
] | 037bb2f32503fecb60d62921f9766d54109f15e2 | https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/helpers/functions.py#L29-L49 | train | 59,219 |
jciskey/pygraph | pygraph/helpers/functions.py | remove_duplicate_edges_directed | def remove_duplicate_edges_directed(dg):
"""Removes duplicate edges from a directed graph."""
# With directed edges, we can just hash the to and from node id tuples and if
# a node happens to conflict with one that already exists, we delete it
# --For aesthetic, we sort the edge ids so that lower edge ... | python | def remove_duplicate_edges_directed(dg):
"""Removes duplicate edges from a directed graph."""
# With directed edges, we can just hash the to and from node id tuples and if
# a node happens to conflict with one that already exists, we delete it
# --For aesthetic, we sort the edge ids so that lower edge ... | [
"def",
"remove_duplicate_edges_directed",
"(",
"dg",
")",
":",
"# With directed edges, we can just hash the to and from node id tuples and if",
"# a node happens to conflict with one that already exists, we delete it",
"# --For aesthetic, we sort the edge ids so that lower edge ids are kept",
"loo... | Removes duplicate edges from a directed graph. | [
"Removes",
"duplicate",
"edges",
"from",
"a",
"directed",
"graph",
"."
] | 037bb2f32503fecb60d62921f9766d54109f15e2 | https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/helpers/functions.py#L52-L66 | train | 59,220 |
jciskey/pygraph | pygraph/helpers/functions.py | remove_duplicate_edges_undirected | def remove_duplicate_edges_undirected(udg):
"""Removes duplicate edges from an undirected graph."""
# With undirected edges, we need to hash both combinations of the to-from node ids, since a-b and b-a are equivalent
# --For aesthetic, we sort the edge ids so that lower edges ids are kept
lookup = {}
... | python | def remove_duplicate_edges_undirected(udg):
"""Removes duplicate edges from an undirected graph."""
# With undirected edges, we need to hash both combinations of the to-from node ids, since a-b and b-a are equivalent
# --For aesthetic, we sort the edge ids so that lower edges ids are kept
lookup = {}
... | [
"def",
"remove_duplicate_edges_undirected",
"(",
"udg",
")",
":",
"# With undirected edges, we need to hash both combinations of the to-from node ids, since a-b and b-a are equivalent",
"# --For aesthetic, we sort the edge ids so that lower edges ids are kept",
"lookup",
"=",
"{",
"}",
"edge... | Removes duplicate edges from an undirected graph. | [
"Removes",
"duplicate",
"edges",
"from",
"an",
"undirected",
"graph",
"."
] | 037bb2f32503fecb60d62921f9766d54109f15e2 | https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/helpers/functions.py#L69-L83 | train | 59,221 |
jciskey/pygraph | pygraph/helpers/functions.py | get_vertices_from_edge_list | def get_vertices_from_edge_list(graph, edge_list):
"""Transforms a list of edges into a list of the nodes those edges connect.
Returns a list of nodes, or an empty list if given an empty list.
"""
node_set = set()
for edge_id in edge_list:
edge = graph.get_edge(edge_id)
a, b = edge['... | python | def get_vertices_from_edge_list(graph, edge_list):
"""Transforms a list of edges into a list of the nodes those edges connect.
Returns a list of nodes, or an empty list if given an empty list.
"""
node_set = set()
for edge_id in edge_list:
edge = graph.get_edge(edge_id)
a, b = edge['... | [
"def",
"get_vertices_from_edge_list",
"(",
"graph",
",",
"edge_list",
")",
":",
"node_set",
"=",
"set",
"(",
")",
"for",
"edge_id",
"in",
"edge_list",
":",
"edge",
"=",
"graph",
".",
"get_edge",
"(",
"edge_id",
")",
"a",
",",
"b",
"=",
"edge",
"[",
"'v... | Transforms a list of edges into a list of the nodes those edges connect.
Returns a list of nodes, or an empty list if given an empty list. | [
"Transforms",
"a",
"list",
"of",
"edges",
"into",
"a",
"list",
"of",
"the",
"nodes",
"those",
"edges",
"connect",
".",
"Returns",
"a",
"list",
"of",
"nodes",
"or",
"an",
"empty",
"list",
"if",
"given",
"an",
"empty",
"list",
"."
] | 037bb2f32503fecb60d62921f9766d54109f15e2 | https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/helpers/functions.py#L86-L97 | train | 59,222 |
jciskey/pygraph | pygraph/helpers/functions.py | get_subgraph_from_edge_list | def get_subgraph_from_edge_list(graph, edge_list):
"""Transforms a list of edges into a subgraph."""
node_list = get_vertices_from_edge_list(graph, edge_list)
subgraph = make_subgraph(graph, node_list, edge_list)
return subgraph | python | def get_subgraph_from_edge_list(graph, edge_list):
"""Transforms a list of edges into a subgraph."""
node_list = get_vertices_from_edge_list(graph, edge_list)
subgraph = make_subgraph(graph, node_list, edge_list)
return subgraph | [
"def",
"get_subgraph_from_edge_list",
"(",
"graph",
",",
"edge_list",
")",
":",
"node_list",
"=",
"get_vertices_from_edge_list",
"(",
"graph",
",",
"edge_list",
")",
"subgraph",
"=",
"make_subgraph",
"(",
"graph",
",",
"node_list",
",",
"edge_list",
")",
"return",... | Transforms a list of edges into a subgraph. | [
"Transforms",
"a",
"list",
"of",
"edges",
"into",
"a",
"subgraph",
"."
] | 037bb2f32503fecb60d62921f9766d54109f15e2 | https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/helpers/functions.py#L100-L105 | train | 59,223 |
jciskey/pygraph | pygraph/helpers/functions.py | merge_graphs | def merge_graphs(main_graph, addition_graph):
"""Merges an ''addition_graph'' into the ''main_graph''.
Returns a tuple of dictionaries, mapping old node ids and edge ids to new ids.
"""
node_mapping = {}
edge_mapping = {}
for node in addition_graph.get_all_node_objects():
node_id = nod... | python | def merge_graphs(main_graph, addition_graph):
"""Merges an ''addition_graph'' into the ''main_graph''.
Returns a tuple of dictionaries, mapping old node ids and edge ids to new ids.
"""
node_mapping = {}
edge_mapping = {}
for node in addition_graph.get_all_node_objects():
node_id = nod... | [
"def",
"merge_graphs",
"(",
"main_graph",
",",
"addition_graph",
")",
":",
"node_mapping",
"=",
"{",
"}",
"edge_mapping",
"=",
"{",
"}",
"for",
"node",
"in",
"addition_graph",
".",
"get_all_node_objects",
"(",
")",
":",
"node_id",
"=",
"node",
"[",
"'id'",
... | Merges an ''addition_graph'' into the ''main_graph''.
Returns a tuple of dictionaries, mapping old node ids and edge ids to new ids. | [
"Merges",
"an",
"addition_graph",
"into",
"the",
"main_graph",
".",
"Returns",
"a",
"tuple",
"of",
"dictionaries",
"mapping",
"old",
"node",
"ids",
"and",
"edge",
"ids",
"to",
"new",
"ids",
"."
] | 037bb2f32503fecb60d62921f9766d54109f15e2 | https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/helpers/functions.py#L108-L129 | train | 59,224 |
jciskey/pygraph | pygraph/helpers/functions.py | create_graph_from_adjacency_matrix | def create_graph_from_adjacency_matrix(adjacency_matrix):
"""Generates a graph from an adjacency matrix specification.
Returns a tuple containing the graph and a list-mapping of node ids to matrix column indices.
The graph will be an UndirectedGraph if the provided adjacency matrix is symmetric.
... | python | def create_graph_from_adjacency_matrix(adjacency_matrix):
"""Generates a graph from an adjacency matrix specification.
Returns a tuple containing the graph and a list-mapping of node ids to matrix column indices.
The graph will be an UndirectedGraph if the provided adjacency matrix is symmetric.
... | [
"def",
"create_graph_from_adjacency_matrix",
"(",
"adjacency_matrix",
")",
":",
"if",
"is_adjacency_matrix_symmetric",
"(",
"adjacency_matrix",
")",
":",
"graph",
"=",
"UndirectedGraph",
"(",
")",
"else",
":",
"graph",
"=",
"DirectedGraph",
"(",
")",
"node_column_mapp... | Generates a graph from an adjacency matrix specification.
Returns a tuple containing the graph and a list-mapping of node ids to matrix column indices.
The graph will be an UndirectedGraph if the provided adjacency matrix is symmetric.
The graph will be a DirectedGraph if the provided adjacency ma... | [
"Generates",
"a",
"graph",
"from",
"an",
"adjacency",
"matrix",
"specification",
".",
"Returns",
"a",
"tuple",
"containing",
"the",
"graph",
"and",
"a",
"list",
"-",
"mapping",
"of",
"node",
"ids",
"to",
"matrix",
"column",
"indices",
"."
] | 037bb2f32503fecb60d62921f9766d54109f15e2 | https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/helpers/functions.py#L132-L160 | train | 59,225 |
jciskey/pygraph | pygraph/helpers/classes/disjoint_set.py | DisjointSet.add_set | def add_set(self):
"""Adds a new set to the forest.
Returns a label by which the new set can be referenced
"""
self.__label_counter += 1
new_label = self.__label_counter
self.__forest[new_label] = -1 # All new sets have their parent set to themselves
self.__set_c... | python | def add_set(self):
"""Adds a new set to the forest.
Returns a label by which the new set can be referenced
"""
self.__label_counter += 1
new_label = self.__label_counter
self.__forest[new_label] = -1 # All new sets have their parent set to themselves
self.__set_c... | [
"def",
"add_set",
"(",
"self",
")",
":",
"self",
".",
"__label_counter",
"+=",
"1",
"new_label",
"=",
"self",
".",
"__label_counter",
"self",
".",
"__forest",
"[",
"new_label",
"]",
"=",
"-",
"1",
"# All new sets have their parent set to themselves",
"self",
"."... | Adds a new set to the forest.
Returns a label by which the new set can be referenced | [
"Adds",
"a",
"new",
"set",
"to",
"the",
"forest",
".",
"Returns",
"a",
"label",
"by",
"which",
"the",
"new",
"set",
"can",
"be",
"referenced"
] | 037bb2f32503fecb60d62921f9766d54109f15e2 | https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/helpers/classes/disjoint_set.py#L21-L29 | train | 59,226 |
jciskey/pygraph | pygraph/helpers/classes/disjoint_set.py | DisjointSet.find | def find(self, node_label):
"""Finds the set containing the node_label.
Returns the set label.
"""
queue = []
current_node = node_label
while self.__forest[current_node] >= 0:
queue.append(current_node)
current_node = self.__forest[current_node]
... | python | def find(self, node_label):
"""Finds the set containing the node_label.
Returns the set label.
"""
queue = []
current_node = node_label
while self.__forest[current_node] >= 0:
queue.append(current_node)
current_node = self.__forest[current_node]
... | [
"def",
"find",
"(",
"self",
",",
"node_label",
")",
":",
"queue",
"=",
"[",
"]",
"current_node",
"=",
"node_label",
"while",
"self",
".",
"__forest",
"[",
"current_node",
"]",
">=",
"0",
":",
"queue",
".",
"append",
"(",
"current_node",
")",
"current_nod... | Finds the set containing the node_label.
Returns the set label. | [
"Finds",
"the",
"set",
"containing",
"the",
"node_label",
".",
"Returns",
"the",
"set",
"label",
"."
] | 037bb2f32503fecb60d62921f9766d54109f15e2 | https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/helpers/classes/disjoint_set.py#L31-L46 | train | 59,227 |
jciskey/pygraph | pygraph/helpers/classes/disjoint_set.py | DisjointSet.union | def union(self, label_a, label_b):
"""Joins two sets into a single new set.
label_a, label_b can be any nodes within the sets
"""
# Base case to avoid work
if label_a == label_b:
return
# Find the tree root of each node
root_a = self.find(label_a)
... | python | def union(self, label_a, label_b):
"""Joins two sets into a single new set.
label_a, label_b can be any nodes within the sets
"""
# Base case to avoid work
if label_a == label_b:
return
# Find the tree root of each node
root_a = self.find(label_a)
... | [
"def",
"union",
"(",
"self",
",",
"label_a",
",",
"label_b",
")",
":",
"# Base case to avoid work",
"if",
"label_a",
"==",
"label_b",
":",
"return",
"# Find the tree root of each node",
"root_a",
"=",
"self",
".",
"find",
"(",
"label_a",
")",
"root_b",
"=",
"s... | Joins two sets into a single new set.
label_a, label_b can be any nodes within the sets | [
"Joins",
"two",
"sets",
"into",
"a",
"single",
"new",
"set",
".",
"label_a",
"label_b",
"can",
"be",
"any",
"nodes",
"within",
"the",
"sets"
] | 037bb2f32503fecb60d62921f9766d54109f15e2 | https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/helpers/classes/disjoint_set.py#L48-L65 | train | 59,228 |
jciskey/pygraph | pygraph/helpers/classes/disjoint_set.py | DisjointSet.__internal_union | def __internal_union(self, root_a, root_b):
"""Internal function to join two set trees specified by root_a and root_b.
Assumes root_a and root_b are distinct.
"""
# Merge the trees, smaller to larger
update_rank = False
# --Determine the larger tree
rank_a = self.... | python | def __internal_union(self, root_a, root_b):
"""Internal function to join two set trees specified by root_a and root_b.
Assumes root_a and root_b are distinct.
"""
# Merge the trees, smaller to larger
update_rank = False
# --Determine the larger tree
rank_a = self.... | [
"def",
"__internal_union",
"(",
"self",
",",
"root_a",
",",
"root_b",
")",
":",
"# Merge the trees, smaller to larger",
"update_rank",
"=",
"False",
"# --Determine the larger tree",
"rank_a",
"=",
"self",
".",
"__forest",
"[",
"root_a",
"]",
"rank_b",
"=",
"self",
... | Internal function to join two set trees specified by root_a and root_b.
Assumes root_a and root_b are distinct. | [
"Internal",
"function",
"to",
"join",
"two",
"set",
"trees",
"specified",
"by",
"root_a",
"and",
"root_b",
".",
"Assumes",
"root_a",
"and",
"root_b",
"are",
"distinct",
"."
] | 037bb2f32503fecb60d62921f9766d54109f15e2 | https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/helpers/classes/disjoint_set.py#L67-L88 | train | 59,229 |
jciskey/pygraph | pygraph/functions/planarity/functions.py | is_planar | def is_planar(graph):
"""Determines whether a graph is planar or not."""
# Determine connected components as subgraphs; their planarity is independent of each other
connected_components = get_connected_components_as_subgraphs(graph)
for component in connected_components:
# Biconnected components... | python | def is_planar(graph):
"""Determines whether a graph is planar or not."""
# Determine connected components as subgraphs; their planarity is independent of each other
connected_components = get_connected_components_as_subgraphs(graph)
for component in connected_components:
# Biconnected components... | [
"def",
"is_planar",
"(",
"graph",
")",
":",
"# Determine connected components as subgraphs; their planarity is independent of each other",
"connected_components",
"=",
"get_connected_components_as_subgraphs",
"(",
"graph",
")",
"for",
"component",
"in",
"connected_components",
":",... | Determines whether a graph is planar or not. | [
"Determines",
"whether",
"a",
"graph",
"is",
"planar",
"or",
"not",
"."
] | 037bb2f32503fecb60d62921f9766d54109f15e2 | https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/functions/planarity/functions.py#L9-L20 | train | 59,230 |
jciskey/pygraph | pygraph/functions/planarity/functions.py | __is_subgraph_planar | def __is_subgraph_planar(graph):
"""Internal function to determine if a subgraph is planar."""
# --First pass: Determine edge and vertex counts validate Euler's Formula
num_nodes = graph.num_nodes()
num_edges = graph.num_edges()
# --We can guarantee that if there are 4 or less nodes, then the graph... | python | def __is_subgraph_planar(graph):
"""Internal function to determine if a subgraph is planar."""
# --First pass: Determine edge and vertex counts validate Euler's Formula
num_nodes = graph.num_nodes()
num_edges = graph.num_edges()
# --We can guarantee that if there are 4 or less nodes, then the graph... | [
"def",
"__is_subgraph_planar",
"(",
"graph",
")",
":",
"# --First pass: Determine edge and vertex counts validate Euler's Formula",
"num_nodes",
"=",
"graph",
".",
"num_nodes",
"(",
")",
"num_edges",
"=",
"graph",
".",
"num_edges",
"(",
")",
"# --We can guarantee that if th... | Internal function to determine if a subgraph is planar. | [
"Internal",
"function",
"to",
"determine",
"if",
"a",
"subgraph",
"is",
"planar",
"."
] | 037bb2f32503fecb60d62921f9766d54109f15e2 | https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/functions/planarity/functions.py#L23-L39 | train | 59,231 |
jciskey/pygraph | pygraph/functions/planarity/kocay_algorithm.py | __setup_dfs_data | def __setup_dfs_data(graph, adj):
"""Sets up the dfs_data object, for consistency."""
dfs_data = __get_dfs_data(graph, adj)
dfs_data['graph'] = graph
dfs_data['adj'] = adj
L1, L2 = __low_point_dfs(dfs_data)
dfs_data['lowpoint_1_lookup'] = L1
dfs_data['lowpoint_2_lookup'] = L2
edge_wei... | python | def __setup_dfs_data(graph, adj):
"""Sets up the dfs_data object, for consistency."""
dfs_data = __get_dfs_data(graph, adj)
dfs_data['graph'] = graph
dfs_data['adj'] = adj
L1, L2 = __low_point_dfs(dfs_data)
dfs_data['lowpoint_1_lookup'] = L1
dfs_data['lowpoint_2_lookup'] = L2
edge_wei... | [
"def",
"__setup_dfs_data",
"(",
"graph",
",",
"adj",
")",
":",
"dfs_data",
"=",
"__get_dfs_data",
"(",
"graph",
",",
"adj",
")",
"dfs_data",
"[",
"'graph'",
"]",
"=",
"graph",
"dfs_data",
"[",
"'adj'",
"]",
"=",
"adj",
"L1",
",",
"L2",
"=",
"__low_poin... | Sets up the dfs_data object, for consistency. | [
"Sets",
"up",
"the",
"dfs_data",
"object",
"for",
"consistency",
"."
] | 037bb2f32503fecb60d62921f9766d54109f15e2 | https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/functions/planarity/kocay_algorithm.py#L45-L59 | train | 59,232 |
jciskey/pygraph | pygraph/functions/planarity/kocay_algorithm.py | __calculate_edge_weights | def __calculate_edge_weights(dfs_data):
"""Calculates the weight of each edge, for embedding-order sorting."""
graph = dfs_data['graph']
weights = {}
for edge_id in graph.get_all_edge_ids():
edge_weight = __edge_weight(edge_id, dfs_data)
weights[edge_id] = edge_weight
return weight... | python | def __calculate_edge_weights(dfs_data):
"""Calculates the weight of each edge, for embedding-order sorting."""
graph = dfs_data['graph']
weights = {}
for edge_id in graph.get_all_edge_ids():
edge_weight = __edge_weight(edge_id, dfs_data)
weights[edge_id] = edge_weight
return weight... | [
"def",
"__calculate_edge_weights",
"(",
"dfs_data",
")",
":",
"graph",
"=",
"dfs_data",
"[",
"'graph'",
"]",
"weights",
"=",
"{",
"}",
"for",
"edge_id",
"in",
"graph",
".",
"get_all_edge_ids",
"(",
")",
":",
"edge_weight",
"=",
"__edge_weight",
"(",
"edge_id... | Calculates the weight of each edge, for embedding-order sorting. | [
"Calculates",
"the",
"weight",
"of",
"each",
"edge",
"for",
"embedding",
"-",
"order",
"sorting",
"."
] | 037bb2f32503fecb60d62921f9766d54109f15e2 | https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/functions/planarity/kocay_algorithm.py#L68-L77 | train | 59,233 |
jciskey/pygraph | pygraph/functions/planarity/kocay_algorithm.py | __sort_adjacency_lists | def __sort_adjacency_lists(dfs_data):
"""Sorts the adjacency list representation by the edge weights."""
new_adjacency_lists = {}
adjacency_lists = dfs_data['adj']
edge_weights = dfs_data['edge_weights']
edge_lookup = dfs_data['edge_lookup']
for node_id, adj_list in list(adjacency_lists.items(... | python | def __sort_adjacency_lists(dfs_data):
"""Sorts the adjacency list representation by the edge weights."""
new_adjacency_lists = {}
adjacency_lists = dfs_data['adj']
edge_weights = dfs_data['edge_weights']
edge_lookup = dfs_data['edge_lookup']
for node_id, adj_list in list(adjacency_lists.items(... | [
"def",
"__sort_adjacency_lists",
"(",
"dfs_data",
")",
":",
"new_adjacency_lists",
"=",
"{",
"}",
"adjacency_lists",
"=",
"dfs_data",
"[",
"'adj'",
"]",
"edge_weights",
"=",
"dfs_data",
"[",
"'edge_weights'",
"]",
"edge_lookup",
"=",
"dfs_data",
"[",
"'edge_lookup... | Sorts the adjacency list representation by the edge weights. | [
"Sorts",
"the",
"adjacency",
"list",
"representation",
"by",
"the",
"edge",
"weights",
"."
] | 037bb2f32503fecb60d62921f9766d54109f15e2 | https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/functions/planarity/kocay_algorithm.py#L80-L105 | train | 59,234 |
jciskey/pygraph | pygraph/functions/planarity/kocay_algorithm.py | __branch_point_dfs_recursive | def __branch_point_dfs_recursive(u, large_n, b, stem, dfs_data):
"""A recursive implementation of the BranchPtDFS function, as defined on page 14 of the paper."""
first_vertex = dfs_data['adj'][u][0]
large_w = wt(u, first_vertex, dfs_data)
if large_w % 2 == 0:
large_w += 1
v_I = 0
v_II =... | python | def __branch_point_dfs_recursive(u, large_n, b, stem, dfs_data):
"""A recursive implementation of the BranchPtDFS function, as defined on page 14 of the paper."""
first_vertex = dfs_data['adj'][u][0]
large_w = wt(u, first_vertex, dfs_data)
if large_w % 2 == 0:
large_w += 1
v_I = 0
v_II =... | [
"def",
"__branch_point_dfs_recursive",
"(",
"u",
",",
"large_n",
",",
"b",
",",
"stem",
",",
"dfs_data",
")",
":",
"first_vertex",
"=",
"dfs_data",
"[",
"'adj'",
"]",
"[",
"u",
"]",
"[",
"0",
"]",
"large_w",
"=",
"wt",
"(",
"u",
",",
"first_vertex",
... | A recursive implementation of the BranchPtDFS function, as defined on page 14 of the paper. | [
"A",
"recursive",
"implementation",
"of",
"the",
"BranchPtDFS",
"function",
"as",
"defined",
"on",
"page",
"14",
"of",
"the",
"paper",
"."
] | 037bb2f32503fecb60d62921f9766d54109f15e2 | https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/functions/planarity/kocay_algorithm.py#L123-L180 | train | 59,235 |
jciskey/pygraph | pygraph/functions/planarity/kocay_algorithm.py | __embed_branch | def __embed_branch(dfs_data):
"""Builds the combinatorial embedding of the graph. Returns whether the graph is planar."""
u = dfs_data['ordering'][0]
dfs_data['LF'] = []
dfs_data['RF'] = []
dfs_data['FG'] = {}
n = dfs_data['graph'].num_nodes()
f0 = (0, n)
g0 = (0, n)
L0 = {'u': 0, 'v... | python | def __embed_branch(dfs_data):
"""Builds the combinatorial embedding of the graph. Returns whether the graph is planar."""
u = dfs_data['ordering'][0]
dfs_data['LF'] = []
dfs_data['RF'] = []
dfs_data['FG'] = {}
n = dfs_data['graph'].num_nodes()
f0 = (0, n)
g0 = (0, n)
L0 = {'u': 0, 'v... | [
"def",
"__embed_branch",
"(",
"dfs_data",
")",
":",
"u",
"=",
"dfs_data",
"[",
"'ordering'",
"]",
"[",
"0",
"]",
"dfs_data",
"[",
"'LF'",
"]",
"=",
"[",
"]",
"dfs_data",
"[",
"'RF'",
"]",
"=",
"[",
"]",
"dfs_data",
"[",
"'FG'",
"]",
"=",
"{",
"}"... | Builds the combinatorial embedding of the graph. Returns whether the graph is planar. | [
"Builds",
"the",
"combinatorial",
"embedding",
"of",
"the",
"graph",
".",
"Returns",
"whether",
"the",
"graph",
"is",
"planar",
"."
] | 037bb2f32503fecb60d62921f9766d54109f15e2 | https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/functions/planarity/kocay_algorithm.py#L183-L209 | train | 59,236 |
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 | train | 59,237 |
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 | train | 59,238 |
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 | train | 59,239 |
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 | train | 59,240 |
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 | train | 59,241 |
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 | train | 59,242 |
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 | train | 59,243 |
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 | train | 59,244 |
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 | train | 59,245 |
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 | train | 59,246 |
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 | train | 59,247 |
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 | train | 59,248 |
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 | train | 59,249 |
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 | train | 59,250 |
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 | train | 59,251 |
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 | train | 59,252 |
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 | train | 59,253 |
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 | train | 59,254 |
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 | train | 59,255 |
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 | train | 59,256 |
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 | train | 59,257 |
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 | train | 59,258 |
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 | train | 59,259 |
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 | train | 59,260 |
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 | train | 59,261 |
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 | train | 59,262 |
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 | train | 59,263 |
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 | train | 59,264 |
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 | train | 59,265 |
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 | train | 59,266 |
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 | train | 59,267 |
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 | train | 59,268 |
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 | train | 59,269 |
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 | train | 59,270 |
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 | train | 59,271 |
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 | train | 59,272 |
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 | train | 59,273 |
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 | train | 59,274 |
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 | train | 59,275 |
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 | train | 59,276 |
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 | train | 59,277 |
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 | train | 59,278 |
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 | train | 59,279 |
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 | train | 59,280 |
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 | train | 59,281 |
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 | train | 59,282 |
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 | train | 59,283 |
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 | train | 59,284 |
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 | train | 59,285 |
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 | train | 59,286 |
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 | train | 59,287 |
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 | train | 59,288 |
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 | train | 59,289 |
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 | train | 59,290 |
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 | train | 59,291 |
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 | train | 59,292 |
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 | train | 59,293 |
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 | train | 59,294 |
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 | train | 59,295 |
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 | train | 59,296 |
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 | train | 59,297 |
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 | train | 59,298 |
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 | train | 59,299 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.