"""simple docstring"""







_a	:	List[str]=					[
    ["""ab-e1""", """ac-e3""", """ad-e5""", """bc-e4""", """bd-e2""", """be-e6""", """bh-e12""", """cd-e2""", """ce-e4""",
     """de-e1""", """df-e8""", """dg-e5""", """dh-e10""", """ef-e3""", """eg-e2""", """fg-e6""", """gh-e6""", """hi-e3"""],
    ["""ab-e1""", """ac-e3""", """ad-e5""", """bc-e4""", """bd-e2""", """be-e6""", """cd-e2""", """de-e1""", """df-e8""",
     """ef-e3""", """eg-e2""", """fg-e6"""],
    ["""ab-e1""", """ac-e3""", """bc-e4""", """bd-e2""", """de-e1""", """df-e8""", """dg-e5""", """ef-e3""", """eg-e2""",
     """eh-e12""", """fg-e6""", """fh-e10""", """gh-e6"""],
    ["""ab-e1""", """ac-e3""", """bc-e4""", """bd-e2""", """bh-e12""", """cd-e2""", """df-e8""", """dh-e10"""],
    ["""ab-e1""", """ac-e3""", """ad-e5""", """bc-e4""", """bd-e2""", """cd-e2""", """ce-e4""", """de-e1""", """df-e8""",
     """dg-e5""", """ef-e3""", """eg-e2""", """fg-e6"""]
]
def     __UpperCAmelCase							(       UpperCAmelCase_       :							Any    )				->     List[Any]:

	'''simple docstring'''





	__snake_case     :				List[Any] 						=					set()
	for row in edge_array:
		for item in row:
			distinct_edge.add(item[0]    )
	return list(UpperCAmelCase_    )
def     __UpperCAmelCase							(       UpperCAmelCase_       :							Optional[Any]     ,				UpperCAmelCase_       :							List[Any]    )				->     Any:

	'''simple docstring'''





	__snake_case     :				Dict 						=					['0'] * len(UpperCAmelCase_    )
	for i, row in enumerate(UpperCAmelCase_    ):
		for item in row:
			if distinct_edge in item[0]:
				__snake_case     :				Dict 						=					'1'
				break
	return "".join(UpperCAmelCase_    )
def     __UpperCAmelCase							(       UpperCAmelCase_       :							Any    )				->     Any:

	'''simple docstring'''





	__snake_case     :				List[Any] 						=					get_distinct_edge(UpperCAmelCase_    )
	__snake_case     :				Tuple 						=					{}

	for item in distinct_edge:
		__snake_case     :				Dict 						=					get_bitcode(UpperCAmelCase_     ,				UpperCAmelCase_    )
		# print('bit',bit)
		# bt=''.join(bit)
		__snake_case     :				List[Any] 						=					bit.count('1'    )
		__snake_case     :				Optional[Any] 						=					[s, bit]
	# Store [Distinct edge, WT(Bitcode), Bitcode] in descending order
	__snake_case     :				Dict 						=					[
	    [k, v[0], v[1]]
	    for k, v in sorted(frequency_table.items()     ,				key=lambda UpperCAmelCase_    : v[1][0]     ,				reverse=UpperCAmelCase_    )
	]
	return sorted_frequency_table
def     __UpperCAmelCase							(       UpperCAmelCase_       :							Tuple    )				->     List[str]:

	'''simple docstring'''





	__snake_case     :				Optional[Any] 						=					{}
	for _, item in enumerate(UpperCAmelCase_    ):
		nodes.setdefault(item[2]     ,				[]    ).append(item[0]    )
	return nodes
def     __UpperCAmelCase							(       UpperCAmelCase_       :							int    )				->     Union[str, Any]:

	'''simple docstring'''





	__snake_case     :				Optional[int] 						=					{}
	for key, value in nodes.items():
		__snake_case     :				Optional[Any] 						=					value
	return cluster
