Rule syntax details: component rules
In this chapter, we will explore the when and then sections of component rules, detailing how to define the conditions and specify the actions for component construction in DocuMine.
When part: filter for entity
The "when" part of a component rule filters the document for relevant entities to be mapped. The "when" section's content specifies conditions the rule has to meet to be executed. It specifically identifies the entity or entities from which a component is intended to be built, and directs the rule engine to filter for these entities.
In the example below, all objects meeting the specified condition are compiled into a single collection. This condition requires that each object be an entity of the type “study_results”.
Example #1:
when $results: List() from collect (Entity(type == "study_results"))
You can also restrict the component building to entities in documents that fulfill specific criteria:
In the example below, only the documents with the “OECD Number” file attribute and the file attribute values “402”, “403”, “404”, and “405” are filtered for the “study results” entity that is bound to the $results variable.
Example #2:
when $oecdNumber: String() from List.of("402", "403", "404", "405") FileAttribute(label == "OECD Number", value == $oecdNumber) $results: List() from collect (Entity(type == "study_results"))
For detailed component rule use cases, please see Use cases: component construction.
Then part: construct component
The "then" part defines the actions to be taken if the conditions in the “when” part are met. It instructs DocuMine to build components (by invoking the componentCreationService method) and link the identified entities with the components.
That part of a rule invokes the componentCreationService and uses the “.joining” method to aggregate the identified information. The example below creates a component called “Study results” that combines all the values collected from the entity filtered for in the “when” section (not part of the code example) that are bound to the “$results” variable.
Example:
then componentCreationService.joining("PrelimResults.0.0", "study_results", $results)
For detailed component rule use cases, please see Use cases: component construction.