当前位置: 首页>>代码示例>>Python>>正文


Python json_graph.tree_data方法代码示例

本文整理汇总了Python中networkx.readwrite.json_graph.tree_data方法的典型用法代码示例。如果您正苦于以下问题:Python json_graph.tree_data方法的具体用法?Python json_graph.tree_data怎么用?Python json_graph.tree_data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在networkx.readwrite.json_graph的用法示例。


在下文中一共展示了json_graph.tree_data方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: create_html

# 需要导入模块: from networkx.readwrite import json_graph [as 别名]
# 或者: from networkx.readwrite.json_graph import tree_data [as 别名]
def create_html(predicted_ids, parent_ids, scores, labels_ids, vocab, filename, output_dir):
    graph = create_graph(
        predicted_ids=predicted_ids,
        parent_ids=parent_ids,
        scores=scores,
        vocab=vocab)

    json_str = json.dumps(json_graph.tree_data(graph, (0, 0)), ensure_ascii=True)

    transcript = [vocab[sym] for sym in labels_ids]
    transcript.remove('EOS')
    transcript = ''.join(transcript)

    output_fname = path.join(output_dir, filename + '.html')
    num_subdirs = filename.count('/')  # too hacky ?

    makedirs(path.dirname(output_fname), exist_ok=True)

    html_str = HTML_TEMPLATE.substitute(DATA=json_str, WALK='../'*num_subdirs, transcript=transcript)

    with open(output_fname, 'w') as f:
        f.write(html_str) 
开发者ID:georgesterpu,项目名称:avsr-tf1,代码行数:24,代码来源:beam_search.py

示例2: as_tree

# 需要导入模块: from networkx.readwrite import json_graph [as 别名]
# 或者: from networkx.readwrite.json_graph import tree_data [as 别名]
def as_tree(graph, root=OPENSTACK_CLUSTER, reverse=False):
        if nx.__version__ >= '2.0':
            linked_graph = json_graph.node_link_graph(
                graph, attrs={'name': 'graph_index'})
        else:
            linked_graph = json_graph.node_link_graph(graph)
        if 0 == nx.number_of_nodes(linked_graph):
            return {}
        if reverse:
            linked_graph = linked_graph.reverse()
        if nx.__version__ >= '2.0':
            return json_graph.tree_data(
                linked_graph,
                root=root,
                attrs={'id': 'graph_index', 'children': 'children'})
        else:
            return json_graph.tree_data(linked_graph, root=root) 
开发者ID:openstack,项目名称:vitrage,代码行数:19,代码来源:topology.py

示例3: generate

# 需要导入模块: from networkx.readwrite import json_graph [as 别名]
# 或者: from networkx.readwrite.json_graph import tree_data [as 别名]
def generate(input_data, output_dir, include_pad=False):

    path_base = os.path.dirname(os.path.realpath(__file__))

    if not os.path.exists(output_dir):
        os.makedirs(output_dir)

    # Copy required files
    shutil.copy2(path_base+"/templates/tree.css", output_dir)
    shutil.copy2(path_base+"/templates/tree.js", output_dir)

    with open(input_data) as beams:
        for i, line in enumerate(beams):
            beam = json.loads(line)

            graph = create_graph(predicted_ids=beam["predicted_tokens"],
                                 parent_ids=beam["parent_ids"],
                                 scores=beam["scores"],
                                 normalized_scores=beam["normalized_scores"],
                                 include_pad=include_pad)

            json_str = json.dumps(
                json_graph.tree_data(graph, (0, 0)),
                ensure_ascii=True)

            html_str = HTML_TEMPLATE.substitute(DATA=json_str, SENT=str(i))
            output_path = os.path.join(output_dir, "{:06d}.html".format(i))
            with open(output_path, "w", encoding="utf-8") as out:
                out.write(html_str)
    print("Output beams written to: {}".format(output_dir)) 
开发者ID:awslabs,项目名称:sockeye,代码行数:32,代码来源:generate_graphs.py

示例4: draw_graph

# 需要导入模块: from networkx.readwrite import json_graph [as 别名]
# 或者: from networkx.readwrite.json_graph import tree_data [as 别名]
def draw_graph(graph):
    from string import Template
    import shutil
    from networkx.readwrite import json_graph
    import json
    
    HTML_TEMPLATE = Template("""
    <!DOCTYPE html>
    <html lang="en">
      <head>
        <meta charset="utf-8">
        <title>Beam Search</title>
        <link rel="stylesheet" type="text/css" href="tree.css">
        <script src="http://d3js.org/d3.v3.min.js"></script>
      </head>
      <body>
        <script>
          var treeData = $DATA
        </script>
        <script src="tree.js"></script>
      </body>
    </html>""")
    
    seq2seq_path = '/scratch/make_build/gram_as_foreight_lang/seq2seq'
    vis_path = base_path+'/vis/graph_beam/'
    os.makedirs(base_path+'/vis/graph_beam/', exist_ok=True)
    shutil.copy2(seq2seq_path+"/bin/tools/beam_search_viz/tree.css", vis_path)
    shutil.copy2(seq2seq_path+"/bin/tools/beam_search_viz/tree.js", vis_path)
    
    json_str = json.dumps(json_graph.tree_data(graph, (0, 0)), ensure_ascii=False)

    html_str = HTML_TEMPLATE.substitute(DATA=json_str)
    output_path = os.path.join(vis_path, "graph.html")
    with open(output_path, "w") as file:
        file.write(html_str)
    print(output_path) 
开发者ID:pandegroup,项目名称:reaction_prediction_seq2seq,代码行数:38,代码来源:top_k_seq2seq.py

示例5: main

# 需要导入模块: from networkx.readwrite import json_graph [as 别名]
# 或者: from networkx.readwrite.json_graph import tree_data [as 别名]
def main():
  beam_data = np.load(ARGS.data)

  # Optionally load vocabulary data
  vocab = None
  if ARGS.vocab:
    with open(ARGS.vocab) as file:
      vocab = file.readlines()
    vocab = [_.strip() for _ in vocab]
    vocab += ["UNK", "SEQUENCE_START", "SEQUENCE_END"]

  if not os.path.exists(ARGS.output_dir):
    os.makedirs(ARGS.output_dir)

  # Copy required files
  shutil.copy2("/home/bowen/pycharm_deployment_directory/synthesis/prototype_models/google_seq2seq/bin/tools/beam_search_viz/tree.css", ARGS.output_dir)
  shutil.copy2("/home/bowen/pycharm_deployment_directory/synthesis/prototype_models/google_seq2seq/bin/tools/beam_search_viz/tree.js", ARGS.output_dir)

  for idx in range(len(beam_data["predicted_ids"])):
    predicted_ids = beam_data["predicted_ids"][idx]
    parent_ids = beam_data["beam_parent_ids"][idx]
    scores = beam_data["scores"][idx]

    graph = create_graph(
        predicted_ids=predicted_ids,
        parent_ids=parent_ids,
        scores=scores,
        vocab=vocab)

    json_str = json.dumps(
        json_graph.tree_data(graph, (0, 0)),
        ensure_ascii=False)

    html_str = HTML_TEMPLATE.substitute(DATA=json_str)
    output_path = os.path.join(ARGS.output_dir, "{:06d}.html".format(idx))
    with open(output_path, "w") as file:
      file.write(html_str)
    print(output_path) 
开发者ID:pandegroup,项目名称:reaction_prediction_seq2seq,代码行数:40,代码来源:generate_beam_viz.py

示例6: main

# 需要导入模块: from networkx.readwrite import json_graph [as 别名]
# 或者: from networkx.readwrite.json_graph import tree_data [as 别名]
def main():
  beam_data = np.load(ARGS.data)

  # Optionally load vocabulary data
  vocab = None
  if ARGS.vocab:
    with open(ARGS.vocab) as file:
      vocab = file.readlines()
    vocab = [_.strip() for _ in vocab]
    vocab += ["UNK", "SEQUENCE_START", "SEQUENCE_END"]

  if not os.path.exists(ARGS.output_dir):
    os.makedirs(ARGS.output_dir)

  # Copy required files
  shutil.copy2("./bin/tools/beam_search_viz/tree.css", ARGS.output_dir)
  shutil.copy2("./bin/tools/beam_search_viz/tree.js", ARGS.output_dir)

  for idx in range(len(beam_data["predicted_ids"])):
    predicted_ids = beam_data["predicted_ids"][idx]
    parent_ids = beam_data["beam_parent_ids"][idx]
    scores = beam_data["scores"][idx]

    graph = create_graph(
        predicted_ids=predicted_ids,
        parent_ids=parent_ids,
        scores=scores,
        vocab=vocab)

    json_str = json.dumps(
        json_graph.tree_data(graph, (0, 0)),
        ensure_ascii=False)

    html_str = HTML_TEMPLATE.substitute(DATA=json_str)
    output_path = os.path.join(ARGS.output_dir, "{:06d}.html".format(idx))
    with open(output_path, "w") as file:
      file.write(html_str)
    print(output_path) 
开发者ID:tobyyouup,项目名称:conv_seq2seq,代码行数:40,代码来源:generate_beam_viz.py


注:本文中的networkx.readwrite.json_graph.tree_data方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。