Skip to content
Snippets Groups Projects
Commit 1333c7ad authored by Aurélien Lamercerie's avatar Aurélien Lamercerie
Browse files

Dot Graph Generation (simple graph)

parent 508975d3
No related branches found
No related tags found
No related merge requests found
...@@ -4,3 +4,6 @@ ...@@ -4,3 +4,6 @@
devtemp*.py devtemp*.py
.project .project
*.ttl.tbc *.ttl.tbc
output/*
*env/*
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
# Importing required modules # Importing required modules
#============================================================================== #==============================================================================
# None import pydot
#============================================================================== #==============================================================================
...@@ -42,6 +42,14 @@ class Graph: ...@@ -42,6 +42,14 @@ class Graph:
res += ")" res += ")"
return res return res
def to_dot_graph(self):
graph = pydot.Dot("My_Graph", graph_type="graph", bgcolor="yellow")
for link in self.link_list:
graph.add_node(link.uw1.to_dot_node())
graph.add_node(link.uw2.to_dot_node())
graph.add_edge(link.to_dot_edge())
return graph
class Link: class Link:
""" link := Link(relation, uw, uw) """ """ link := Link(relation, uw, uw) """
...@@ -57,6 +65,12 @@ class Link: ...@@ -57,6 +65,12 @@ class Link:
res += self.uw2.to_string() + ")" res += self.uw2.to_string() + ")"
return res return res
def to_dot_edge(self):
n1_name = self.uw1.to_dot_node().get_name()
n2_name = self.uw2.to_dot_node().get_name()
edge = pydot.Edge(n1_name, n2_name, color="blue")
return edge
class Relation: class Relation:
""" relation := Relation(id) """ """ relation := Relation(id) """
...@@ -89,6 +103,12 @@ class UniversalWord: ...@@ -89,6 +103,12 @@ class UniversalWord:
res += ".@" + attr.to_string() res += ".@" + attr.to_string()
return res return res
def to_dot_node(self):
node_name = self.headword.to_string() # TODO: à revoir pour id unique
node_label = self.headword.to_string()
node = pydot.Node(node_name, label=node_label)
return node
class Headword: class Headword:
""" headword := Headword(id) """ """ headword := Headword(id) """
......
...@@ -146,6 +146,12 @@ def main(argv): ...@@ -146,6 +146,12 @@ def main(argv):
unl = parse_unl(InputStream(unl_part)) unl = parse_unl(InputStream(unl_part))
print("----- UNL string:\n" + unl.to_string()) print("----- UNL string:\n" + unl.to_string())
# -- Generate dot file
unl_dot_graph = unl.to_dot_graph()
print("----- DOT string:\n" + unl_dot_graph.to_string())
unl_dot_graph.write_raw("output/output_raw.dot")
unl_dot_graph.write_png("output/output.png")
if __name__ == '__main__': if __name__ == '__main__':
main(sys.argv) main(sys.argv)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment