IATI Ruleset Spec¶
An IATI Ruleset is a JSON document. The structure is described below.
A JSON schema is availible to test that the structure of a Ruleset is correct.
Each JSON document has the form.:
{
"CONTEXT": {
"RULE_NAME": {
"cases": CASE_DICT_ARRAY
}
}
}
Where CONTEXT is an xpath expression. This will be used to select the XML elements that the contained rules will be tested against.
RULE_NAME is one of rule names listed below
CASE_DICT is a dictionary where the contents depend on RULE_NAME
CASE_DICT_ARRAY is an array of case dictionaries. The contents of each dictionary depend on the RULE_NAME
The possible keys in a case dictionary are:
conditionAn xpath string. If this evaluates to True, the rule will be ignored.
evalAn xpath string. Can evaluate to True or False.
pathsAn array of xpath strings. These are evaluated to give a list of elements that the named rule then operates upon.
lessA string containing the xpath of the smaller value (or older value when working with dates).
moreA string containing the xpath of the larger value (or more recent value when working with dates).
regexA string containing a perl style regular expression.
sumA number.
excludedAn array of xpath strings. Evaluate which elements should not coexist with other elements.
dateA string containing the xpath to a date.
startA string containing the xpath to a start date.
endA string containing the xpath to an end date.
oneA string containing the xpath of something that must exist or
allmust be followed.allA string containing the condition that must be met for all elements if
oneis not met.foreachAn array of xpath strings. Containing a set of xpaths to be evaluated under a different rule.
doAn array of rules. To evaluate with
foreach.subsAn array of xpath strings. These are to be evaluated with the rules in
do.
Rule Names¶
- Rule names are listed in bold
Keys: The keys for each rule are then listed.
Followed by a brief description of the rule’s function.
- no_more_than_one
Keys:
condition,pathsThere must be no more than one element described by the given paths.
- atleast_one
Keys:
condition,pathsThere must be at least one element described by the given paths.
- only_one_of
Keys:
excluded,pathsIf there’s a match of the elements in
excluded, there must not be any matches inpaths, if there are no matches inexcluded, there must be exactly one element frompaths.- one_or_all
Keys:
one,allonemust exist otherwiseallother attributes or elements must exist.- dependent
Keys:
condition,pathsIf one of the provided paths exists, they must all exist.
- sum
Keys:
condition,paths,sumThe numerical sum of the values of elements matched by
pathsmust match the value for thesumkey- date_order
Keys:
condition,less,moreThe date matched by
lessmust not be after the date matched bymore. If either of these dates is not found, the rule is ignored.- date_now
Keys:
dateThe
datemust not be after the current date.- time_limit
Keys:
start,endThe difference between the
startdate and theenddate must not be greater than a year.- between_dates
Keys:
date,start,endThe
datemust be between thestartandenddates.- regex_matches
Keys:
condition,paths,regexThe provided
regexmust match the text of all elements matched bypaths- regex_no_matches
Keys:
condition,paths,regexThe provided
regexmust match the text of none of the elements matched bypaths- startswith
Keys:
condition,paths,startThe text of each element matched by
pathsmust start with the text of the element matched bystart- unique
Keys:
condition,pathsThe text of each of the elements described by
pathsmust be unique- if_then
Keys:
condition,cases,if,thenIf the condition evaluated in
ifis true, thenthenmust resolve to true as well- loop
Keys:
foreach,do,cases,subsAll elements in
foreachare evaluated under the rules insidedo- strict_sum
Keys:
paths,sumThe decimal sum of the values of elements matched by
pathsmust match the value for thesumkey