| """Stage 1: build the 1930s banned list and upload it to the destination repo.
|
|
|
| Seed = croqaz/vintage-ft-v1 banned.txt (D1, 1900 cutoff) embedded verbatim + a
|
| supplement of post-1930 terms. ALLOW_1930 strips the pre-1931-legit entries for
|
| the 1930 cutoff; EXTRA_1930_BANNED backfills clear post-1930 terms. The final list,
|
| allow-list, removed-from-seed audit, and metadata are written under _banned/ in
|
| {DST_REPO} and the total term count is printed.
|
|
|
| Run: python scripts/build_list.py
|
| """
|
| import json
|
| import re
|
| import time
|
|
|
| from huggingface_hub import CommitOperationAdd, hf_hub_download
|
|
|
| import config
|
| from common import api, HF_TOKEN, ensure_dst_repo
|
|
|
|
|
| def _norm(term):
|
| """Normalize a term for matching: lowercase, collapse internal whitespace."""
|
| return re.sub(r"\s+", " ", term.strip().lower())
|
|
|
|
|
| def _clean_terms(raw_iterable):
|
| """Drop blanks/comments/code-fence markers; normalize; dedupe (keep order)."""
|
| seen = set()
|
| out = []
|
| for line in raw_iterable:
|
| s = line.strip()
|
| if not s or s.startswith("#") or s.startswith("```"):
|
| continue
|
| t = _norm(s)
|
| if t and t not in seen:
|
| seen.add(t)
|
| out.append(t)
|
| return out
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| SEED_RAW = """
|
| # Curated post-1900 anachronisms -> HARD VETO (D1).
|
| # A hit forces the text to be dropped. Terms here are AUTHORITATIVE: they are
|
| # never overridden by the allow-list (unlike the auto-parsed banned_seed.txt).
|
| # Phrases match whole-word, case-insensitive; a short phrase ("world war") also
|
| # matches longer mentions ("world war ii").
|
|
|
| 1000W of power
|
| 100W of power
|
| 180W of power
|
| 2000W of power
|
| 20th century fox
|
| 21st century
|
| 9/11
|
| abortion law
|
| Ada program
|
| aeroplane
|
| ai language model
|
| aircraft
|
| airliner
|
| airplane
|
| airport
|
| always-on display
|
| android phone
|
| antibiotic
|
| antimatter
|
| apartheid
|
| app store
|
| arcade games
|
| artificial intelligence
|
| as an AI
|
| astronaut
|
| atomic bomb
|
| automation
|
| bash script
|
| berlin wall
|
| big bang
|
| big-bang
|
| binary pulsar
|
| bioacoustic
|
| black hole
|
| blitzkrieg
|
| blockchain
|
| blog
|
| blog post
|
| blogger
|
| bluetooth
|
| boeing 777
|
| bubble gum
|
| bubblegum
|
| C program
|
| C#
|
| c++
|
| C++
|
| cell phone
|
| cell tower
|
| cellphone
|
| cellular connectivity
|
| chatbot
|
| chatgpt
|
| chemotherapy
|
| chromosome
|
| cinema
|
| climate change
|
| Clojure function
|
| Clojure program
|
| code snippet
|
| cold war
|
| command-line
|
| compiler
|
| computer
|
| COVID-19
|
| CPU
|
| credit card
|
| credit-card
|
| CSS
|
| CSV file
|
| d-day
|
| dark energy
|
| dark matter
|
| database
|
| DDR3
|
| DDR4
|
| DDR5
|
| DDR6
|
| DDR7
|
| deep learning
|
| desktop computer
|
| digital edition
|
| digital media
|
| diode
|
| DNA
|
| download
|
| drone
|
| DVD
|
| DynamoDB
|
| e-book
|
| e-commerce
|
| e-learning
|
| e-mail
|
| ebook
|
| effective field theory
|
| electric beard trimmer
|
| electric toothbrush
|
| electro-optic
|
| Elixir function
|
| Elixir program
|
| email
|
| emoji
|
| empire state building
|
| EU countries
|
| European Union
|
| eurovision
|
| Excel spreadsheet
|
| Excel table
|
| fascism
|
| fascist
|
| fax
|
| ferromagnetic material
|
| ferromagnetism
|
| fiber-optic
|
| fibre-optic
|
| final fantasy X
|
| first world war
|
| FizzBuzz
|
| fortran
|
| Frenkel defect
|
| FTP server
|
| function in C
|
| function in Go
|
| function in R
|
| gaming
|
| gaming industry
|
| gender affirming
|
| gender nonconforming
|
| gene expression
|
| gene therapy
|
| general relativity
|
| genome
|
| gestapo
|
| gigabyte
|
| Go code
|
| Go function
|
| Go program
|
| godzilla
|
| Golang function
|
| Golang microservice
|
| Golang program
|
| GPS
|
| GPU
|
| graphene
|
| gravitational redshift
|
| great depression
|
| Grignard reagent
|
| hardware
|
| harry potter
|
| hashtag
|
| haskell code
|
| haskell function
|
| haskell program
|
| Hawking radiation
|
| HDD
|
| headphone
|
| helicopter
|
| Higgs boson
|
| Higgs field
|
| hip hop
|
| hip-hop
|
| hiroshima
|
| hollywood
|
| holocaust
|
| hormone
|
| HTML
|
| http
|
| HTTP POST
|
| Hubble's Law
|
| hydrogen bomb
|
| illegal immigratio
|
| internet
|
| ionic compounds
|
| iOS application
|
| iPad
|
| iPhone
|
| iron curtain
|
| iWatch
|
| java applet
|
| java class
|
| java code
|
| java function
|
| java program
|
| JavaScript
|
| jazz
|
| jet engine
|
| jet flight
|
| jetliner
|
| korean war
|
| kotlin function
|
| kotlin program
|
| laptop
|
| Large Hadron Collider
|
| large language model
|
| laser
|
| Lattice QCD
|
| LCD
|
| league of nations
|
| lepton-jet
|
| leptoquark
|
| lesbian
|
| lgbt
|
| Liquid-crystal display
|
| low bass
|
| machine learning
|
| matlab
|
| mechanisation
|
| mechanization
|
| megabyte
|
| metal-organic
|
| metamaterial
|
| Michelson-Morley experiment
|
| microchip
|
| microprocessor
|
| microservice
|
| microwave
|
| minecraft
|
| mobile phone
|
| molecule
|
| moon landing
|
| motherboard
|
| motion picture
|
| movie
|
| MQTT broker
|
| mRNA
|
| MySQL
|
| NAFTA
|
| navigation system
|
| Navy Seals
|
| nazi
|
| nazism
|
| neural network
|
| neurology
|
| neutron
|
| Node.js
|
| nuclear bomb
|
| nuclear reaction
|
| nuclear reactor
|
| nuclear weapon
|
| nuremberg trials
|
| nylon
|
| OCaml function
|
| official website
|
| omega-3
|
| online
|
| optical fiber
|
| PDF version
|
| pearl harbor
|
| penicillin
|
| perl function
|
| perl program
|
| perl script
|
| PHP
|
| pink floyd
|
| pixel
|
| plastic-free
|
| plutonium
|
| podcast
|
| polyester
|
| polyethylene
|
| polymer
|
| polystyrene
|
| pornographic
|
| PostgreSQL
|
| PowerShell
|
| program in C++
|
| program in Javascript
|
| program in Python
|
| programming language
|
| proton
|
| python code
|
| Python Flask
|
| python function
|
| python program
|
| python script
|
| pytorch
|
| quantum
|
| quantum chromodynamics
|
| quantum field theory
|
| quark-gluon plasma
|
| R code
|
| radar
|
| radio broadcast
|
| reality television
|
| reality TV
|
| reboot
|
| Redis key-value
|
| regular expression
|
| REST API
|
| RESTful API
|
| rna
|
| rock 'n' roll
|
| rock and roll
|
| rocket ship
|
| Ruby code
|
| Ruby function
|
| Ruby program
|
| Ruby script
|
| Rust function
|
| Rust program
|
| same-sex marriage
|
| satellite
|
| satellite-dish
|
| Scala code
|
| Scala program
|
| Schottky defect
|
| screenplay
|
| SDK
|
| search engine
|
| search-engine
|
| second world war
|
| selfie
|
| semiconductor
|
| server in Java
|
| shamebloody
|
| Shell command
|
| smart phone
|
| smart watch
|
| smartphone
|
| smartwatch
|
| social media
|
| software
|
| sonar
|
| soviet union
|
| space race
|
| space shuttle
|
| space station
|
| spacecraft
|
| spaceflight
|
| spaceship
|
| special effects
|
| spectral classification
|
| spectrometry
|
| spin electronics
|
| spintronics
|
| SQL
|
| SSD
|
| star wars
|
| stellar classification
|
| stereo
|
| Super Bowl
|
| super mario
|
| superconductivity
|
| superconductor
|
| swift app
|
| swift function
|
| synthetic tissue
|
| television
|
| terrabyte
|
| the beatles
|
| the movies
|
| trans activist
|
| trans people
|
| transistor
|
| tRNA
|
| trotsky
|
| try-catch block
|
| TV show
|
| twentieth century
|
| ultra lightweight
|
| TypeScript
|
| united nations
|
| upload
|
| ussr
|
| vegan
|
| veganism
|
| video camera
|
| video game
|
| videogame
|
| vietnam war
|
| virtual reality
|
| vitamin
|
| web site
|
| website
|
| WebSocket
|
| went viral
|
| wi-fi
|
| wifi
|
| Wittig reagent
|
| world war
|
| WW1
|
| WW2
|
| WW3
|
| wwi
|
| wwii
|
| www
|
| X-files
|
| X-men
|
| X-ray astronomy
|
| xanthan gum
|
|
|
| # --- people ---
|
| adolf hitler
|
| albert einstein
|
| anne sexton
|
| benito mussolini
|
| bob dylan
|
| bob marley
|
| carlos santana
|
| donald trump
|
| einstein
|
| elvis presley
|
| ernest hemingway
|
| franklin roosevelt
|
| franz kafka
|
| gandhi
|
| hitler
|
| j. d. salinger
|
| j. r. r. tolkien
|
| j.d. salinger
|
| j.r.r. tolkien
|
| James Bond
|
| john f. kennedy
|
| john fitzgerald kennedy
|
| joseph stalin
|
| lenin
|
| mahatma gandhi
|
| mao zedong
|
| marilyn monroe
|
| martin luther king jr.
|
| mussolini
|
| Nikola Tesla
|
| Robert Downey Jr.
|
| stalin
|
| sylvia plath
|
| taylor swift
|
| Tony Stark
|
| vladimir lenin
|
| walt disney
|
| william faulkner
|
|
|
| # --- brands (founded post-1900) ---
|
| AstraZeneca
|
| burger king
|
| facebook
|
| github
|
| google
|
| instagram
|
| mcdonald's
|
| mcdonalds
|
| microsoft
|
| netflix
|
| nintendo
|
| openai
|
| panasonic
|
| samsung
|
| tiktok
|
| twitter
|
| youtube
|
| # --- supplementary post-1930 terms (not in croqaz; added for 1930 coverage) ---
|
| positron
|
| deuterium
|
| cyclotron
|
| electron microscope
|
| nuclear fission
|
| nuclear fusion
|
| manhattan project
|
| chain reaction
|
| radioactive fallout
|
| carbon dating
|
| radiocarbon
|
| standard model
|
| quantum entanglement
|
| quantum computer
|
| double helix
|
| genetic engineering
|
| stem cell
|
| crispr
|
| supersonic
|
| cosmonaut
|
| integrated circuit
|
| semiconductor chip
|
| silicon chip
|
| personal computer
|
| operating system
|
| source code
|
| web browser
|
| web page
|
| world wide web
|
| usb
|
| hyperlink
|
| mobile app
|
| transistor radio
|
| world war ii
|
| world war 2
|
| nazi germany
|
| nagasaki
|
| new deal
|
| isbn
|
| paperback edition
|
| project gutenberg
|
| xerox
|
| atom bomb
|
| maser
|
| jet aircraft
|
| jet plane
|
| nasa
|
| nato
|
| fbi
|
| cia
|
| wikipedia
|
| bitcoin
|
| cryptocurrency
|
| coca-cola company
|
| disney world
|
| kleenex
|
| """
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| ALLOW_1930 = {
|
|
|
| "aeroplane", "airplane", "aircraft", "airliner", "airport", "aviation",
|
| "aviator", "airship", "zeppelin", "dirigible", "biplane", "monoplane",
|
| "automobile", "motorcar", "motor car", "motorcycle", "locomotive",
|
| "steamship", "submarine", "helicopter",
|
|
|
| "radio", "radio broadcast", "wireless", "telephone", "telegraph", "telegram",
|
| "phonograph", "gramophone", "cinema", "cinematograph", "motion picture",
|
| "moving picture", "movie", "movies", "the movies", "film", "photograph",
|
| "photography", "camera", "video camera", "typewriter", "stereo", "microphone",
|
| "television",
|
|
|
| "quantum", "quantum theory", "quantum mechanics", "quantum physics",
|
| "relativity", "theory of relativity", "special relativity", "general relativity",
|
| "photon", "electron", "proton", "atom", "atomic", "atomic theory", "isotope",
|
| "ion", "radioactivity", "radioactive", "radium", "uranium", "x-ray", "x ray",
|
| "xray", "roentgen", "spectroscopy", "spectrometry", "spectral classification",
|
| "stellar classification", "thermodynamics", "entropy", "electromagnetic",
|
| "ferromagnetism", "ferromagnetic material", "molecule", "ionic compounds",
|
| "michelson-morley experiment", "cathode ray", "vacuum tube", "polymer",
|
| "planck", "bohr", "rutherford", "curie",
|
|
|
| "vitamin", "hormone", "insulin", "gene", "genetics", "chromosome", "heredity",
|
| "evolution", "natural selection", "darwin", "mendel", "bacteria", "bacterium",
|
| "virus", "vaccine", "vaccination", "antiseptic", "anesthesia", "anaesthesia",
|
| "neurology", "germ theory",
|
|
|
| "psychoanalysis", "freud", "subconscious", "unconscious", "psychology",
|
|
|
| "electricity", "electric", "dynamo", "generator", "turbine", "engine",
|
| "petroleum", "gasoline", "petrol", "kerosene", "celluloid", "rubber",
|
| "skyscraper", "elevator", "escalator", "subway", "tram", "streetcar",
|
| "jazz", "ragtime", "aspirin", "plastic", "bakelite", "rayon",
|
| "mechanization", "mechanisation", "fascism", "fascist",
|
|
|
| "first world war", "world war", "the world war", "wwi", "ww1", "great war",
|
| "twentieth century", "nineteenth century", "league of nations",
|
|
|
| "einstein", "albert einstein", "nikola tesla", "lenin", "vladimir lenin",
|
| "gandhi", "mahatma gandhi", "franz kafka", "leon trotsky", "trotsky",
|
| "joseph stalin", "stalin", "ernest hemingway", "william faulkner", "walt disney",
|
| }
|
| ALLOW_1930 = {_norm(t) for t in ALLOW_1930}
|
|
|
|
|
|
|
|
|
|
|
| EXTRA_1930_BANNED = {
|
|
|
| "neutron",
|
| "positron",
|
| "deuterium",
|
| "nuclear fission",
|
| "nuclear fusion",
|
| "nuclear reactor", "nuclear physics", "nuclear energy", "nuclear power",
|
| "atomic bomb", "atom bomb", "hydrogen bomb", "nuclear weapon",
|
| "manhattan project", "chain reaction",
|
| "antibiotic", "penicillin", "sulfa drug", "sulfanilamide",
|
| "dna", "rna", "double helix", "genome", "genetic code",
|
| "radar", "sonar", "jet engine", "jet aircraft", "jet plane",
|
| "television broadcast", "transistor",
|
| "cyclotron",
|
| "electron microscope",
|
|
|
| "computer program", "digital computer", "electronic computer",
|
| "microprocessor", "microchip", "integrated circuit", "semiconductor",
|
| "internet", "world wide web", "website", "email", "e-mail", "software",
|
| "smartphone", "laser", "maser",
|
|
|
| "world war ii", "world war 2", "second world war", "cold war",
|
| "united nations", "nato", "nazi", "nazi germany", "holocaust", "auschwitz",
|
| "pearl harbor", "hiroshima", "nagasaki", "d-day", "normandy landing",
|
| "iron curtain", "berlin wall", "soviet union", "ussr",
|
| "spanish civil war",
|
|
|
| "nasa", "fbi", "cia", "gestapo", "luftwaffe", "wehrmacht",
|
|
|
| "isbn", "paperback", "photocopy", "xerox", "ballpoint",
|
| }
|
| EXTRA_1930_BANNED = {_norm(t) for t in EXTRA_1930_BANNED}
|
|
|
|
|
| FORMAT_TELL_PATTERNS = {
|
| "copyright_post_1930": r"(?:©|copyright|\(c\))\s*(?:19[3-9]\d|20\d\d)",
|
| "modern_year_reserved": r"all\s+rights\s+reserved",
|
| "isbn": r"\bisbn(?:-1[03])?\b",
|
| "url_www": r"\bwww\.",
|
| "url_http": r"https?://",
|
| "url_dotcom": r"\b[\w-]+\.(?:com|org|net|edu|gov|io)\b",
|
| "loc_cip": r"library\s+of\s+congress\s+cata-?\s*loging|cataloging-in-publication",
|
| "printed_usa_modern": r"printed\s+in\s+the\s+united\s+states\s+of\s+america",
|
| "gutenberg_license": r"project\s+gutenberg(?:-tm)?(?:\s+(?:license|ebook|literary))",
|
| "email_addr": r"\b[\w.-]+@[\w.-]+\.\w{2,}\b",
|
| }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| TIER3_TERMS = {
|
|
|
| "compiler", "hardware", "gaming", "gaming industry", "drone",
|
| "satellite", "satellite-dish", "twitter", "black hole", "deep learning",
|
| "holocaust", "pearl harbor", "great depression", "lesbian",
|
|
|
| "computer", "automation", "online", "download", "upload", "reboot", "pixel",
|
| "diode", "microwave", "fax", "stereo", "antimatter", "supersonic",
|
| "chemotherapy", "omega-3", "low bass", "ultra lightweight",
|
| "special effects", "screenplay", "navigation system", "hollywood",
|
| "hip hop", "hip-hop", "rock and roll", "rock 'n' roll", "climate change",
|
|
|
|
|
| "positron", "neutron", "deuterium", "cyclotron", "antimatter",
|
| "plastic-free",
|
| }
|
|
|
|
|
|
|
| STRIP_ONLY_TERMS = {
|
| "photocopy", "paperback", "paperback edition", "pdf version",
|
| "digital edition", "digital media", "e-book", "ebook",
|
| "official website", "web site", "website", "web page", "web browser",
|
| "project gutenberg", "www", "http", "online",
|
| }
|
|
|
|
|
| TIER1_TERMS = {
|
|
|
| "chatgpt", "openai", "github", "google", "facebook", "instagram", "tiktok",
|
| "youtube", "netflix", "microsoft", "samsung", "panasonic", "nintendo",
|
| "astrazeneca", "burger king", "mcdonald's", "mcdonalds", "disney world",
|
| "kleenex", "boeing 777", "coca-cola company", "iphone", "ipad", "iwatch",
|
| "android phone", "app store", "smartphone", "smart phone", "smartwatch",
|
| "smart watch", "blockchain", "bitcoin", "cryptocurrency", "covid-19",
|
| "pytorch", "node.js", "minecraft", "super mario", "final fantasy x",
|
| "godzilla", "star wars", "x-men", "x-files", "harry potter", "super bowl",
|
| "eurovision",
|
|
|
| "adolf hitler", "benito mussolini", "mussolini", "mao zedong",
|
| "donald trump", "taylor swift", "elvis presley", "bob dylan", "bob marley",
|
| "the beatles", "pink floyd", "marilyn monroe", "john f. kennedy",
|
| "john fitzgerald kennedy", "martin luther king", "robert downey jr.",
|
| "tony stark", "james bond", "carlos santana", "anne sexton", "sylvia plath",
|
| "j.r.r. tolkien", "j. r. r. tolkien", "j.d. salinger", "j. d. salinger",
|
|
|
| "transistor", "microprocessor", "microchip", "integrated circuit",
|
| "semiconductor chip", "silicon chip", "internet", "world wide web",
|
| "css", "html", "javascript", "typescript", "php", "fortran",
|
| "dna", "rna", "mrna", "trna", "crispr", "genome", "double helix",
|
| "stem cell", "gene therapy", "genetic engineering", "nylon",
|
| "wifi", "wi-fi", "bluetooth", "usb", "gpu", "cpu", "ssd", "hdd", "dvd",
|
| "laptop", "quantum computer", "quantum chromodynamics",
|
| "quantum field theory", "large hadron collider", "higgs boson",
|
| "higgs field", "hawking radiation", "dark matter", "dark energy",
|
| "graphene", "spintronics", "metamaterial",
|
| "space shuttle", "space station", "moon landing", "spaceflight",
|
| "spacecraft", "cosmonaut", "astronaut", "nuclear weapon", "nuclear reactor",
|
| "hydrogen bomb", "atomic bomb", "atom bomb", "manhattan project",
|
| "nuremberg trials", "auschwitz", "berlin wall", "iron curtain", "cold war",
|
| "world war ii", "world war 2", "second world war", "wwii", "ww2", "d-day",
|
| }
|
|
|
|
|
| def assign_tiers(final_terms):
|
| """Map every banned term to a tier: 1, 2, 3, or 'strip'.
|
|
|
| Precedence: strip-only > tier 3 > tier 1 > default tier 2. (Strip and tier-3
|
| win over tier-1 so an ambiguous/boilerplate term is never treated as hard.)
|
| Returns (tiers_by_term, counts).
|
| """
|
| strip = {_norm(t) for t in STRIP_ONLY_TERMS}
|
| t3 = {_norm(t) for t in TIER3_TERMS} - strip
|
| t1 = {_norm(t) for t in TIER1_TERMS} - strip - t3
|
|
|
| tiers = {}
|
| for t in final_terms:
|
| if t in strip:
|
| tiers[t] = "strip"
|
| elif t in t3:
|
| tiers[t] = 3
|
| elif t in t1:
|
| tiers[t] = 1
|
| else:
|
| tiers[t] = 2
|
| counts = {
|
| "tier1": sum(1 for v in tiers.values() if v == 1),
|
| "tier2": sum(1 for v in tiers.values() if v == 2),
|
| "tier3": sum(1 for v in tiers.values() if v == 3),
|
| "strip": sum(1 for v in tiers.values() if v == "strip"),
|
| }
|
| return tiers, counts
|
|
|
|
|
| def build_banned_list():
|
| """Construct the final banned term list from seed + allow + extra. Returns
|
| (final_terms_sorted, meta_dict, removed_from_seed_list)."""
|
| seed = _clean_terms(SEED_RAW.splitlines())
|
| seed_set = set(seed)
|
|
|
| removed_from_seed = sorted(seed_set & ALLOW_1930)
|
| kept_from_seed = seed_set - ALLOW_1930
|
|
|
|
|
| extra_effective = EXTRA_1930_BANNED - ALLOW_1930
|
| added_by_extra = sorted(extra_effective - kept_from_seed)
|
|
|
| final = sorted(kept_from_seed | extra_effective)
|
| tiers, tier_counts = assign_tiers(final)
|
|
|
| meta = {
|
| "cutoff_year": config.CUTOFF_YEAR,
|
| "n_seed": len(seed),
|
| "n_removed_by_allow": len(removed_from_seed),
|
| "n_added_by_extra": len(added_by_extra),
|
| "n_allow_list": len(ALLOW_1930),
|
| "n_format_tells": len(FORMAT_TELL_PATTERNS),
|
| "n_final_terms": len(final),
|
| "n_total_banned_signals": len(final) + len(FORMAT_TELL_PATTERNS),
|
| "tier_counts": tier_counts,
|
| "drop_rule": "1x tier1 OR (>=2 distinct tier2/tier3 with >=1 tier2). "
|
| "tier3 never fires alone; strip-only never contributes.",
|
| "built_at": time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime()),
|
| "policy": "tiered_confidence",
|
| }
|
| return final, meta, removed_from_seed, added_by_extra, tiers
|
|
|
|
|
|
|
|
|
|
|
| def try_download_banned_list():
|
| """Load a cached banned list + tiers from the destination repo if present.
|
|
|
| Requires tiers.json to be present; a pre-tier cached list is treated as a
|
| cache miss so it gets rebuilt with tiers.
|
| """
|
| try:
|
| list_path = hf_hub_download(config.DST_REPO, "_banned/banned_list.txt", repo_type="dataset", token=HF_TOKEN)
|
| meta_path = hf_hub_download(config.DST_REPO, "_banned/list_meta.json", repo_type="dataset", token=HF_TOKEN)
|
| tier_path = hf_hub_download(config.DST_REPO, "_banned/tiers.json", repo_type="dataset", token=HF_TOKEN)
|
| with open(list_path, "r", encoding="utf-8") as f:
|
| terms = [_norm(l) for l in f if l.strip()]
|
| with open(meta_path, "r", encoding="utf-8") as f:
|
| meta = json.load(f)
|
| with open(tier_path, "r", encoding="utf-8") as f:
|
| raw = json.load(f)
|
|
|
| tiers = {k: (v if v == "strip" else int(v)) for k, v in raw.items()}
|
| print("Loaded cached banned list + tiers from destination repo.")
|
| return terms, meta, tiers
|
| except Exception:
|
| return None, None, None
|
|
|
|
|
| def _write_tier_files(d, tiers):
|
| """Write per-tier text files + tiers.json to local dir d; return their paths."""
|
| buckets = {1: [], 2: [], 3: [], "strip": []}
|
| for term, tier in tiers.items():
|
| buckets[tier].append(term)
|
| paths = {}
|
| for tier, name in [(1, "tier1.txt"), (2, "tier2.txt"), (3, "tier3.txt"), ("strip", "strip_only.txt")]:
|
| p = d / name
|
| p.write_text("\n".join(sorted(buckets[tier])) + "\n", encoding="utf-8")
|
| paths[name] = p
|
| tj = d / "tiers.json"
|
| with open(tj, "w", encoding="utf-8") as f:
|
| json.dump({k: v for k, v in sorted(tiers.items())}, f, indent=2)
|
| paths["tiers.json"] = tj
|
| return paths
|
|
|
|
|
| def build_and_upload_banned_list():
|
| final, meta, removed_from_seed, added_by_extra, tiers = build_banned_list()
|
| config.ensure_dirs()
|
| d = config.BANNED_DIR
|
| (d / "banned_list.txt").write_text("\n".join(final) + "\n", encoding="utf-8")
|
| (d / "allow_list.txt").write_text("\n".join(sorted(ALLOW_1930)) + "\n", encoding="utf-8")
|
| with open(d / "removed_from_seed.json", "w", encoding="utf-8") as f:
|
| json.dump({"removed_from_seed_because_pre_1931": removed_from_seed,
|
| "added_by_extra_1930_banned": added_by_extra}, f, indent=2, sort_keys=True)
|
| with open(d / "list_meta.json", "w", encoding="utf-8") as f:
|
| json.dump(meta, f, indent=2, sort_keys=True)
|
| with open(d / "format_tells.json", "w", encoding="utf-8") as f:
|
| json.dump(FORMAT_TELL_PATTERNS, f, indent=2, sort_keys=True)
|
| tier_paths = _write_tier_files(d, tiers)
|
|
|
| ops = [
|
| CommitOperationAdd("_banned/banned_list.txt", str(d / "banned_list.txt")),
|
| CommitOperationAdd("_banned/allow_list.txt", str(d / "allow_list.txt")),
|
| CommitOperationAdd("_banned/removed_from_seed.json", str(d / "removed_from_seed.json")),
|
| CommitOperationAdd("_banned/list_meta.json", str(d / "list_meta.json")),
|
| CommitOperationAdd("_banned/format_tells.json", str(d / "format_tells.json")),
|
| ]
|
| ops += [CommitOperationAdd(f"_banned/{name}", str(p)) for name, p in tier_paths.items()]
|
|
|
| api.create_commit(
|
| repo_id=config.DST_REPO, repo_type="dataset", operations=ops,
|
| commit_message=(f"add 1930s tiered banned list ({meta['n_final_terms']} terms; "
|
| f"tiers {meta['tier_counts']})"),
|
| )
|
| return final, meta, tiers
|
|
|
|
|
| def load_or_build():
|
| """Return (banned_terms, meta, tiers): cached copy unless FORCE_REBUILD_LIST."""
|
| ensure_dst_repo()
|
| if config.FORCE_REBUILD_LIST:
|
| terms, meta, tiers = None, None, None
|
| else:
|
| terms, meta, tiers = try_download_banned_list()
|
| if terms is None:
|
| terms, meta, tiers = build_and_upload_banned_list()
|
| return terms, meta, tiers
|
|
|
|
|
| def main():
|
| terms, meta, tiers = load_or_build()
|
| print("=" * 60)
|
| print("BANNED LIST SUMMARY (tiered)")
|
| print("=" * 60)
|
| print(json.dumps(meta, indent=2, sort_keys=True))
|
| tc = meta.get("tier_counts", {})
|
| print(f"\nTOTAL WORDS/PHRASES IN BANNED LIST: {len(terms):,}")
|
| print(f" tier 1 (hard, 1 hit drops): {tc.get('tier1', 0):,}")
|
| print(f" tier 2 (moderate): {tc.get('tier2', 0):,}")
|
| print(f" tier 3 (weak, never fires alone): {tc.get('tier3', 0):,}")
|
| print(f" strip-only (boilerplate, no drop): {tc.get('strip', 0):,}")
|
| print(f"Plus {len(FORMAT_TELL_PATTERNS)} format-tell patterns (strip-only).")
|
| return terms, meta, tiers
|
|
|
|
|
| if __name__ == "__main__":
|
| main()
|
|
|