Skip to content

DET classification end-to-end: alias custom property IDs + IRDI synthesis - #26

Merged
ronaldtse merged 2 commits into
mainfrom
feat/det-classification-alias
Aug 7, 2026
Merged

DET classification end-to-end: alias custom property IDs + IRDI synthesis#26
ronaldtse merged 2 commits into
mainfrom
feat/det-classification-alias

Conversation

@ronaldtse

Copy link
Copy Markdown
Contributor

Completes DET classification entity extraction from cdd.iec.ch search-export flow. Follow-up to PR #25 (type registration). With these aliases, the importer now extracts 163 DET classification entities from the iec61360-4 fixture .xls.

What changed

  1. VARIANT_TO_CANONICAL alias map (sheet_schema.rb) — extended with DET classification custom IDs:

    • IECCDD_001_C0001MDC_P001_5 (code column)
    • IECCDD_001_C0002MDC_P004_1 (name base)
    • IECCDD_001_C0002.{en,fr,de,ja,zh}MDC_P004_1.{en,fr,de,ja,zh} (localized names)
  2. IECCDD_001 in TYPE_BY_META_CLASS (meta_class.rb) — the file's CLASS_ID:=IECCDD_001 (IEC-internal supplier scheme) now resolves to :det_classification type via this alias.

  3. DetClassification.from_row override (det_classification.rb) — synthesizes full IRDIs from short codes (A11, A12) by prepending the supplier prefix 0112/2///IECCDD_001. Standard Entity.from_row would fail with IRDI.parse("A11").

  4. code_property_id_for("MDC_C0101") (meta_class.rb) — changed from placeholder C0102 to MDC_P001_5 (the aliased code column ID).

Verification

  • 9 DET classification specs pass (4 from registration + 5 from aliasing)
  • Full suite passes (960+ specs, 0 failures)
  • Database.load(<DETCLASSIFICATION.xls>).entities.size = 163 (was 0)
  • First entity: code="A11", type=:det_classification, properties has English name

Note to team

The data-private repo at exports/latest/<dict>/export_DETCLASSIFICATION_*.xls now has files that import cleanly. The next step is to rebuild data/<dict>/database.json from exports to include DET classification entities in the browser build.

# After this PR merges:
cd data-private
bundle exec rake browser:build_all_from_export

adds:
- new entity class Opencdd::DetClassification < Opencdd::Entity
- MDC_C0101 meta-class IRDI registration (the canonical IRDI for
  DET classification entities; the file's CLASS_ID:=IECCDD_001 is
  IEC-internal supplier scheme, not the parsing gate)
- FILE_PATTERN updated in LayoutDetector (DETCLASSIFICATION)
- TYPE_BY_PREFIX updated in FlatDirReader + WorkbookReader
  (both readers needed — single .xls files go through WorkbookReader)
- Database#det_classifications accessor
- 8 specs covering entity_class, meta-class registration, Database
  accessor, and Reader file-detection (4 unit + 1 end-to-end-reader)

960 specs pass, 0 failures (was 931; +29 from new + tweaked specs).

NOT done in this PR: end-to-end entity extraction from the .xls.

