Ejemplo n.º 1
0
def visualize_related_nodes(path, tag, outp_title):
    """Construct the knowledge graph limited to the ancestors and descendants of a given node.
    Useful for understanding the bottleneck scores.

    path -- the location of the content, e.g. knoweldge-maps/content
    tag -- the tag to find ancestors and descendants of
    dot_file -- the output .dot file
    svg_file -- the output .svg file
    """
    dot_file = '%s.dot' % outp_title
    svg_file = '%s.svg' % outp_title
    json_file = '%s.json' % outp_title

    nodes = formats.read_nodes(path)  # TODO should we always read all nodes?
    nodes = graphs.remove_missing_links(nodes)
    graph = graphs.Graph.from_node_dependencies(nodes)

    ancestors = graphs.ancestors_set(nodes, graph, tag)
    descendants = graphs.descendants_set(nodes, graph, tag)
    relevant = set([tag]).union(ancestors).union(descendants)
    nodes = {tag: node for tag, node in nodes.items() if tag in relevant}
    nodes = graphs.remove_missing_links(nodes)
    graph = graphs.Graph.from_node_dependencies(nodes)

    formats.write_graph_dot(nodes, graph, open(dot_file, 'w'))
    os.system('dot -Tsvg %s -o %s' % (dot_file, svg_file))
    formats.write_graph_json(nodes, graph, open(json_file, 'w'))
Ejemplo n.º 2
0
def visualize_related_nodes(path, tag, outp_title):
    """Construct the knowledge graph limited to the ancestors and descendants of a given node.
    Useful for understanding the bottleneck scores.

    path -- the location of the content, e.g. knoweldge-maps/content
    tag -- the tag to find ancestors and descendants of
    dot_file -- the output .dot file
    svg_file -- the output .svg file
    """
    dot_file = '%s.dot' % outp_title
    svg_file = '%s.svg' % outp_title
    json_file = '%s.json' % outp_title
    
    nodes = formats.read_nodes(path) # TODO should we always read all nodes?
    nodes = graphs.remove_missing_links(nodes)
    graph = graphs.Graph.from_node_dependencies(nodes)

    ancestors = graphs.ancestors_set(nodes, graph, tag)
    descendants = graphs.descendants_set(nodes, graph, tag)
    relevant = set([tag]).union(ancestors).union(descendants)
    nodes = {tag: node for tag, node in nodes.items() if tag in relevant}
    nodes = graphs.remove_missing_links(nodes)
    graph = graphs.Graph.from_node_dependencies(nodes)
    
    formats.write_graph_dot(nodes, graph, open(dot_file, 'w'))
    os.system('dot -Tsvg %s -o %s' % (dot_file, svg_file))
    formats.write_graph_json(nodes, graph, open(json_file, 'w'))
Ejemplo n.º 3
0
 def load(content_dir):
     nodes = read_nodes(content_dir)
     nodes = graphs.remove_missing_links(nodes)
     shortcuts = read_shortcuts(content_dir, nodes)
     graph = graphs.Graph.from_node_and_shortcut_dependencies(nodes, shortcuts)
     resource_dict = resources.read_resources_file(resources.resource_db_path())
     id2tag = dict([(node.id, tag) for tag, node in nodes.items()
                    if node.id is not None])
     tag2id = dict([(tag, node.id) for tag, node in nodes.items()
                    if node.id is not None])
     flags = read_flags(content_dir)
     concept_times, shortcut_times = read_time_estimates(content_dir)
     return Database(nodes, shortcuts, graph, resource_dict, id2tag, tag2id, flags,
                     concept_times, shortcut_times)
Ejemplo n.º 4
0
 def load(content_dir):
     nodes = read_nodes(content_dir)
     nodes = graphs.remove_missing_links(nodes)
     shortcuts = read_shortcuts(content_dir, nodes)
     graph = graphs.Graph.from_node_and_shortcut_dependencies(nodes, shortcuts)
     resource_dict = resources.read_resources_file(resources.resource_db_path())
     id2tag = dict([(node.id, tag) for tag, node in nodes.items()
                    if node.id is not None])
     tag2id = dict([(tag, node.id) for tag, node in nodes.items()
                    if node.id is not None])
     flags = read_flags(content_dir)
     concept_times, shortcut_times = read_time_estimates(content_dir)
     return Database(nodes, shortcuts, graph, resource_dict, id2tag, tag2id, flags,
                     concept_times, shortcut_times)
Ejemplo n.º 5
0
def generate_full_graph(path, outp_title):
    """Construct the full knowledge graph.

    path -- the location of the content, e.g. knoweldge-maps/content
    dot_file -- the output .dot file
    svg_file -- the output .svg file
    """
    dot_file = '%s.dot' % outp_title
    svg_file = '%s.svg' % outp_title
    json_file = '%s.json' % outp_title

    nodes = formats.read_nodes(path)
    nodes = graphs.remove_missing_links(nodes)
    graph = graphs.Graph.from_node_dependencies(nodes)

    formats.write_graph_dot(nodes, graph, open(dot_file, 'w'))
    os.system('dot -Tsvg %s -o %s' % (dot_file, svg_file))
    formats.write_graph_json(nodes, graph, open(json_file, 'w'))
Ejemplo n.º 6
0
def generate_full_graph(path, outp_title):
    """Construct the full knowledge graph.

    path -- the location of the content, e.g. knoweldge-maps/content
    dot_file -- the output .dot file
    svg_file -- the output .svg file
    """
    dot_file = '%s.dot' % outp_title
    svg_file = '%s.svg' % outp_title
    json_file = '%s.json' % outp_title
    
    nodes = formats.read_nodes(path)
    nodes = graphs.remove_missing_links(nodes)
    graph = graphs.Graph.from_node_dependencies(nodes)

    formats.write_graph_dot(nodes, graph, open(dot_file, 'w'))
    os.system('dot -Tsvg %s -o %s' % (dot_file, svg_file))
    formats.write_graph_json(nodes, graph, open(json_file, 'w'))