CinvanaAI
← All projects

Tool · Data & provenance / Games & interaction

Dice Expression Extractor

Find dice expressions in JSON and keep the field, action and record each one belongs to.

Repository: CinvanaAI/dice-expression-extractor

Recorded synthetic example. Source with a complete offline example.

See the idea in action.

Two expressions, their exact JSON paths, their hit-dice/damage roles, and graph rows carrying the Gear Spark context.

Example input
An invented Clockwork Mote with hit_dice 2d4+2 and Gear Spark damage 1d6+1.
Captured result
{
  "input": {
    "name": "Clockwork Mote",
    "hit_dice": "2d4+2",
    "actions": [
      {
        "name": "Gear Spark",
        "damage": [
          {
            "damage_dice": "1d6+1"
          }
        ]
      }
    ],
    "description": "Flavor text mentioning 20d20 is deliberately ignored."
  },
  "extracted": [
    {
      "expression": "2d4+2",
      "normalized_expression": "2d4+2",
      "quantity": 2,
      "sides": 4,
      "modifier": 2,
      "field_path": "$.hit_dice",
      "roll_type": "hit_dice",
      "context": null
    },
    {
      "expression": "1d6+1",
      "normalized_expression": "1d6+1",
      "quantity": 1,
      "sides": 6,
      "modifier": 1,
      "field_path": "$.actions[0].damage[0].damage_dice",
      "roll_type": "damage",
      "context": "Gear Spark"
    }
  ],
  "graph_rows": [
    {
      "record_id": "synthetic:clockwork-mote",
      "graph_id": "synthetic",
      "die_id": "synthetic:d4",
      "dice_id": "synthetic:2d4+2",
      "expression": "2d4+2",
      "normalized_expression": "2d4+2",
      "quantity": 2,
      "sides": 4,
      "modifier": 2,
      "field_path": "$.hit_dice",
      "roll_type": "hit_dice",
      "context": null
    },
    {
      "record_id": "synthetic:clockwork-mote",
      "graph_id": "synthetic",
      "die_id": "synthetic:d6",
      "dice_id": "synthetic:1d6+1",
      "expression": "1d6+1",
      "normalized_expression": "1d6+1",
      "quantity": 1,
      "sides": 6,
      "modifier": 1,
      "field_path": "$.actions[0].damage[0].damage_dice",
      "roll_type": "damage",
      "context": "Gear Spark"
    }
  ]
}

Try the example.

From the repository root, follow the dependency requirements in the README. This example uses supplied synthetic material.

python -m pip install -e .
python -m examples.walkthrough

Two expressions, their exact JSON paths, their hit-dice/damage roles, and graph rows carrying the Gear Spark context.

Complete setup and instructions ↗

The interesting part.

Field-aware extraction deliberately ignores dice-like prose and retains JSON-path/action context.

Focused extraction

Where it came from.

Dice subsystem from the DnDGraph experiment.

Removes the embedded database connection and credential; emits pure results and optional graph rows.

It is independently useful; no Neo4j writer or full D&D rules implementation is implied.

Source ↗

Follow the family: DnDGraph import and dice extraction

  • Shared historical projectD&D 5e Graph ETL

    See the broader ETL or focused dice boundary from the same experiment. Shared source experiment; not proof of current code dependency.

    Source 1 ↗, Source 2 ↗