Matheel 0.3.2__tar.gz → 0.3.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. {matheel-0.3.2 → matheel-0.3.3}/PKG-INFO +70 -48
  2. {matheel-0.3.2 → matheel-0.3.3}/README.md +69 -47
  3. {matheel-0.3.2 → matheel-0.3.3}/matheel/chunking.py +0 -67
  4. {matheel-0.3.2 → matheel-0.3.3}/matheel/code_metrics.py +0 -4
  5. {matheel-0.3.2 → matheel-0.3.3}/matheel/model_routing.py +0 -4
  6. {matheel-0.3.2 → matheel-0.3.3}/matheel/preprocessing.py +0 -4
  7. {matheel-0.3.2 → matheel-0.3.3}/matheel/similarity.py +3 -33
  8. {matheel-0.3.2 → matheel-0.3.3}/matheel/vectors.py +1 -1
  9. {matheel-0.3.2 → matheel-0.3.3}/matheel.egg-info/PKG-INFO +70 -48
  10. {matheel-0.3.2 → matheel-0.3.3}/pyproject.toml +1 -1
  11. {matheel-0.3.2 → matheel-0.3.3}/tests/test_similarity.py +1 -0
  12. {matheel-0.3.2 → matheel-0.3.3}/LICENSE +0 -0
  13. {matheel-0.3.2 → matheel-0.3.3}/matheel/__init__.py +0 -0
  14. {matheel-0.3.2 → matheel-0.3.3}/matheel/cli.py +0 -0
  15. {matheel-0.3.2 → matheel-0.3.3}/matheel/comparison_suite.py +0 -0
  16. {matheel-0.3.2 → matheel-0.3.3}/matheel/feature_weights.py +0 -0
  17. {matheel-0.3.2 → matheel-0.3.3}/matheel.egg-info/SOURCES.txt +0 -0
  18. {matheel-0.3.2 → matheel-0.3.3}/matheel.egg-info/dependency_links.txt +0 -0
  19. {matheel-0.3.2 → matheel-0.3.3}/matheel.egg-info/entry_points.txt +0 -0
  20. {matheel-0.3.2 → matheel-0.3.3}/matheel.egg-info/requires.txt +0 -0
  21. {matheel-0.3.2 → matheel-0.3.3}/matheel.egg-info/top_level.txt +0 -0
  22. {matheel-0.3.2 → matheel-0.3.3}/setup.cfg +0 -0
  23. {matheel-0.3.2 → matheel-0.3.3}/tests/test_chunking.py +0 -0
  24. {matheel-0.3.2 → matheel-0.3.3}/tests/test_cli.py +0 -0
  25. {matheel-0.3.2 → matheel-0.3.3}/tests/test_code_metrics.py +0 -0
  26. {matheel-0.3.2 → matheel-0.3.3}/tests/test_comparison_suite.py +0 -0
  27. {matheel-0.3.2 → matheel-0.3.3}/tests/test_feature_weights.py +0 -0
  28. {matheel-0.3.2 → matheel-0.3.3}/tests/test_gradio_app.py +0 -0
  29. {matheel-0.3.2 → matheel-0.3.3}/tests/test_model_routing.py +0 -0
  30. {matheel-0.3.2 → matheel-0.3.3}/tests/test_preprocessing.py +0 -0
  31. {matheel-0.3.2 → matheel-0.3.3}/tests/test_real_models.py +0 -0
  32. {matheel-0.3.2 → matheel-0.3.3}/tests/test_vectors.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: matheel
3
- Version: 0.3.2
3
+ Version: 0.3.3
4
4
  Summary: Matheel: A CLI and Python package for source-code similarity detection.
5
5
  Author: Fahad Ebrahim
6
6
  License-Expression: MIT
@@ -48,7 +48,13 @@ Dynamic: license-file
48
48
 
49
49
  # Matheel
50
50
 
