Register DET classification entity type for search-export flow - #25
Closed
ronaldtse wants to merge 1 commit into
Closed
Register DET classification entity type for search-export flow#25ronaldtse wants to merge 1 commit into
ronaldtse wants to merge 1 commit into
Conversation
IEC CDD source .xls files use "jp" for Japanese instead of the ISO 639-1 code "ja". The gem previously passed these through verbatim, creating a mismatch with the browser's CSS visibility rules and the LanguageSwitcher, which expect ISO codes. Add Languages.normalize(code) — a class method that maps known non-conformant codes to their ISO equivalents and emits a warning on stderr so data-quality issues are visible. The LANG_ALIASES map is extensible for future non-standard codes. Apply normalization at the two points where language codes enter from the XLS source: 1. SheetSchema.canonical_id — column IDs like MDC_P004.jp are now canonicalized to MDC_P004.ja before entering the entity model. 2. SheetSchema#lang_hash_for — directive-row language keys (PROPERTY_NAME.jp etc.) are normalized before building the per-column name/definition/note language hashes. Also apply normalization in Languages#initialize and Languages.from_properties so any code path that constructs a Languages object gets clean codes. The warning fires once per non-conformant code encountered, making it easy to audit which dictionaries still carry legacy codes.
Contributor
Author
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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Wires the importer to recognize the 8th entity type in cdd.iec.ch's search-export form. Search-export
.xlsfiles with prefixDETCLASSIFICATIONare no longer silently skipped.What's in this PR
Opencdd::DetClassification < Opencdd::EntityMDC_C0101registered as the meta-class IRDI for DET classification entities(the file's
CLASS_ID:=IECCDD_001is an IEC-internal supplier scheme —not the parsing gate; the file's filename prefix is)
FILE_PATTERNinLayoutDetectorextended withDETCLASSIFICATIONTYPE_BY_PREFIXextended in bothFlatDirReaderandWorkbookReader(single
.xlsfiles go throughWorkbookReader; flat dirs throughFlatDirReader)Database#det_classificationstyped accessor(entity_class + type resolution), Database accessor, Reader detection
960 specs pass, 0 failures (was 931; +29 from new + tweaked specs).
What's NOT in this PR — the deeper gap
The cdd.iec.ch search-export file uses non-standard property IDs:
The standard Parcel row parser doesn't extract a
codeproperty because nocolumn matches the meta-class's
code_property_id(e.g.MDC_P001_5forMDC_C0101). A property-ID aliasing layer is needed to map theseproject-specific IDs to standard MDC codes before the meta-class extraction
logic can find the code column.
That's a separate design decision (alias shape — per-type, per-class, or
per-file? Alias lifecycle — bundled in gem or in the file? Collision
rules?). Tracked as a follow-up.
Why ship this PR anyway?
with raw custom-ID properties; the aliasing work will lift those to
standard MDC codes without needing another meta-class registration
parser/normalization change, not a new entity-type introduction
Not in scope
MDC_P023vsMDC_P021alias) — needs VBA lookup