lutaml / expressir

Ruby parser for the ISO EXPRESS language
3 stars 3 forks source link

Define "EXPRESS Path" syntax and DSL for accessing EXPRESS models #16

Closed ronaldtse closed 3 years ago

ronaldtse commented 4 years ago

EXPRESS remark tags allow the syntax of {schema}.{entity}.... to access a data model. However, in LutaML we also want to access other things that belongs to the model, including:

We need to come up with a way of accessing such information, e.g.

  ENTITY action_directive_relationship;
    name            : label;
    description     : OPTIONAL STRING;
    relating        : action_directive;
    related         : action_directive;
    relation_type   : STRING;
   WHERE
    WR1 : acyclic_action_directive_relationship(SELF, [related], 'ACTION_SCHEMA.ACTION_DIRECTIVE_RELATIONSHIP');
  END_ENTITY;

In order to list out all attributes of an entity, suppose we are in a Metanorma Liquid environment, the code could be:

{% for attribute in action_schema.action_directive_relationship.attributes %}
{{ attribute.id }} has the type {{ attribute.type }}
{% endfor %}

which can give out text like:

name has the type label
description has the type OPTIONAL STRING
relating has the type action_directive;
related has the type action_directive;
relation_type has the type STRING;
ronaldtse commented 4 years ago

In order to list out all attributes of an entity, suppose we are in a Metanorma Liquid environment[...]

@w00lf assuming we have a syntax of accessing the EXPRESS model internals, how do we expose this information in Liquid?

w00lf commented 4 years ago

In order to list out all attributes of an entity, suppose we are in a Metanorma Liquid environment[...]

@w00lf assuming we have a syntax of accessing the EXPRESS model internals, how do we expose this information in Liquid?

I will create a wrapper interface inside lutaml gem, it will accept express repository as input object and will have find method to access objects, each lutaml flavor will inherit this wrapper and overwrite find method according to the internal objects.

ronaldtse commented 4 years ago

@w00lf could you help describe the syntax here for reference? Thanks!

w00lf commented 4 years ago

@w00lf could you help describe the syntax here for reference? Thanks!

Sure, the final wrapper inside Lutaml will pack variables and methods of Schema/Entity into Hash like structure so that we can access them inside liquid code like so:

{% for schema in my_context.schemas %}
== {{schema.id}}

{% for entity in schema.entities %}
=== {{entity.id}}
supertypes -> {{entity.supertypes.id}}
explicit -> {{entity.explicit.first.id}}

{% endfor %}

{% endfor %}

We also can iterate through all entity attributes through liquid for loop, example:

{% for attribute in entity %}
{{entity[0]}} - will render attribute` name
{{entity[1]}} - will render attribute` value
{% endfor %}
ronaldtse commented 4 years ago

@w00lf can you add this to the README of metanorma-plugin-lutaml gem? Thanks!

w00lf commented 4 years ago

@w00lf can you add this to the README of metanorma-plugin-lutaml gem? Thanks!

Done - https://github.com/metanorma/metanorma-plugin-lutaml/pull/2

ronaldtse commented 3 years ago

Thanks guys!