Download tests/data/test_clean.py from Kolgrim/hades: direct link, hf CLI and curl.
- Browser
- Download file 1.85 kB
-
https://huggingface.co/Kolgrim/hades/resolve/main/tests/data/test_clean.py
- Command line
-
hf download hf://Kolgrim/hades/tests/data/test_clean.py
-
curl -L -o test_clean.py https://huggingface.co/Kolgrim/hades/resolve/main/tests/data/test_clean.py
1.85 kB
| from hades.data.clean import dedupe, keep, normalize_text | |
| from hades.data.sources.base import Record | |
| ENGLISH = ("Secure Shell is a cryptographic network protocol for operating network services securely over an " | |
| "unsecured network. Typical applications include remote command-line login and remote command execution. " | |
| "Administrators should disable password authentication where keys are available.") | |
| def rec(text, source="s", id="1", group="security"): | |
| return Record(source=source, id=id, license="L", group=group, text=text) | |
| def test_lone_surrogate_replaced(): | |
| assert normalize_text("a\ud800b") == "a�b" | |
| def test_control_chars_replaced_but_whitespace_kept(): | |
| assert normalize_text("a\x00b\x1bc\td\re\nf") == "a�b�c\td\re\nf" | |
| def test_nfc(): | |
| assert normalize_text("é") == "é" | |
| def test_inline_whitespace_preserved(): | |
| assert normalize_text("x y") == "x y" | |
| def test_html_stripped(): | |
| assert normalize_text("<p>hi</p>", html=True) == "hi" | |
| assert normalize_text("<p>a & b</p><script>x()</script>", html=True) == "a & b" | |
| def test_blank_lines_collapsed(): | |
| assert normalize_text("a\n\n\n\n\n\nb") == "a\n\n\nb" | |
| def test_keep_rules(): | |
| assert keep(rec(ENGLISH)) | |
| assert not keep(rec("too short")) | |
| assert not keep(rec("Привет мир, это тест на русском языке. " * 10)) | |
| assert not keep(rec("\n".join(["same line here"] * 50))) | |
| assert keep(rec("\n".join(["Oct 28 sshd[1]: Failed password for root"] * 50), group="logs")) | |
| def test_dedupe_across_sources(): | |
| out = list(dedupe([rec(ENGLISH, "a", "1"), rec(ENGLISH, "b", "2"), rec(ENGLISH + "!", "b", "3")])) | |
| assert [r.id for r in out] == ["1", "3"] | |
| def test_record_json_roundtrip(): | |
| r = rec("x\ny é", "cve", "CVE-1") | |
| assert Record.from_json(r.to_json()) == r | |