From 218695c392c1118d2f055a0232cab94b72eb8f52 Mon Sep 17 00:00:00 2001 From: Joeri Exelmans Date: Wed, 12 Apr 2023 18:08:47 +0200 Subject: [PATCH] Add more parameters to OML generator --- src/xopp2oml/template.oml | 2 +- src/xopp2oml/writer.py | 21 +++++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/xopp2oml/template.oml b/src/xopp2oml/template.oml index 8165a01..a55d48f 100644 --- a/src/xopp2oml/template.oml +++ b/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 diff --git a/src/xopp2oml/writer.py b/src/xopp2oml/writer.py index 12589ea..758d541 100644 --- a/src/xopp2oml/writer.py +++ b/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)