Selaa lähdekoodia

Update OML generator to use DTDesign namespaces

Joeri Exelmans 2 vuotta sitten
vanhempi
commit
456a33570c
4 muutettua tiedostoa jossa 26 lisäystä ja 11 poistoa
  1. 2 2
      README.md
  2. 2 2
      drawio2py/drawio2oml.py
  3. 18 3
      drawio2py/oml_generator.py
  4. 4 4
      drawio2py/template.oml

+ 2 - 2
README.md

@@ -8,8 +8,8 @@ As shown in the figure above, the transformation between `.drawio` files and a [
 
 Additionally, an OML generator is included too, but it is only one-directional. The generated OML description will use the following vocabulary:
 
-https://msdl.uantwerpen.be/git/lucasalbertins/DTDesign/src/7cc40c9d6e3888968b2ef94f5d6e64afe90b45da/examples/oml/CDF/src/oml/flandersmake.be/cdf/vocabulary/drawio.oml
+https://msdl.uantwerpen.be/git/lucasalbertins/DTDesign/src/12a00b2ebf15802842b15ba3b9b2f5ceb38d369a/examples/oml/SystemDesignOntology2Layers/src/oml/ua.be/sdo2l/vocabulary/formalisms/drawio.oml
 
 An example of a generated OML file can be found here:
 
-https://msdl.uantwerpen.be/git/lucasalbertins/DTDesign/src/7cc40c9d6e3888968b2ef94f5d6e64afe90b45da/examples/oml/CDF/src/oml/flandersmake.be/cdf/description/my_drawio.oml
+https://msdl.uantwerpen.be/git/lucasalbertins/DTDesign/src/12a00b2ebf15802842b15ba3b9b2f5ceb38d369a/examples/oml/SystemDesignOntology2Layers/src/oml/ua.be/sdo2l/description/artifacts/my_drawio.oml

+ 2 - 2
drawio2py/drawio2oml.py

@@ -13,7 +13,7 @@ if __name__ == "__main__":
 
     if args.output == None:
         import sys
-        oml_generator.write_oml(asyntax, "my_drawio", sys.stdout)
+        oml_generator.write_oml(asyntax, sys.stdout)
     else:
         with open(args.output[0], 'wt') as f:
-            oml_generator.write_oml(asyntax, "my_drawio", f)
+            oml_generator.write_oml(asyntax, f)

+ 18 - 3
drawio2py/oml_generator.py

@@ -1,12 +1,26 @@
 import io
 from drawio2py import abstract_syntax
 
+CDF_NAMESPACES = {
+    "description": "http://flandersmake.be/cdf/description/my_drawio",
+    "drawio": "http://flandersmake.be/cdf/vocabulary/drawio",
+    "object_diagram": "http://flandersmake.be/cdf/vocabulary/object_diagram",
+    "dict": "http://flandersmake.be/cdf/vocabulary/dict",
+}
+
+DTDESIGN_NAMESPACES = {
+    "description": "http://ua.be/sdo2l/description/artifacts/",
+    "drawio": "http://ua.be/sdo2l/vocabulary/formalisms/drawio",
+    "object_diagram": "http://ua.be/sdo2l/vocabulary/formalisms/object_diagram",
+    "dict": "http://ua.be/sdo2l/vocabulary/formalisms/dict",
+}
+
 def to_oml_string_literal(python_string):
     # Not sure which characters to escape in OML.
     # At the very least, quotes should be escaped:
     return '"' + python_string.replace('"', '\\"') + '"'
 
-def write_oml(drawio_file: abstract_syntax.DrawIOFile, oml_namespace:str, ostream: io.TextIOBase):
+def write_oml(drawio_file: abstract_syntax.DrawIOFile, ostream: io.TextIOBase):
     import jinja2
     import os
 
@@ -20,6 +34,7 @@ def write_oml(drawio_file: abstract_syntax.DrawIOFile, oml_namespace:str, ostrea
 
     for piece in template.generate(
             file=drawio_file,
-            namespace=oml_namespace,
-            enumerate=enumerate):
+            enumerate=enumerate,
+            output_shorthand="my_drawio",
+            namespaces=DTDESIGN_NAMESPACES):
         ostream.write(piece)

+ 4 - 4
drawio2py/template.oml

@@ -58,11 +58,11 @@ drawio:hasY {{p.y}}
 // Input file: '{{file.filename}}'
 // Generator: https://msdl.uantwerpen.be/git/rparedis/DrawioConvert/src/library
 
-description <http://flandersmake.be/cdf/description/{{namespace}}#> as {{namespace}} {
+description <{{namespaces.description}}/{{output_shorthand}}#> as {{output_shorthand}} {
 
-  uses <http://flandersmake.be/cdf/vocabulary/drawio#> as drawio
-  uses <http://flandersmake.be/cdf/vocabulary/object_diagram#> as object_diagram
-  uses <http://flandersmake.be/cdf/vocabulary/dict#> as dict
+  uses <{{namespaces.drawio}}#> as drawio
+  uses <{{namespaces.object_diagram}}#> as object_diagram
+  uses <{{namespaces.dict}}#> as dict
 
   ci model : drawio:Model [
     drawio:isCompressed {{ "true" if file.compressed else "false"}}