code: def build_graph_from_queries(
      queries,
      transaction,
      concept_dict_converter=concept_dict_to_networkx,
  ):
      """
      Builds a graph of Things, interconnected by _roles_ and _has_ edges, from a set of Query objects
  
      Args:
          queries: An iterable of Query objects
          transaction: A TypeDB transaction
          concept_dict_converter: The function to use to convert from concept_dicts to a TypeDB model. This could be
              a typical model or a mathematical model
  
      Returns:
          A networkx graph
      """
  
      query_concept_graphs = []
  
      for query in queries:
          print("Working on query: " + query.string)
          concept_maps = transaction.query().match(query.string)
          print("Query completed")
  
          concept_dicts = [
              concept_dict_from_concept_map(concept_map)
              for concept_map in concept_maps
          ]
          print("Constructed concept_dicts")
  
          answer_concept_graphs = []
          for concept_dict in concept_dicts:
              try:
                  answer_concept_graphs.append(
                      concept_dict_converter(concept_dict, query.graph)
                  )
              except ValueError as e:
                  raise ValueError(
                      str(e)
                      + f'Encountered processing query:\n "{query.string}"'
                  )
  
          if len(answer_concept_graphs) > 1:
              query_concept_graph = combine_n_graphs(
                  answer_concept_graphs
              )
              query_concept_graphs.append(query_concept_graph)
          else:
              if len(answer_concept_graphs) > 0:
                  query_concept_graphs.append(answer_concept_graphs[0])
              else:
                  warnings.warn(
                      f'There were no results for query: \n"{query}"\nand so nothing will be added to the '
                      f"graph for this query"
                  )
  
      if len(query_concept_graphs) == 0:
          # Raise exception when none of the queries returned any results
          raise RuntimeError(
              f"The graph from queries: "
              f"{[query.string for query in queries]}\n"
              f"could not be created, since none of these queries returned results"
          )
  
      concept_graph = combine_n_graphs(query_concept_graphs)
      return concept_graph
  
file_path: typedb-ml/typedb_ml/networkx/queries_to_networkx.py
imports: import warnings
  from functools import reduce
  import networkx
  from typedb_ml.typedb.thing import build_thing
  from typedb_ml.networkx.concept_dict_to_networkx import concept_dict_to_networkx
label_desc: Use image node_id 1 for calling a global function with example usage: build_graph_from_queries(queries, transaction, concept_dict_converter) and returns: concept_graph