Library: Sub 3 – Combination Rule and Stack Rule

Building Pattern--> Structural -->

Combination Rule and Stack Rule

If you are building a map comprised of multiple simple triangle rules, there are different approaches to utilising them all effectively in one rule. All the conditions taken into account can either be stacked in one relationship’s rule, or they can be combined from sub-relationships’ rules into an overall relationship’s rule.

Stacked rules are best used when the number of conditions for a rule is low, as fewer relationships will need to be created. If the number of conditions significantly grows, it is recommended to use combination rules as it improves the readability and makes it more easy to maintain the map.

To demonstrate how to use and build combination/stack rules, this article will show you how to build a film recommendation tool that uses both types of rules.

First, build the basic structure of the map, as shown in Figure 1:

Figure 1: model base structure, double triangle

The model will make a film recommendation to a user, by checking whether a film is in the genre the user wants to watch, and contains subjects the user is interested in. 

The relationships need to be set as either plural or singular and questions need to be switched off for some of the relationships, as shown in the table below:

Relationship name

Plural / Singular

Question On / Off

has genre

Plural

Off

evokes subject

Plural

Off

wants to watch subject

Plural

On

gets recommended a movie based on content

Singular

Off

wants to watch genre

Singular

On

 As there are only 2 parameters, it is better to use a stack rule to combine the two parameters to produce an overall film recommendation. The stack rule will be created on the ‘gets recommended a movie based on content’ relationship, as shown in Figure 2  & 3:

Figure 2: Creating the stack rule

Figure 3: Complete stack rule

Rainbird will ask the user what genre and subjects a person is interested in, and only return a result if a film has both the genre and subjects the user specifies, as all conditions in the rule are set to mandatory.

Currently, the map will not return any results, so you will need to create concept instances for the “Movie”, “Genre” and “Subject” concepts, and create facts between the “movie” concept instances and the “Genre” and “Subject” concept instances. An example is shown in Figure 4 below:


Figure 4: Facts for the ‘Parasite’ concept instance

To improve the validity of the film recommendation, logistical information  (cinema location, projection time), as well as meta information about the movie (rating, length and language) will be taken into consideration when returning a result.

Expand the original model to include the logistic and meta data concepts and relationships, as shown in Figure 5:

Figure 5: Overview of the final model

The relationships settings need to be set as shown in the table below:

Relationship name

Plural / Singular

Question On / Off

wants to watch in cinema

Singular

On

wants to watch on time

Singular

On

wants rating bracket

Plural

On

wants language

Plural

On

wants length bracket

Plural

On

has projection location

Plural

Off

has projection time

Plural

Off

has rating bracket

Singular

Off

has language

Singular

Off

has length bracket

Singular

Off

You will need to create concept instances for the new concepts added to the map.  New relationship instances/facts between ‘Movie’ concept instances and the new concept instances will also need to be created.

The new relationships need to be taken into account for the final recommendation. The relationships that make up each triangle could be added to the stack rule created previously on the ‘gets recommendation relationship”. However, as you can see from Figure 6, this would make the rule on the relationship “overstacked”:

Figure 6: Over stacked rule

The rule in figure 6 needs less work to implement as it is all built on one relationship, but maintaining the rule will be difficult.

To improve the accessibility, the rules will be segmented into 3 different sub-rules on 3 new relationships between the “Person” and “Film” concepts:

  • ”get recommendation based on logistic” to enclose the “Location” and “Time bracket” triangles
  • ”get recommendation based on meta info” to enclose the “Rating”, “Language” and “Length” triangles
  • “get recommendation based on content” to enclose the “Genre” and “Subjects” triangles

You will also need to create an additional relationship between the “Person” and “Movie” concepts that will combine the three combination rules. Figure 7 below is a visual representation of how the combined rule logic works:

Figure 7: Combined rule logic

Your rules should be structured as shown in Figure 8 below:

Figure 8: Combination rule structure

To ensure Rainbird always returns a result, the conditions in the overall rule are set as optional: 

Figure 9: Conditions in the overall rule are all set to optional

Now, if not all the conditions in the rule are satisfied, Rainbird will still infer that the most suitable movie to recommend is the result with the highest certainty factor.

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

Query & Results

The stack rule is built on the ‘gets recommended a movie based on content’ relationship.

The combined rule is built on the ‘get recommendation combined’ relationship

Article Feedback form
Did you find this article useful?

Version 1.02 – Last Update: 19/02/2021

Bitnami