diff --git a/.gitignore b/.gitignore index 950f50f256db44189a66537501d054cbdb6f91f5..8eb57bee0ba7eef2df9b8e3f58d7a9da34f351eb 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,6 @@ devtemp*.py .project *.ttl.tbc +output/* +*env/* + diff --git a/asd/unl.py b/asd/unl.py index ff21b261c91a93e06dd992d7291c0d9d7ee425a3..ad0b48fbaac9c6a58ca93e7da552f58683805138 100644 --- a/asd/unl.py +++ b/asd/unl.py @@ -11,7 +11,7 @@ # Importing required modules #============================================================================== -# None +import pydot #============================================================================== @@ -42,6 +42,14 @@ class Graph: 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: """ link := Link(relation, uw, uw) """ @@ -57,6 +65,12 @@ class Link: res += self.uw2.to_string() + ")" 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: """ relation := Relation(id) """ @@ -89,6 +103,12 @@ class UniversalWord: res += ".@" + attr.to_string() 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: """ headword := Headword(id) """ diff --git a/parse.py b/parse.py index 0c236429dcb1f3a4567dd520f5c24d5e6eae3132..76559d3a77bc589ad29a93d7f360101bd7303e9a 100644 --- a/parse.py +++ b/parse.py @@ -145,6 +145,12 @@ def main(argv): print("-- UNL Parsing (UNL Representation) ") unl = parse_unl(InputStream(unl_part)) 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__': diff --git a/requirements.txt b/requirements.txt index 7545404907866e05b070ec90199690d5c441c641..726e85c982b015cf23be2ff758f1bd095ff6c303 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ antlr4-python3-runtime==4.9.3 +pydot