From 3d15a592373c67767587c6d01de394d604d9a89a Mon Sep 17 00:00:00 2001 From: Alexander Dyuzhev Date: Wed, 13 Sep 2023 21:33:00 +0300 Subject: [PATCH 1/2] template 04-schemas.adoc integrated, #52 --- src/main/java/org/metanorma/Util.java | 16 +- src/main/resources/04-schemas.adoc | 798 ++++++++++++++++++ .../stepmod.base_xsl/res_doc/sect_schema.xsl | 10 +- .../resources/stepmod2mn.resource.adoc.xsl | 12 +- 4 files changed, 830 insertions(+), 6 deletions(-) create mode 100644 src/main/resources/04-schemas.adoc diff --git a/src/main/java/org/metanorma/Util.java b/src/main/java/org/metanorma/Util.java index 9554a24..ef1e514 100644 --- a/src/main/java/org/metanorma/Util.java +++ b/src/main/java/org/metanorma/Util.java @@ -19,6 +19,7 @@ import java.util.jar.Manifest; import java.util.logging.Level; import java.util.logging.Logger; +import java.util.stream.Collectors; /** * @@ -54,7 +55,20 @@ public static InputStream getStreamFromResources(ClassLoader classLoader, String } return stream; } - + + public static String getFileContentFromResources(String fileName) throws Exception { + ClassLoader classLoader = ClassLoader.getSystemClassLoader(); + try (InputStream is = classLoader.getResourceAsStream(fileName)) { + if (is == null) { + System.out.println("Cannot get resource \"" + fileName + "\" from Jar file."); + return null; + } + try (InputStreamReader isr = new InputStreamReader(is); + BufferedReader reader = new BufferedReader(isr)) { + return reader.lines().collect(Collectors.joining("\n")); + } + } + } public static void FlushTempFolder(Path tmpfilepath) { if (Files.exists(tmpfilepath)) { //Files.deleteIfExists(tmpfilepath); diff --git a/src/main/resources/04-schemas.adoc b/src/main/resources/04-schemas.adoc new file mode 100644 index 0000000..ca8a499 --- /dev/null +++ b/src/main/resources/04-schemas.adoc @@ -0,0 +1,798 @@ +[lutaml_express, schemas, context, leveloffset=+1] +--- +{% for schema in context.schemas %} +{% assign schemaname = schema.id | append: "$" | remove: "_schema$" | remove: "$" | replace: "_", " " | capitalize %} +[[{{ schema.id }}]] +[type="express"] +== {{ schemaname }} schema + +{% capture newLine %} + +{% endcapture %} + +=== General + +// NOTE: Disabled upon request: Keith Hunten at WG12/21 2021-03-31 meeting +// === General <> + +{{ schema.remarks | join: newLine }} + +This clause defines the information requirements to which +implementations shall conform using the EXPRESS language as defined +in ISO 10303-11. The following EXPRESS declaration begins the +*{{ schema.id }}* and identifies the necessary external references. + +Short names of entities defined in this schema are described in +<>. +Unambiguous identification of this schema is defined in +<>. + +[underline]#EXPRESS specification:# + +[source%unnumbered] +-- +{{ schema.source }} +-- + +{% for interface in schema.interfaces -%} +((({{interface.schema.id}},Schema interface))) +{%- endfor %} + +//// +// constants not allowed for by SC 4 +{% if schema.constants.size > 0 %} +[type="express"] +=== {{ schemaname }} constant definitions + +{% for constant in schema.constants %} +[[{{schema.id}}.{{constant.id}}]] +[type="express"] +==== {{ constant.id }} + +{% if constant.source %} +[source%unnumbered] +-- +{{ constant.source }} +-- +{% endif %} + +{{ constant.remarks | join: newLine }} + +{% endfor %} +{% endif %} +//// + +[NOTE] +==== +The schemas referenced above are specified in the following parts: + +{% assign reference_froms = schema.interfaces | where: "kind", :REFERENCE %} +{% for from in reference_froms %} +{% assign from_schema = context.schemas | where: "id", from.schema.id | first %} +{% assign version = from_schema.version %} +{% assign version_number = version.items[2].value %} +{% assign version_part = version.items[3].value %} + +{{ from_schema.id }}:: ISO {{ version_number }}-{{ version_part }} +{% endfor %} +==== + +NOTE: See <> for a graphical representation of this schema. + + +{% assign remark_items = schema.remark_items | where: "id", "__fund_cons" | first %} +{% if remark_items %} +=== Fundamental concepts and assumptions + +{% for remark in remark_items.remarks %} +{{ remark }} + +{% endfor %} +{% endif %} + +{% if schema.types.size > 0 %} +[type="express"] +=== {{ schemaname }} type {% if schema.types.size == 1 %}definition{% else %}definitions{% endif %} + +{% for type in schema.types %} +[[{{schema.id}}.{{type.id}}]] +[type="express"] +==== {{ type.id }} <> ((({{ type.id }},Object definition))) + +{% if type.underlying_type._class == 'Expressir::Model::DataTypes::Select' %} +// output the boilerplate select descriptions for selects +{% if type.underlying_type.extension_type %} + +// an extended and extensible SELECT type +// and +// an extended not extensible SELECT type + +// TODO: This should be express:{{ type.underlying_type.extension_type.schema_id }}.{{ type.underlying_type.extension_type }} +The *{{ type.id }}* type is an extension of the +*<>* type. + +{% if type.underlying_type.extension_items.size > 0 %} +It adds the data {% if type.underlying_type.extension_items.size > 1 %}types{% else %}type{% endif %} +// TODO: This should be express:{{ item.schema_id }}.{{ item }} +{%- for item in type.underlying_type.extension_items %} +*<>*{% if forloop.length > 1 %}{% if forloop.rindex0 == 1 %} and {% elsif forloop.rindex0 != 0 %}, {% endif %}{% endif %} +{%- endfor %} +to the list of alternate data types. +{% endif %} + +{% if type.underlying_type.extensible %} +NOTE: The list of entity data types will be +extended in application resources that use the constructs of +this resource. +{% endif %} + +{% else %} + +{% if type.underlying_type.extensible %} +// extensible SELECT type + +{% if type.underlying_type.extension_items.size > 0 %} +// an extensible non-empty SELECT type +The *{{ type.id }}* type is an extensible list of alternate +data types. It provides a mechanism to refer to instances of +the data types included in the *{{ type.id }}* type or in its +extensions. + +NOTE: The list of entity data types will be +extended in application resources that use the constructs of +this resource. + +{% else %} +// an extensible empty SELECT type + +The *{{ type.id }}* type is an extensible list of alternate +data types. It provides a mechanism to refer to instances of +the data types included in the types that extend the +*{{ type.id }}* type. + +//The type shall be +//extended in schemas that use the constructs of this +//resource. + +NOTE: This empty extensible select requires extension in a further +schema to ensure that entities that refer to it have at least one +valid instantiation. + +{% endif %} + +{% else %} +// a non extensible SELECT type +The *{{ type.id }}* type is a list of alternate data types. It +provides a mechanism to refer to an instance of one of these data +types. + +{% endif %} +{% endif %} +{% endif %} + +{{ type.remarks | join: newLine }} + +{% if type.source %} +[underline]#EXPRESS specification:# + +[source%unnumbered] +-- +{{ type.source }} +-- +{% endif %} + +{% if type.underlying_type._class == 'Expressir::Model::DataTypes::Enumeration' %} + +{% if type.underlying_type.items.size > 0 %} +[underline]#Enumerated item definitions:# + +{% for item in type.underlying_type.items %} + +[[{{schema.id}}.{{type.id}}.{{item.id}}]] +{% if item.remarks.size > 0 %} +*{{ item.id }}*:: {{ item.remarks | join: newLine }} +{% endif %} + +{% endfor %} + +{% endif %} +{% endif %} + + +{% assign found = false %} +{% for where1 in type.where_rules %} +{% if where1.remarks.size > 0 %} +{% assign found = true %} +{% endif %} +{% endfor %} + +{% if found and type.where_rules.size > 0 %} +[underline]#Formal propositions:# + +{% for where1 in type.where_rules %} +{% if where1.remarks.size > 0 %} +[[{{schema.id}}.{{type.id}}.{{where1.id}}]] +*{{ where1.id }}*: {{ where1.remarks | join: newLine }} +{% endif %} + +{% endfor %} +{% endif %} + +{% assign found = false %} +{% for where1 in type.informal_propositions %} +{% if where1.remarks.size > 0 %} +{% assign found = true %} +{% endif %} +{% endfor %} + +{% if found and type.informal_propositions.size > 0 %} +[underline]#Informal propositions:# + +{% for where1 in type.informal_propositions %} +{% if where1.remarks.size > 0 %} +[[{{schema.id}}.{{type.id}}.{{where1.id}}]] +*{{ where1.id }}*: {{ where1.remarks | join: newLine }} +{% endif %} + + +{% endfor %} +{% endif %} + +{% endfor %} + + +{% endif %} + + + +{% if schema.entities.size > 0 %} +[type="express"] +=== {{ schemaname }} entity {% if schema.entities.size == 1 %}definition{% else %}definitions{% endif %} + +{% for entity in schema.entities %} +[[{{schema.id}}.{{entity.id}}]] +[type="express"] +==== {{ entity.id }} <> ((({{ entity.id }},Object definition))) + +{{ entity.remarks | join: newLine }} + +[underline]#EXPRESS specification:# + +[source%unnumbered] +-- +{{ entity.source }} +-- + +{% assign found = false %} +{% for attribute in entity.attributes %} +{% if attribute.remarks.size > 0 %} +{% assign found = true %} +{% endif %} +{% endfor %} + +{% if entity.attributes.size > 0 and found %} +[underline]#Attribute definitions:# + +{% for attribute in entity.attributes %} +{% if attribute.remarks.size > 0 %} +[[{{schema.id}}.{{entity.id}}.{{attribute.id}}]] +*{{ attribute.id }}*: {{ attribute.remarks | join: newLine }} +{% endif %} + +{% endfor %} +{% endif %} + +{% assign found = false %} +{% for where1 in entity.where_rules %} +{% if where1.remarks.size > 0 %} +{% assign found = true %} +{% endif %} +{% endfor %} + +{% if found and entity.where_rules.size > 0 %} +[underline]#Formal propositions:# + +{% for where1 in entity.where_rules %} +{% if where1.remarks.size > 0 %} +[[{{schema.id}}.{{entity.id}}.{{where1.id}}]] +*{{ where1.id }}*: {{ where1.remarks | join: newLine }} +{% endif %} + +{% endfor %} +{% endif %} + +{% assign found = false %} +{% for where1 in entity.informal_propositions %} +{% if where1.remarks.size > 0 %} +{% assign found = true %} +{% endif %} +{% endfor %} + +{% if found and entity.informal_propositions.size > 0 %} +[underline]#Informal propositions:# + +{% for where1 in entity.informal_propositions %} +{% if where1.remarks.size > 0 %} +[[{{schema.id}}.{{entity.id}}.{{where1.id}}]] +*{{ where1.id }}*: {{ where1.remarks | join: newLine }} +{% endif %} + +{% endfor %} +{% endif %} + + + +{% endfor %} +{% endif %} + + + + + + +{% if schema.rules.size > 0 %} +[type="express"] +{% if schema.rules.size == 1 %} +[[{{schema.id}}.{{schema.rules[0].id}}]] +=== {{ schemaname }} rule definition: {schema.rules[0].id} +{% else %} +=== {{ schemaname }} rule definitions +{% endif %} +{% for rule in schema.rules %} +{% if schema.rules.size > 1 %} +[[{{schema.id}}.{{rule.id}}]] +[type="express"] +==== {{ rule.id }} ((({{ rule.id }},Object definition))) +{% endif %} + +{{ rule.remarks | join: newLine }} + +[underline]#EXPRESS specification:# + +[source%unnumbered] +-- +{{ rule.source }} +-- + +{% if rule.applies_to.size > 0 %} +[underline]#Argument definitions:# + +{% for entity in rule.applies_to %} +[[{{schema.id}}.{{rule.id}}.{{entity.id}}]] +{{ entity.id }}:: {{ entity.remarks | join: newLine }} + +{% endfor %} +{% endif %} + + + +{% if rule.constants.size > 0 %} +[underline]#Rule constants:# + +{% for constant in rule.constants %} +[[{{schema.id}}.{{rule.id}}.{{constant.id}}]] +{{ constant.id }}:: {{ constant.remarks | join: newLine }} + +{% endfor %} +{% endif %} + + +{% if rule.types.size > 0 %} +[underline]#Rule types:# + +{% for type in rule.types %} +[[{{schema.id}}.{{rule.id}}.{{type.id}}]] +{{ type.id }}:: {{ type.remarks | join: newLine }} + + +{% if type.underlying_type and type.underlying_type.items and type.underlying_type.items.size > 0 %} + +{% for item in type.underlying_type.items %} +[[{{schema.id}}.{{rule.id}}.{{type.id}}.{{item.id}}]] +{% if item.remarks.size > 0 %} +* Item {{ item.id }}:: {{ item.remarks | join: newLine }} +{% endif %} +{% endfor %} +{% endif %} + + +{% endfor %} +{% endif %} + + + +{% assign found = false %} +{% for variable in rule.variables %} +{% if rule.remarks.size > 0 %} +{% assign found = true %} +{% endif %} +{% endfor %} + +{% if found %} +[underline]#Rule variables:# + + +{% for variable in rule.variables %} +{% if variable.remarks.size > 0 %} +[[{{schema.id}}.{{rule.id}}.{{variable.id}}]] +*{{ variable.id }}*: {{ variable.remarks | join: newLine }} +{% endif %} +{% endfor %} +{% endif %} + + +{% assign found = false %} +{% for statement in function.statements %} +{% if statement.remarks %} +{% assign found = true %} +{% endif %} +{% endfor %} + +{% if found %} +[underline]#Rule statements:# + +{% if statement.remarks %} + + +{% for statement in rule.statements %} + +{% if statement.id %} +{% assign statementid = statement.id %} +{% else %} +{% assign statementid = forloop.index %} +{% endif %} + +[[{{schema.id}}.{{rule.id}}.{{statementid}}]] +{{ statementid }}:: {{ statement.remarks | join: newLine }} + + +{% endfor %} +{% endif %} +{% endif %} + + +{% assign found = false %} +{% for where1 in rule.where_rules %} +{% if where1.remarks.size > 0 %} +{% assign found = true %} +{% endif %} +{% endfor %} + +{% if found and rule.where_rules.size > 0 %} +[underline]#Formal propositions:# + +{% for where1 in rule.where_rules %} +{% if where1.remarks.size > 0 %} +[[{{schema.id}}.{{rule.id}}.{{where1.id}}]] +*{{ where1.id }}*: {{ where1.remarks | join: newLine }} +{% endif %} + +{% endfor %} +{% endif %} + +{% assign found = false %} +{% for where1 in rule.informal_propositions %} +{% if where1.remarks.size > 0 %} +{% assign found = true %} +{% endif %} +{% endfor %} + +{% if found and rule.informal_propositions.size > 0 %} +[underline]#Informal propositions:# + +{% for where1 in rule.informal_propositions %} +{% if where1.remarks.size > 0 %} +[[{{schema.id}}.{{entity.id}}.{{where1.id}}]] +*{{ where1.id }}*: {{ where1.remarks | join: newLine }} +{% endif %} + +{% endfor %} +{% endif %} + + + +{% endfor %} +{% endif %} + + + + + +{% if schema.subtype_constraints.size > 0 %} +{% if schema.subtype_constraints.size == 1 %} +[[{{schema.id}}.{{schema.constraints[0].id}}]] +[type="express"] +=== {{schemaname}} subtype constraint definition: {{schema.subtype_constraints[0].id }} +{% else %} +[type="express"] +=== {{schemaname}} subtype constraint definitions +{% endif %} + +{% for constraint in schema.subtype_constraints %} +{% if schema.subtype_constraints.size > 1 %} +[type="express"] +[[{{schema.id}}.{{constraint.id}}]] +==== {{ constraint.id }} ((({{ constraint.id }},Object definition))) +{% endif %} + +{{ constraint.remarks | join: newLine }} + +[underline]#EXPRESS specification:# + +[source%unnumbered] +-- +{{ constraint.source }} +-- + +{% endfor %} +{% endif %} + + + + + + +{% if schema.functions.size > 0 %} +[type="express"] +=== {{ schemaname }} function {% if schema.types.size == 1 %}definition{% else %}definitions{% endif %} +{% for function in schema.functions %} +[[{{schema.id}}.{{function.id}}]] +[type="express"] +==== {{ function.id }} ((({{ function.id }},Object definition))) + +{{ function.remarks | join: newLine }} + +[underline]#EXPRESS specification:# + +[source%unnumbered] +-- +{{ function.source }} +-- + +{% assign found = false %} +{% for parameter in function.parameters %} +{% if parameter.remarks.size > 0 %} +{% assign found = true %} +{% endif %} +{% endfor %} + +{% if found and function.parameters.size > 0 %} +[underline]#Argument definitions:# + +{% for parameter in function.parameters %} +{% if parameter.remarks.size > 0 %} +[[{{schema.id}}.{{function.id}}.{{parameter.id}}]] +*{{ parameter.id }}*: {{ parameter.remarks | join: newLine }} +{% endif %} + +{% endfor %} +{% endif %} + +{% if function.constants.size > 0 %} +[underline]#Function constants:# + +{% for constant in function.constants %} +[[{{schema.id}}.{{function.id}}.{{constant.id}}]] +{{ constant.id }}:: {{ constant.remarks | join: newLine }} + +{% endfor %} +{% endif %} + + +{% if function.types.size > 0 %} +[underline]#Function types:# + +{% for type in function.types %} +[[{{schema.id}}.{{function.id}}.{{type.id}}]] +{{ type.id }}:: {{ type.remarks | join: newLine }} + + +{% if type.underlying_type and type.underlying_type.items and type.underlying_type.items.size > 0 %} + +{% for item in type.underlying_type.items %} +[[{{schema.id}}.{{function.id}}.{{type.id}}.{{item.id}}]] +{% if item.remarks.size > 0 %} +* Item {{ item.id }}: {{ item.remarks | join: newLine }} +{% endif %} +{% endfor %} +{% endif %} + + +{% endfor %} +{% endif %} + + + +{% assign found = false %} +{% for variable in function.variables %} +{% if variable.remarks.size > 0 %} +{% assign found = true %} +{% endif %} +{% endfor %} + +{% if found %} +[underline]#Function variables:# + +{% for variable in function.variables %} +{% if variable.remarks.size > 0 %} + +[[{{schema.id}}.{{function.id}}.{{variable.id}}]] +{{ variable.id }}:: {{ variable.remarks | join: newLine }} + +{% endif %} +{% endfor %} +{% endif %} + +{% assign found = false %} +{% for statement in function.statements %} +{% if statement.remarks.size > 0 %} +{% assign found = true %} +{% endif %} +{% endfor %} + +{% if found %} +[underline]#Function statements:# + +{% for statement in function.statements %} + +{% if statement.remarks.size > 0 %} + +{% if statement.id %} +{% assign statementid = statement.id %} +{% else %} +{% assign statementid = forloop.index %} +{% endif %} + +[[{{schema.id}}.{{function.id}}.{{ statementid }}]] +{{ statementid }}:: {{ statement.remarks | join: newLine }} + + + +{% endif %} + +{% endfor %} +{% endif %} + + +{% endfor %} +{% endif %} + + + + + + + +{% if schema.procedures.size > 0 %} +[type="express"] +=== {{ schemaname }} procedure {% if schema.types.size == 1 %}definition{% else %}definitions{% endif %} +{% for procedure in schema.procedures %} +[[{{schema.id}}.{{procedure.id}}]] +[type="express"] +==== {{ procedure.id }} ((({{ procedure.id }},Object definition))) + +{{ procedure.remarks | join: newLine }} + +[underline]#EXPRESS specification:# + +[source%unnumbered] +-- +{{ procedure.source }} +-- + +{% assign found = false %} +{% for parameter in procedure.parameters %} +{% if parameter.remarks.size > 0 %} +{% assign found = true %} +{% endif %} +{% endfor %} + +{% if found and procedure.parameters.size > 0 %} +_Argument definitions:_ + +{% for parameter in procedure.parameters %} +{% if parameter.remarks.size > 0 %} +[[{{schema.id}}.{{procedure.id}}.{{parameter.id}}]] +*{{ parameter.id }}*: {{ parameter.remarks | join: newLine }} +{% endif %} + +{% endfor %} +{% endif %} + + +{% if procedure.types.size > 0 %} +_Procedure types:_ + +{% for type in procedure.types %} +[[{{schema.id}}.{{procedure.id}}.{{type.id}}]] +{{ type.id }}:: {{ type.remarks | join: newLine }} + + +{% if type.underlying_type and type.underlying_type.items and type.underlying_type.items.size > 0 %} + +{% for item in type.underlying_type.items %} +[[{{schema.id}}.{{procedure.id}}.{{type.id}}.{{item.id}}]] +{% if item.remarks.size > 0 %} +* Item {{ item.id }}: {{ item.remarks | join: newLine }} +{% endif %} +{% endfor %} +{% endif %} + + +{% endfor %} +{% endif %} + + +{% if procedure.constants.size > 0 %} +_Procedure constants:_ + +{% for constant in procedure.constants %} +[[{{schema.id}}.{{procedure.id}}.{{constant.id}}]] +{{ constant.id }}:: {{ constant.remarks | join: newLine }} + +{% endfor %} +{% endif %} + +{% assign found = false %} +{% for variable in procedure.variables %} +{% if procedure.remarks.size > 0 %} +{% assign found = true %} +{% endif %} +{% endfor %} + +{% if found %} +_Procedure variables:_ + +{% for variable in procedure.variables %} +{% if variable.remarks.size > 0 %} +[[{{schema.id}}.{{procedure.id}}.{{variable.id}}]] +{{ variable.id }}:: {{ variable.remarks | join: newLine }} + +{% endif %} +{% endfor %} +{% endif %} + +{% assign found = false %} +{% for statement in procedure.statements %} +{% if statement.remarks.size > 0 %} +{% assign found = true %} +{% endif %} +{% endfor %} + + + +{% if found %} +_Procedure statements:_ + +{% for statement in procedure.statements %} + +{% if statement.remarks %} + +{% if statement.id %} +{% assign statementid = statement.id %} +{% else %} +{% assign statementid = forloop.index %} +{% endif %} + +[[{{schema.id}}.{{procedure.id}}.{{statementid }}]] +{{ statementid }}:: {{ statement.remarks | join: newLine }} + + + +{% endif %} +{% endfor %} +{% endif %} + + +{% endfor %} +{% endif %} + +[source%unnumbered] +-- +END_SCHEMA; -- {{ schema.id }} +-- + + +{% endfor %} +--- + diff --git a/src/main/resources/stepmod.base_xsl/res_doc/sect_schema.xsl b/src/main/resources/stepmod.base_xsl/res_doc/sect_schema.xsl index 7635f43..e420bd5 100644 --- a/src/main/resources/stepmod.base_xsl/res_doc/sect_schema.xsl +++ b/src/main/resources/stepmod.base_xsl/res_doc/sect_schema.xsl @@ -9,6 +9,7 @@ $Id: sect_schema.xsl,v 1.3 2003/08/24 22:10:35 thendrix Exp $ --> @@ -35,6 +36,13 @@ $Id: sect_schema.xsl,v 1.3 2003/08/24 22:10:35 thendrix Exp $ - + + + + + + + + diff --git a/src/main/resources/stepmod2mn.resource.adoc.xsl b/src/main/resources/stepmod2mn.resource.adoc.xsl index 6c698fd..2b5b138 100644 --- a/src/main/resources/stepmod2mn.resource.adoc.xsl +++ b/src/main/resources/stepmod2mn.resource.adoc.xsl @@ -338,13 +338,17 @@ - + + + - + --> + + + From b00b1b3b4c45cde4ac2997fb012c6cf150ee45ca Mon Sep 17 00:00:00 2001 From: Alexander Dyuzhev Date: Wed, 13 Sep 2023 22:11:32 +0300 Subject: [PATCH 2/2] updated for #47 --- src/main/resources/stepmod.base_xsl/module.xsl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/resources/stepmod.base_xsl/module.xsl b/src/main/resources/stepmod.base_xsl/module.xsl index df8bc61..638d874 100644 --- a/src/main/resources/stepmod.base_xsl/module.xsl +++ b/src/main/resources/stepmod.base_xsl/module.xsl @@ -4167,7 +4167,8 @@ $module_ok,' Check the normatives references')"/> --> - + +