Skip to main content

Sieve Scope v1.5.0

English | 日本語

"See through the formatting, and look into the pure logic of the algorithm." A fully local, zero-dependency, deterministic (100% reproducible) code plagiarism and structural similarity detection engine. Extends Sieve-Core's deterministic similarity engine and Sieve-Referee's multi-hypothesis LUT judgment philosophy to the source code domain.

PyPI Version Python Version CI License: MIT


💡 Concept & Philosophy

The starting point of this project is Sieve-Core, a core engine that applies the "sieve of set theory" design philosophy of Sieve-AI—inspired by the Sieve of Eratosthenes—to the more general domain of text and data processing.

Next, Sieve Referee, which adds a "sieve of combinatorics" to Sieve-Core, is a zero-dependency Python library that extracts reliable information from noise based on corroboration from multiple independent sources.

Then, Sieve Scope further adds a two-axis evaluation and redesigns the approach, making it an explainable code plagiarism detection engine that observes the surface format (variable names, comments, whitespace) and the essential logic (algorithm structure) separately.

Traditional string comparison and simple similarity measures struggle to distinguish between:

  • Plagiarism by merely renaming variables (variable laundering)
  • Coincidental matches due to shared templates (boilerplate)

Sieve Scope observes two axes independently:

  • AST (Abstract Syntax Tree) — extracting the "logic skeleton" with identifiers removed
  • tokenize — extracting "identifier vocabulary and order"

By inheriting the hypothesis mask (H1–H7) and LUT from Sieve-Referee, it fully explains why a judgment was made.

The name "Sieve Scope" comes from the design philosophy of seeing through the surface of code (format) and comparing only the pure logic, like a microscope.


🔥 Key Features

  • 7-bit Observation Space (H1–H7)
    Independently evaluates AST skeleton, identifier vocabulary, positional/order (g_POS), constants (g_CONST), and vocabulary context (g_FREQ).
  • v0_mask compatibility
    The legacy 4-bit v0_mask is preserved and regression-tested.
  • Strict Cluster Safety Invariant
    H4 is promoted to 1 only when the cluster size is at least 3 and there is direct similarity evidence (H2∨H3). Indirect "telephone game" chains are never mixed into direct judgments.
  • Short-Circuit Optimization
    Pairs with no structural or vocabulary similarity (H2=0 ∧ H3=0) are immediately returned as 1000-000, skipping expensive hash computations.
  • Skip Visibility & Robustness (v1.3.1)
    Empty or statement-less files are excluded from comparison and listed under the result's skipped key (not_applicable), files that fail to parse are listed with parse_failed, and an unparseable pair carries scores: null ("no observation") instead of omitting the key. A file whose analysis hits a RecursionError is contained per file — the rest of the corpus is still evaluated — and when the process pool is unavailable (e.g. frozen apps) the analysis falls back to byte-identical sequential evaluation.
  • Zero Dependencies & Deterministic
    Implemented using only the Python standard library. No external packages, no API costs, no probabilistic elements.

📐 7-bit Observation Space

The evaluation function f_v1.3(C1, C2) projects a code pair into seven boolean hypotheses (H1, H2, H3, H4, H5, H6, H7).

Hypothesis Name What it measures Criterion / Threshold
H1 Parseability Can both be parsed as Python syntax? Success/failure of AST construction
H2 AST Skeleton Do the AST node type sequences match exactly? Exact match of skeleton strings
H3 Identifier Similarity Jaccard + sequence similarity of identifiers Score > 0.50
H4 Cluster Safety Direct similarity + membership in a valid cluster (size ≥3) Invariant condition satisfied
H5 g_POS SHA-256 hash of recursive AST field representation Exact hash match
H6 g_CONST Constants / literals set match Sorted (type, value) constant list exact match — type-aware since v1.4.0, so 1 and "1" are distinguished
H7 g_FREQ Weighted identifier bi-gram Dice coefficient Score >= 0.60

Mask notation is v0_mask (4-bit) - extension (3-bit). Example: 1100-011 → H1=1, H2=1, H3=0, H4=0 / H5=0, H6=1, H7=1


📊 How to Read the Mask (Examples)

The labels below are examples for reading the mask — the engine's output is the mask itself, not these labels. Treat each row as one illustrative way a mask can arise, not as an enumerated judgment vocabulary.

v0_mask Extended Example Judgment Label Description
1110 1110-111 EXACT_CLONE Observation-space exact match
1100 1100-110 VARIABLE_LAUNDERING Logic matches but surface differs
1010 1010-011 COINCIDENTAL_FRAMEWORK_MATCH Logic differs but surface matches
1000 1000-000 INDEPENDENT_LOGIC No direct similarity (short-circuit)
1110 1110-101 CONSTANT_MODIFIED_CLONE Only constants differ
1110 1110-011 PERMUTATED_CLONE Non-commutative order reversed

💻 Quick Start

from sieve_scope import SieveScopeEngineV1_3, SieveClusterAnalyzerV1_3

engine = SieveScopeEngineV1_3(jaccard_threshold=0.50, freq_dice_threshold=0.60)

code_a = "def calc_sum(a, b):\n    return a + b"
code_b = "def calc_sum(x, y):\n    return x + y"

