def to_dot(g, stream=sys.stdout, options=None): """ Args: - g (rdflib.graph): RDF graph to transform into `dot` representation - stream (default: sys.stdout | file): Where to write the output Returns: - (graph): `dot` representation of the graph """ digraph = produce_graph.produce_graph(g, options=options) stream.write('digraph g {\n') # draw nodes, i.e. for (node, node_data) in digraph.nodes_iter(data=True): node_str = '"%s" [label="%s"] ;\n' stream.write(node_str % (node, node_data['label'])) for (source, target, edge_data) in digraph.edges_iter(data=True): edge_str = '"%s" -> "%s" [label="%s"] ;\n' stream.write(edge_str % (source, target, edge_data['label'])) stream.write('}\n') return g
def test_is_a_arcs(): options = ['is-a-arcs'] digraph = produce_graph.produce_graph(g, options=options) # is-a arc should be in the digraph is_a_arc = make_is_a_arc() assert graph_utils.is_edge_in_edges(is_a_arc, digraph.edges_iter(data=True)) # existential arc should not be in digraph existential_arc = make_existential_arc() assert not graph_utils.is_edge_in_edges(existential_arc, digraph.edges_iter(data=True))
def sample_unnormalized(): digraph = produce_graph.produce_graph(unnormalized_g, options=['existential-arcs']) return digraph
def make_existential_digraph(): options = ['existential-arcs'] return produce_graph.produce_graph(g, options=options)
def sample_digraph(): return produce_graph.produce_graph(g, options=['existential-arcs'])