Library: Sub 3 – canAdd

Relationship Attributes -->

canAdd

Depending on the purpose of the model, you may want to allow end-users to submit their own answers to a question. The “canAdd” function, also referred to as “add instances” in Rainbird studio, is a setting that allows the user to add their own response(s) to a question

To demonstrate the canAdd feature, we have built a model which recommends cocktails based on the available ingredients to the user. Rainbird will ask a question to the end-user about the ingredients they have available. Rainbird will propose a list of ingredients from which the user can select an answer:

Figure 1: multiple choice questions

For instruction on how to change the way Rainbird presents a question, please consult the  ‘question types’    article in the library.

Depending on the “Add instances” setting, the user will or will not be able to add their own answer (for example, any additional ingredients they have). There might be various reasons why we want to allow people to add answers or not, in our example, it may be that we can or can’t buy more ingredients.

To allow the user to add his own answer, the add instances setting, inside the relationship settings, under question properties, needs to be set to “All” (or “Object”) in the relationship setting as shown in the figure below. By default, Add Instances is set to “All” when a relationship is created.

Figure 2: Add instances setting

The user can add a new instance when Rainbird asks a question by typing in their own answer and clicking add:

Figure 3: how to add an instance

If ‘add instances‘ is set to ‘none’, the end-user will only be able to choose from the answers presented to them. By default, ‘add instances’ is set to ‘all’, as if no answers are proposed, the user will not be able to answer the question , which could be a problem. Caution should be exercised when setting the ‘add instances’ to ‘none’.

On top of “All” and “None, there’s two more options to this setting: Object and Subject. It allows to build more accurate models and specify for each relationship, to which, and only which of the object or subject concept the user can add instances.

Object and Subject related:

You can also set the ‘add instances’ setting to only allow the user to add new objects or subjects. We’ll explain why you may want to restrict what kind of instances a user can enter later in this article. More information on objects and subjects can be found in the ‘Subject/Object and Relationship‘ article.

Before we go into more detail about the canAdd function, let’s explain a bit more about the example model.

The model can be used in two ways:

1) It recommends a cocktail to make based on the available ingredients selected by the user

 

Query on relationship: ”has cocktail suggestion”

2) It gives a list of ingredients needed to make cocktails based on the cocktail the user selects

Query on relationship: ”bartender needs ingredients”

 

The model also has 3 other relationships  which will prompt the end-user with a question when Rainbird queries them at run-time:

  • ”cocktail uses ingredients”
  • ”has available ingredients”
  • ”wants to do cocktail”

The setting canAdd instances will be changed on these 3 relationships, as the questions sit under these relationships.

Here is a screenshot of the Knowledge map:


Figure 4: Cocktail recipe knowledge map

 

Instances have been added to the “Cocktails” and “Ingredients” concepts so that the end-user will have answers to select while completing the query.

The model will behave in different ways depending on the canAdd option.

If all 3 relationships are set to All (as it will be by default), the user will be able to add cocktails and ingredients, which can represent the scenario of a bar in which there’s no fix menu (the bartender agrees to do any kind of cocktails), and where new ingredients can be easily provided (they have a garden or shop right next to the bar).

Figure 5: Add instance activated for the “cocktail uses ingredients” question

Note that in the above image, the Rainbird will ask the user a question on the “cocktail uses ingredients” relationship for each ingredient concept instance the user entered at run-time. Additionally, Rainbird remembers the concept instance that the user created, whilst answering the first “cocktail uses ingredients” question, and proposes it as an answer to the second question. Some answers are greyed out, as facts have been created inside the knowledge map to give Rainbird a basic understanding of cocktails. More information on facts can be found in the ‘Facts and Concept Instances‘ article.

If the bartender can only make cocktails from a menu and cannot buy more ingredients,  canadd on all relationships would be set to “None”. Now, the end-user will not be able to add either cocktails or ingredient;  the model will only be able to infer results from the pre-existing data.

Figure 6: Cocktail choice question without “canAdd” option

Let’s say the bartender can make any cocktail he wants, but has limited stock he cannot replenish. We would want to change the behaviour of our map to allow the user to add instances for cocktails, but not for ingredients. We will need to use one of the two other canAdd options, “Subject” or “Object”.

We’ll need to set the 3 relationships that trigger the questions as shown in the following table:


Relationship Name   canAdd setting
”cocktail uses ingredients”   Subject
”has available ingredients”   None
”wants to do cocktail”   All


Figure 7: table of the canAdd cocktails only settings per relationship

 Now, the model will behave like this:

Figure 8: demonstration of the new behavior (canAdd instances for cocktails only)

If we wanted the end-user to only be able to add ingredients instances only, we would need to use the following settings:

Relationship Name   canAdd setting
”cocktail uses ingredients”   Object
”has available ingredients”   All
”wants to do cocktail”   None

Figure 9: Table of the canAdd ingredients only settings per relationship

The RBLang below will generate the example map built in the article. Click on ‘Export .rbird’ to download the knowledge map, or ‘copy RBLang’ and paste the code directly into Rainbird.

Query and Results

When viewing the knowledge map generated by the RBLang below, please run the query on the relationship ‘has cocktail suggestion’.

Article Feedback form
Did you find this article useful?

Version 1.01 – Last Update: 16/02/2021
Bitnami