def     __UpperCAmelCase							(       UpperCAmelCase_       :							str    )				->     List[str]:

	'''simple docstring'''





	return [i * 1_00 / len(UpperCAmelCase_    ) for i in cluster]
def     __UpperCAmelCase							(       )				->     int:

	'''simple docstring'''





	print('\nNodes\n'    )
	for key, value in nodes.items():
		print(UpperCAmelCase_     ,				UpperCAmelCase_    )
	print('\nSupport\n'    )
	print(UpperCAmelCase_    )
	print('\n Cluster \n'    )
	for key, value in sorted(cluster.items()     ,				reverse=UpperCAmelCase_    ):
		print(UpperCAmelCase_     ,				UpperCAmelCase_    )
	print('\n Graph\n'    )
	for key, value in graph.items():
		print(UpperCAmelCase_     ,				UpperCAmelCase_    )
	print('\n Edge List of Frequent subgraphs \n'    )
	for edge_list in freq_subgraph_edge_list:
		print(UpperCAmelCase_    )
def     __UpperCAmelCase							(       UpperCAmelCase_       :							Union[str, Any]     ,				UpperCAmelCase_       :							Optional[int]     ,				UpperCAmelCase_       :							int     ,				UpperCAmelCase_       :							Union[str, Any]    )				->     List[str]:

	'''simple docstring'''





	for i in cluster[ca]:
		__snake_case     :				Union[str, Any] 						=					0
		__snake_case     :				Dict 						=					ca + 1
		while ca < max(cluster.keys()    ):
			for j in cluster[ca]:
				if int(UpperCAmelCase_     ,				2    ) & int(UpperCAmelCase_     ,				2    ) == int(UpperCAmelCase_     ,				2    ):
					if tuple(nodes[i]    ) in graph:
						graph[tuple(nodes[i]    )].append(nodes[j]    )
					else:
						__snake_case     :				str 						=					[nodes[j]]
					count += 1
			if count == 0:
				__snake_case     :				str 						=					ca + 1
			else:
				break
def     __UpperCAmelCase							(       UpperCAmelCase_       :							List[str]     ,				UpperCAmelCase_       :							Dict    )				->     List[Any]:

	'''simple docstring'''





	__snake_case     :				Optional[Any] 						=					cluster[max(cluster.keys()    )]
	__snake_case     :				int 						=					'Header'
	__snake_case     :				int 						=					{}
	for i in x:
		if (["Header"],) in graph:
			graph[(["Header"],)].append(x[i]    )
		else:
			__snake_case     :				Optional[int] 						=					[x[i]]
	for i in x:
		__snake_case     :				Union[str, Any] 						=					[['Header']]
	__snake_case     :				Tuple 						=					1
	while i < max(UpperCAmelCase_    ) - 1:
		create_edge(UpperCAmelCase_     ,				UpperCAmelCase_     ,				UpperCAmelCase_     ,				UpperCAmelCase_    )
		__snake_case     :				Optional[int] 						=					i + 1
	return graph
def     __UpperCAmelCase							(       UpperCAmelCase_       :							Optional[Any]     ,				UpperCAmelCase_       :							Optional[Any]     ,				UpperCAmelCase_       :							List[str]     ,				UpperCAmelCase_       :							Optional[int]=None    )				->     Any:

	'''simple docstring'''





	__snake_case     :				int 						=					(path or []) + [start]
	if start == end:
		paths.append(UpperCAmelCase_    )
	for node in graph[start]:
		if tuple(UpperCAmelCase_    ) not in path:
			my_dfs(UpperCAmelCase_     ,				tuple(UpperCAmelCase_    )     ,				UpperCAmelCase_     ,				UpperCAmelCase_    )
def     __UpperCAmelCase							(       UpperCAmelCase_       :							Union[str, Any]     ,				UpperCAmelCase_       :							Union[str, Any]     ,				UpperCAmelCase_       :							Tuple    )				->     List[Any]:

	'''simple docstring'''





	__snake_case     :				str 						=					int(s / 1_00 * (len(UpperCAmelCase_    ) - 1)    )
	for i in cluster[k]:
		my_dfs(UpperCAmelCase_     ,				tuple(cluster[k][i]    )     ,				(['Header'],)    )
def     __UpperCAmelCase							(       UpperCAmelCase_       :							Union[str, Any]    )				->     int:

	'''simple docstring'''





	__snake_case     :				List[Any] 						=					[]
	for edges in paths:
		__snake_case     :				int 						=					[]
		for j in range(len(UpperCAmelCase_    ) - 1    ):
			__snake_case     :				Optional[Any] 						=					list(edges[j]    )
			for e in temp:
				__snake_case     :				int 						=					(e[0], e[1])
				el.append(UpperCAmelCase_    )
		freq_sub_el.append(UpperCAmelCase_    )
	return freq_sub_el
def     __UpperCAmelCase							(       UpperCAmelCase_       :							Tuple    )				->     List[str]:

	'''simple docstring'''





	for i in range(len(UpperCAmelCase_    )    ):
		for j in range(len(edge_array[i]    )    ):
			__snake_case     :				Dict 						=					edge_array[i][j].split('-'    )
			__snake_case     :				Optional[Any] 						=					t


if __name__ == "__main__":
	preprocess(edge_array)
	_a	:	Optional[int]=					get_frequency_table(edge_array)
	_a	:	Any=					get_nodes(frequency_table)
	_a	:	Any=					get_cluster(nodes)
	_a	:	Dict=					get_support(cluster)
	_a	:	Union[str, Any]=					construct_graph(cluster, nodes)
	find_freq_subgraph_given_support(60, cluster, graph)
	_a	:	list=					[]
	_a	:	Optional[Any]=					freq_subgraphs_edge_list(paths)
	print_all()









"""simple docstring"""







import unittest

from datasets import load_dataset

from transformers import load_tool

from .test_tools_common import ToolTesterMixin






class  __A							(			unittest.TestCase,       _SCREAMING_SNAKE_CASE     ):






 """simple docstring"""




 def  SCREAMING_SNAKE_CASE				(						self		)   ->	str:
     a											=load_tool('''document-question-answering'''		)
     self.tool.setup()
     a											=load_tool('''document-question-answering'''					,       remote=__A		)


 def  SCREAMING_SNAKE_CASE				(						self		)   ->	Optional[Any]:
     a											=load_dataset('''hf-internal-testing/example-documents'''					,       split='''test'''		)
     a											=dataset[0]['''image''']

     a											=self.tool(__A					,       '''When is the coffee break?'''		)
     self.assertEqual(__A					,       '''11-14 to 11:39 a.m.'''		)


 def  SCREAMING_SNAKE_CASE				(						self		)   ->	Optional[int]:
     a											=load_dataset('''hf-internal-testing/example-documents'''					,       split='''test'''		)
     a											=dataset[0]['''image''']

     a											=self.remote_tool(__A					,       '''When is the coffee break?'''		)
     self.assertEqual(__A					,       '''11-14 to 11:39 a.m.'''		)


 def  SCREAMING_SNAKE_CASE				(						self		)   ->	Union[str, Any]:
     a											=load_dataset('''hf-internal-testing/example-documents'''					,       split='''test'''		)
     a											=dataset[0]['''image''']

     self.tool(document=__A					,       question='''When is the coffee break?'''		)





 def  SCREAMING_SNAKE_CASE				(						self		)   ->	Optional[int]:
     a											=load_dataset('''hf-internal-testing/example-documents'''					,       split='''test'''		)
     a											=dataset[0]['''image''']

     a											=self.remote_tool(document=__A					,       question='''When is the coffee break?'''		)
     self.assertEqual(__A					,       '''11-14 to 11:39 a.m.'''		)