## 4 CAS Development
### CAS Implementation
#### 4.3.2 System implementation  
This project developed a program called Ontogen. This program was written in Python and Java. In the Arvalis use case, Ontogen takes as input specific sensor measurements provided by Arvalis in an Excel file and produces the output as the state of CropWaterNeed property. The program itself can be divided into three modules:  
* Virtual sensors: read data from Excel files. * Aggregators: run functions to produce aggregated data. * Inference engine: The core is OWLAPI ([[https://github.com/owlcs/owlapi](https://github.com/owlcs/owlapi)]([https://github.com/owlcs/owlapi](https://github.com/owlcs/owlapi))) and SWRLAPI ([[https://github.com/protegeproject/swrlapi](https://github.com/protegeproject/swrlapi)]([https://github.com/protegeproject/swrlapi](https://github.com/protegeproject/swrlapi))). This module uses a set of SWRL rules, and all the data provided from the previous module to infer the high-level context. The aggregations are encoded in Python as a function. The deductions are executed by the SWRLAPI Drool inference engine integrated into Ontogen. In detail, the reasoning process of the inference engine in Ontogen can be explained as follows. First, Ontogen generates an OWL file that contains all the individuals and the IRRIG ontology necessary for the rule engine; it creates all the individuals that describe sensor measurements. It also creates the individuals, instances of **caso:Deduction**, necessary to define the daily deduction per instance of the class **caso:Property**. The file name is the concatenation of the feature of interest name and the beginning date. Second, it launches the Drools rule engine and applies it to the individuals previously created. The Drools engine updates the **caso:Deduction** instance. It links an instance of the class **caso:State** with an instance of **caso:Deduction** via the object property caso:hasResultState. Then, it creates a new OWL file that contains the results of the inference engine. The OWL file is updated from the previous file. The rule for Drools is coded in SWRL. There are a total of 25 rules in SWRL and two queries in semantic query-enhanced web rule language (SQWRL):  
* 5 rules for crop growth. * 1 rule for rain intensity. * 1 rule for root zone soil moisture level. * 16 rules for crop water need. * 2 SQWRL queries for the results after the reasoning. Each rule is put in a rule file with a \".rule\" extension. The rule files are available on the GitLab repository of INRAE via the following link [[https://gitlab.irstea.fr/irrig/public/tree/master/Rule](https://gitlab.irstea.fr/irrig/public/tree/master/Rule)]([https://gitlab.irstea.fr/irrig/public/tree/master/Rule](https://gitlab.irstea.fr/irrig/public/tree/master/Rule)). The DSS consists of (1) a knowledge base and an inference engine, mostly for high-level context inference, and (2) several functions for numeric data calculation. Except for the case of SleepingDuration, it is a numeric value, but the inference engine produces its value. The knowledge-base contains a rules-base and a facts-base. Technically speaking, the DSS is a part of the Ontogen program. Each day, the DSS takes phenomenon observations as input and produces an irrigation decision. Please note that the Arvalis dataset does not provide the sensor measurements but the daily aggregated values of those measurements. Figure 7 shows the algorithm implemented by the DSS. At 06:00:00 on day d, the system triggers the DSS to start the computation. First, the DSS retrieves the observations relevant to days d-1 and d recorded in the Arvalis dataset. Please note that in the algorithm of Figure 7, the data retrieved at the instant [d 06:00:00] belong to the period [d-1 00:00:00, d 06:00:00]. The DSS checks the value of the evaluation of the CropGrowth property of day d-1.