{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "37c285e7",
   "metadata": {},
   "source": [
    "# Version 2 quickstart\n",
    "\n",
    "A short reader for version 2.0.0 of the bundle (the data behind the online map; see `DATASETS.md`). It lists the files, prints each table's columns and row count, shows what version 2 changed against ReFinED's links, and opens the network.\n",
    "\n",
    "Run it from the folder that holds `datasets_release_v2/`, or from inside that folder."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "a11b9548",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-12-02T21:20:06.711380Z",
     "iopub.status.busy": "2026-12-02T21:20:06.710936Z",
     "iopub.status.idle": "2026-12-02T21:20:07.302681Z",
     "shell.execute_reply": "2026-12-02T21:20:07.302337Z"
    }
   },
   "outputs": [],
   "source": [
    "from __future__ import annotations\n",
    "\n",
    "from pathlib import Path\n",
    "\n",
    "# Parquet\n",
    "import pyarrow as pa\n",
    "import pyarrow.parquet as pq\n",
    "import pyarrow.dataset as ds\n",
    "\n",
    "# Graphs\n",
    "import numpy as np\n",
    "\n",
    "# NumPy 2.x compatibility patch (NetworkX GraphML/GEXF readers may expect np.float_ etc.)\n",
    "if not hasattr(np, \"float_\"):\n",
    "    np.float_ = np.float64  # type: ignore[attr-defined]\n",
    "if not hasattr(np, \"int_\"):\n",
    "    np.int_ = np.int64  # type: ignore[attr-defined]\n",
    "if not hasattr(np, \"complex_\"):\n",
    "    np.complex_ = np.complex128  # type: ignore[attr-defined]\n",
    "\n",
    "import networkx as nx\n",
    "\n",
    "\n",
    "\n",
    "def human_bytes(n: int) -> str:\n",
    "    units = [\"B\", \"KB\", \"MB\", \"GB\", \"TB\"]\n",
    "    x = float(n)\n",
    "    for u in units:\n",
    "        if x < 1024.0 or u == units[-1]:\n",
    "            return f\"{x:.2f} {u}\"\n",
    "        x /= 1024.0\n",
    "    return f\"{x:.2f} TB\"\n",
    "\n",
    "\n",
    "# The folder with the unzipped files: run from the folder that holds datasets_release_v2/, or from inside it.\n",
    "DATA = Path(\"datasets_release_v2\")\n",
    "if not DATA.exists() and (Path.cwd() / \"mentions\").exists():\n",
    "    DATA = Path(\".\")\n",
    "assert DATA.exists(), \"Could not find datasets_release_v2/ (run from the folder that holds it, or from within it).\"\n",
    "\n",
    "\n",
    "def list_files(base: Path) -> list[Path]:\n",
    "    return sorted([p for p in base.rglob(\"*\") if p.is_file()])\n",
    "\n",
    "\n",
    "def parquet_schema_and_rows(path: Path) -> tuple[int, list[tuple[str, str]]]:\n",
    "    pf = pq.ParquetFile(path)\n",
    "    schema = pf.schema_arrow\n",
    "    cols = [(name, str(schema.field(name).type)) for name in schema.names]\n",
    "    return pf.metadata.num_rows, cols\n",
    "\n",
    "\n",
    "def graph_attr_summary(G: nx.Graph) -> dict:\n",
    "    node_keys = set()\n",
    "    edge_keys = set()\n",
    "    for _, d in G.nodes(data=True):\n",
    "        node_keys.update(d.keys())\n",
    "    for _, _, d in G.edges(data=True):\n",
    "        edge_keys.update(d.keys())\n",
    "    return {\n",
    "        \"n\": G.number_of_nodes(),\n",
    "        \"m\": G.number_of_edges(),\n",
    "        \"directed\": G.is_directed(),\n",
    "        \"node_attrs\": sorted(node_keys),\n",
    "        \"edge_attrs\": sorted(edge_keys),\n",
    "    }\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "836cb976",
   "metadata": {},
   "source": [
    "## 0) Environment"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "2b48aac1",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-12-02T21:20:07.305302Z",
     "iopub.status.busy": "2026-12-02T21:20:07.305115Z",
     "iopub.status.idle": "2026-12-02T21:20:07.308186Z",
     "shell.execute_reply": "2026-12-02T21:20:07.307859Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "python: 3.10.8\n",
      "cwd: /Users/wouter/gitrepos/PPA-Ends-of-Prosody/datasets_release_v2\n",
      "data root: /Users/wouter/gitrepos/PPA-Ends-of-Prosody/datasets_release_v2\n",
      "numpy: 1.26.4\n",
      "networkx: 3.4.2\n",
      "pyarrow: 19.0.0\n",
      "pandas: 2.2.3\n"
     ]
    }
   ],
   "source": [
    "import sys\n",
    "\n",
    "print(\"python:\", sys.version.split()[0])\n",
    "print(\"cwd:\", Path.cwd())\n",
    "print(\"data root:\", DATA.resolve())\n",
    "print(\"numpy:\", np.__version__)\n",
    "print(\"networkx:\", nx.__version__)\n",
    "print(\"pyarrow:\", pa.__version__)\n",
    "try:\n",
    "    import pandas as pd\n",
    "    print(\"pandas:\", pd.__version__)\n",
    "except Exception:\n",
    "    print(\"pandas: (not available)\")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4fd8f9fb",
   "metadata": {},
   "source": [
    "## 1) Files and sizes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "77c48536",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-12-02T21:20:07.310255Z",
     "iopub.status.busy": "2026-12-02T21:20:07.310126Z",
     "iopub.status.idle": "2026-12-02T21:20:07.314664Z",
     "shell.execute_reply": "2026-12-02T21:20:07.314356Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "n_files: 18\n",
      "  40.24 MB  wikidata.zip\n",
      "  36.34 MB  wikidata/qid_stats_wd2sql_enriched.parquet\n",
      "  31.04 MB  mentions/mentions_v2.parquet\n",
      "  25.60 MB  mentions.zip\n",
      "  12.91 MB  exports_network/page_index_ppa_corpus_2025-02-03_1308.parquet\n",
      "   7.94 MB  wikidata/qid_aliases.parquet\n",
      "   7.56 MB  network/network_v2.graphml\n",
      "   5.39 MB  exports_network.zip\n",
      "   2.34 MB  wikidata/persons_v2.parquet\n",
      " 744.79 KB  network.zip\n",
      " 188.04 KB  wikidata/literary_entity_where_when__collections_Literary__cluster_earliest__nworks_3149__score0.9.parquet\n",
      " 124.40 KB  exports_network/work_universe__cluster_earliest__nworks_3149.parquet\n",
      "  98.67 KB  exports_network/poet_universe_v2.parquet\n",
      "  15.74 KB  metadata/rules_v2.csv\n",
      "  12.24 KB  00_quickstart.ipynb\n",
      "   8.58 KB  metadata.zip\n",
      "   4.10 KB  DATASETS.md\n",
      "   1.50 KB  metadata/provenance_v2.json\n",
      "\n",
      "Top-level subfolders:\n",
      "- exports_network   13.12 MB\n",
      "- mentions       31.04 MB\n",
      "- metadata       17.25 KB\n",
      "- network         7.56 MB\n",
      "- wikidata       46.81 MB\n"
     ]
    }
   ],
   "source": [
    "files = list_files(DATA)\n",
    "print(f\"n_files: {len(files)}\")\n",
    "\n",
    "# show largest first\n",
    "largest = sorted(((p, p.stat().st_size) for p in files), key=lambda x: -x[1])\n",
    "for p, sz in largest[:30]:\n",
    "    print(f\"{human_bytes(sz):>10}  {p.relative_to(DATA)}\")\n",
    "\n",
    "print(\"\\nTop-level subfolders:\")\n",
    "for p in sorted([x for x in DATA.iterdir() if x.is_dir()]):\n",
    "    total = sum(f.stat().st_size for f in p.rglob(\"*\") if f.is_file())\n",
    "    print(f\"- {p.name:12s} {human_bytes(total):>10}\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e3dfa16c",
   "metadata": {},
   "source": [
    "## 2) Parquet tables: columns and row counts\n",
    "\n",
    "Only the Parquet metadata is read here, not the tables themselves."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "b88a0f0a",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-12-02T21:20:07.316726Z",
     "iopub.status.busy": "2026-12-02T21:20:07.316588Z",
     "iopub.status.idle": "2026-12-02T21:20:07.323312Z",
     "shell.execute_reply": "2026-12-02T21:20:07.322980Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "= mentions_v2\n",
      "rows: 2,110,879\n",
      " - wikidata_qid: string\n",
      " - wd_label_en: string\n",
      " - mention_text: string\n",
      " - page_id: string\n",
      " - work_id: string\n",
      " - score: double\n",
      " - page_char_start: int64\n",
      " - page_char_end: int64\n",
      " - source: string\n",
      " - title: string\n",
      " - author: string\n",
      " - pub_year: double\n",
      " - refined_qid: string\n",
      " - rule_id: string\n",
      "\n",
      "= poet_universe_v2\n",
      "rows: 3,372\n",
      " - wikidata_qid: string\n",
      " - poet_name: string\n",
      " - birth_year: double\n",
      " - n_mentions: int64\n",
      " - n_works: int64\n",
      "\n",
      "= work_universe\n",
      "rows: 3,148\n",
      " - work_id: string\n",
      " - pub_year: double\n",
      " - decade: int64\n",
      " - title: string\n",
      " - source: string\n",
      " - collections: string\n",
      " - cluster_id: string\n",
      "\n",
      "= page_index\n",
      "rows: 1,982,024\n",
      " - page_id: string\n",
      " - work_id: string\n",
      " - label: string\n",
      " - page_num: double\n",
      " - n_chars: int64\n",
      "\n",
      "= persons_v2\n",
      "rows: 44,171\n",
      " - wikidata_qid: string\n",
      " - label: string\n",
      " - description: string\n",
      " - birth_year: int32\n",
      " - death_year: int32\n",
      " - occupations: string\n",
      " - is_poet: bool\n",
      "\n",
      "= qid_stats_wd2sql_enriched\n",
      "rows: 314,344\n",
      " - wikidata_qid: string\n",
      " - n_occurrences: int64\n",
      " - n_surface_forms: int64\n",
      " - surface_forms_list: list<element: string>\n",
      " - wd2sql_id: int64\n",
      " - wd_label_en: string\n",
      " - wd_description_en: string\n",
      " - is_human_q5: bool\n",
      " - sex_or_gender_qids: string\n",
      " - sex_or_gender_labels: string\n",
      " - place_of_birth_qids: string\n",
      " - place_of_birth_labels: string\n",
      " - place_of_death_qids: string\n",
      " - place_of_death_labels: string\n",
      " - citizenship_qids: string\n",
      " - citizenship_labels: string\n",
      " - occupation_qids: string\n",
      " - occupation_labels: string\n",
      " - field_of_work_qids: string\n",
      " - field_of_work_labels: string\n",
      " - languages_qids: string\n",
      " - languages_labels: string\n",
      " - educated_at_qids: string\n",
      " - educated_at_labels: string\n",
      " - member_of_qids: string\n",
      " - member_of_labels: string\n",
      " - employer_qids: string\n",
      " - employer_labels: string\n",
      " - genre_qids: string\n",
      " - genre_labels: string\n",
      " - movement_qids: string\n",
      " - movement_labels: string\n",
      " - notable_works_qids: string\n",
      " - notable_works_labels: string\n",
      " - given_name_qids: string\n",
      " - given_name_labels: string\n",
      " - family_name_qids: string\n",
      " - family_name_labels: string\n",
      " - date_of_birth: string\n",
      " - date_of_death: string\n",
      " - is_poet_q49757: bool\n",
      " - is_writer_q36180: bool\n",
      " - viaf: string\n",
      " - isni: string\n",
      " - gnd: string\n",
      " - lccn: string\n",
      "\n",
      "= qid_aliases\n",
      "rows: 314,344\n",
      " - wikidata_qid: string\n",
      " - n_surface_forms: int64\n",
      " - total_occurrences: int64\n",
      " - surface_forms: list<element: string>\n",
      "\n",
      "= literary_entity_where_when\n",
      "rows: 14,484\n",
      " - wikidata_qid: string\n",
      " - n_occurrences: int64\n",
      " - n_works: int64\n",
      " - min_year: int32\n",
      " - max_year: int32\n"
     ]
    }
   ],
   "source": [
    "PARQUETS = {\n",
    "    \"mentions_v2\": DATA / \"mentions\" / \"mentions_v2.parquet\",\n",
    "    \"poet_universe_v2\": DATA / \"exports_network\" / \"poet_universe_v2.parquet\",\n",
    "    \"work_universe\": DATA / \"exports_network\" / \"work_universe__cluster_earliest__nworks_3149.parquet\",\n",
    "    \"page_index\": DATA / \"exports_network\" / \"page_index_ppa_corpus_2025-02-03_1308.parquet\",\n",
    "    \"persons_v2\": DATA / \"wikidata\" / \"persons_v2.parquet\",\n",
    "    \"qid_stats_wd2sql_enriched\": DATA / \"wikidata\" / \"qid_stats_wd2sql_enriched.parquet\",\n",
    "    \"qid_aliases\": DATA / \"wikidata\" / \"qid_aliases.parquet\",\n",
    "    \"literary_entity_where_when\": DATA / \"wikidata\"\n",
    "    / \"literary_entity_where_when__collections_Literary__cluster_earliest__nworks_3149__score0.9.parquet\",\n",
    "}\n",
    "\n",
    "for k, p in PARQUETS.items():\n",
    "    assert p.exists(), f\"Missing: {p}\"\n",
    "\n",
    "for k, p in PARQUETS.items():\n",
    "    nrows, cols = parquet_schema_and_rows(p)\n",
    "    print(\"\\n=\", k)\n",
    "    print(\"rows:\", f\"{nrows:,}\")\n",
    "    for name, typ in cols:\n",
    "        print(f\" - {name}: {typ}\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "56091a54",
   "metadata": {},
   "source": [
    "## 3) What version 2 changed\n",
    "\n",
    "`refined_qid` is ReFinED's link and `wikidata_qid` the link version 2 uses. Where the two differ, the identity was changed; `rule_id` names the documented rule wherever one set the link."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "9f5ded84",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-12-02T21:20:07.325308Z",
     "iopub.status.busy": "2026-12-02T21:20:07.325202Z",
     "iopub.status.idle": "2026-12-02T21:20:07.922512Z",
     "shell.execute_reply": "2026-12-02T21:20:07.922158Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "mentions: 2,110,879\n",
      " - linked to the person ReFinED chose: 1,863,211\n",
      " - linked to someone else:             78,626\n",
      " - linked to no one:                   169,042\n",
      " - set by a documented rule:           3,380\n",
      "\n",
      "Most frequent changes (ReFinED -> version 2):\n",
      "Q15837802  ->  James Macpherson                        2336\n",
      "Robert Lowell  ->  James Russell Lowell                1588\n",
      "Pliny the Elder  ->  Pliny the Younger                 1497\n",
      "Q174353  ->  Orpheus                                   1351\n",
      "Richard Brinsley Sheridan  ->  Thomas Sheridan          962\n",
      "Q188794  ->  Proto-Isaiah                               836\n",
      "Honoré de Balzac  ->  Jean-Louis Guez de Balzac         820\n",
      "Oliver Cromwell  ->  Thomas Cromwell                    781\n",
      "Richard I of England  ->  Richard II of England         777\n",
      "Friedrich Schlegel  ->  August Wilhelm von Schlegel     755\n",
      "Charles Darwin  ->  Erasmus Darwin                      733\n",
      "Cato the Elder  ->  Cato the Younger                    669\n",
      "Rachel Speght  ->  Thomas Speght                        547\n",
      "Johann Wilhelm Spengel  ->  Leonhard von Spengel        546\n",
      "William Morris  ->  Richard Morris                      538\n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "\n",
    "m = pq.read_table(PARQUETS[\"mentions_v2\"], columns=[\"wikidata_qid\", \"refined_qid\", \"rule_id\", \"mention_text\"]).to_pandas()\n",
    "persons = pq.read_table(PARQUETS[\"persons_v2\"], columns=[\"wikidata_qid\", \"label\"]).to_pandas()\n",
    "label = dict(zip(persons.wikidata_qid, persons.label))          # QIDs not on the person list are shown as they are\n",
    "\n",
    "same = (m.wikidata_qid == m.refined_qid)\n",
    "print(f\"mentions: {len(m):,}\")\n",
    "print(f\" - linked to the person ReFinED chose: {same.sum():,}\")\n",
    "print(f\" - linked to someone else:             {(m.wikidata_qid.notna() & ~same).sum():,}\")\n",
    "print(f\" - linked to no one:                   {m.wikidata_qid.isna().sum():,}\")\n",
    "print(f\" - set by a documented rule:           {m.rule_id.notna().sum():,}\")\n",
    "\n",
    "print(\"\\nMost frequent changes (ReFinED -> version 2):\")\n",
    "ch = m[m.wikidata_qid.notna() & ~same]\n",
    "top = (ch.refined_qid.map(lambda q: label.get(q, q)) + \"  ->  \" + ch.wikidata_qid.map(lambda q: label.get(q, q))).value_counts().head(15)\n",
    "print(top.to_string())"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d553a9d4",
   "metadata": {},
   "source": [
    "## 4) Poet universe"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "dd02afc0",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-12-02T21:20:07.924864Z",
     "iopub.status.busy": "2026-12-02T21:20:07.924618Z",
     "iopub.status.idle": "2026-12-02T21:20:07.931996Z",
     "shell.execute_reply": "2026-12-02T21:20:07.931590Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "poets: 3372\n",
      "wikidata_qid           poet_name  birth_year  n_mentions  n_works\n",
      "      Q79759         John Milton      1608.0       41084     1964\n",
      "       Q6691               Homer      -900.0       28735     1897\n",
      "        Q692 William Shakespeare      1564.0       52679     1818\n",
      "       Q1398              Virgil       -70.0       25484     1794\n",
      "     Q213355         John Dryden      1631.0       23469     1477\n",
      "       Q6197              Horace       -65.0       13265     1472\n",
      "     Q164047      Alexander Pope      1688.0       18370     1404\n",
      "       Q5683    Geoffrey Chaucer      1343.0       36843     1391\n",
      "       Q1541              Cicero      -106.0       12654     1255\n",
      "       Q7198                Ovid       -43.0        8962     1147\n"
     ]
    }
   ],
   "source": [
    "poets = pq.read_table(PARQUETS[\"poet_universe_v2\"]).to_pandas()\n",
    "print(\"poets:\", len(poets))\n",
    "print(poets.sort_values(\"n_works\", ascending=False).head(10).to_string(index=False))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4b2d5596",
   "metadata": {},
   "source": [
    "## 5) The network"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "e5fa2d74",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-12-02T21:20:07.934373Z",
     "iopub.status.busy": "2026-12-02T21:20:07.934213Z",
     "iopub.status.idle": "2026-12-02T21:20:08.822308Z",
     "shell.execute_reply": "2026-12-02T21:20:08.821912Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "network_v2.graphml\n",
      " - poets, links: 2374 39400\n",
      " - node attrs: ['birth_year', 'community', 'label', 'n_works', 'x', 'y']\n",
      " - edge attrs: ['assoc', 'expected', 'w_win', 'w_works']\n",
      "\n",
      "Communities:\n",
      " - Romantic and Victorian poetry: 504\n",
      " - Romance Renaissance and classicism: 385\n",
      " - Continental comparison: 300\n",
      " - Early modern English poetry: 261\n",
      " - Classical antiquity: 251\n",
      " - Eighteenth-century criticism: 243\n",
      " - Modern and transatlantic field: 229\n",
      " - Medieval writing: 201\n",
      "\n",
      "Most linked poets:\n",
      "       Q45546   514  William Wordsworth  (Romantic and Victorian poetry)\n",
      "      Q173869   440  Alfred Tennyson  (Romantic and Victorian poetry)\n",
      "       Q93343   423  Percy Bysshe Shelley  (Romantic and Victorian poetry)\n",
      "       Q82083   411  John Keats  (Romantic and Victorian poetry)\n",
      "        Q5679   399  Lord Byron  (Romantic and Victorian poetry)\n",
      "         Q692   398  William Shakespeare  (Early modern English poetry)\n",
      "       Q79025   366  Walter Scott  (Romantic and Victorian poetry)\n",
      "        Q1067   356  Dante Alighieri  (Romance Renaissance and classicism)\n",
      "      Q315511   334  Algernon Charles Swinburne  (Romantic and Victorian poetry)\n",
      "     Q4352055   331  Edmund Spenser  (Early modern English poetry)\n"
     ]
    }
   ],
   "source": [
    "from collections import Counter\n",
    "\n",
    "G = nx.read_graphml(DATA / \"network\" / \"network_v2.graphml\")\n",
    "info = graph_attr_summary(G)\n",
    "print(\"network_v2.graphml\")\n",
    "print(\" - poets, links:\", info[\"n\"], info[\"m\"])\n",
    "print(\" - node attrs:\", info[\"node_attrs\"])\n",
    "print(\" - edge attrs:\", info[\"edge_attrs\"])\n",
    "\n",
    "print(\"\\nCommunities:\")\n",
    "for name, n in Counter(nx.get_node_attributes(G, \"community\").values()).most_common():\n",
    "    print(f\" - {name}: {n}\")\n",
    "\n",
    "print(\"\\nMost linked poets:\")\n",
    "for qid, d in sorted(G.degree, key=lambda x: x[1], reverse=True)[:10]:\n",
    "    print(f\"   {qid:>10s}  {d:4d}  {G.nodes[qid]['label']}  ({G.nodes[qid]['community']})\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "180261d3",
   "metadata": {},
   "source": [
    "## 6) Provenance"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "e53ca3f1",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-12-02T21:20:08.824443Z",
     "iopub.status.busy": "2026-12-02T21:20:08.824333Z",
     "iopub.status.idle": "2026-12-02T21:20:08.827047Z",
     "shell.execute_reply": "2026-12-02T21:20:08.826739Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "version: 2.0.0\n",
      "date: 2026-12-02\n",
      "scope: every ReFinED person link with score >= 0.85 in the PPA Literary collection (the relinking run's pages)\n",
      "identity: chosen again by a language model (gpt-6-luna, Princeton AI Sandbox) from the passage and up to 30 Wikidata candidates of that name (person list v2), or none; requests of up to 5 passages of one name in one book\n",
      "answers_by_prompt_version: {'1': 258834, '2': 1817128, '3': 21342}\n",
      "rules: documented corrections applied after the model (column rule_id): global fixes, conventions (e.g. Ossian -> James Macpherson), and per-person rules where the model repeated an error ReFinED made\n",
      "poet_universe: poet flag (Wikidata) as in version 1, or an occupation with 'poet' for people new to the data; >= 2 mentions in >= 2 works of the work universe; born by 1900 or no birth year\n",
      "network: five-page windows; a link when two poets are named together in >= 3 works and in more works than expected (assoc > 0); each poet's 150 strongest links kept; communities: consensus of 500 weighted Louvain runs; positions: ForceAtlas2 from the published layout\n",
      "work_universe_tag: cluster_earliest__nworks_3149\n",
      "corpus_start_year: 1559\n",
      "corpus_end_year: 1929\n",
      "n_mentions: 2110879\n",
      "n_poets: 3372\n",
      "network_nodes: 2374\n",
      "network_edges: 39400\n",
      "modularity: 0.5992\n",
      "left_out: 77 mentions in 35 requests without a usable answer\n",
      "version_1: doi:10.5281/zenodo.18623170 (the article's data, unchanged)\n"
     ]
    }
   ],
   "source": [
    "import json\n",
    "\n",
    "prov = json.loads((DATA / \"metadata\" / \"provenance_v2.json\").read_text(encoding=\"utf-8\"))\n",
    "for k, v in prov.items():\n",
    "    print(f\"{k}: {v}\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "corppa",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
