Processing WIF Weaving Drafts
1. Parse WIF file sections (INI-style: [WIF], [CONTENTS], [THREADING], [TIEUP], [TREADLING], [LIFTPLAN]?, [WARP], [WEFT], [COLOR TABLE])
2. Run mechanical validation → structured report (pass/fail + issue list)
3. Run provenance validation → structured report (metadata completeness)
4. Compute drawdown from threading + tie-up + treadling/liftplan
5. Render 4-panel draft chart + color-accurate preview
6. Package into print-ready PDF with repeat count, sett, yardage
Output validation as a structured report, not a thrown exception:
JSON{ "status": "fail", "errors": [ {"code": "TREADLE_OUT_OF_RANGE", "section": "TIEUP", "detail": "Treadle 9 referenced but Treadles=8", "severity": "blocking"} ], "warnings": [ {"code": "MISSING_PROVENANCE", "detail": "No [TEXT] author field found", "severity": "advisory"} ] }
Use severity: blocking to halt rendering; advisory issues can pass through with a flag in the final PDF appendix.
Progress:
- Step 1: Parse all WIF sections into structured data
- Step 2: Detect draft type (treadle-loom vs. liftplan/dobby) and branch accordingly
- Step 3: Mechanical validation
- Step 4: Provenance validation
- Step 5: Compute drawdown
- Step 6: Render chart + color preview
- Step 7: Package as print-ready PDF
Step 1: Parse
Map each section to structured data:
[THREADING]: warp thread number → shaft number[TIEUP]: shaft number → set of treadles it's tied to[TREADLING]: pick number → treadle number(s)[LIFTPLAN]: pick number → set of shafts (alternative to TIEUP+TREADLING on dobby looms)[WARP]/[WEFT]: thread color indices, referencing[COLOR TABLE][WEAVING]: Shafts=, Treadles=, RisingShed= (loom capability declarations)
Edge case — missing [TIEUP] entirely: Check for [LIFTPLAN] as the alternative mechanism. If neither exists, fail with code: NO_SHED_MECHANISM, blocking — the draft cannot be rendered.
Edge case — liftplan-only file: Skip tie-up/treadling validation; validate liftplan shaft references directly against Shafts= count instead.
Edge case — malformed [COLOR TABLE]: If color indices in [WARP]/[WEFT] reference table entries that don't exist, fall back to a default greyscale palette and emit code: COLOR_INDEX_UNRESOLVED as a warning — do not block rendering over cosmetic data.
Step 2: Detect draft type
If [LIFTPLAN] is present and non-empty, treat as liftplan-driven (common on computer-assisted/dobby looms). If [TREADLING]+[TIEUP] are present, treat as treadle-driven. If both exist, prefer [LIFTPLAN] and emit an advisory noting the file is dual-encoded.
Step 3: Mechanical validation
Checks, each emitted as a discrete report entry:
- Every threading entry's shaft number ≤
Shafts= - Every tie-up entry's treadle number ≤
Treadles= - Every treadling pick references a treadle that exists in tie-up (no orphan picks)
- Every warp end (by thread count) has a threading assignment — flag gaps as
UNASSIGNED_THREAD - Shaft count and treadle count are both ≥ 1 and within realistic loom bounds (warn above 40 shafts/treadles as likely data corruption)
Step 4: Provenance validation
Checks against [TEXT] and [WEAVING] metadata:
- Author/source field present
- Date or era present
- For named historical patterns (filename matches known pattern-family naming conventions, e.g., "Overshot", "Summer_Winter", "Crackle" followed by a number), cross-check against known archives (e.g., Marguerite Davison's A Handweaver's Pattern Book, Bergman's collections) and flag if unattributed.
This never blocks rendering — provenance issues are always severity: advisory.
Step 5: Compute drawdown
For each pick (row) and each warp end (column), determine warp-over or weft-under:
- Treadle-driven: pick → treadle → (via tie-up) → shafts raised → for each thread, if its assigned shaft is raised, warp shows; else weft shows
- Liftplan-driven: pick → shafts raised directly → same per-thread logic
Output as a 2D boolean grid (rows = picks, columns = ends), suitable for rendering or for structural analysis (identifying plain weave, twill, satin, overshot blocks).
Step 6: Render
4-panel layout:
- Top: threading chart (shaft assignments per warp end)
- Top-right: tie-up grid
- Center: drawdown grid (from Step 5)
- Left: treadling/liftplan sequence
Apply [COLOR TABLE] for warp/weft thread colors in the preview; separately generate a high-contrast black/white version for structural clarity.
Step 7: Package
Compute and include:
- Pattern repeat count (detect periodicity in drawdown grid)
- Sett (ends per inch / picks per inch, if present in
[WEAVING]) - Yardage estimate (requires finished width/length inputs, or flag as "not computable — missing dimensions")
- Provenance appendix (even if advisory warnings exist, archive all available metadata in PDF document properties + a printed appendix page)
Example 1 — Mechanical validation failure:
Input: WIF with [TIEUP] referencing treadle 9, [WEAVING] states Treadles=8
Output:
JSON{"status": "fail", "errors": [{"code": "TREADLE_OUT_OF_RANGE", "section": "TIEUP", "detail": "Treadle 9 referenced, max is 8", "severity": "blocking"}]}
Example 2 — Missing TIEUP, liftplan present:
Input: WIF with no [TIEUP] section, [LIFTPLAN] fully populated, Shafts=16
Output:
JSON{"status": "pass", "mode": "liftplan", "warnings": []}
Proceeds to drawdown computation using liftplan path, skipping tie-up checks entirely.
Example 3 — No shed mechanism at all:
Input: WIF with neither [TIEUP] nor [LIFTPLAN]
Output:
JSON{"status": "fail", "errors": [{"code": "NO_SHED_MECHANISM", "detail": "Cannot compute drawdown without TIEUP or LIFTPLAN", "severity": "blocking"}]}
Example 4 — Provenance warning (non-blocking):
Input: File named Colonial_Overshot_47.wif, no [TEXT] section
Output:
JSON{"status": "pass", "warnings": [{"code": "MISSING_PROVENANCE", "detail": "No author/source found; filename suggests historical Overshot pattern — recommend cross-referencing Davison archive", "severity": "advisory"}]}
Rendering and packaging proceed; warning is included in the PDF appendix.
Example 5 — Malformed color table:
Input: [WARP] references color index 12, [COLOR TABLE] only defines indices 0–9
Output:
JSON{"status": "pass", "warnings": [{"code": "COLOR_INDEX_UNRESOLVED", "detail": "Warp thread references color 12, undefined. Using greyscale fallback.", "severity": "advisory"}]}
- Always run mechanical validation before computing the drawdown — out-of-range shaft/treadle references will corrupt or crash drawdown computation.
- Prefer
[LIFTPLAN]over[TIEUP]+[TREADLING]when both are present; note the dual-encoding rather than silently picking one. - Preserve all original WIF metadata in the packaged PDF, even fields not shown in the visual chart — archival value matters for historical patterns.
- Treat provenance issues as advisory, never blocking — don't prevent a weaver from printing a pattern just because attribution is incomplete.
- Default to color-blind-safe, high-contrast rendering for the structural (black/white) drawdown panel in addition to the archival color preview.
- Don't skip mechanical validation because a file "parses fine" — a WIF file can be syntactically valid INI but mechanically invalid (out-of-range references).
- Don't assume
[TIEUP]/[TREADLING]and[LIFTPLAN]are interchangeable or that a file has both — check which mechanism is actually present before building the pipeline branch. - Don't block the entire pipeline on cosmetic issues like unresolved color indices — fall back gracefully and warn.
- Don't discard provenance metadata during packaging because it isn't shown in the main chart — archive it in PDF properties and an appendix page.
- Don't treat shaft/treadle counts above typical ranges (e.g., >40) as automatically valid — flag as likely data corruption for manual review rather than rendering a nonsensical draft.