# DTAG: A Methodology for Aggregating Digital Twins Using the WOTDT Ontology
## 4 DTw Aggregation Methodology
### Mappings Aggregation
#### Shapes Aggregation (SHACL Shapes)  
As explained earlier in this article, the aggregation of the shape models uses SHACL shapes. The goal of the SHACL shape aggregation activity is to perform aggregation between two SHACL shape models to obtain a single SHACL shape model. This model has to follow the ontology obtained from the ontology aggregation activity and also contains all the restriction rules to validate the semantic data that are stored in the Knowledge Graph of the DTwA. This activity involves the DTwA user performing the aggregation process, and the domain experts providing information about the validation rules and constraints that are useful to validate the knowledge graph of the DTwA. Therefore, the output of this activity is a SHACL shape model that contains all the validation rules and constraints that allow for the validation of the knowledge graph of the resultant DTwA. Furthermore, this SHACL shape model should be referenced in the instantiation of the DTwA using WoTDT ontology. In addition to mapping models, SHACL shape models are ontology-based; therefore, the three aggregation scenarios that are in the ontology model aggregation will also be in the shapes model aggregation. For the first and second scenarios, no merging process is needed because the aggregated ontologies are already aligned. Therefore, the DTws shapes have to be referenced by the DTwA instantiation using the WoTDT ontology. However, in the third scenario, a merge between the SHACL shapes models has to be performed since the ontologies have been aligned previously, as well as the generation of new restriction rules in the case that the ontologies have been extended. In Figure 17, the workflow of this activity is presented depending on the particular aggregation scenario. With the goal of performing the merging process between SHACL shapes models, there is no literature on how two mapping models should be merged. However, a possible solution could be the use of the instance matching method, as well as in the mapping models aggregation section, since SHACL shape models are written in the RDF language. Once the instance matching is performed, the DTwA user and the domain experts should analyse the constraints of each pair of related instances from the instance matching process and compare each of the constraints that each of them contains. After comparison, the DTwA user decides which constraints to keep to satisfy the needs to be covered by the DTwA. An example of this decision can be if there is a constraint for an instance of sh:minCount equal to \"2\", and in the other shape model, there is a constraint for the same instance of \"sh:maxCount\" equal to \"1\". For these instances, the user can select one of them or instead create a new constraint that may include the two constraints, like, for example, sh:minCount equals \"1\". Once this instance matching process has been performed, the DTwA user has to validate the SHACL shape obtained from the aggregation to ensure that their syntax is correct. For this purpose, the SHACL standard provides specific shapes (SHACL shapes validation: [[https://www.w3.org/TR/shacl/#shacl-shacl](https://www.w3.org/TR/shacl/#shacl-shacl)]([https://www.w3.org/TR/shacl/#shacl-shacl](https://www.w3.org/TR/shacl/#shacl-shacl)), accessed on 18 May 2024) to validate the syntax of the generated shape graphs. Figure 16: Mapping model aggregation instantiation result. Furthermore, since a specific naming pattern has been chosen for the URIs of the DTwA instances, as explained in the mapping model aggregation, the instances and their respective restrictions existing in the shapes should be modified to validate the instance URIs with the new naming strategy. Finally, the resultant SHACL shape model from the aggregation process has to be referenced in the instantiation of the DTwA using the WoTDT ontology and establish links from this SHACL shape model to the SHACL shape models of the DTws involved in the aggregation process.