I was searching how to make a concept automatically adapt to its plural/singular version depending on a user’s input value (ex: the number inserted in a number datafield), but I am feeling a bit overwhelmed by all the special functions and tools I could use for this purpose. Is there a particular special function that would be the best suited for this situation?
Hi Marina,
You are right that ClauseBase offers many options to deal with this situation. For the situation you described , three particular approaches come to mind.
1. @one-else
First, there is the @one-else
special function, which takes the following form:
Example: @one-else(#concept^number-datafield, "the singular word", "the plural words")
.
Instead of writing static text between quotation marks, you could also force the use of a singular version in the second element of the special function (i.e.: “the singular word” would become @singular(#concept) and “the plural words” would become @plural(#concept)). More on that below.
You can see a practical demonstration of this function in our tutorial video ‘Singular and plural special functions’ here.
In addition, we received a similar question in the Community Forum, for which we provided a detailed answer that you can access here.
2. @singular/@plural
The second option would be to create a condition to make ClauseBase retrieve the plural or singular label of a specific concept, depending on the number inserted in a number datafield.
Example: {#concept^number-datafield = 1: @singular(#concept) | #concept^number-datafield > 1: @plural(#concept)}
Naturally, this is just a roundabout way of creating the kind of situation that @one-else envision so the approach under 1. is recommended.
3. Using change sets in Q&A
In Q&A mode, you can make a “change term” change set that changes the use of the default version (singular or plural) of a concept to the other version (plural or singular) based on the fulfillment of a certain condition.
If you make a change set like that and attach a condition to this change set that activates as soon as #concept^number-datafield
is more than 1 (for example), that could also automate the switch to a singular or plural version.
For more information on this, check out this Help Center article.
Thank you, Senne!
Hello,
I have a follow-up question here: is it possible to use option 1 @one-else with two or more datafields?
I have a clause with a list of texts datafield. I followed the instructions in the KB article " How to: create a list with both predefined options and free input" (e.g. a list of payments).
However, I have a clause introducing my datafield(s) that needs to be adjusted depending on the number of fields filled-in by the user in both the predefined input list and the free input list:
#employer will pay the following @one-else(@count(#payments^list_type_payments-predefined), “amount”, “amounts”) to #employee, to the extent @one-else(@count(#payments^list_type_payments-predefined), “it is”, “they are”) not yet paid:
-
AND
-
{“salary end of contract” in #payments^list_type_payments-predefined: the normal gross salary until #termination-date}
-
{“indemnity in lieu of notice” in #payments^list_type_payments-predefined: @INDEMNITYINLIEU}
-
{"vacation pay"in #payments^list_type_payments-predefined: the departure holiday pay, calculated according to the applicable legal provisions}
-
@bullets(#payments^list_payments_free)
How do I make sure that the @one-else(@count) function also take into account the number of elements in #payments^list_payments_free?
Thank you!
Astrid
Hi Astrid,
Welcome to the forum!
Good question. I think what you are looking for, is the @union special function. It allows you to combine two lists into one.
(By the way, as you can read in the help site, there are also related special functions for taking the intersection of two or more lists of elements, or subtracting one list from another).
Hi all,
I also have a follow-up question on this.
I want to use a conditional change set, to make a concept label either singular/plural.
It should be conditional to a repeating (yes/no) datafield.
(Simplified) Example:
#person^name (free text repeating datafield)
#person^legal-person (repeating yes-no datafield)
If there is more than 1 datafield that has a “#person^legal-person = True”, than the concept label #legal-persons should become Plural by default.
I don’t seem to find this option in the conditions of a change set - Should I work with a ‘custom function’ in the change set?
Thanks for the help
Hi Tom,
That would indeed be something that you would need to resort to a custom function for if you wanted to use a change set.
However, a slightly easier alternative approach could be to replace the occurrences of #legal-persons
in your document with an external snippet that contains on the condition that checks whether more than one #person^legal-person = true
, e.g. as follows:
@if(@silence(@count(@filter(#person^_legal-person, @x = true)) > 1), @plural(#-legal-person), @singular(#-legal-person))
The above works well, and in addition provides similar flexibility to just using a concept label as you can still change the concept label of #legal-person
.
N.B.: the underscore in #person^_legal-person
is absolutely essential as you want to reference the entire list of true/false values in #person^legal-person. Cf. Repeating list datafields | Clause9.
P.S.: The reason we are using @if in the above grammar instead of a ‘normal’ condition is that the expression @filter(#person^_legal-person, @x = true)
results in an error as long as no true/false values have been inserted in the datafield. Using @silence around @if avoids this.
Following up on this after having thought about this during the weekend: there is a much easier solution to this that, however, has a small downside.
You could ask a separate true/false question in the Q&A along the following lines: “Is there more than one legal person?”, to which you can then attach the relevant change set. No need to attach a datafield to this question, it would just be used to trigger the change set.
The downside is that in fact you are implicitly asking the same question multiple times, as the #person table will also, for each individual person, ask the question whether they are a legal person again.
However, as it saves a lot of complexity in automating/maintaining the template (i.e. no need to replace all mentions of #legal-person
with an external snippet), I feel it is a worthwhile trade-off.
Hi Robbert,
Thanks for the tips and advice!
The external snippet solution worked, but has created a new problem: the grammatical conjugation.
I tried:
- <@#external_snippet> ;
- <#legal-person> in the snippet itself; and
- @#external_snippet <is: #legal-person>.
But none of the above seem to work?
What am I doing wrong?
Thanks for the advice!
Tom
You are right, none of those will work with an external snippet. That is one more downside of that approach, apologies.
In view of the need for grammatical conjugations, the alternative solution I suggested is the way to go, i.e. adding a separate question in the Q&A.