"""Build refs.bib and refs_index.csv from References/INDEX.csv (only papers whose full-text PDF is present) + harvested metadata. Authors/venues come from slr/raw/candidates.jsonl (OpenAlex metadata); entries without metadata fall back to the PDF filename (Year_Author_...). Adds two non-PDF resources that the work itself uses: the BigFlow-NIDS paper (PDF in the repository root) and MITRE ATT&CK (data used in step 07a).""" import csv, json, os, re, unicodedata ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) idx = list(csv.DictReader(open(os.path.join(ROOT, "References", "INDEX.csv")))) cand = {} for line in open(os.path.join(ROOT, "slr", "raw", "candidates.jsonl")): c = json.loads(line); cand[c["id"]] = c def safe(t): """characters beyond Latin Extended-A (not typeset by the default fonts) are transliterated to ASCII""" return "".join(ch if ord(ch) < 0x180 else (unicodedata.normalize("NFKD", ch).encode("ascii", "ignore").decode() or "?") for ch in t) def esc(t): t = safe(t) t = t.replace("\\", " ").replace("&", r"\&").replace("%", r"\%").replace("#", r"\#").replace("_", r"\_").replace("$", r"\$").replace("~", " ") t = re.sub(r"<[^>]+>", "", t) # strip html tags in titles return re.sub(r"\s+", " ", t).strip() def ascii_key(s): return re.sub(r"[^a-z0-9]", "", unicodedata.normalize("NFKD", s).encode("ascii", "ignore").decode().lower()) STOP = {"a", "an", "the", "of", "on", "for", "and", "in", "to", "towards", "toward", "with", "using", "from"} def first_word(t): for w in re.findall(r"[A-Za-z]+", t): if w.lower() not in STOP: return w.lower() return "x" MISC = re.compile(r"arxiv|preprint|ssrn|research square|techrxiv|zenodo|mendeley|authorea|osf|hal\b", re.I) CONF = re.compile(r"conference|proceedings|symposium|workshop|congress|\bicc\b|globecom|infocom|\bieee .* (conf|symp)", re.I) OVERRIDE = { # keyed by PDF basename; fields verified on page 1 of the PDF; the generated KEY is kept so existing citations stay valid "2025_Luay_Temporal_Analysis_of_NetFlow_Datasets_for_NIDS_arXiv2503.04404.pdf": dict(typ="misc", author="Majed Luay and Siamak Layeghy and Seyedehfaezeh Hosseininoorbin and Mohanad Sarhan and Nour Moustafa and Marius Portmann", title="{Temporal Analysis of NetFlow Datasets for Network Intrusion Detection Systems}", year="2025", howpublished="arXiv:2503.04404", doi=""), "2018_Mirsky_Kitsune_Ensemble_of_Autoencoders_arXiv1802.09089.pdf": dict(typ="misc", author="Yisroel Mirsky and Tomer Doitshman and Yuval Elovici and Asaf Shabtai", title="{Kitsune: An Ensemble of Autoencoders for Online Network Intrusion Detection}", year="2018", howpublished="arXiv:1802.09089", doi=""), "2020_Mulyanto_Effectiveness_of_Focal_Loss_for_Minority_Classification_in_N.pdf": dict(typ="article", author="Mulyanto Mulyanto and Muhamad Faisal and Setya Widyawan Prakosa and Jenq-Shiou Leu", title="{Effectiveness of Focal Loss for Minority Classification in Network Intrusion Detection Systems}", year="2021", journal="Symmetry", volume="13", number="1", pages="4", doi="10.3390/sym13010004"), "2026_Wolf_Systematic_Evaluation_of_Synthetic_Data_Augmentation_for_Mul.pdf": dict(typ="misc", author="Maximilian Wolf and Dieter Landes and Andreas Hotho and Daniel Schl{\\\"o}r", title="{Systematic Evaluation of Synthetic Data Augmentation for Multi-class NetFlow Traffic}", year="2024", howpublished="arXiv:2408.16034"), "2026_Uddin_BigFlow_NIDS_dataset_DataInBrief.pdf": dict(typ="article", author="Mohammed Borhan Uddin and Mohammad Shamsul Arefin and M. M. Musharaf Hussain", title="{{BigFlow-NIDS}: A large-scale dataset for network intrusion detection in big data environment}", year="2026", journal="Data in Brief", volume="65", pages="112530", doi="10.1016/j.dib.2026.112530"), } used, rows, out = set(), [], [] for r in idx: c = cand.get(r["openalex_id"], {}) names = c.get("authors") or [] fn = os.path.basename(r["file"]); fa = fn.split("_")[1] if fn.count("_") >= 2 else "Anon" if not names: names = [fa] last = ascii_key(names[0].split()[-1]) or ascii_key(fa) key = f"{last}{r['year']}{first_word(r['title'])}" k, n = key, 0 while k in used: n += 1; k = key + chr(96 + n) used.add(k) venue = esc(r["venue"] or c.get("venue", "")) typ = "misc" if (not venue or MISC.search(venue)) else ("inproceedings" if CONF.search(venue) else "article") auth = " and ".join(names) + (" and others" if len(names) >= 6 else "") f = {"author": esc(auth), "title": "{" + esc(r["title"]) + "}", "year": r["year"]} if typ == "article": f["journal"] = venue elif typ == "inproceedings": f["booktitle"] = venue else: f["howpublished"] = venue or "preprint" if r["doi"]: f["doi"] = r["doi"] ov = OVERRIDE.get(os.path.basename(r["file"])) if ov: f = {a: b for a, b in ov.items() if a != "typ" and b != ""}; typ = ov["typ"] out.append("@%s{%s,\n%s\n}\n" % (typ, k, ",\n".join(f" {a} = {{{b}}}" if a != "title" else f" title = {b}" for a, b in f.items()))) rows.append([k, r["year"], r["title"], r["theme"], r["tier"], r["file"]]) # resources used by the work itself if not any("BigFlow-NIDS" in r[2] for r in rows): out.append("""@article{uddin2026bigflow, author = {Mohammed Borhan Uddin and Mohammad Shamsul Arefin and M. M. Musharaf Hussain}, title = {{BigFlow-NIDS}: A large-scale dataset for network intrusion detection in big data environment}, journal = {Data in Brief}, volume = {65}, pages = {112530}, year = {2026}, doi = {10.1016/j.dib.2026.112530} } """) rows.append(["uddin2026bigflow", "2026", "BigFlow-NIDS: A large-scale dataset for network intrusion detection in big data environment", "datasets", "core", "BigFlow-NIDS_ A large-scale dataset for network intrusion detection in big data environment.pdf"]) out.append("""@misc{mitre2026attack, author = {{MITRE Corporation}}, title = {{MITRE ATT\\&CK} Enterprise Matrix, version 20.0 (STIX data)}, year = {2026}, howpublished = {\\url{https://github.com/mitre-attack/attack-stix-data}} } """) rows.append(["mitre2026attack", "2026", "MITRE ATT&CK Enterprise v20.0 (STIX data used in step 07a)", "resource", "core", "impl/data/external/attack/enterprise-attack.json"]) open(os.path.join(ROOT, "thesis", "refs.bib"), "w").write("\n".join(out)) with open(os.path.join(ROOT, "thesis", "refs_index.csv"), "w", newline="") as f: w = csv.writer(f, lineterminator="\n"); w.writerow(["key", "year", "title", "theme", "tier", "pdf"]); w.writerows(rows) print(len(rows), "entries;", sum(1 for o in out if o.startswith("@article")), "article,", sum(1 for o in out if o.startswith("@inproceedings")), "inproceedings,", sum(1 for o in out if o.startswith("@misc")), "misc")