Example: Investigate a Goal     

A common requirement in a Oracle-based application is to determine a value of a particular attribute (known as the goal) by asking the user a series of questions.  Ideally the application should only ask the minimum of questions necessary to get an answer.  This is known as investigating a goal.

Investigating a goal is done by repeatedly calling Attribute.getNextQuestion() and acting on the Question object that is returned. The Attribute.isUnknown() method indicates the state of the goal being investigated :

 

When the goal state is known, the typical response would be to show the user either the value of the goal or a message about the goal exhaustion.

When the goal state is unknown, the next action is usually to ask the user for the value of an attribute.  The attribute that needs an answer is given by the Question.getAttribute() method (with the Question.getEntityInstance() providing the entity instance in which the attribute should be set).  The Question.getQuestionText() method returns a string for the attribute (in question form) suitable for displaying to the user.

Once a value has been collected from the user, it should be set inside the Session.  Note that if the attribute returned by Question.getAttribute() is null it is an indication that all the instances of a Relationship need to be collected.  The Relationship can be determined by Question.getRelationship().  In this case, rather than setting the value of a single attribute, the application should prompt the user for instances of the entity, and create EntityInstance objects for each one.  Once all entity instances have been determined the entity should be marked as complete via Relationship.setInstance(). Until this happens, Attribute.getNextQuestion() will continue to return the relationship to be collected.

Once the question has been answered, Attribute.getNextQuestion() can be called again to continue the investigation of the goal.  Eventually, the goal will become known; note however, that the result could still be uncertain/unknown, depending upon the supplied ruleset and data.

The following code fragments perform a simple goal investigation to find a value for attribute ID "a5".  They use the standard text input/output capabilities provided by Java and C# respectively, and understand how to collect both entities and attributes - click on the appropriate link to view either the Java or the C# example:

 

Java Code Example:

 

C# Code Example:

 

See also:

Display a Screen