Add more parameters to OML generator

This commit is contained in:
Joeri Exelmans 2023-04-12 18:08:47 +02:00
parent dffe13e9a7
commit 218695c392
2 changed files with 20 additions and 3 deletions

View file

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

View file

@ -22,6 +22,8 @@ DTDESIGN_NAMESPACES = {
"xopp": "http://ua.be/sdo2l/vocabulary/formalisms/xopp", "xopp": "http://ua.be/sdo2l/vocabulary/formalisms/xopp",
"object_diagram": "http://ua.be/sdo2l/vocabulary/formalisms/object_diagram", "object_diagram": "http://ua.be/sdo2l/vocabulary/formalisms/object_diagram",
"dict": "http://ua.be/sdo2l/vocabulary/formalisms/dict", "dict": "http://ua.be/sdo2l/vocabulary/formalisms/dict",
"artifacts": "http://ua.be/sdo2l/description/artifacts/",
} }
def to_oml_string_literal(python_string): def to_oml_string_literal(python_string):
@ -32,7 +34,20 @@ def to_oml_string_literal(python_string):
def to_base64_string(bytes): def to_base64_string(bytes):
return '"' + base64.b64encode(bytes).decode('utf-8') + '"' 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 jinja2
import os import os
@ -48,5 +63,7 @@ def writeOML(xournalFile: abstract_syntax.XournalFile, inputfile:str, namespace:
file=xournalFile, file=xournalFile,
inputfile=inputfile, inputfile=inputfile,
enumerate=enumerate, enumerate=enumerate,
namespaces=DTDESIGN_NAMESPACES): output_namespace=namespaces['artifacts']+model_name+"_xopp",
shorthand=model_name+"_xopp",
namespaces=namespaces):
ostream.write(piece) ostream.write(piece)