# From code similarity detection to model driven similarity detection: first milestones

Jarod Blain, Corentin Guillevic, Alex Moulin, Ali Benjilany, Pascal Andre,

Hugo Bruneliere, Dalila Tamzalit

► To cite this version:

Jarod Blain, Corentin Guillevic, Alex Moulin, Ali Benjilany, Pascal Andre, et al.. From code similarity detection to model driven similarity detection: first milestones. Journées du GDR GPL 2021, Jun 2021, Nice (Sophia Antipolis), France. hal-05431000

HAL Id: hal-05431000

https://hal.science/hal-05431000v1

Submitted on 24 Dec 2025

HAL is a multi-disciplinary open access
archive for the deposit and dissemination of sci-
entific research documents, whether they are pub-
lished or not. The documents may come from
teaching and research institutions in France or
abroad, or from public or private research centers.

L'archive ouverte pluridisciplinaire HAL, est
destinée au dépôt et à la diffusion de documents
scientifiques de niveau recherche, publiés ou non,
émanant des établissements d'enseignement et de
recherche français ou étrangers, des laboratoires
publics ou privés.

<figure><img src="image_1.png" /></figure>

Distributed under a Creative Commons Attribution 4.0 International License
# From code similarity detection to model driven similarity detection: first milestones

Jarod BLAIN<fnref n="1" />, Coretin GUILLEVIC<fnref n="1" />, Alex MOULIN<fnref n="1" />, Ali BENJILANY<fnref n="2" />

## Objectives

* Detect similarities in software applications:

* source code level

* model level

* Identify the best tool.

* Produce similarity metrics.

* Provide guidelines

## Scope

* Object-oriented code similarity is the similarity between syntax, function output, code structure, architecture.

* Comparing code is useful in a lot of situations (see **Use Cases**) and used in education, engineering, research, etc

* Structure analysis is very effective but difficult due to its specific aspect.

* The state of the art shows that every software has a flaw when it comes to overall comparison (not based on one use case).

* The ultimate goal is to have one tool that can do it all (a do-it-all tool) achieved by building a collaborative toolbox, picking the best from existing software.

* Going from source code to models.

<figure><img src="image_2.png" /></figure>

## Insights

* Clones and duplicates increase software tests and maintenance costs.

* Factoring out duplicates and inconsistencies management needs duplicates detection that can lean on similarity calculation.

* Experimentations done on the code of the **Benchmarks** according to **Use Cases**.

* 15 tools identified and 7 tested.

* State of the art: 23 papers studied and spread out into 5 categories: tool comparison, tools, metrics, methods & approaches, and models.

* "Plagiarism detection must be integrated into the toolset and activities of MDE instructors." [1]

* "When source code is copied and modified, which code similarity detection techniques or tools get the most accurate results?" [3]

## Milestone 1 - From code similarity detection...

### Tool Comparison

* Different existing tools compared [4].

* The best (overall) tool is JPlag according to its results and ease of use.

<caption>Matches sorted by average similarity (What is this?)</caption>

download.csv

<figure><img src="image_3.png" /></figure>

JPlag
Detecting Software Plagiarism

> "A metric is an information that can be extracted from code resulting in a number (e.g. number of lines)".

### Metrics Study

* Similarity ratio = f(software engineering metrics, similarity metrics).

* Metrics help also for abstraction means.

* We experimented a simplified version to validate our computation formula.

<table><thead><tr><th>%</th><th>v1</th><th>v2</th><th>v3</th><th>v4</th><th>v5</th><th>final</th></tr></thead><tbody><tr><th>v1</th><td>73.93</td><td>80.64</td><td>19.71</td><td>24.31</td><td>28.10</td><td></td></tr><tr><th>v2</th><td></td><td>89.28</td><td>24.32</td><td>21.22</td><td>19.06</td><td></td></tr><tr><th>v3</th><td></td><td></td><td>15.48</td><td>19.21</td><td>22.54</td><td></td></tr><tr><th>v4</th><td></td><td></td><td></td><td>80.38</td><td>74.47</td><td></td></tr><tr><th>v5</th><td></td><td></td><td></td><td></td><td>92.92</td><td></td></tr></tbody></table>

<table><thead><tr><th>%</th><th>v1</th><th>v2</th><th>v3</th><th>v4</th><th>v5</th><th>final</th></tr></thead><tbody><tr><th>v1</th><td>86.14</td><td>87.34</td><td>54.64</td><td>51.08</td><td>48.10</td><td></td></tr><tr><th>v2</th><td></td><td>78.57</td><td>43.78</td><td>41.79</td><td>40.12</td><td></td></tr><tr><th>v3</th><td></td><td></td><td>60.80</td><td>55.91</td><td>52.02</td><td></td></tr><tr><th>v4</th><td></td><td></td><td></td><td>87.03</td><td>78.75</td><td></td></tr><tr><th>v5</th><td></td><td></td><td></td><td></td><td>90.10</td><td></td></tr></tbody></table>

<table><thead><tr><th>%</th><th>v1</th><th>v2</th><th>v3</th><th>v4</th><th>v5</th><th>final</th></tr></thead><tbody><tr><th>v1</th><td>83.55</td><td>94.18</td><td>42.38</td><td>39.13</td><td>34.92</td><td></td></tr><tr><th>v2</th><td></td><td>79.64</td><td>28.52</td><td>26.35</td><td>23.53</td><td></td></tr><tr><th>v3</th><td></td><td></td><td>47.80</td><td>44.13</td><td>39.37</td><td></td></tr><tr><th>v4</th><td></td><td></td><td></td><td>89.51</td><td>80.40</td><td></td></tr><tr><th>v5</th><td></td><td></td><td></td><td></td><td>89.85</td><td></td></tr></tbody></table>

## A SimpleGame Example (code similarity)

<figure><img src="image_4.png" /></figure>

Two versions of the same game, written by a different person

<figure><img src="image_5.png" /><figcaption>Modisco's Java model discoverer</figcaption></figure>

<table><thead><tr><th rowspan="2">Number of</th><th colspan="2">Metrics</th><th rowspan="2">Similarity ratio</th></tr><tr><th>Game v1 class</th><th>Game v2 class</th></tr></thead><tbody><tr><td>Try catch</td><td>0</td><td>2</td><td>0,00%</td></tr><tr><td>methods</td><td>3</td><td>4</td><td>75,00%</td></tr><tr><td>calls</td><td>11</td><td>8</td><td>72,73%</td></tr><tr><td>if statements</td><td>1</td><td>1</td><td>100,00%</td></tr><tr><td>lines</td><td>58</td><td>92</td><td>63,04%</td></tr><tr><td></td><td colspan="2">Average similarity</td><td>62,15%</td></tr></tbody></table>

Plagiarism detection requires code or model **mutation** to introduce the malicious copy strategy (future work).

## Milestone 2 - ... to model similarity detection

<figure><img src="image_6.png" /></figure>

* Same results, different entities : (Java → Constructor - KDM model → MethodUnit - Operation<---> UML).

* Model similarity detection reveals changes made on the architecture of a program regardless of code details thanks to the rise in abstraction, while the code similarity detection returns a global rate of similarity.

* Abstraction requires fine heuristics to obtain high-level concepts [2].

→ Meanwhile, the upcoming milestones of the research might come up with a proof of the efficiency of a certain model-based comparison compared to the others. Much remains to do, especially in reverse engineering and comparison implementation.

## References

[1] Salvador Pérez, Manuel Wimmer, and Jordi Cabot. "Efficient plagiarism detection for software modeling assignments". In:Computer Science Education30 (Jan. 2020), pp. 1–29.doi:10.1080/08993408.2020.1711495

[2] Pascal André et al. "JavaCompExt: Extracting Architectural Elements from Java Source Code". In:WCRE. Lille, France: IEEE, Oct. 2009, pp. 317–318.doi:10.1109/WCRE.2009.53.

[3] Chaiyong Ragkhitwetsagul, Jens Krinke, and David Clark. "A comparison of code similarity analysers". In:Empirical Software Engineering23.4 (2018), pp. 2464–2519.

[4] Master TER Report 2021 https://uncloud.univ-nantes.fr/index.php/s/k2Ezp4bJ8bki3Sn

## Use Cases

<figure><img src="image_7.png" /></figure>

* Plagiarism

* Licensing

* Clone detection

* Code refactoring & Code reuse

* Pattern detection

* Software defects,

* Malware insertion

Best tools
**JPLAG**
**MOSS**

<figure><img src="image_8.png" /></figure>

According to our experimentations, JPLAG and MOSS are very good in their comparison results, they both give accurate detailed and easy to understand results. JPlag is used in this poster for it's easiness and simplicity.

## Benchmarks

<figure><img src="image_9.png" /></figure>

* Simple programs

* Student applications

* Lego EV3+android applications

* Git repositories

* Plagiarism benchmarks

## Further information

Supervisors: ANDRE Pascal, BRUNELIERE Hugo, TAMZALIT Dalila

Students report: https://uncloud.univ-nantes.fr/index.php/s/k2Ezp4bJ8bki3Sn
https://www.ls2n.fr/equipe/aelos/
https://www.ls2n.fr/equipe/naomod/

Poster credit - https://colinpurrington.com/tips/poster-design/

<footnote n="1">¹Université de Nantes, CNRS, LS2N, F-44000, Nantes, France</footnote>

<footnote n="2">²Ecole Nationale Supérieure d'Informatique et d'Analyse des Systèmes, Rabat, Maroc</footnote>

<footnote n="1">¹ Etudiants en M1 ALMA- ² Elève ingénieur</footnote>