metanorma / pubid-iec

PubID spec and implementation for IEC deliverables
BSD 2-Clause "Simplified" License
2 stars 0 forks source link

Need typed_name_stage #127

Closed opoudjis closed 6 months ago

opoudjis commented 10 months ago

I am using pubid-iec in metanorma-iec pretty much the same way that I am using pubid-iso in metanorma-iso. ISO and IEC have the same specification for identifiers, and the IEC gem inherits heavily from ISO.

I note that I am missing functionality in pubid-iec that is available in pubid-iso.

I need the following to be working in pubid-iec just as it is in pubid-iso

# for id is_a? Pubid::Iec::Identifier

id.amendments&.first&.stage&.name
id.corrigendums&.first&.stage&.name
id.typed_stage_name
id.typed_stage_abbrev
id.stage.name
config.stages["names"] # as I found on debugging: the YAML of stage definitions STILL does not include names

When in doubt, expose the same things in IEC that you do in ISO.

In addition, the stage abbreviations listing in the config YAML, https://github.com/metanorma/pubid-iec/blob/main/stages.yaml , is insufficient: all of the following type-specific stage abbreviations need to be included, since we allow users to enter them in Metanorma. (The metanorma-iec test of that is ADTR.)

STAGE_CODES = {
        "PNW" => "1000", "ANW" => "2000", "CAN" => "2098", "ACD" => "2099",
        "CD" => "3020", "BWG" => "3092", "A2CD" => "3099", "2CD" => "3520",
        "3CD" => "3520", "4CD" => "3520", "5CD" => "3520", "6CD" => "3520",
        "7CD" => "3520", "8CD" => "3520", "9CD" => "3520", "CDM" => "3591",
        "A3CD" => "3592", "A4CD" => "3592", "A5CD" => "3592", "A6CD" => "3592",
        "A7CD" => "3592", "A8CD" => "3592", "A9CD" => "3592", "ACDV" => "3599",
        "CCDV" => "4020", "CDVM" => "4091", "NCDV" => "4092",
        "NADIS" => "4093", "ADIS" => "4099", "ADTR" => "4099",
        "ADTS" => "4099", "RDISH" => "5000", "RFDIS" => "5000",
        "CDISH" => "5020", "CDPAS" => "5020", "CDTR" => "5020",
        "CDTS" => "5020", "CFDIS" => "5020", "DTRM" => "5092",
        "DTSM" => "5092", "NDTR" => "5092", "NDTS" => "5092",
        "NFDIS" => "5092", "APUB" => "5099", "BPUB" => "6000",
        "PPUB" => "6060", "RR" => "9092", "AMW" => "9220", "WPUB" => "9599",
        "DELPUB" => "9960", "PWI" => "0000", "NWIP" => "1000", "WD" => "2000",
        "CDV" => "4000", "FDIS" => "5000"
      }.freeze

For their definitions, see https://www.iec.ch/standards-development/stage-codes

It turns out you have these stages in lib/pubid/iec/renderer/urn.rb , but they need to be in config so I can query them. And for that matter, that list is more full.

Docstages that are not in your list, such as 50.20, are causing errors in URN generation:

def render_stage(stage, _opts, params)
      ":stage-#{sprintf('%05.2f', stage.to_s(:urn))}"
    end

    def to_s(format = :short)
=>   5|       return "" if empty_abbr?

stage.to_s is returning "" because there is no abbreviation defined. This is presumably your mechanism for working out whether the stage is defined for IEC, but your list of stages is incomplete, and IEC is very explicit that CFDIS = 5020 is a stage that International Standards go through: hhttps://www.iec.ch/system/files/2023-05/StageCodes_IS_v2.pdf

50.20 is in fact legal (it is included in the list above), and is not triggering abort as an unrecognised state (or at least, should not be!)

opoudjis commented 10 months ago

https://github.com/metanorma/metanorma-iec/issues/154 has been stuck for a very long time; please work on this soon.

opoudjis commented 10 months ago

@mico You have not populated names: in stages.yaml, therefore id.typed_stage_name is continuing to crash.

I am typing in the names myself from https://www.iec.ch/standards-development/stage-codes

opoudjis commented 10 months ago

This ticket is NOT YET DONE. The error I highlighted above with 50.20 triggering a floating point error is still there.

@ronaldtse DO NOT CLOSE TICKETS THAT YOU HAVE NO ASSURANCE ARE CLOSED. YOU ARE WASTING MY TIME BY HAVING ME CHECK INTEGRATIONS THAT ARE NOT YET READY.

@mico I am not going to keep telling you what to fix. You can find the PR with the pubid-iec integration at https://github.com/metanorma/metanorma-iec/pull/254 . You make it work.

opoudjis commented 10 months ago

Over and above the functionality required above, I need the ability to map an arbitrary supplied stage abbreviation to its harmonised code; e.g. given ADTR, recover 40.99.

Currently, I'm attempting this at:

def iso_id_stage(node)
        ret = "#{get_stage(node)}.#{get_substage(node)}"
        /[A-Z]/.match?(ret) and
          ret = Pubid::Iec::Identifier.config
            .stages["abbreviations"][get_stage(node)]
        /^\d\d\.\d\d$/.match?(ret) or ret = "10.20" # ret = nil
        ret
      end

But Pubid::Iec::Identifier.config.stages["abbreviations"] does not contain all the typed abbreviations of pubid-iec: ATDR for example is hidden in lib/pubid/iec/identifier/technical_report.rb

So you also need to provide me a function mapping any stage abbreviation to its code. FWIW, I will know the document type at the time of lookup; so I can create e.g. Pubid::Iec::Identifier.create(type: :tr, number: 0) which is_a? Pubid::Iec::Identifier::TechnicalReport.

If you then expose a method like Pubid::Iec::Identifier.stage_abbrev_to_code, which is inherited by Pubid::Iec::Identifier::TechnicalReport, I can recover the value of ADTR, and you do not need to move the stage definitions out of each subclass.

opoudjis commented 10 months ago

stages.yaml needs a subset of the following added:

names:
  ACD: Approved for CD
  ACDV: Approved for CDV
  ADTR: Approved for DTR
  ADTS: Approved for DTS
  APUB: Approved for publication
  BPUB: Being published
  CAN: Draft cancelled
  CD: Draft circulated as CD
  CDM: CD to be discussed at meeting
  CCDV: Draft circulated as CDV
  CDISH: Draft circulated as DISH
  CDVM: Rejected CDV to be discussed at a meeting
  CFDIS: Draft circulated as FDIS
  CDPAS: Draft circulated as DPAS
  CDTR: Draft circulated as DTR
  CDTS: Draft circulated as DTS
  DTRM: Rejected DTR to be discussed at meeting
  DTSM: Rejected DTS to be discussed at meeting
  DECDISH: DISH at editing check
  DECFDIS: FDIS at editing check
  DECPUB: Publication at editing check
  DEL: Deleted/abandoned
  DELPUB: Deleted publication
  MERGED: Merged
  NCDV: CDV rejected
  NDTR: DTR rejected
  NDTS: DTS rejected
  NFDIS: FDIS rejected
  PCC: Preparation of CC
  PNW: New work item proposal
  PPUB: Publication issued
  PRVC: Preparation of RVC
  PRVDISH: Preparation of RVDISH
  PRVD: Preparation of RVD
  PRVDPAS: Preparation of RVDPAS
  PRVDTR: Preparation of RVDTR
  PRVDTS: Preparation of RVDTS
  PRVN: Preparation of RVN
  PWI: Preliminary work item
  RDISH: DISH received and registered
  RFDIS: FDIS received and registered
  RPUB: Publication received and registered
  SPLIT: Split
  TCDV: Translation of CDV
  TDISH: Translation of DISH
  TDTR: Translation of DTR
  TDTS: Translation of DTS
  TPUB: Translation of publication
  WPUB: Publication withdrawn

Many of these are already included in the identifier subclass definitions. So you will need to sort through them.

mico commented 10 months ago

This ticket is NOT YET DONE. The error I highlighted above with 50.20 triggering a floating point error is still there.

@ronaldtse DO NOT CLOSE TICKETS THAT YOU HAVE NO ASSURANCE ARE CLOSED. YOU ARE WASTING MY TIME BY HAVING ME CHECK INTEGRATIONS THAT ARE NOT YET READY.

@mico I am not going to keep telling you what to fix. You can find the PR with the pubid-iec integration at metanorma/metanorma-iec#254 . You make it work.

@opoudjis I was going to make separate tickets from this one. There are too many tasks in one ticket. Don't mix several tasks in one ticket next time, so it will be easier to track progress.

mico commented 10 months ago

id.amendments&.first&.stage&.name id.corrigendums&.first&.stage&.name

@opoudjis Amendments and corrigendum for IEC don't have types stages, so you will always get nil for these cases

ronaldtse commented 10 months ago

There's a lot of commotion here, and would be great if we can minimize them in tickets...

In any case I am wondering what are the typed-stages we are missing? Can we make up a list of what's missing and fill them in?

I think all @opoudjis wants is a mapping from the typed-stage-abbrev to the harmonized code.

opoudjis commented 6 months ago

This is now resolved.