Skip to main content

Sieve Scope v1.3

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


📊 Representative LUT Patterns

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.

---

## 🔬 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

- 🏛️ Architecture Specification

- 🔌 API & Integration Guide

- 🚀 Deployment Guide

- 🔐 CI/CD & Security Guide

## 📄 License
MIT License. See LICENSE for details.

## 👤 Author
Kai IWASAKI

Metadata

Release files for sieve-scope 1.4.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.4.0
File Size Uploaded Provenance Actions
sieve_scope-1.4.0.tar.gz 19.3 kB Without provenance Details for sieve_scope-1.4.0.tar.gz

Built distribution (wheel)

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

Total release size: 31.0 kB

Release files / sieve_scope-1.4.0.tar.gz

Download URL sieve_scope-1.4.0.tar.gz
Size 19.3 kB
Tags Source
SHA-256 checksum
How to use checksums
abbf959985772752c8c4bf45e82fc9ee54a2768855c93f3a9eab45264a713881
BLAKE2b-256 checksum
How to use checksums
ab0968b112f3a3f2dc86f7ef36e9312f2744222cc87c56ea15f8d74efe7f21fa
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.4.0-py3-none-any.whl

Download URL sieve_scope-1.4.0-py3-none-any.whl
Size 11.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
03a4d9834587c117ac8744bb36cb718822a52dd299abe373d08dae96caa35cbf
BLAKE2b-256 checksum
How to use checksums
8ec01491d05f5ede9fa46d1eb0368c9447a1d8e4871848e01ee334e76dfa13e6
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.4.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