# A Semantic Model for Enhancing Data-Driven Open Banking Services
## 4 Reconciliation and Inference
### Semantic Inference  
This last use case is devoted to illustrating two inference tasks oriented towards allowing customer classification and concept suggestion by means of semantic reasoning.  
First, the values of the _obs:debtRatio_ data property of the _Customer_ class are calculated by means of several SPARQL queries for each customer (_obs:itemHasCustomer_) and company (_obs:itemHasCompany_). The debt ratio is calculated with Equation (1), which is applied to the aggregation of the amounts (_obs:itemCurrencyAmt_) of all the items of the class _Opened_ (these amounts are the outstanding items), divided by the sum of the amount of all the customer's items. Then, in accordance with the debt values, a set of SWRL semantic rules were defined to establish a classification of customers, as follows: the _Low_ label is assigned to those customers with a debt ratio lower than 30% (The rule is shown in Code Listing 2), the _Medium_ label is assigned to those with a debt ratio between 30% and 70% (The rule is shown in Code Listing 3), and finally, the _High_ label is assigned to customers with a debt ratio higher than 70% (The rule is shown in Code Listing 4).  
\[debtRatio=\frac{\sum\text{amount\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\; \;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;  
```
invoke:Customer(?c) ^ obs:debtRatio(?c,?dRatio) ^ swrlb:lessThan(?dRatio, 70) ^ swrlb:greaterThanOrEqual(?dRatio, 30) -> obs:debtType(?c, \"Average\")
```  
Listing 4: High debt.  
```
ons:Customer(?c) ^ obs:debtRatio(?c,?dRatio) ^ swrlb:greaterThanOrEqual(?dRatio, 70) -> obs:debtType(?c, \"High\")
```  
Listing 5: Debt Type.  
Therefore, the value of data property _obs:debtType_ is inferred by the reasoner in the proposed semantic model, hence allowing an additional population of this element in the RDF repository. In this way, to obtain a given customer's classification according to his/her debt with a particular company, the SPARQL Query shown in Code Listing 5 can be used (this refers to the specific case of customer ID 367 with company ID 226).  
```
PREFIX obs:<[[http://ontologies.khaos.uma.es/obo/](http://ontologies.khaos.uma.es/obo/)]([http://ontologies.khaos.uma.es/obo/](http://ontologies.khaos.uma.es/obo/))> SELECT?debtType WHERE(?item obs:itemHasCompany?c. FILTER(?c=company226)?item obs:itemHasCustomer?u. FILTER(?u=customer367)?u obs:debtType?debtType }
```  
Listing 5: Debt Type.  
Second, taking advantage of the information stored in the knowledge graph, it is possible to infer concepts suggested for different bank movements. To this end, the SWRL Rule shown in Code Listing 6 was defined to merge information from classes _Opened_ and _Customer_, comprising the data properties that annotate the customer's fiscal identification number (_fiscalId_), the maturity date of the item (_itemMaturityDate_), and the amount of the closed item (_itemAmount_). The semantic reasoner is then used to concatenate these values and to form the _suggestedConcept_ data property, thereby reconciling bank movements.  
```
obs:Opened(?o) ^ obs:Customer(?c) ^ obs:fiscalId(?c,?fId) ^ obs:itemMaturityDate(?o,?Date) ^ obs:itemHasCustomer(?o,?c) ^ obs:itemAmount(?o,?a) ^ swrlb:stringConcat(?con,?fId,?mDate,?a) -> obs:suggestedConcept(?o,?con)
```  
Listing 6: Suggested concept.  
An example of a SPARQL query for this use case is shown in Query shown in Code Listing 7, where, given the URI of an individual of the _Opened class_, the reasoner is able to calculate the value for the _suggestedConcept_ property.  
```
PREFIIX obs:<[[http://ontologies.khaos.uma.es/obo/](http://ontologies.khaos.uma.es/obo/)]([http://ontologies.khaos.uma.es/obo/](http://ontologies.khaos.uma.es/obo/))> SELECT?concept WHERE(?rdf:type obs:Opened. FILTER(?i = obs:item843)?i obs:suggestedConcept?concept }
```  
Listing 7: Example of suggested concept query.