Matheel 0.3.2__tar.gz → 0.3.4__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.
- {matheel-0.3.2 → matheel-0.3.4}/PKG-INFO +73 -48
- {matheel-0.3.2 → matheel-0.3.4}/README.md +72 -47
- {matheel-0.3.2 → matheel-0.3.4}/matheel/chunking.py +0 -67
- {matheel-0.3.2 → matheel-0.3.4}/matheel/cli.py +1 -1
- {matheel-0.3.2 → matheel-0.3.4}/matheel/code_metrics.py +258 -67
- {matheel-0.3.2 → matheel-0.3.4}/matheel/model_routing.py +0 -4
- matheel-0.3.4/matheel/native_codebleu.py +1071 -0
- {matheel-0.3.2 → matheel-0.3.4}/matheel/preprocessing.py +243 -12
- {matheel-0.3.2 → matheel-0.3.4}/matheel/similarity.py +3 -33
- {matheel-0.3.2 → matheel-0.3.4}/matheel/vectors.py +1 -1
- {matheel-0.3.2 → matheel-0.3.4}/matheel.egg-info/PKG-INFO +73 -48
- {matheel-0.3.2 → matheel-0.3.4}/matheel.egg-info/SOURCES.txt +1 -0
- {matheel-0.3.2 → matheel-0.3.4}/pyproject.toml +1 -1
- matheel-0.3.4/tests/test_code_metrics.py +518 -0
- matheel-0.3.4/tests/test_preprocessing.py +574 -0
- {matheel-0.3.2 → matheel-0.3.4}/tests/test_similarity.py +1 -0
- matheel-0.3.2/tests/test_code_metrics.py +0 -256
- matheel-0.3.2/tests/test_preprocessing.py +0 -67
- {matheel-0.3.2 → matheel-0.3.4}/LICENSE +0 -0
- {matheel-0.3.2 → matheel-0.3.4}/matheel/__init__.py +0 -0
- {matheel-0.3.2 → matheel-0.3.4}/matheel/comparison_suite.py +0 -0
- {matheel-0.3.2 → matheel-0.3.4}/matheel/feature_weights.py +0 -0
- {matheel-0.3.2 → matheel-0.3.4}/matheel.egg-info/dependency_links.txt +0 -0
- {matheel-0.3.2 → matheel-0.3.4}/matheel.egg-info/entry_points.txt +0 -0
- {matheel-0.3.2 → matheel-0.3.4}/matheel.egg-info/requires.txt +0 -0
- {matheel-0.3.2 → matheel-0.3.4}/matheel.egg-info/top_level.txt +0 -0
- {matheel-0.3.2 → matheel-0.3.4}/setup.cfg +0 -0
- {matheel-0.3.2 → matheel-0.3.4}/tests/test_chunking.py +0 -0
- {matheel-0.3.2 → matheel-0.3.4}/tests/test_cli.py +0 -0
- {matheel-0.3.2 → matheel-0.3.4}/tests/test_comparison_suite.py +0 -0
- {matheel-0.3.2 → matheel-0.3.4}/tests/test_feature_weights.py +0 -0
- {matheel-0.3.2 → matheel-0.3.4}/tests/test_gradio_app.py +0 -0
- {matheel-0.3.2 → matheel-0.3.4}/tests/test_model_routing.py +0 -0
- {matheel-0.3.2 → matheel-0.3.4}/tests/test_real_models.py +0 -0
- {matheel-0.3.2 → matheel-0.3.4}/tests/test_vectors.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: matheel
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.4
|
|
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
|
|
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
|
|
|
@@ -75,11 +81,17 @@ pip install "matheel[dev]"
|
|
|
75
81
|
|
|
76
82
|
`matheel[all]` installs the currently supported optional backends in one command: Chonkie code chunking, metrics runtime dependencies (RUBY graph/tree, TSED, CodeBERTScore), model2vec, PyLate, and the Gradio app dependencies.
|
|
77
83
|
|
|
84
|
+
Matheel now ships a native CodeBLEU implementation that uses `tree_sitter_language_pack` for parser resolution, so real syntax/dataflow scoring no longer depends on installing the pip `codebleu` package. The pip package is still useful for validation/comparison work if you want to cross-check the native scores on selected examples; Matheel does not currently claim exact pip parity on every possible input.
|
|
85
|
+
|
|
78
86
|
## Quick Start
|
|
79
87
|
|
|
80
|
-
The
|
|
88
|
+
The repository root includes `sample_pairs.zip`, a small Java archive with:
|
|
89
|
+
|
|
90
|
+
- `code_1.java`
|
|
91
|
+
- `code_3_plag.java`
|
|
92
|
+
- additional plagiarized and non-plagiarized comparisons
|
|
81
93
|
|
|
82
|
-
CLI:
|
|
94
|
+
CLI archive comparison:
|
|
83
95
|
|
|
84
96
|
```bash
|
|
85
97
|
matheel compare sample_pairs.zip \
|
|
@@ -90,31 +102,37 @@ matheel compare sample_pairs.zip \
|
|
|
90
102
|
--num 10
|
|
91
103
|
```
|
|
92
104
|
|
|
93
|
-
Python:
|
|
105
|
+
Python pairwise scoring with the sample pair:
|
|
94
106
|
|
|
95
107
|
```python
|
|
96
|
-
from
|
|
108
|
+
from zipfile import ZipFile
|
|
97
109
|
|
|
98
|
-
|
|
99
|
-
|
|
110
|
+
from matheel.similarity import calculate_similarity
|
|
111
|
+
|
|
112
|
+
with ZipFile("sample_pairs.zip") as archive:
|
|
113
|
+
code_a = archive.read("code_1.java").decode("utf-8")
|
|
114
|
+
code_b = archive.read("code_3_plag.java").decode("utf-8")
|
|
115
|
+
|
|
116
|
+
score = calculate_similarity(
|
|
117
|
+
code_a,
|
|
118
|
+
code_b,
|
|
100
119
|
model_name="huggingface/CodeBERTa-small-v1",
|
|
101
|
-
threshold=0.2,
|
|
102
|
-
number_results=10,
|
|
103
120
|
feature_weights={
|
|
104
121
|
"semantic": 0.7,
|
|
105
122
|
"levenshtein": 0.3,
|
|
106
123
|
},
|
|
107
124
|
)
|
|
108
|
-
|
|
125
|
+
|
|
126
|
+
print(round(score, 4))
|
|
109
127
|
```
|
|
110
128
|
|
|
111
|
-
## Supported
|
|
129
|
+
## Supported Scope
|
|
112
130
|
|
|
113
|
-
|
|
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.
|
|
131
|
+
Supported languages:
|
|
116
132
|
|
|
117
|
-
|
|
133
|
+
- Chunking remains text-first and can run on any source text.
|
|
134
|
+
- Preprocessing heuristics and code-aware metrics are now regression-tested for a unified 20-language scope: `Java`, `Python`, `C`, `C++`, `Go`, `JavaScript`, `TypeScript`, `Kotlin`, `Scala`, `Swift`, `Solidity`, `Dart`, `PHP`, `Ruby`, `Rust`, `C#`, `Lua`, `Julia`, `R`, and `Objective-C` (`objc`).
|
|
135
|
+
- Native CodeBLEU with real syntax/dataflow now covers that same 20-language scope.
|
|
118
136
|
|
|
119
137
|
Similarity features:
|
|
120
138
|
|
|
@@ -137,12 +155,14 @@ Code metrics:
|
|
|
137
155
|
- `tsed`
|
|
138
156
|
- `codebertscore`
|
|
139
157
|
|
|
140
|
-
`ruby` now uses a full staged implementation (`graph -> tree -> string`), with optional runtime dependencies enabled via `matheel[metrics]`.
|
|
141
|
-
|
|
142
158
|
Chunking methods:
|
|
143
159
|
|
|
144
160
|
- `none`
|
|
145
|
-
-
|
|
161
|
+
- `code`
|
|
162
|
+
- `chonkie_token`
|
|
163
|
+
- `chonkie_sentence`
|
|
164
|
+
- `chonkie_recursive`
|
|
165
|
+
- `chonkie_fast`
|
|
146
166
|
|
|
147
167
|
Vector backends:
|
|
148
168
|
|
|
@@ -169,15 +189,6 @@ Sentence Transformers pooling methods:
|
|
|
169
189
|
|
|
170
190
|
`auto` inspects Hugging Face model metadata and routes to the correct backend when the model exposes a known library.
|
|
171
191
|
|
|
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
192
|
## CLI
|
|
182
193
|
|
|
183
194
|
Compare a directory or ZIP archive:
|
|
@@ -218,9 +229,12 @@ Pairwise scoring:
|
|
|
218
229
|
```python
|
|
219
230
|
from matheel.similarity import calculate_similarity
|
|
220
231
|
|
|
232
|
+
code_a = "def add(a, b):\n return a + b\n"
|
|
233
|
+
code_b = "def add(x, y):\n return x + y\n"
|
|
234
|
+
|
|
221
235
|
score = calculate_similarity(
|
|
222
|
-
|
|
223
|
-
|
|
236
|
+
code_a,
|
|
237
|
+
code_b,
|
|
224
238
|
model_name="huggingface/CodeBERTa-small-v1",
|
|
225
239
|
vector_backend="auto",
|
|
226
240
|
max_token_length=256,
|
|
@@ -241,10 +255,10 @@ Directory or ZIP ranking:
|
|
|
241
255
|
from matheel.similarity import get_sim_list
|
|
242
256
|
|
|
243
257
|
results = get_sim_list(
|
|
244
|
-
"
|
|
258
|
+
"sample_pairs.zip",
|
|
245
259
|
model_name="huggingface/CodeBERTa-small-v1",
|
|
246
260
|
threshold=0.4,
|
|
247
|
-
number_results=
|
|
261
|
+
number_results=10,
|
|
248
262
|
vector_backend="auto",
|
|
249
263
|
max_token_length=256,
|
|
250
264
|
chunking_method="chonkie_token",
|
|
@@ -260,45 +274,56 @@ results = get_sim_list(
|
|
|
260
274
|
"gst": 0.05,
|
|
261
275
|
},
|
|
262
276
|
)
|
|
263
|
-
```
|
|
264
|
-
|
|
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
277
|
|
|
273
|
-
|
|
278
|
+
print(results.head())
|
|
279
|
+
```
|
|
274
280
|
|
|
275
281
|
## Docs
|
|
276
282
|
|
|
277
|
-
- Docs
|
|
283
|
+
- Docs folder landing page: [docs/README.md](docs/README.md)
|
|
284
|
+
- Canonical docs index: [docs/index.md](docs/index.md)
|
|
278
285
|
- Quick usage: [docs/usage.md](docs/usage.md)
|
|
279
286
|
- Preprocessing: [docs/preprocessing.md](docs/preprocessing.md)
|
|
280
287
|
- Chunking: [docs/chunking.md](docs/chunking.md)
|
|
281
|
-
- Vectors: [docs/vectors.md](docs/vectors.md)
|
|
282
|
-
-
|
|
288
|
+
- Vectors and routing: [docs/vectors.md](docs/vectors.md)
|
|
289
|
+
- Lexical metrics and baselines: [docs/lexical.md](docs/lexical.md)
|
|
283
290
|
- Code metrics: [docs/code_metrics.md](docs/code_metrics.md)
|
|
284
291
|
- Comparison suite: [docs/comparison_suite.md](docs/comparison_suite.md)
|
|
285
292
|
|
|
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
293
|
## Examples
|
|
289
294
|
|
|
295
|
+
- Colab walkthrough: [examples/matheel_examples_colab.ipynb](examples/matheel_examples_colab.ipynb)
|
|
290
296
|
- Quick archive check: [examples/sample_pairs_demo.py](examples/sample_pairs_demo.py)
|
|
291
297
|
- Preprocessing: [examples/preprocessing_demo.py](examples/preprocessing_demo.py)
|
|
292
298
|
- Chunking: [examples/chunking_demo.py](examples/chunking_demo.py)
|
|
293
299
|
- Vector backends: [examples/vectors_demo.py](examples/vectors_demo.py)
|
|
294
|
-
-
|
|
300
|
+
- Lexical metrics and baselines: [examples/lexical_demo.py](examples/lexical_demo.py)
|
|
295
301
|
- Code metrics: [examples/code_metrics_demo.py](examples/code_metrics_demo.py)
|
|
296
302
|
- Comparison suite: [examples/comparison_suite_demo.py](examples/comparison_suite_demo.py)
|
|
297
303
|
|
|
304
|
+
All examples use the same sample pair from `sample_pairs.zip`: `code_1.java` and `code_3_plag.java`.
|
|
305
|
+
|
|
298
306
|
## Gradio
|
|
299
307
|
|
|
300
308
|
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
309
|
|
|
310
|
+
## Acknowledgments
|
|
311
|
+
|
|
312
|
+
Matheel builds on several open-source libraries:
|
|
313
|
+
|
|
314
|
+
- [Sentence Transformers](https://pypi.org/project/sentence-transformers/)
|
|
315
|
+
- [Chonkie](https://pypi.org/project/chonkie/)
|
|
316
|
+
- [model2vec](https://pypi.org/project/model2vec/)
|
|
317
|
+
- [PyLate](https://pypi.org/project/pylate/)
|
|
318
|
+
- [RapidFuzz](https://pypi.org/project/rapidfuzz/)
|
|
319
|
+
- [tree-sitter-language-pack](https://pypi.org/project/tree-sitter-language-pack/)
|
|
320
|
+
- [NetworkX](https://pypi.org/project/networkx/)
|
|
321
|
+
- [APTED](https://pypi.org/project/apted/)
|
|
322
|
+
- [bert-score](https://pypi.org/project/bert-score/)
|
|
323
|
+
- [Gradio](https://pypi.org/project/gradio/)
|
|
324
|
+
|
|
325
|
+
The project also depends on the standard scientific Python stack and related tooling, including NumPy, pandas, Click, SentencePiece, and func-timeout.
|
|
326
|
+
|
|
302
327
|
## License
|
|
303
328
|
|
|
304
329
|
This project is licensed under the [MIT License](LICENSE).
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
# Matheel
|
|
2
2
|
|
|
3
|
-
Matheel is a
|
|
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
|
|
|
@@ -27,11 +33,17 @@ pip install "matheel[dev]"
|
|
|
27
33
|
|
|
28
34
|
`matheel[all]` installs the currently supported optional backends in one command: Chonkie code chunking, metrics runtime dependencies (RUBY graph/tree, TSED, CodeBERTScore), model2vec, PyLate, and the Gradio app dependencies.
|
|
29
35
|
|
|
36
|
+
Matheel now ships a native CodeBLEU implementation that uses `tree_sitter_language_pack` for parser resolution, so real syntax/dataflow scoring no longer depends on installing the pip `codebleu` package. The pip package is still useful for validation/comparison work if you want to cross-check the native scores on selected examples; Matheel does not currently claim exact pip parity on every possible input.
|
|
37
|
+
|
|
30
38
|
## Quick Start
|
|
31
39
|
|
|
32
|
-
The
|
|
40
|
+
The repository root includes `sample_pairs.zip`, a small Java archive with:
|
|
41
|
+
|
|
42
|
+
- `code_1.java`
|
|
43
|
+
- `code_3_plag.java`
|
|
44
|
+
- additional plagiarized and non-plagiarized comparisons
|
|
33
45
|
|
|
34
|
-
CLI:
|
|
46
|
+
CLI archive comparison:
|
|
35
47
|
|
|
36
48
|
```bash
|
|
37
49
|
matheel compare sample_pairs.zip \
|
|
@@ -42,31 +54,37 @@ matheel compare sample_pairs.zip \
|
|
|
42
54
|
--num 10
|
|
43
55
|
```
|
|
44
56
|
|
|
45
|
-
Python:
|
|
57
|
+
Python pairwise scoring with the sample pair:
|
|
46
58
|
|
|
47
59
|
```python
|
|
48
|
-
from
|
|
60
|
+
from zipfile import ZipFile
|
|
49
61
|
|
|
50
|
-
|
|
51
|
-
|
|
62
|
+
from matheel.similarity import calculate_similarity
|
|
63
|
+
|
|
64
|
+
with ZipFile("sample_pairs.zip") as archive:
|
|
65
|
+
code_a = archive.read("code_1.java").decode("utf-8")
|
|
66
|
+
code_b = archive.read("code_3_plag.java").decode("utf-8")
|
|
67
|
+
|
|
68
|
+
score = calculate_similarity(
|
|
69
|
+
code_a,
|
|
70
|
+
code_b,
|
|
52
71
|
model_name="huggingface/CodeBERTa-small-v1",
|
|
53
|
-
threshold=0.2,
|
|
54
|
-
number_results=10,
|
|
55
72
|
feature_weights={
|
|
56
73
|
"semantic": 0.7,
|
|
57
74
|
"levenshtein": 0.3,
|
|
58
75
|
},
|
|
59
76
|
)
|
|
60
|
-
|
|
77
|
+
|
|
78
|
+
print(round(score, 4))
|
|
61
79
|
```
|
|
62
80
|
|
|
63
|
-
## Supported
|
|
81
|
+
## Supported Scope
|
|
64
82
|
|
|
65
|
-
|
|
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.
|
|
83
|
+
Supported languages:
|
|
68
84
|
|
|
69
|
-
|
|
85
|
+
- Chunking remains text-first and can run on any source text.
|
|
86
|
+
- Preprocessing heuristics and code-aware metrics are now regression-tested for a unified 20-language scope: `Java`, `Python`, `C`, `C++`, `Go`, `JavaScript`, `TypeScript`, `Kotlin`, `Scala`, `Swift`, `Solidity`, `Dart`, `PHP`, `Ruby`, `Rust`, `C#`, `Lua`, `Julia`, `R`, and `Objective-C` (`objc`).
|
|
87
|
+
- Native CodeBLEU with real syntax/dataflow now covers that same 20-language scope.
|
|
70
88
|
|
|
71
89
|
Similarity features:
|
|
72
90
|
|
|
@@ -89,12 +107,14 @@ Code metrics:
|
|
|
89
107
|
- `tsed`
|
|
90
108
|
- `codebertscore`
|
|
91
109
|
|
|
92
|
-
`ruby` now uses a full staged implementation (`graph -> tree -> string`), with optional runtime dependencies enabled via `matheel[metrics]`.
|
|
93
|
-
|
|
94
110
|
Chunking methods:
|
|
95
111
|
|
|
96
112
|
- `none`
|
|
97
|
-
-
|
|
113
|
+
- `code`
|
|
114
|
+
- `chonkie_token`
|
|
115
|
+
- `chonkie_sentence`
|
|
116
|
+
- `chonkie_recursive`
|
|
117
|
+
- `chonkie_fast`
|
|
98
118
|
|
|
99
119
|
Vector backends:
|
|
100
120
|
|
|
@@ -121,15 +141,6 @@ Sentence Transformers pooling methods:
|
|
|
121
141
|
|
|
122
142
|
`auto` inspects Hugging Face model metadata and routes to the correct backend when the model exposes a known library.
|
|
123
143
|
|
|
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
144
|
## CLI
|
|
134
145
|
|
|
135
146
|
Compare a directory or ZIP archive:
|
|
@@ -170,9 +181,12 @@ Pairwise scoring:
|
|
|
170
181
|
```python
|
|
171
182
|
from matheel.similarity import calculate_similarity
|
|
172
183
|
|
|
184
|
+
code_a = "def add(a, b):\n return a + b\n"
|
|
185
|
+
code_b = "def add(x, y):\n return x + y\n"
|
|
186
|
+
|
|
173
187
|
score = calculate_similarity(
|
|
174
|
-
|
|
175
|
-
|
|
188
|
+
code_a,
|
|
189
|
+
code_b,
|
|
176
190
|
model_name="huggingface/CodeBERTa-small-v1",
|
|
177
191
|
vector_backend="auto",
|
|
178
192
|
max_token_length=256,
|
|
@@ -193,10 +207,10 @@ Directory or ZIP ranking:
|
|
|
193
207
|
from matheel.similarity import get_sim_list
|
|
194
208
|
|
|
195
209
|
results = get_sim_list(
|
|
196
|
-
"
|
|
210
|
+
"sample_pairs.zip",
|
|
197
211
|
model_name="huggingface/CodeBERTa-small-v1",
|
|
198
212
|
threshold=0.4,
|
|
199
|
-
number_results=
|
|
213
|
+
number_results=10,
|
|
200
214
|
vector_backend="auto",
|
|
201
215
|
max_token_length=256,
|
|
202
216
|
chunking_method="chonkie_token",
|
|
@@ -212,45 +226,56 @@ results = get_sim_list(
|
|
|
212
226
|
"gst": 0.05,
|
|
213
227
|
},
|
|
214
228
|
)
|
|
215
|
-
```
|
|
216
|
-
|
|
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
229
|
|
|
225
|
-
|
|
230
|
+
print(results.head())
|
|
231
|
+
```
|
|
226
232
|
|
|
227
233
|
## Docs
|
|
228
234
|
|
|
229
|
-
- Docs
|
|
235
|
+
- Docs folder landing page: [docs/README.md](docs/README.md)
|
|
236
|
+
- Canonical docs index: [docs/index.md](docs/index.md)
|
|
230
237
|
- Quick usage: [docs/usage.md](docs/usage.md)
|
|
231
238
|
- Preprocessing: [docs/preprocessing.md](docs/preprocessing.md)
|
|
232
239
|
- Chunking: [docs/chunking.md](docs/chunking.md)
|
|
233
|
-
- Vectors: [docs/vectors.md](docs/vectors.md)
|
|
234
|
-
-
|
|
240
|
+
- Vectors and routing: [docs/vectors.md](docs/vectors.md)
|
|
241
|
+
- Lexical metrics and baselines: [docs/lexical.md](docs/lexical.md)
|
|
235
242
|
- Code metrics: [docs/code_metrics.md](docs/code_metrics.md)
|
|
236
243
|
- Comparison suite: [docs/comparison_suite.md](docs/comparison_suite.md)
|
|
237
244
|
|
|
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
245
|
## Examples
|
|
241
246
|
|
|
247
|
+
- Colab walkthrough: [examples/matheel_examples_colab.ipynb](examples/matheel_examples_colab.ipynb)
|
|
242
248
|
- Quick archive check: [examples/sample_pairs_demo.py](examples/sample_pairs_demo.py)
|
|
243
249
|
- Preprocessing: [examples/preprocessing_demo.py](examples/preprocessing_demo.py)
|
|
244
250
|
- Chunking: [examples/chunking_demo.py](examples/chunking_demo.py)
|
|
245
251
|
- Vector backends: [examples/vectors_demo.py](examples/vectors_demo.py)
|
|
246
|
-
-
|
|
252
|
+
- Lexical metrics and baselines: [examples/lexical_demo.py](examples/lexical_demo.py)
|
|
247
253
|
- Code metrics: [examples/code_metrics_demo.py](examples/code_metrics_demo.py)
|
|
248
254
|
- Comparison suite: [examples/comparison_suite_demo.py](examples/comparison_suite_demo.py)
|
|
249
255
|
|
|
256
|
+
All examples use the same sample pair from `sample_pairs.zip`: `code_1.java` and `code_3_plag.java`.
|
|
257
|
+
|
|
250
258
|
## Gradio
|
|
251
259
|
|
|
252
260
|
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
261
|
|
|
262
|
+
## Acknowledgments
|
|
263
|
+
|
|
264
|
+
Matheel builds on several open-source libraries:
|
|
265
|
+
|
|
266
|
+
- [Sentence Transformers](https://pypi.org/project/sentence-transformers/)
|
|
267
|
+
- [Chonkie](https://pypi.org/project/chonkie/)
|
|
268
|
+
- [model2vec](https://pypi.org/project/model2vec/)
|
|
269
|
+
- [PyLate](https://pypi.org/project/pylate/)
|
|
270
|
+
- [RapidFuzz](https://pypi.org/project/rapidfuzz/)
|
|
271
|
+
- [tree-sitter-language-pack](https://pypi.org/project/tree-sitter-language-pack/)
|
|
272
|
+
- [NetworkX](https://pypi.org/project/networkx/)
|
|
273
|
+
- [APTED](https://pypi.org/project/apted/)
|
|
274
|
+
- [bert-score](https://pypi.org/project/bert-score/)
|
|
275
|
+
- [Gradio](https://pypi.org/project/gradio/)
|
|
276
|
+
|
|
277
|
+
The project also depends on the standard scientific Python stack and related tooling, including NumPy, pandas, Click, SentencePiece, and func-timeout.
|
|
278
|
+
|
|
254
279
|
## License
|
|
255
280
|
|
|
256
281
|
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 {}
|
|
@@ -64,7 +64,7 @@ def main():
|
|
|
64
64
|
help='Optional code-level metric added to the final score.',
|
|
65
65
|
)
|
|
66
66
|
@click.option('--code-metric-weight', default=0.0, show_default=True, help='Weight applied to the selected code metric.')
|
|
67
|
-
@click.option('--code-language', default='java', show_default=True, help='Language hint for code-level metrics.
|
|
67
|
+
@click.option('--code-language', default='java', show_default=True, help='Language hint for code-level metrics. Native CodeBLEU, RUBY, and TSED support: java, python, c, cpp, go, javascript, typescript, kotlin, scala, swift, solidity, dart, php, ruby, rust, csharp, lua, julia, r, objc.')
|
|
68
68
|
@click.option('--codebleu-component-weights', default='0.25,0.25,0.25,0.25', show_default=True, help='Comma-separated weights for ngram, weighted_ngram, syntax, dataflow.')
|
|
69
69
|
@click.option('--crystalbleu-max-order', default=4, show_default=True, help='Maximum n-gram order for CrystalBLEU.')
|
|
70
70
|
@click.option('--crystalbleu-trivial-ngram-count', default=50, show_default=True, help='How many frequent n-grams to ignore in CrystalBLEU.')
|