51
- Matheel is a simple, function-based Python package and CLI for source-code similarity. It combines semantic embeddings, lexical similarity, chunking, preprocessing, and code-aware metrics without forcing a class-heavy API.
51
+ Matheel is a function-based Python package and CLI for source-code similarity. It combines semantic embeddings, lexical similarity, chunking, preprocessing, and code-aware metrics in one workflow.
52
+
53
+ ## Demos
54
+
55
+ - Hugging Face Space demo: [buelfhood/matheel-framework](https://huggingface.co/spaces/buelfhood/matheel-framework)
56
+ - Gradio Colab notebook: [Open in Colab](https://colab.research.google.com/github/FahadEbrahim/matheel/blob/main/gradio_app/matheel_gradio_colab_demo.ipynb)
57
+ - Examples Colab notebook: [Open in Colab](https://colab.research.google.com/github/FahadEbrahim/matheel/blob/main/examples/matheel_examples_colab.ipynb)
52
58
 
53
59
  ## Installation
54
60
 
@@ -77,9 +83,13 @@ pip install "matheel[dev]"
77
83
 
78
84
  ## Quick Start
79
85
 
80
- The repo includes a small Java archive at `sample_pairs.zip` for quick validation.
86
+ The repository root includes `sample_pairs.zip`, a small Java archive with:
81
87
 
82
- CLI:
88
+ - `code_1.java`
89
+ - `code_3_plag.java`
90
+ - additional plagiarized and non-plagiarized comparisons
91
+
92
+ CLI archive comparison:
83
93
 
84
94
  ```bash
85
95
  matheel compare sample_pairs.zip \
@@ -90,31 +100,36 @@ matheel compare sample_pairs.zip \
90
100
  --num 10
91
101
  ```
92
102
 
93
- Python:
103
+ Python pairwise scoring with the sample pair:
94
104
 
95
105
  ```python
96
- from matheel.similarity import get_sim_list
106
+ from zipfile import ZipFile
97
107
 
98
- results = get_sim_list(
99
- "sample_pairs.zip",
108
+ from matheel.similarity import calculate_similarity
109
+
110
+ with ZipFile("sample_pairs.zip") as archive:
111
+ code_a = archive.read("code_1.java").decode("utf-8")
112
+ code_b = archive.read("code_3_plag.java").decode("utf-8")
113
+
114
+ score = calculate_similarity(
115
+ code_a,
116
+ code_b,
100
117
  model_name="huggingface/CodeBERTa-small-v1",
101
- threshold=0.2,
102
- number_results=10,
103
118
  feature_weights={
104
119
  "semantic": 0.7,
105
120
  "levenshtein": 0.3,
106
121
  },
107
122
  )
108
- print(results.head())
123
+
124
+ print(round(score, 4))
109
125
  ```
110
126
 
111
- ## Supported Languages
127
+ ## Supported Scope
112
128
 
113
- - Chunking is language-agnostic by default because it can split any text.
114
- - `CodeBLEU`-style metrics are intentionally scoped to `Java`, `Python`, `C`, and `C++`.
115
- - Generic preprocessing works across languages, but code-aware metrics are most defensible in that four-language scope.
129
+ Supported languages:
116
130
 
117
- ## Supported Methods
131
+ - Chunking and preprocessing are text-first and can run on any source text.
132
+ - Code-aware metrics are currently scoped to `Java`, `Python`, `C`, and `C++`.
118
133
 
119
134
  Similarity features:
120
135
 
@@ -137,12 +152,14 @@ Code metrics:
137
152
  - `tsed`
138
153
  - `codebertscore`
139
154
 
140
- `ruby` now uses a full staged implementation (`graph -> tree -> string`), with optional runtime dependencies enabled via `matheel[metrics]`.
141
-
142
155
  Chunking methods:
143
156
 
144
157
  - `none`
145
- - Chonkie-backed when installed: `code`, `chonkie_token`, `chonkie_sentence`, `chonkie_recursive`, `chonkie_fast`
158
+ - `code`
159
+ - `chonkie_token`
160
+ - `chonkie_sentence`
161
+ - `chonkie_recursive`
162
+ - `chonkie_fast`
146
163
 
147
164
  Vector backends:
148
165
 
@@ -169,15 +186,6 @@ Sentence Transformers pooling methods:
169
186
 
170
187
  `auto` inspects Hugging Face model metadata and routes to the correct backend when the model exposes a known library.
171
188
 
172
- ## Core Parts
173
-
174
- - Preprocessing: whitespace and comment normalization before any scoring.
175
- - Chunking: Chonkie-backed document splitting with per-method options.
176
- - Vectors: dense single-vector, learned static single-vector, and multivector late interaction.
177
- - Lexical metrics and baselines: normalized Levenshtein, Jaro-Winkler, Winnowing, and Greedy String Tiling.
178
- - Code metrics: built-in CodeBLEU-style metrics and CrystalBLEU.
179
- - Comparison suite: run multiple configurations, rank them, and optionally write summary/detail artifacts.
180
-
181
189
  ## CLI
182
190
 
183
191
  Compare a directory or ZIP archive:
@@ -218,9 +226,12 @@ Pairwise scoring:
218
226
  ```python
219
227
  from matheel.similarity import calculate_similarity
220
228
 
229
+ code_a = "def add(a, b):\n return a + b\n"
230
+ code_b = "def add(x, y):\n return x + y\n"
231
+
221
232
  score = calculate_similarity(
222
- "def add(a, b):\n return a + b\n",
223
- "def add(x, y):\n return x + y\n",
233
+ code_a,
234
+ code_b,
224
235
  model_name="huggingface/CodeBERTa-small-v1",
225
236
  vector_backend="auto",
226
237
  max_token_length=256,
@@ -241,10 +252,10 @@ Directory or ZIP ranking:
241
252
  from matheel.similarity import get_sim_list
242
253
 
243
254
  results = get_sim_list(
244
- "sample_codes",
255
+ "sample_pairs.zip",
245
256
  model_name="huggingface/CodeBERTa-small-v1",
246
257
  threshold=0.4,
247
- number_results=50,
258
+ number_results=10,
248
259
  vector_backend="auto",
249
260
  max_token_length=256,
250
261
  chunking_method="chonkie_token",
@@ -260,45 +271,56 @@ results = get_sim_list(
260
271
  "gst": 0.05,
261
272
  },
262
273
  )
263
- ```
264
274
 
265
- ## Hugging Face Routing
266
-
267
- Matheel can inspect Hugging Face model metadata and route automatically:
268
-
269
- - `sentence-transformers` models go to the Sentence Transformers path
270
- - `model2vec` models go to the model2vec static path
271
- - `PyLate` models go to the multivector late-interaction path
272
-
273
- If metadata is unavailable, Matheel falls back to simple name and tag heuristics, then defaults to the Sentence Transformers path.
275
+ print(results.head())
276
+ ```
274
277
 
275
278
  ## Docs
276
279
 
277
- - Docs index: [docs/index.md](docs/index.md)
280
+ - Docs folder landing page: [docs/README.md](docs/README.md)
281
+ - Canonical docs index: [docs/index.md](docs/index.md)
278
282
  - Quick usage: [docs/usage.md](docs/usage.md)
279
283
  - Preprocessing: [docs/preprocessing.md](docs/preprocessing.md)
280
284
  - Chunking: [docs/chunking.md](docs/chunking.md)
281
- - Vectors: [docs/vectors.md](docs/vectors.md)
282
- - Edit distance and feature weights: [docs/lexical.md](docs/lexical.md)
285
+ - Vectors and routing: [docs/vectors.md](docs/vectors.md)
286
+ - Lexical metrics and baselines: [docs/lexical.md](docs/lexical.md)
283
287
  - Code metrics: [docs/code_metrics.md](docs/code_metrics.md)
284
288
  - Comparison suite: [docs/comparison_suite.md](docs/comparison_suite.md)
285
289
 
286
- The `docs/` folder is already structured well for a later GitHub Pages setup if you decide to publish the docs site from the repository.
287
-
288
290
  ## Examples
289
291
 
292
+ - Colab walkthrough: [examples/matheel_examples_colab.ipynb](examples/matheel_examples_colab.ipynb)
290
293
  - Quick archive check: [examples/sample_pairs_demo.py](examples/sample_pairs_demo.py)
291
294
  - Preprocessing: [examples/preprocessing_demo.py](examples/preprocessing_demo.py)
292
295
  - Chunking: [examples/chunking_demo.py](examples/chunking_demo.py)
293
296
  - Vector backends: [examples/vectors_demo.py](examples/vectors_demo.py)
294
- - Edit distance and feature weights: [examples/lexical_demo.py](examples/lexical_demo.py)
297
+ - Lexical metrics and baselines: [examples/lexical_demo.py](examples/lexical_demo.py)
295
298
  - Code metrics: [examples/code_metrics_demo.py](examples/code_metrics_demo.py)
296
299
  - Comparison suite: [examples/comparison_suite_demo.py](examples/comparison_suite_demo.py)
297
300
 
301
+ All examples use the same sample pair from `sample_pairs.zip`: `code_1.java` and `code_3_plag.java`.
302
+
298
303
  ## Gradio
299
304
 
300
305
  The Gradio demo stays in `gradio_app/` and is aligned with the Hugging Face Space setup. The UI supports embeddings, lexical metrics, baseline algorithms (Winnowing and GST), and the code-aware metrics (CodeBLEU, CrystalBLEU, RUBY, TSED, CodeBERTScore), with metric-specific advanced fields. The core package and CLI can read either a ZIP archive or a directory; the Gradio upload flow remains ZIP-based.
301
306
 
307
+ ## Acknowledgments
308
+
309
+ Matheel builds on several open-source libraries:
310
+
311
+ - [Sentence Transformers](https://pypi.org/project/sentence-transformers/)
312
+ - [Chonkie](https://pypi.org/project/chonkie/)
313
+ - [model2vec](https://pypi.org/project/model2vec/)
314
+ - [PyLate](https://pypi.org/project/pylate/)
315
+ - [RapidFuzz](https://pypi.org/project/rapidfuzz/)
316
+ - [tree-sitter-language-pack](https://pypi.org/project/tree-sitter-language-pack/)
317
+ - [NetworkX](https://pypi.org/project/networkx/)
318
+ - [APTED](https://pypi.org/project/apted/)
319
+ - [bert-score](https://pypi.org/project/bert-score/)
320
+ - [Gradio](https://pypi.org/project/gradio/)
321
+
322
+ The project also depends on the standard scientific Python stack and related tooling, including NumPy, pandas, Click, SentencePiece, and func-timeout.
323
+
302
324
  ## License
303
325
 
304
326
  This project is licensed under the [MIT License](LICENSE).
@@ -1,6 +1,12 @@
1
1
  # Matheel
2
2
 
3
- Matheel is a simple, function-based Python package and CLI for source-code similarity. It combines semantic embeddings, lexical similarity, chunking, preprocessing, and code-aware metrics without forcing a class-heavy API.
3
+ Matheel is a function-based Python package and CLI for source-code similarity. It combines semantic embeddings, lexical similarity, chunking, preprocessing, and code-aware metrics in one workflow.
4
+
5
+ ## Demos
6
+
7
+ - Hugging Face Space demo: [buelfhood/matheel-framework](https://huggingface.co/spaces/buelfhood/matheel-framework)
8
+ - Gradio Colab notebook: [Open in Colab](https://colab.research.google.com/github/FahadEbrahim/matheel/blob/main/gradio_app/matheel_gradio_colab_demo.ipynb)
9
+ - Examples Colab notebook: [Open in Colab](https://colab.research.google.com/github/FahadEbrahim/matheel/blob/main/examples/matheel_examples_colab.ipynb)
4
10
 
5
11
  ## Installation
6
12
 
@@ -29,9 +35,13 @@ pip install "matheel[dev]"
29
35
 
30
36
  ## Quick Start
31
37
 
32
- The repo includes a small Java archive at `sample_pairs.zip` for quick validation.
38
+ The repository root includes `sample_pairs.zip`, a small Java archive with:
33
39
 
34
- CLI:
40
+ - `code_1.java`
41
+ - `code_3_plag.java`
42
+ - additional plagiarized and non-plagiarized comparisons
43
+
44
+ CLI archive comparison:
35
45
 
36
46
  ```bash
37
47
  matheel compare sample_pairs.zip \
@@ -42,31 +52,36 @@ matheel compare sample_pairs.zip \
42
52
  --num 10
43
53
  ```
44
54
 
45
- Python:
55
+ Python pairwise scoring with the sample pair:
46
56
 
47
57
  ```python
48
- from matheel.similarity import get_sim_list
58
+ from zipfile import ZipFile
49
59
 
50
- results = get_sim_list(
51
- "sample_pairs.zip",
60
+ from matheel.similarity import calculate_similarity
61
+
62
+ with ZipFile("sample_pairs.zip") as archive:
63
+ code_a = archive.read("code_1.java").decode("utf-8")
64
+ code_b = archive.read("code_3_plag.java").decode("utf-8")
65
+
66
+ score = calculate_similarity(
67
+ code_a,
68
+ code_b,
52
69
  model_name="huggingface/CodeBERTa-small-v1",
53
- threshold=0.2,
54
- number_results=10,
55
70
  feature_weights={
56
71
  "semantic": 0.7,
57
72
  "levenshtein": 0.3,
58
73
  },
59
74
  )
60
- print(results.head())
75
+
76
+ print(round(score, 4))
61
77
  ```
62
78
 
63
- ## Supported Languages
79
+ ## Supported Scope
64
80
 
65
- - Chunking is language-agnostic by default because it can split any text.
66
- - `CodeBLEU`-style metrics are intentionally scoped to `Java`, `Python`, `C`, and `C++`.
67
- - Generic preprocessing works across languages, but code-aware metrics are most defensible in that four-language scope.
81
+ Supported languages:
68
82
 
69
- ## Supported Methods
83
+ - Chunking and preprocessing are text-first and can run on any source text.
84
+ - Code-aware metrics are currently scoped to `Java`, `Python`, `C`, and `C++`.
70
85
 
71
86
  Similarity features:
72
87
 
@@ -89,12 +104,14 @@ Code metrics:
89
104
  - `tsed`
90
105
  - `codebertscore`
91
106
 
92
- `ruby` now uses a full staged implementation (`graph -> tree -> string`), with optional runtime dependencies enabled via `matheel[metrics]`.
93
-
94
107
  Chunking methods:
95
108
 
96
109
  - `none`
97
- - Chonkie-backed when installed: `code`, `chonkie_token`, `chonkie_sentence`, `chonkie_recursive`, `chonkie_fast`
110
+ - `code`
111
+ - `chonkie_token`
112
+ - `chonkie_sentence`
113
+ - `chonkie_recursive`
114
+ - `chonkie_fast`
98
115
 
99
116
  Vector backends:
100
117
 
@@ -121,15 +138,6 @@ Sentence Transformers pooling methods:
121
138
 
122
139
  `auto` inspects Hugging Face model metadata and routes to the correct backend when the model exposes a known library.
123
140
 
124
- ## Core Parts
125
-
126
- - Preprocessing: whitespace and comment normalization before any scoring.
127
- - Chunking: Chonkie-backed document splitting with per-method options.
128
- - Vectors: dense single-vector, learned static single-vector, and multivector late interaction.
129
- - Lexical metrics and baselines: normalized Levenshtein, Jaro-Winkler, Winnowing, and Greedy String Tiling.
130
- - Code metrics: built-in CodeBLEU-style metrics and CrystalBLEU.
131
- - Comparison suite: run multiple configurations, rank them, and optionally write summary/detail artifacts.
132
-
133
141
  ## CLI
134
142
 
135
143
  Compare a directory or ZIP archive:
@@ -170,9 +178,12 @@ Pairwise scoring:
170
178
  ```python
171
179
  from matheel.similarity import calculate_similarity
172
180
 
181
+ code_a = "def add(a, b):\n return a + b\n"
182
+ code_b = "def add(x, y):\n return x + y\n"
183
+
173
184
  score = calculate_similarity(
174
- "def add(a, b):\n return a + b\n",
175
- "def add(x, y):\n return x + y\n",
185
+ code_a,
186
+ code_b,
176
187
  model_name="huggingface/CodeBERTa-small-v1",
177
188
  vector_backend="auto",
178
189
  max_token_length=256,
@@ -193,10 +204,10 @@ Directory or ZIP ranking:
193
204
  from matheel.similarity import get_sim_list
194
205
 
195
206
  results = get_sim_list(
196
- "sample_codes",
207
+ "sample_pairs.zip",
197
208
  model_name="huggingface/CodeBERTa-small-v1",
198
209
  threshold=0.4,
199
- number_results=50,
210
+ number_results=10,
200
211
  vector_backend="auto",
201
212
  max_token_length=256,
202
213
  chunking_method="chonkie_token",
@@ -212,45 +223,56 @@ results = get_sim_list(
212
223
  "gst": 0.05,
213
224
  },
214
225
  )
215
- ```
216
226
 
217
- ## Hugging Face Routing
218
-
219
- Matheel can inspect Hugging Face model metadata and route automatically:
220
-
221
- - `sentence-transformers` models go to the Sentence Transformers path
222
- - `model2vec` models go to the model2vec static path
223
- - `PyLate` models go to the multivector late-interaction path
224
-
225
- If metadata is unavailable, Matheel falls back to simple name and tag heuristics, then defaults to the Sentence Transformers path.
227
+ print(results.head())
228
+ ```
226
229
 
227
230
  ## Docs
228
231
 
229
- - Docs index: [docs/index.md](docs/index.md)
232
+ - Docs folder landing page: [docs/README.md](docs/README.md)
233
+ - Canonical docs index: [docs/index.md](docs/index.md)
230
234
  - Quick usage: [docs/usage.md](docs/usage.md)
231
235
  - Preprocessing: [docs/preprocessing.md](docs/preprocessing.md)
232
236
  - Chunking: [docs/chunking.md](docs/chunking.md)
233
- - Vectors: [docs/vectors.md](docs/vectors.md)
234
- - Edit distance and feature weights: [docs/lexical.md](docs/lexical.md)
237
+ - Vectors and routing: [docs/vectors.md](docs/vectors.md)
238
+ - Lexical metrics and baselines: [docs/lexical.md](docs/lexical.md)
235
239
  - Code metrics: [docs/code_metrics.md](docs/code_metrics.md)
236
240
  - Comparison suite: [docs/comparison_suite.md](docs/comparison_suite.md)
237
241
 
238
- The `docs/` folder is already structured well for a later GitHub Pages setup if you decide to publish the docs site from the repository.
239
-
240
242
  ## Examples
241
243
 
244
+ - Colab walkthrough: [examples/matheel_examples_colab.ipynb](examples/matheel_examples_colab.ipynb)
242
245
  - Quick archive check: [examples/sample_pairs_demo.py](examples/sample_pairs_demo.py)
243
246
  - Preprocessing: [examples/preprocessing_demo.py](examples/preprocessing_demo.py)
244
247
  - Chunking: [examples/chunking_demo.py](examples/chunking_demo.py)
245
248
  - Vector backends: [examples/vectors_demo.py](examples/vectors_demo.py)
246
- - Edit distance and feature weights: [examples/lexical_demo.py](examples/lexical_demo.py)
249
+ - Lexical metrics and baselines: [examples/lexical_demo.py](examples/lexical_demo.py)
247
250
  - Code metrics: [examples/code_metrics_demo.py](examples/code_metrics_demo.py)
248
251
  - Comparison suite: [examples/comparison_suite_demo.py](examples/comparison_suite_demo.py)
249
252
 
253
+ All examples use the same sample pair from `sample_pairs.zip`: `code_1.java` and `code_3_plag.java`.
254
+
250
255
  ## Gradio
251
256
 
252
257
  The Gradio demo stays in `gradio_app/` and is aligned with the Hugging Face Space setup. The UI supports embeddings, lexical metrics, baseline algorithms (Winnowing and GST), and the code-aware metrics (CodeBLEU, CrystalBLEU, RUBY, TSED, CodeBERTScore), with metric-specific advanced fields. The core package and CLI can read either a ZIP archive or a directory; the Gradio upload flow remains ZIP-based.
253
258
 
259
+ ## Acknowledgments
260
+
261
+ Matheel builds on several open-source libraries:
262
+
263
+ - [Sentence Transformers](https://pypi.org/project/sentence-transformers/)
264
+ - [Chonkie](https://pypi.org/project/chonkie/)
265
+ - [model2vec](https://pypi.org/project/model2vec/)
266
+ - [PyLate](https://pypi.org/project/pylate/)
267
+ - [RapidFuzz](https://pypi.org/project/rapidfuzz/)
268
+ - [tree-sitter-language-pack](https://pypi.org/project/tree-sitter-language-pack/)
269
+ - [NetworkX](https://pypi.org/project/networkx/)
270
+ - [APTED](https://pypi.org/project/apted/)
271
+ - [bert-score](https://pypi.org/project/bert-score/)
272
+ - [Gradio](https://pypi.org/project/gradio/)
273
+
274
+ The project also depends on the standard scientific Python stack and related tooling, including NumPy, pandas, Click, SentencePiece, and func-timeout.
275
+
254
276
  ## License
255
277
 
256
278
  This project is licensed under the [MIT License](LICENSE).
@@ -49,73 +49,6 @@ def available_chunk_aggregations():
49
49
  return ("mean", "max", "first")
50
50
 
51
51
 
52
- def _normalize_chunk_settings(chunk_size, chunk_overlap):
53
- size = int(chunk_size or 0)
54
- overlap = int(chunk_overlap or 0)
55
- if size <= 0:
56
- size = 1
57
- if overlap < 0:
58
- overlap = 0
59
- if overlap >= size:
60
- overlap = size - 1
61
- return size, overlap
62
-
63
-
64
- def _window_chunks(items, chunk_size, chunk_overlap, separator):
65
- if not items:
66
- return []
67
-
68
- size, overlap = _normalize_chunk_settings(chunk_size, chunk_overlap)
69
- step = max(1, size - overlap)
70
- chunks = []
71
- start = 0
72
-
73
- while start < len(items):
74
- current = items[start : start + size]
75
- if not current:
76
- break
77
- value = separator.join(current).strip()
78
- if value:
79
- chunks.append(value)
80
- start += step
81
-
82
- return chunks
83
-
84
-
85
- def chunk_by_lines(text, chunk_size=20, chunk_overlap=0):
86
- lines = (text or "").splitlines()
87
- if not lines:
88
- return [""]
89
- return _window_chunks(lines, chunk_size, chunk_overlap, "\n")
90
-
91
-
92
- def chunk_by_tokens(text, chunk_size=200, chunk_overlap=0):
93
- tokens = (text or "").split()
94
- if not tokens:
95
- return [""]
96
- return _window_chunks(tokens, chunk_size, chunk_overlap, " ")
97
-
98
-
99
- def chunk_by_characters(text, chunk_size=1000, chunk_overlap=0):
100
- value = text or ""
101
- if not value:
102
- return [""]
103
-
104
- size, overlap = _normalize_chunk_settings(chunk_size, chunk_overlap)
105
- step = max(1, size - overlap)
106
- chunks = []
107
- start = 0
108
-
109
- while start < len(value):
110
- current = value[start : start + size]
111
- if not current:
112
- break
113
- chunks.append(current)
114
- start += step
115
-
116
- return chunks
117
-
118
-
119
52
  def parse_chunker_options(chunker_options):
120
53
  if chunker_options is None:
121
54
  return {}
@@ -186,10 +186,6 @@ def keyword_set_for_language(language):
186
186
  return _CODEBLEU_KEYWORD_CACHE[key]
187
187
 
188
188
 
189
- def code_metric_language_supported(language):
190
- return normalize_code_language(language) in _SUPPORTED_CODE_LANGUAGES
191
-
192
-
193
189
  def tokenize_for_code_metrics(text):
194
190
  return _TOKEN_RE.findall(text or "")
195
191
 
@@ -130,7 +130,3 @@ def resolve_vector_backend(requested_backend, model_name=None, model_info=None):
130
130
 
131
131
  def backend_is_multivector(vector_backend):
132
132
  return normalize_vector_backend_name(vector_backend) == "pylate"
133
-
134
-
135
- def backend_is_static(vector_backend):
136
- return normalize_vector_backend_name(vector_backend) in ("model2vec", "static_hash")
@@ -192,7 +192,3 @@ def preprocess_code(text, mode="none"):
192
192
  return collapse_whitespace(value)
193
193
 
194
194
  raise ValueError(f"Unsupported preprocess mode: {mode}")
195
-
196
-
197
- def preprocess_codes(texts, mode="none"):
198
- return [preprocess_code(text, mode=mode) for text in texts]
@@ -27,7 +27,6 @@ from .vectors import (
27
27
  build_multivector_embeddings,
28
28
  build_static_hash_vectors,
29
29
  build_chunked_single_vectors,
30
- configure_model_max_token_length,
31
30
  configure_sentence_transformer_pooling,
32
31
  detect_model_max_token_length,
33
32
  encode_single_vectors,
@@ -430,6 +429,7 @@ def gst_similarity_from_tokens(tokens1, tokens2, min_match_length=5):
430
429
  marked1 = [False] * len(tokens1)
431
430
  marked2 = [False] * len(tokens2)
432
431
  covered_tokens = 0
432
+ total_tokens = float(len(tokens1) + len(tokens2))
433
433
 
434
434
  # Repeatedly extract the longest non-overlapping matching tiles, then score
435
435
  # the proportion of both token streams that the tiles cover.
@@ -465,7 +465,7 @@ def gst_similarity_from_tokens(tokens1, tokens2, min_match_length=5):
465
465
  matches.append((index1, index2, length))
466
466
 
467
467
  if best_length < effective_min_match_length or not matches:
468
- break
468
+ return (2.0 * covered_tokens) / total_tokens
469
469
 
470
470
  accepted_matches = []
471
471
  for index1, index2, length in sorted(matches, key=lambda item: (-item[2], item[0], item[1])):
@@ -480,7 +480,7 @@ def gst_similarity_from_tokens(tokens1, tokens2, min_match_length=5):
480
480
  accepted_matches.append((index1, index2, length))
481
481
 
482
482
  if not accepted_matches:
483
- break
483
+ return (2.0 * covered_tokens) / total_tokens
484
484
 
485
485
  for index1, index2, length in accepted_matches:
486
486
  for offset in range(length):
@@ -488,8 +488,6 @@ def gst_similarity_from_tokens(tokens1, tokens2, min_match_length=5):
488
488
  marked2[index2 + offset] = True
489
489
  covered_tokens += length
490
490
 
491
- return (2.0 * covered_tokens) / float(len(tokens1) + len(tokens2))
492
-
493
491
 
494
492
  def build_document_embeddings(
495
493
  model,
@@ -677,34 +675,6 @@ def combined_similarity_from_embeddings(
677
675
  return combine_weighted_scores(feature_scores, feature_weights)
678
676
 
679
677
 
680
- def paraphrase_mining_with_combined_score(
681
- model,
682
- sentences,
683
- k=100,
684
- feature_weights=None,
685
- similarity_function="cosine",
686
- pooling_method="mean",
687
- max_token_length=None,
688
- ):
689
- resolved_feature_weights = resolve_feature_weights(feature_weights=feature_weights)
690
- model = configure_model_max_token_length(model, max_token_length=max_token_length)
691
- embeddings = build_document_embeddings(
692
- model,
693
- list(sentences),
694
- pooling_method=pooling_method,
695
- )
696
- results = rank_code_pairs(
697
- list(sentences),
698
- embeddings,
699
- resolved_feature_weights,
700
- similarity_function=similarity_function,
701
- )
702
- limit = max(0, int(k or 0))
703
- if limit:
704
- return results[:limit]
705
- return results
706
-
707
-
708
678
  def rank_code_pairs(
709
679
  codes,
710
680
  embeddings,
@@ -599,7 +599,7 @@ def multivector_similarity(left, right, bidirectional=True, vector_backend=None)
599
599
 
600
600
  def _pylate_scores_available():
601
601
  try:
602
- from pylate.scores import colbert_scores_pairwise # noqa: F401
602
+ __import__("pylate.scores")
603
603
  except ImportError:
604
604
  return False
605
605
  return True
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: matheel
3
- Version: 0.3.2
3
+ Version: 0.3.3
4
4
  Summary: Matheel: A CLI and Python package for source-code similarity detection.
5
5
  Author: Fahad Ebrahim
6
6
  License-Expression: MIT
@@ -48,7 +48,13 @@ Dynamic: license-file
48
48
 
49
49
  # Matheel
50
50
 
51
- Matheel is a simple, function-based Python package and CLI for source-code similarity. It combines semantic embeddings, lexical similarity, chunking, preprocessing, and code-aware metrics without forcing a class-heavy API.
51
+ Matheel is a function-based Python package and CLI for source-code similarity. It combines semantic embeddings, lexical similarity, chunking, preprocessing, and code-aware metrics in one workflow.
52
+
53
+ ## Demos
54
+
55
+ - Hugging Face Space demo: [buelfhood/matheel-framework](https://huggingface.co/spaces/buelfhood/matheel-framework)
56
+ - Gradio Colab notebook: [Open in Colab](https://colab.research.google.com/github/FahadEbrahim/matheel/blob/main/gradio_app/matheel_gradio_colab_demo.ipynb)
57
+ - Examples Colab notebook: [Open in Colab](https://colab.research.google.com/github/FahadEbrahim/matheel/blob/main/examples/matheel_examples_colab.ipynb)
52
58
 
53
59
  ## Installation
54
60
 
@@ -77,9 +83,13 @@ pip install "matheel[dev]"
77
83
 
78
84
  ## Quick Start
79
85
 
80
- The repo includes a small Java archive at `sample_pairs.zip` for quick validation.
86
+ The repository root includes `sample_pairs.zip`, a small Java archive with:
81
87
 
82
- CLI:
88
+ - `code_1.java`
89
+ - `code_3_plag.java`
90
+ - additional plagiarized and non-plagiarized comparisons
91
+
92
+ CLI archive comparison:
83
93
 
84
94
  ```bash
85
95
  matheel compare sample_pairs.zip \
@@ -90,31 +100,36 @@ matheel compare sample_pairs.zip \
90
100
  --num 10
91
101
  ```
92
102
 
93
- Python:
103
+ Python pairwise scoring with the sample pair:
94
104
 
95
105
  ```python
96
- from matheel.similarity import get_sim_list
106
+ from zipfile import ZipFile
97
107
 
98
- results = get_sim_list(
99
- "sample_pairs.zip",
108
+ from matheel.similarity import calculate_similarity
109
+
110
+ with ZipFile("sample_pairs.zip") as archive:
111
+ code_a = archive.read("code_1.java").decode("utf-8")
112
+ code_b = archive.read("code_3_plag.java").decode("utf-8")
113
+
114
+ score = calculate_similarity(
115
+ code_a,
116
+ code_b,
100
117
  model_name="huggingface/CodeBERTa-small-v1",
101
- threshold=0.2,
102
- number_results=10,
103
118
  feature_weights={
104
119
  "semantic": 0.7,
105
120
  "levenshtein": 0.3,
106
121
  },
107
122
  )
108
- print(results.head())
123
+
124
+ print(round(score, 4))
109
125
  ```
110
126
 
111
- ## Supported Languages
127
+ ## Supported Scope
112
128
 
113
- - Chunking is language-agnostic by default because it can split any text.
114
- - `CodeBLEU`-style metrics are intentionally scoped to `Java`, `Python`, `C`, and `C++`.
115
- - Generic preprocessing works across languages, but code-aware metrics are most defensible in that four-language scope.
129
+ Supported languages:
116
130
 
117
- ## Supported Methods
131
+ - Chunking and preprocessing are text-first and can run on any source text.
132
+ - Code-aware metrics are currently scoped to `Java`, `Python`, `C`, and `C++`.
118
133
 
119
134
  Similarity features:
120
135
 
@@ -137,12 +152,14 @@ Code metrics:
137
152
  - `tsed`
138
153
  - `codebertscore`
139
154
 
140
- `ruby` now uses a full staged implementation (`graph -> tree -> string`), with optional runtime dependencies enabled via `matheel[metrics]`.
141
-
142
155
  Chunking methods:
143
156
 
144
157
  - `none`
145
- - Chonkie-backed when installed: `code`, `chonkie_token`, `chonkie_sentence`, `chonkie_recursive`, `chonkie_fast`
158
+ - `code`
159
+ - `chonkie_token`
160
+ - `chonkie_sentence`
161
+ - `chonkie_recursive`
162
+ - `chonkie_fast`
146
163
 
147
164
  Vector backends:
148
165
 
@@ -169,15 +186,6 @@ Sentence Transformers pooling methods:
169
186
 
170
187
  `auto` inspects Hugging Face model metadata and routes to the correct backend when the model exposes a known library.
171
188
 
172
- ## Core Parts
173
-
174
- - Preprocessing: whitespace and comment normalization before any scoring.
175
- - Chunking: Chonkie-backed document splitting with per-method options.
176
- - Vectors: dense single-vector, learned static single-vector, and multivector late interaction.
177
- - Lexical metrics and baselines: normalized Levenshtein, Jaro-Winkler, Winnowing, and Greedy String Tiling.
178
- - Code metrics: built-in CodeBLEU-style metrics and CrystalBLEU.
179
- - Comparison suite: run multiple configurations, rank them, and optionally write summary/detail artifacts.
180
-
181
189
  ## CLI
182
190
 
183
191
  Compare a directory or ZIP archive:
@@ -218,9 +226,12 @@ Pairwise scoring:
218
226
  ```python
219
227
  from matheel.similarity import calculate_similarity
220
228
 
229
+ code_a = "def add(a, b):\n return a + b\n"
230
+ code_b = "def add(x, y):\n return x + y\n"
231
+
221
232
  score = calculate_similarity(
222
- "def add(a, b):\n return a + b\n",
223
- "def add(x, y):\n return x + y\n",
233
+ code_a,
234
+ code_b,
224
235
  model_name="huggingface/CodeBERTa-small-v1",
225
236
  vector_backend="auto",
226
237
  max_token_length=256,
@@ -241,10 +252,10 @@ Directory or ZIP ranking:
241
252
  from matheel.similarity import get_sim_list
242
253
 
243
254
  results = get_sim_list(
244
- "sample_codes",
255
+ "sample_pairs.zip",
245
256
  model_name="huggingface/CodeBERTa-small-v1",
246
257
  threshold=0.4,
247
- number_results=50,
258
+ number_results=10,
248
259
  vector_backend="auto",
249
260
  max_token_length=256,
250
261
  chunking_method="chonkie_token",
@@ -260,45 +271,56 @@ results = get_sim_list(
260
271
  "gst": 0.05,
261
272
  },
262
273
  )
263
- ```
264
274
 
265
- ## Hugging Face Routing
266
-
267
- Matheel can inspect Hugging Face model metadata and route automatically:
268
-
269
- - `sentence-transformers` models go to the Sentence Transformers path
270
- - `model2vec` models go to the model2vec static path
271
- - `PyLate` models go to the multivector late-interaction path
272
-
273
- If metadata is unavailable, Matheel falls back to simple name and tag heuristics, then defaults to the Sentence Transformers path.
275
+ print(results.head())
276
+ ```
274
277
 
275
278
  ## Docs
276
279
 
277
- - Docs index: [docs/index.md](docs/index.md)
280
+ - Docs folder landing page: [docs/README.md](docs/README.md)
281
+ - Canonical docs index: [docs/index.md](docs/index.md)
278
282
  - Quick usage: [docs/usage.md](docs/usage.md)
279
283
  - Preprocessing: [docs/preprocessing.md](docs/preprocessing.md)
280
284
  - Chunking: [docs/chunking.md](docs/chunking.md)
281
- - Vectors: [docs/vectors.md](docs/vectors.md)
282
- - Edit distance and feature weights: [docs/lexical.md](docs/lexical.md)
285
+ - Vectors and routing: [docs/vectors.md](docs/vectors.md)
286
+ - Lexical metrics and baselines: [docs/lexical.md](docs/lexical.md)
283
287
  - Code metrics: [docs/code_metrics.md](docs/code_metrics.md)
284
288
  - Comparison suite: [docs/comparison_suite.md](docs/comparison_suite.md)
285
289
 
286
- The `docs/` folder is already structured well for a later GitHub Pages setup if you decide to publish the docs site from the repository.
287
-
288
290
  ## Examples
289
291
 
292
+ - Colab walkthrough: [examples/matheel_examples_colab.ipynb](examples/matheel_examples_colab.ipynb)
290
293
  - Quick archive check: [examples/sample_pairs_demo.py](examples/sample_pairs_demo.py)
291
294
  - Preprocessing: [examples/preprocessing_demo.py](examples/preprocessing_demo.py)
292
295
  - Chunking: [examples/chunking_demo.py](examples/chunking_demo.py)
293
296
  - Vector backends: [examples/vectors_demo.py](examples/vectors_demo.py)
294
- - Edit distance and feature weights: [examples/lexical_demo.py](examples/lexical_demo.py)
297
+ - Lexical metrics and baselines: [examples/lexical_demo.py](examples/lexical_demo.py)
295
298
  - Code metrics: [examples/code_metrics_demo.py](examples/code_metrics_demo.py)
296
299
  - Comparison suite: [examples/comparison_suite_demo.py](examples/comparison_suite_demo.py)
297
300
 
301
+ All examples use the same sample pair from `sample_pairs.zip`: `code_1.java` and `code_3_plag.java`.
302
+
298
303
  ## Gradio
299
304
 
300
305
  The Gradio demo stays in `gradio_app/` and is aligned with the Hugging Face Space setup. The UI supports embeddings, lexical metrics, baseline algorithms (Winnowing and GST), and the code-aware metrics (CodeBLEU, CrystalBLEU, RUBY, TSED, CodeBERTScore), with metric-specific advanced fields. The core package and CLI can read either a ZIP archive or a directory; the Gradio upload flow remains ZIP-based.
301
306
 
307
+ ## Acknowledgments
308
+
309
+ Matheel builds on several open-source libraries:
310
+
311
+ - [Sentence Transformers](https://pypi.org/project/sentence-transformers/)
312
+ - [Chonkie](https://pypi.org/project/chonkie/)
313
+ - [model2vec](https://pypi.org/project/model2vec/)
314
+ - [PyLate](https://pypi.org/project/pylate/)
315
+ - [RapidFuzz](https://pypi.org/project/rapidfuzz/)
316
+ - [tree-sitter-language-pack](https://pypi.org/project/tree-sitter-language-pack/)
317
+ - [NetworkX](https://pypi.org/project/networkx/)
318
+ - [APTED](https://pypi.org/project/apted/)
319
+ - [bert-score](https://pypi.org/project/bert-score/)
320
+ - [Gradio](https://pypi.org/project/gradio/)
321
+
322
+ The project also depends on the standard scientific Python stack and related tooling, including NumPy, pandas, Click, SentencePiece, and func-timeout.
323
+
302
324
  ## License
303
325
 
304
326
  This project is licensed under the [MIT License](LICENSE).
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "matheel"
7
- version = "0.3.2"
7
+ version = "0.3.3"
8
8
  authors = [
9
9
  { name = "Fahad Ebrahim" }
10
10
  ]
@@ -8,6 +8,7 @@ from matheel import similarity
8
8
 
9
9
  class FakeModel:
10
10
  def encode(self, inputs, convert_to_numpy=True):
11
+ _ = convert_to_numpy
11
12
  if isinstance(inputs, str):
12
13
  return np.asarray(_vectorize(inputs), dtype=float)
13
14
  return np.asarray([_vectorize(item) for item in inputs], dtype=float)
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes