relaton / relaton-iso

RelatonIso: ISO Standards metadata using the BibliographicItem model
BSD 2-Clause "Simplified" License
2 stars 1 forks source link

Extend hash to biblio mappers through the rest of the relaton stack #55

Closed andrew2net closed 5 years ago

andrew2net commented 5 years ago

This is part of the Relaton YAML refactor. https://github.com/metanorma/relaton-bib/issues/7

@opoudjis In ISO we have main, intro, and part pieces of title. The pieces come from scrapper as hash { title_intro: "Intro", title_main: "Main", title_part: "Part" }. The question is: How are titles stored in YAML? Are they stored as strings? I.e. Geographic information -- Metadata -- Part 2: Extensions for acquisition and processing. So we have to split them into pieces in the mapping process. Or are they stored as a hash of pieces?

opoudjis commented 5 years ago

Crap.

The user friendly approach is to store them as a single string. The clean approach is to store them as a hash, and the YAML encoding is meant to be close to what is being populated in Relaton.

I suggest we allow both, through special processing in the hash_to_bib method. If it is passed a string for the title, it breaks it up. If it is pass the hash, it passes through the hash.

So the parent method is:

    def title_hash_to_bib(ret)
      return unless ret[:title]
      ret[:title] = array(ret[:title])
      ret[:title] = ret[:title].map do |t|
        t.is_a?(Hash) ? t : { content: t, language: "en", script: "Latn",
                              format: "text/plain", type: "main" }
      end
    end

In ISO, we should allow a hash like:

title: {
  language: en
  title_intro: "Intro"
  title_main: "Main"
  title_part: "Part"
}

as well as:

title: {
  language: en
  content: "Intro -- Main -- Part 2: Part"
}

And specialise the method to:

    def title_hash_to_bib(ret)
      return unless ret[:title]
      ret[:title] = array(ret[:title])
      ret[:title] = ret[:title].map do |t|
        titleparts = {}
        titleparts = split_title(t) unless t_is_a?(Hash)
        titleparts = split_title(t[:content]) if t[:content]
        t.is_a?(Hash) ? t.merge(titleparts) : 
              { language: "en", script: "Latn", format: "text/plain", type: "main" }.merge(titleparts)
      end
    end

Where split_title splits a single string title up into {title_intro: x, title-main: y, title_part: z}.