Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should template allow for lists of terms #20

Closed
jeromesimeon opened this issue Dec 21, 2017 · 10 comments
Closed

Should template allow for lists of terms #20

jeromesimeon opened this issue Dec 21, 2017 · 10 comments
Labels

Comments

@jeromesimeon
Copy link
Member

For instance:

Seller may terminate this Agreement:
(a) if Buyer fails to pay...
(b) if Buyer is in [{"material":?material}] breach...
(c) if Buyer becomes insolvent...
@dselman
Copy link
Contributor

dselman commented Jan 12, 2018

Another good example of this is in the volume discount template, which includes a decision table like construct.

@jeromesimeon
Copy link
Member Author

jeromesimeon commented Jan 24, 2018

I've been reviewing the volume discount template and I think
supporting an arbitrary number of rows would require a couple of
extensions to the current template format.

One extension is the ability to specify a piece of repeating text
(which would correspond to an array in the corresponding
JSON). Another extension needed is the ability to describe alternative
texts.

One possiblity that addresses both requirements is to rely on a simple
kind of regular expressions. Here is a short proposal which suggests
some new markup to do that:

Markup for optional text with corresponding JSON field:

[?{myOptionalField} some text goes here]

Markup for repeated text with corresponding JSON field:

[+{myArrayField} some text that might be repeated one or more times goes here]

Markup for alternative texts:

[some left text goes here \| some right text goes here]

With those new constructs in mind, the decision table from the
volumediscount template could be written as follows:

Volume-Based Card Acceptance Agreement [Abbreviated]

This Agreement is by and between Card, Inc., a New York corporation, and you, the Merchant. By accepting the Card, you agree to be bound by the Agreement. 
Discount means an amount that we charge you for accepting the Card, which amount is: ...

| Annual Dollar Volume      | Discount             |
[+{discountRates}| [ Less than $[{volumeUpTo}] million \| [{volumeAbove}] million to [{volumeUpTo}] \| Greater than [{volumeAbove}] million] | [{rate}]% |]

_______________________					_____________________
 Card, Inc.								Merchant

Now if you parse the corresponding clause text with this template:

Volume-Based Card Acceptance Agreement [Abbreviated]

This Agreement is by and between Card, Inc., a New York corporation, and you, the Merchant. By accepting the Card, you agree to be bound by the Agreement. 
Discount means an amount that we charge you for accepting the Card, which amount is: ...

| Annual Dollar Volume      | Discount             |
| Less than $1 million      | 3.00%                |
| $1 million to $10 million | 2.90%                |
| Greater than $10 million  | 2.80%                |

It should succeed and return with the following JSON:

{
    'discountRates' : [
	{ 'volumeUpTo' : 1,
	  'rate' : 3.00 },
	{ 'volumeUpTo' : 10,
	  'volumeAbove' : 1,
	  'rate' : 2.90 },
	{ 'volumeAbove' : 10,
	  'rate' : 2.80 }
    ]
}

@jeromesimeon
Copy link
Member Author

Note that something along those lines would also address issue #16 and possibly #17.

@dselman
Copy link
Contributor

dselman commented Jan 24, 2018

Like it.

@dselman
Copy link
Contributor

dselman commented Feb 21, 2019

An example that uses arrays in the model.

latedeliveryandpenalty.zip

@dselman
Copy link
Contributor

dselman commented Feb 21, 2019

Code that prevents using Arrays in the template model:
https://github.com/accordproject/cicero/blob/master/packages/cicero-core/src/template.js#L328

@dselman
Copy link
Contributor

dselman commented Mar 5, 2019

Current state is that you CAN use arrays in your models - but not the template model itself.

@otawakkil
Copy link

It would be interesting to support any arbitrary sequence of chars as separator in arrays.
For example, in a table like this one:
| DEAL | 16.00 | 15.90 | 15.65 | 14.75 | 13.20 |
' | ' is the delimiter.
And we can even go a step further by supporting Regex to be used as separators.

@adrianffletcher
Copy link

Attached is another example which is a fuel surcharge clause which is rather cumbersome as we have to define new model variables for each element in the table and we require a fixed number of rows in the table.

Screen Shot 2019-05-16 at 11 44 46

fuel-surchargev0.1.2.zip

@jeromesimeon
Copy link
Member Author

We now have support for lists using blocks (tied to Markdown lists), either as: {{#ulist}} ... {{/ulist}} or {{#olist}} ... {{/olist}} in version 0.20. I'm closing. Reopen if you disagree! (Or open a new issue if new feature needed).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants