This is the second in a series of posts about Relationships in Intelligent Advisor. The first post can be found here. When we left the last article we had built a simple design to illustrate the concept of containment relationships or reference relationships. In this second chapter, we will discuss the following ideas and how they might be useful to you on the subject of memberships:
- Defining Membership of a Relationship
- Using Membership of a Relationship
We saw in the previous chapter that having reference relationships in an interview allows the end user to participate in the selection of members of a relationship. For example, which pet belongs to which family member, and which pet food is for which pet. This concept of membership is an important one. If we think of each relationship as a group (of people, of pets or whatever). But what happens if you don’t want to ask this sort of question of an end user, but you want or need to work it out yourself? For example, you need to group together all the family members who are adults (and those who are children)?
We could of course do something like this InstanceCountIf(the family members, the family member’s age > 18) to extract the family members whose age is greater than 18. But this is only useful in the sense that it tells us how many people there are in that group. If you actually intend to do something with that group, such as make some calculations, examine them in different ways, then it’s not so interesting.
Let’s make a step forward to make an example. How can we deliver the requirement? Begin, as we did before, by creating a new Relationship. Let’s call it the the adult family members.
In the screen capture above, you can see the instances of the family member with the different people and a small example of a family member with the new information. And you can see also the relationship at the bottom that I created. Here is the detail of how that membership was built:
The key here is the first rule. The second one should be fairly straightforward since this comes up almost everywhere – the age of a citizen from the date of birth.
“Is a member of” is a great function to leverage membership of a relationship. It is also available in a short format IsMemberOf(). But let’s look at the long version we have here. A given family member is considered a member of the “adult family members” group if they meet the conditions. And selecting the relationship in the debugger allows us to see the rules have done their job.
As you can see above, the relationship is defined in the normal way. The relationship is just like the existing relationship which groups all of the family members but this time it is called the adult family members. And it is up to us to define how to become a member of the group – which we do in that first rule that defines the conditions of membership. So it looks like this in the debugger.
Note the three key points – this relationship is inferred by your rule, so the developer (or the end user, when we finally get round to sharing this information with them) cannot change the results here. The only way to change the results is to change the rules. Secondly, we are not creating family members here – you can see that these three family members were created normally at the top of the debugger window. Finally, the View decision button lets you check why these family members are in this group.
Now that we have our group defined and available to us, we can use it like any other relationship:
InstanceCount(the adult family members)
In fact this membership can be used in your rule in just the same way as any other. And the relationship can also be used as a condition itself:
In the third part of this series, we will discuss a feature that should make more sense when we look at an example, but it is the concept of a reverse relationship. If a pet belongs to a family member, we can describe that in two directions ; “The family member’s pet” or “the pet’s family member”. And many of us who have pets will understand that this is useful. But obviously in a real scenario, if I’m looking at family members and their visits to the clinic, then it can be useful to look at a visit to the clinic and look for the family member to whom it belongs. Membership can be interesting in both directions. More in part three of this back to basics series!