result = engine.evaluate_pair(code_a, code_b)

print(result["v0_mask"])   # e.g., 1100
print(result["mask"])      # e.g., 1100-110

Configuration / Thresholds

  • jaccard_threshold (default: 0.50): Threshold for H3 Multiset Jaccard + sequence similarity.
  • freq_dice_threshold (default: 0.60): Threshold for H7 Weighted identifier bi-gram Dice coefficient.

Note on Calibration & Defaults (v1.3): Exhaustive grid search experiments on synthetic benchmark datasets demonstrate optimal class separation ($F1 = 1.0000$) across a wide threshold range of 0.35 to 0.75. However, the default threshold parameters are strictly maintained at 0.50 / 0.60 in order to preserve backwards compatibility with v0, maintain regression test stability, and prevent potential false positives caused by shared domain vocabulary in production codebases.


🔍 Language-Independent Layer (v1.5.0)

Separate from the 7-bit observation space (never mixed into the masks).

Tokenizer — tokenize_source(source) returns three parallel lists: the normalized column (ID/NUM/STR), the raw token column, and (line, column) positions. Numbers are judged first; identifiers are maximal \w runs that do not start with a digit ([^\W\d]\w*), so Japanese identifiers stay one class and 123abc splits into NUM + ID. One comprehensive regex, no std-lib tokenize, no exceptions on any input.

Explanation layer (§3.2)

  • explain_pair(a, b) — {"spans": [...], "span_count": N}: at most 200 spans per pair (EXPLAIN_MAX_SPANS) with the true total recorded; span dicts carry a_start/a_end/b_start/b_end and kind — exact when every original token matches, renamed when at least one differs (e.g. a renamed identifier). No body text is included.

Base exclusion (§3.3)

  • analyze_corpus(corpus, base_sources=...) — base documents leave the comparison universe and their matching token runs are removed before evaluation; the result carries base_removal with the removed token count, ratio and original-position segments per submission. A submission stripped to nothing gets the empty-input treatment (not_applicable → skipped) and never enters the comparison.

Language-agnostic comparison (§3.5)

  • language_agnostic_pair(a, b) — the per-mille match rate (match_per_mille, per side) and the shared spans as a result SEPARATE from the 7-bit result. The spans are the §3.2 spans: at most 200 (EXPLAIN_MAX_SPANS) with the true total in span_count; the rate is always computed over ALL shared runs, capped or not.

CLI (--spans / --base)

  • python -m sieve_scope TARGET [--spans] [--base PATH ...]: JSON to stdout; --spans adds the per-pair explanation spans (§3.2), --base activates the base exclusion (§3.3) (rc2 + Error: on usage errors and on the --spans × --base combination).

All outputs are deterministic and independent of PYTHONHASHSEED (blake2b, the builtin hash() is never used).


🔬 Testing & Verification

Cross-Python Validation Summary 24 regression cases (test_v1_3_full_suite.py): PASSED

5 compatibility tests (test_v1_3_regression.py): PASSED

6 edge-case & parallel determinism tests (test_v1_3_edge_cases.py): PASSED

81 synthetic threshold configurations (threshold_tuning.py): PASSED

All test suites and synthetic experiments passed completely without errors across Python 3.9, 3.10, 3.11, and 3.12.

Threshold Calibration & Synthetic Validation The threshold parameters (H3 Multiset Jaccard: 0.50, H7 Weighted Bi-gram Dice: 0.60) were designed and calibrated using a synthetic validation pair set (Positive 6 pairs / Negative 3 pairs). The engine's 1110-111 indicates an exact match in the current 7-dimensional observation space (Observation Clones), and does not guarantee complete semantic equivalence (Semantic Clones).


📚 Documentation

📄 License

MIT License. See LICENSE for details.

👤 Author

Kai IWASAKI

Metadata

Release files for sieve-scope 1.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sieve-scope 1.5.0
File Size Uploaded Provenance Actions
sieve_scope-1.5.0.tar.gz 39.7 kB Without provenance Details for sieve_scope-1.5.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for sieve-scope 1.5.0
File Interpreter ABI Platform Actions
sieve_scope-1.5.0-py3-none-any.whl Python 3 none any Details for sieve_scope-1.5.0-py3-none-any.whl

Total release size: 60.5 kB

Release files / sieve_scope-1.5.0.tar.gz

Download URL sieve_scope-1.5.0.tar.gz
Size 39.7 kB
Tags Source
SHA-256 checksum
How to use checksums
57856c0d60fc9c5bf5f83b34dee1f8d1d0f4c857c494c711e95114f4a39033c4
BLAKE2b-256 checksum
How to use checksums
9a36df719f6e135f56f6eaa8fe7c22938a24599ba11a0eda83690861f7d9555e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.9

Release files / sieve_scope-1.5.0-py3-none-any.whl

Download URL sieve_scope-1.5.0-py3-none-any.whl
Size 20.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1086a0881a3ca7e2ec3d5771fe99ec8e7a177b5800c487a621e867e5f8a2815b
BLAKE2b-256 checksum
How to use checksums
298161c421d5a7e0d32bdf12bb2bc00da273bf1f0633245835120b689e8bc28c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.9

Security for sieve-scope 1.5.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page