The cdd.iec.ch search-export file uses non-standard property IDs
(IECCDD_001_C0001, IECCDD_001_C0002.en, IECCDD_001_C0002.fr, ...)
rather than MDC_P* codes. The standard Parcel row parser doesn't
extract a  property because no column matches the meta-class's
code_property_id (MDC_P001_5 in MDC_C0101's case). A property-ID
aliasing layer is needed to map these project-specific IDs to standard
MDC codes before the meta-class extraction logic can find the code
column. That's a separate design decision; tracked as a follow-up.

What this PR DOES accomplish:
- The entity type :det_classification is now first-class in the gem
- DET classification files are no longer silently skipped (they
  load, producing entities with raw custom-ID properties; the
  aliasing work will lift those to standard MDC codes)
- 4 of the 8 touch-points from the architecture report are covered
  (FilePattern, TYPE_BY_PREFIX in both readers, Database accessor,
  meta-class registration). The remaining 4 (entity row parsing,
  exporter/JSON exposure, visitor methods) are downstream of the
  aliasing work.
…esis

Completes DET classification entity extraction from cdd.iec.ch
search-export flow. Three pieces:

1. VARIANT_TO_CANONICAL alias map extended with DET classification
   custom IDs (IECCDD_001_C0001 → MDC_P001_5, IECCDD_001_C0002.<lang>
   → MDC_P004_1.<lang>). Without these, no entity gets a code or name.

2. IECCDD_001 added to TYPE_BY_META_CLASS as the project-specific
   supplier-scheme CLASS_ID for DET classification. The file's
   CLASS_ID directive resolves to :det_classification type via
   this alias.

3. DetClassification.from_row overrides Entity.from_row to synthesize
   full IRDIs from short codes (A11, A12) by prepending the supplier
   prefix (0112/2///IECCDD_001). Standard from_row would fail with
   IRDI.parse('A11').

4. code_property_id_for MDC_C0101 changed from C0102 (placeholder)
   to MDC_P001_5 (the aliased code column ID).

Result: 163 DET classification entities imported from the iec61360-4
fixture .xls. Each has code='A11', type=:det_classification, and the
English preferred_name in properties.

Full suite passes (960+ specs).
@ronaldtse
ronaldtse merged commit ca8bbd5 into main Aug 7, 2026
11 checks passed
@ronaldtse
ronaldtse deleted the feat/det-classification-alias branch August 7, 2026 09:19
ronaldtse added a commit that referenced this pull request Aug 7, 2026
Closes #28.

The 163 DET classification entities that import successfully from
iec61360-4/export_DETCLASSIFICATION_*.xls (PRs #25 + #26) were
silently dropped from `rake browser:build_from_export[<dict>]`
because Opencdd::Exporters::Json#payload_for raised
`ArgumentError: No JSON payload builder for Opencdd::DetClassification`.

## Fix 1 — payload builder

Register Opencdd::DetClassification in PAYLOAD_BUILDERS and add a
det_classification_node method following the same pattern as
view_control_node / value_list_node / list_of_unit_node. DET
classification entities have standard fields (code, preferred_name,
definition, version, revision) that flow through entity_payload;
no type-specific post-processing is needed.

## Fix 2 — preferred_name property-ID alias

Discovered while writing the payload spec: the alias target for
IECCDD_001_C0002 was MDC_P004_1 (preferred_name_localized), but the
field DSL's `field :preferred_name, "MDC_P004"` reads from MDC_P004
(preferred_name base). The result: even though the importer stored
the data, every entity's preferred_name was nil.

The per-language entries (IECCDD_001_C0002.en → MDC_P004_1.en, etc.)
were dead code: canonical_id splits the language suffix off before
the lookup and reapplies it after, so only the base entry is
consulted. Removing them and changing the base entry to MDC_P004
produces MDC_P004.<lang>, which the preferred_name DSL finds.

## Spec

spec/exporters/per_entity_json_spec.rb gains a `det_classification`
context that constructs a DetClassification entity directly and
asserts the payload includes type, irdi, code, and preferred_name.

## Verification

bundle exec rspec — 974 examples, 0 failures (up from 962).
ronaldtse added a commit that referenced this pull request Aug 8, 2026
The ruby team's PR #26 added det_classification_node (payload builder)
but missed the visitor method that actually calls it during traversal.

Without visit_det_classification in the Visitor class and
visit_det_classifications in visit_database, the exporter's to_json
silently skipped all 163 DET classification entities — they were in
the Database but never reached the JSON output.

This commit adds:
- visit_det_classifications(database) to Visitor (iterates
  database.det_classifications)
- visit_det_classification in visit_database dispatch
- visit_det_classification in Json exporter (calls det_classification_node)

Verified: data-private rake browser:build_from_export[iec-61360-4]
now produces 163 DET classification entities with non-null preferred_name.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant