Rules and templates
To manage Rules in the Intelligent Automation Cloud, go to Advanced > Rules. You can create, edit, delete, copy, and export/import Rules.
Rules can also be created from templates (Advanced > Rule Templates).
Rule Structure
To edit Rules in advanced mode, you need to learn the Drools language.
A typical rule file can contain one or several rules with the following structure:
Basic Rule Structure
rule "name"
attributes
when
LHS - conditional part
then
RHS - executional block
end
Rule Types
The Intelligent Automation Cloud has the following Rule Types:
- Adjudication. Adjudication Rules use a majority rule algorithm that you can set to determine how many Workers you want to have to agree in order to reach a consensus.
- Gold Adjudication. These Rules are used to automatically generate gold questions based upon Adjudication (Majority found).
Gold Adjudication Rule Example
# This rule first checks to see if a majority has been reached and then it marks these records as gold.
rule "0. Check, if exist majority"
agenda-group "calculation"
dialect "mvel"
salience 100
no-loop
when
$ctx:RuleContext (initialized == true , assigments.size >= 2, majority.size >= 1, $threshold:properties.MAJORITY_HIT_THRESHOLD)
eval($ctx.majority().size() >= $ctx.questions.size() * $threshold)
then
insert(new String("MAJORITY_FOUND"));
$ctx.logExecutedRule(kcontext.getRule().getName());
end
rule "1 Determine new gold questions"
dialect "mvel"
salience 90
no-loop
when
String(toString == "MAJORITY_FOUND")
$ctx:RuleContext()
$rqc:RuleQuestionContext()
eval($rqc.count($ctx.majority()) == $rqc.answers.size())
then
$rqc.markAsGoldQuestion();
$ctx.logExecutedRule(kcontext.getRule().getName(), $rqc);
end
- Qualification. Qualification Rules are used to evaluate Worker performance in Qualification Tasks. They allow the Intelligent Automation Cloud to grant Accuracy Based Qualifications to Workers based on their performance on such Tasks.
- Composite. Composite Rules - Advanced Options control Task progression and escalation through Business Process.
- Task Comparator. Task Comparator (Manual tasks sorting) is used as a global parameter for environments (separately for Development and Production) which defines the order of displaying Tasks of the same type (Campaign) to Workers.
- Task Distribution. This Rule is used as a Workforce parameter to make possible to complete the Tasks in a custom order. See the Dynamic Task Distribution among Crowds topic.
Task Distribution Rule Example
package com.freedomoss.requester;
#list any import classes here.
import com.freedomoss.objective.model.RuleContext;
import com.freedomoss.objective.model.DistributionRuleContext;
import com.freedomoss.requester.service.mes.TaskDistributionStrategyContext;
import com.freedomoss.requester.service.mes.TaskDistributionStrategyEnum;
import com.freedomoss.requester.service.mes.ITaskDistributionStrategy;
import com.freedomoss.requester.service.mes.impl.TaskDistributionStrategyFactory;
import com.freedomoss.requester.service.mes.impl.AdvancedStrategy
import com.freedomoss.requester.model.AwsHit;
import com.freedomoss.workfusion.model.mes.Workforce;
import com.freedomoss.workfusion.model.mes.Crowd;
import com.freedomoss.model.HitSubmissionDataItem;
import com.freedomoss.model.HitSubmissionDataItemValue;
import org.slf4j.Logger;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.Map;
import java.util.HashMap;
import java.util.Iterator;
#declare any global variables here
global DistributionRuleContext source
global Logger log
global Map params
rule "Distribute"
auto-focus true
no-loop
when
$ctx: DistributionRuleContext();
then
$ctx.setDistribution(getTasksDistribution($ctx.getDistributionContext()));
end
function Map<Crowd, List<AwsHit>> getTasksDistribution(TaskDistributionStrategyContext context) {
Map<Crowd, List<AwsHit>> result = new HashMap<Crowd, List<AwsHit>>();
Workforce workforce = context.getWorkforce();
List<Crowd> crowds = workforce.getEnabledCrowds();
for (Crowd crowd: crowds){
result.put(crowd, new ArrayList<AwsHit>());
}
List<AwsHit> hits = context.getHits();
Map<Long, List<HitSubmissionDataItem>> hitDataItemsMap = context.getHitDataItemsMap();
for (AwsHit hit: context.getHits()) {
for(HitSubmissionDataItem item: hitDataItemsMap.get(hit.getId())) {
for(HitSubmissionDataItemValue val:item.getValues()){
System.out.println("================== VALUES language: "+val.getName()+" =====================");
}
HitSubmissionDataItemValue languageObj = item.getValue("language");
if(languageObj != null){
String language = languageObj.getItemValue();
if ("en".equals(language)){
Crowd crowd = crowds.get(0);
result.get(crowd).add(hit);
} else {
Crowd crowd = crowds.get(1);
result.get(crowd).add(hit);
}
}
}
}
return result;
}
Rule Parameters Overview
All of the Rules in the Intelligent Automation Cloud have rule parameters associated with them.
These parameters allow non technical users of the platform to configure and customize the behavior of the rules. Rule Parameters are created in Rule Templates > Edit Template > Params tab.

Creating a Rule
To create a new Rule in the Intelligent Automation Cloud:
- Go to Campaigns > Rules.

- Click the Create button.

- Enter a unique Rule Name.
- Select Rule Type from the appropriate dropdown.
- Select a Rule Template from the Adjudication Strategy dropdown.
- Optional: If you want to create a Rule from scratch (without selecting a template), click the Switch to Advanced View link and write a custom Drools code.
- Click the Save button in the bottom right corner.
Creating a Rule Template
Rule Templates are intended for re-using code when creating new Rules and for creating Rule Parameters.
To create a new Rule Template in the Intelligent Automation Cloud:
- Go to Campaigns > Rule Templates.

- Click the Create button.

- Enter a unique Rule Template Name.
- Add Description.
- Write a custom Drools code in the Code Editor.
- Click the Save button.
Adding Rule Parameters
Rule Parameters allow non technical users of the platform to configure and customize the behavior of the rules.
To add Rule Parameters:
- Go to Campaigns > Rule Templates.
- Click an appropriate Rule in the Name column.

- Switch to the Params tab.

- Click the Add Param button – the Edit Param dialog will be displayed under the grid.

- Enter the parameter Name (will be displayed for user).
- Enter the unique parameter Code (this code will be used in the Rule code). Example of using parameters in rule code:
{{RETRACT_ROUND_SIZE}}. - Select the parameter Type (control type: number, text, or text area).
- Enter the parameter Default Value.
- Add Description.
- Click the Save button.