code-search-net-java / finalize_filtered.py
PiotrSty's picture
drop rows without a detected open licence (47,818 rows); update card/manifest
b00b75e verified
Raw History Blame Contribute Delete
6.73 kB
#!/usr/bin/env python
"""Write README/manifest/checksums for the open-licence-only dataset, upload."""
import hashlib
import json
from datetime import datetime, timezone
from pathlib import Path
import pyarrow.parquet as pq
from huggingface_hub import HfApi
HERE = Path(__file__).resolve().parent
RID = "PiotrSty/code-search-net-java"
PARQUET = HERE / "code_search_net_java.parquet"
BUILD = HERE / "code_search_net_java.build.json"
README = HERE / "README.md"
MANIFEST = HERE / "manifest.json"
CHECKSUMS = HERE / "checksums.json"
FILES = [
"code_search_net_java.parquet", "code_search_net_java.sample.jsonl",
"code_search_net_java.build.json", "README.md", "build_csn_java.py",
"make_sample.py", "sample_licenses.json", "audit_licenses.py",
"apply_licenses.py", "filter_open.py", "finalize_filtered.py",
"repos.txt", "repo_licenses.jsonl", "license_summary.json",
]
def sha(b):
return hashlib.sha256(b).hexdigest()
def readme(build):
rows = build["rows"]
repos = build["repos"]
splits = " · ".join(f"{k} {v:,}" for k, v in build["splits"].items())
lic = sorted(build["license_distribution_rows"].items(), key=lambda x: -x[1])
lic_table = "\n".join(
f"| `{k}` | {v:,} | {100*v/rows:.1f}% |" for k, v in lic)
cls = " · ".join(
f"{k} {v:,}" for k, v in build["license_class_rows"].items())
removed_rows = build["filtered_out_unknown_rows"]
removed_repos = build["filtered_out_unknown_repos"]
return f"""---
license: other
language:
- en
tags:
- code
- java
- code-search-net
- function-documentation
pretty_name: CodeSearchNet Java (open-licence functions + docstrings)
size_categories:
- 100K<n<1M
configs:
- config_name: default
data_files:
- split: train
path: code_search_net_java.parquet
---
# CodeSearchNet Java — open-licence functions + docstrings
Working copy (2026-12-05). Derived from the official
[`code-search-net/code_search_net`](https://huggingface.co/datasets/code-search-net/code_search_net)
Java configuration, **filtered to repositories with a detected open-source
licence** (SPDX). Rows from repositories with `NOASSERTION`/`unknown` were
removed.
- **{rows:,} rows**, **{repos:,} repositories** (from 4,769 audited; removed
{removed_rows:,} rows / {removed_repos} repos with no detected licence)
- **{build['chars']:,} characters**, **{build['tokens']:,} tokens**
(tiktoken `cl100k_base`)
- parquet `{build['bytes']:,}` bytes (zstd), 20 columns
- splits: {splits}
## Licences (rows)
| SPDX | rows | % |
|---|---:|---:|
{lic_table}
Class mix: {cls}. All retained rows carry a detected open-source licence;
permissive is the largest class, but weak/strong copyleft (LGPL/EPL/GPL/AGPL)
remain and carry notice/source obligations.
## Schema
```
id, repo, path, func_name, url, split, language, docstring, code, text,
token_count, doc_chars, code_chars, license_basis, source, added,
record_sha256, license, license_class, license_source
```
`text` = docstring + `\\n\\n` + code. `id` is unique. `record_sha256` is the
canonical per-row SHA-256.
## Collection
- Official CodeSearchNet Java shards, concatenated.
- Filters: code ≥ 20 chars, text ≥ 100 chars, exact-code dedup, and the
open-licence filter above.
- Per-repo audit: GitHub REST `/repos/{{owner}}/{{repo}}/license` over 4,769
repositories (2026-12-05); full table in `repo_licenses.jsonl`.
## Rights
- **Upstream**: CodeSearchNet, Apache-2.0 dataset; re-distribution is permitted,
but the upstream "permissive" filter is not exhaustive (AGPL/GPL/LGPL/EPL are
present).
- **Per-row licence**: `license` (SPDX), `license_class`, `license_source` are
audited per repository and joined into every row.
- **Removed**: {removed_rows:,} rows from {removed_repos} repositories without a
detected open licence (`NOASSERTION`/`unknown`).
- **Not release-ready as a single licence**: copyleft rows require their
notice/source obligations. A permissive-only slice is
`license_class == "permissive"`.
## Not checked
- Whether GitHub's LICENSE-file detection matches the repo's actual terms.
- Notice/source obligations for EPL, LGPL, GPL and AGPL rows.
- Cross-corpus dedup against other code corpora.
"""
def main():
build = json.loads(BUILD.read_text(encoding="utf-8"))
README.write_text(readme(build), encoding="utf-8")
cols = [f.name for f in pq.read_schema(PARQUET)]
manifest = json.loads(MANIFEST.read_text(encoding="utf-8"))
manifest.update({
"generated_at": datetime.now(timezone.utc).isoformat(timespec="seconds"),
"dataset_sha256": sha(PARQUET.read_bytes()),
"dataset_bytes": PARQUET.stat().st_size,
"rows": build["rows"],
"columns": cols,
"filter": build["filter"],
"filtered_out_unknown_rows": build["filtered_out_unknown_rows"],
"filtered_out_unknown_repos": build["filtered_out_unknown_repos"],
"license_distribution_rows": build["license_distribution_rows"],
"license_class_rows": build["license_class_rows"],
"license_distribution_repos": build["license_distribution_repos"],
"license_class_repos": build["license_class_repos"],
"license_audit_status": build["license_audit_status"],
"license_audit_repos": build["license_audit_repos"],
})
MANIFEST.write_text(json.dumps(manifest, indent=2, ensure_ascii=False), encoding="utf-8")
checks = {f: sha((HERE / f).read_bytes()) for f in FILES}
CHECKSUMS.write_text(json.dumps(checks, indent=2), encoding="utf-8")
manifest["checksums_sha256"] = sha(CHECKSUMS.read_bytes())
MANIFEST.write_text(json.dumps(manifest, indent=2, ensure_ascii=False), encoding="utf-8")
api = HfApi()
api.upload_folder(folder_path=str(HERE), repo_id=RID, repo_type="dataset",
ignore_patterns=["raw/**", "*.fix.parquet", "*.licensed.parquet",
"*.open.parquet", "__pycache__/**"],
commit_message="drop rows without a detected open licence (47,818 rows); update card/manifest")
info = api.repo_info(RID, repo_type="dataset")
print("private:", info.private, "| sha:", info.sha)
for it in api.list_repo_tree(RID, repo_type="dataset", recursive=True):
if getattr(it, "path", "") == "code_search_net_java.parquet":
lfs = getattr(it, "lfs", None)
remote = getattr(lfs, "sha256", None) if lfs else None
print("remote parquet sha:", remote)
print("MATCH:", remote == checks["code_search_net_java.parquet"])
print("rows:", build["rows"], "chars:", build["chars"], "tokens:", build["tokens"])
print("rows by class:", build["license_class_rows"])
if __name__ == "__main__":
main()