Преглед изворни кода

Add more parameters to OML generator

Joeri Exelmans пре 2 година
родитељ
комит
218695c392
2 измењених фајлова са 20 додато и 3 уклоњено
  1. 1 1
      src/xopp2oml/template.oml
  2. 19 2
      src/xopp2oml/writer.py

+ 1 - 1
src/xopp2oml/template.oml

@@ -5,7 +5,7 @@
 // Minimal mode enabled: All XML attributes and non-text nodes are omitted.
 {%- endif %}
 
-description <{{namespaces.description}}#> as {{namespaces.shorthand}} {
+description <{{output_namespace}}#> as {{shorthand}} {
 
   uses <{{namespaces.xopp}}#> as xopp
   uses <{{namespaces.object_diagram}}#> as object_diagram

+ 19 - 2
src/xopp2oml/writer.py

@@ -22,6 +22,8 @@ DTDESIGN_NAMESPACES = {
     "xopp": "http://ua.be/sdo2l/vocabulary/formalisms/xopp",
     "object_diagram": "http://ua.be/sdo2l/vocabulary/formalisms/object_diagram",
     "dict": "http://ua.be/sdo2l/vocabulary/formalisms/dict",
+
+    "artifacts": "http://ua.be/sdo2l/description/artifacts/",
 }
 
 def to_oml_string_literal(python_string):
@@ -32,7 +34,20 @@ def to_oml_string_literal(python_string):
 def to_base64_string(bytes):
     return '"' + base64.b64encode(bytes).decode('utf-8') + '"'
 
-def writeOML(xournalFile: abstract_syntax.XournalFile, inputfile:str, namespace:str, ostream: io.TextIOBase):
+def writeOML(
+    xournalFile: abstract_syntax.XournalFile,
+    inputfile:str,
+    model_name: str,
+    ostream: io.TextIOBase,
+    namespaces=DTDESIGN_NAMESPACES):
+    """ Write out a Xournal++ file as an OML description.
+    Parameters:
+        xournalFile: abstract syntax of a parsed .xopp file
+        inputfile: name of input file (only for documentation/traceability purposes - any value can be used here)
+        model_name: used to determine the namespace of the generated OML description
+        namespace: namespace of xopp-OML-vocabulary
+        ostream: output stream to write to
+    """
     import jinja2
     import os
 
@@ -48,5 +63,7 @@ def writeOML(xournalFile: abstract_syntax.XournalFile, inputfile:str, namespace:
         file=xournalFile,
         inputfile=inputfile,
         enumerate=enumerate,
-        namespaces=DTDESIGN_NAMESPACES):
+        output_namespace=namespaces['artifacts']+model_name+"_xopp",
+        shorthand=model_name+"_xopp",
+        namespaces=namespaces):
             ostream.write(piece)