From 96f449a620406b6d704d053a73205a6bd668f8dd Mon Sep 17 00:00:00 2001 From: Andrei Kislichenko Date: Thu, 12 Dec 2024 12:12:14 -0500 Subject: [PATCH] update exten, localyty, & move flavor attr to ext in YAML --- lib/relaton_bib/bib_item_locality.rb | 7 +- lib/relaton_bib/bibliographic_item.rb | 37 ++--- lib/relaton_bib/bibtex_parser.rb | 7 +- lib/relaton_bib/document_relation.rb | 21 +-- .../document_relation_collection.rb | 8 +- lib/relaton_bib/extent.rb | 39 ++++++ lib/relaton_bib/hash_converter.rb | 132 +++++++++++------- lib/relaton_bib/version.rb | 2 +- lib/relaton_bib/xml_parser.rb | 18 +-- relaton-bib.gemspec | 2 +- spec/examples/asciibib.adoc | 3 +- spec/examples/bib_item.xml | 36 ++--- spec/examples/bib_item.yml | 100 ++++++------- spec/examples/bibdata_item.xml | 36 ++--- spec/examples/bibdata_item_fr.xml | 36 ++--- spec/examples/from_bibtex.xml | 22 +-- spec/examples/hash.yml | 97 ++++++------- spec/relaton_bib/bibliographic_item_spec.rb | 2 +- spec/relaton_bib/hash_converter_spec.rb | 28 ++-- spec/relaton_bib/xml_parser_spec.rb | 2 +- 20 files changed, 362 insertions(+), 273 deletions(-) create mode 100644 lib/relaton_bib/extent.rb diff --git a/lib/relaton_bib/bib_item_locality.rb b/lib/relaton_bib/bib_item_locality.rb index 99cee99..4ec9db0 100644 --- a/lib/relaton_bib/bib_item_locality.rb +++ b/lib/relaton_bib/bib_item_locality.rb @@ -119,7 +119,12 @@ def to_xml(builder) # @returnt [Hash] def to_hash - { "locality_stack" => single_element_array(locality) } + hash = Hash.new { |h, k| h[k] = [] } + locality.each_with_object(hash) do |l, obj| + k, v = l.to_hash.first + obj[k] << v + end + { "locality_stack" => hash } end # diff --git a/lib/relaton_bib/bibliographic_item.rb b/lib/relaton_bib/bibliographic_item.rb index d44c8ae..0f0943d 100644 --- a/lib/relaton_bib/bibliographic_item.rb +++ b/lib/relaton_bib/bibliographic_item.rb @@ -17,6 +17,7 @@ require "relaton_bib/validity" require "relaton_bib/document_relation" require "relaton_bib/bib_item_locality" +require_relative "extent" require "relaton_bib/xml_parser" require "relaton_bib/bibtex_parser" require "relaton_bib/biblio_note" @@ -105,7 +106,7 @@ class BibliographicItem # @return [Array] attr_reader :place - # @return [Array] + # @return [Array] attr_reader :extent # @return [Array] @@ -154,7 +155,7 @@ class BibliographicItem # @param series [Array] # @param medium [RelatonBib::Medium, nil] # @param place [Array] - # @param extent [Array] + # @param extent [Array] # @param accesslocation [Array] # @param classification [Array] # @param validity [RelatonBib:Validity, nil] @@ -417,7 +418,7 @@ def to_hash(embedded: false) # rubocop:disable Metrics/AbcSize, Metrics/Cyclomat hash["series"] = single_element_array(series) if series&.any? hash["medium"] = medium.to_hash if medium hash["place"] = single_element_array(place) if place&.any? - hash["extent"] = single_element_array(extent) if extent&.any? + hash["extent"] = extent.map(&:to_hash) if extent&.any? hash["size"] = size.to_hash if size&.any? if accesslocation&.any? hash["accesslocation"] = single_element_array(accesslocation) @@ -429,16 +430,15 @@ def to_hash(embedded: false) # rubocop:disable Metrics/AbcSize, Metrics/Cyclomat hash["fetched"] = fetched.to_s if fetched hash["keyword"] = single_element_array(keyword) if keyword&.any? hash["license"] = single_element_array(license) if license&.any? - hash["doctype"] = doctype.to_hash if doctype - hash["subdoctype"] = subdoctype if subdoctype - if editorialgroup&.presence? - hash["editorialgroup"] = editorialgroup.to_hash + if has_ext? + hash["ext"] = {} + hash["ext"]["schema-version"] = ext_schema if !embedded && respond_to?(:ext_schema) && ext_schema + hash["ext"]["doctype"] = doctype.to_hash if doctype + hash["ext"]["subdoctype"] = subdoctype if subdoctype + hash["ext"]["editorialgroup"] = editorialgroup.to_hash if editorialgroup&.presence? + hash["ext"]["ics"] = single_element_array ics if ics.any? + hash["ext"]["structuredidentifier"] = structuredidentifier.to_hash if structuredidentifier&.presence? end - hash["ics"] = single_element_array ics if ics.any? - if structuredidentifier&.presence? - hash["structuredidentifier"] = structuredidentifier.to_hash - end - hash["ext"] = { "schema-version" => ext_schema } if !embedded && respond_to?(:ext_schema) && ext_schema hash end @@ -572,7 +572,7 @@ def to_asciibib(prefix = "") # rubocop:disable Metrics/AbcSize, Metrics/Cyclomat link.each { |l| out += l.to_asciibib prefix, link.size } out += medium.to_asciibib prefix if medium place.each { |pl| out += pl.to_asciibib prefix, place.size } - extent.each { |ex| out += ex.to_asciibib "#{pref}extent", extent.size } + extent.each { |ex| out += ex.to_asciibib prefix, extent.size } out += size.to_asciibib pref if size accesslocation.each { |al| out += "#{pref}accesslocation:: #{al}\n" } classification.each do |cl| @@ -634,7 +634,7 @@ def render_xml(**opts) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength,Me series.each { |s| s.to_xml builder } medium&.to_xml builder place.each { |pl| pl.to_xml builder } - extent.each { |e| builder.extent { e.to_xml builder } } + extent.each { |e| e.to_xml builder } size&.to_xml builder accesslocation.each { |al| builder.accesslocation al } license.each { |l| builder.license l } @@ -644,10 +644,9 @@ def render_xml(**opts) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength,Me kwrd.each { |kw| builder.keyword { kw.to_xml(builder) } } validity&.to_xml builder if block_given? then yield builder - elsif opts[:bibdata] && (doctype || editorialgroup || ics&.any? || - structuredidentifier&.presence?) + elsif opts[:bibdata] && has_ext? ext = builder.ext do |b| - doctype.to_xml b if doctype + doctype&.to_xml b b.subdoctype subdoctype if subdoctype editorialgroup&.to_xml b ics.each { |i| i.to_xml b } @@ -661,5 +660,9 @@ def render_xml(**opts) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength,Me xml["schema-version"] = schema unless opts[:embedded] xml end + + def has_ext? # rubocop:disable Metrics/CyclomaticComplexity + doctype || subdoctype || editorialgroup || ics&.any? || structuredidentifier&.presence? + end end end diff --git a/lib/relaton_bib/bibtex_parser.rb b/lib/relaton_bib/bibtex_parser.rb index fd67a74..6159265 100644 --- a/lib/relaton_bib/bibtex_parser.rb +++ b/lib/relaton_bib/bibtex_parser.rb @@ -169,9 +169,9 @@ def fetch_relation(bibtex) end # @param bibtex [BibTeX::Entry] - # @return [Array] + # @return [Array] def fetch_extent(bibtex) # rubocop:disable Metrics/MethodLength,Metrics/AbcSize - bibtex.select do |k, _v| + locs = bibtex.select do |k, _v| %i[chapter pages volume].include? k end.reduce([]) do |mem, loc| if loc[0] == :pages @@ -182,8 +182,9 @@ def fetch_extent(bibtex) # rubocop:disable Metrics/MethodLength,Metrics/AbcSize from = loc[1].to_s to = nil end - mem << BibItemLocality.new(type, from, to) + mem << Locality.new(type, from, to) end + [RelatonBib::Extent.new(locs)] end # @param bibtex [BibTeX::Entry] diff --git a/lib/relaton_bib/document_relation.rb b/lib/relaton_bib/document_relation.rb index 0b98fb2..b27c197 100644 --- a/lib/relaton_bib/document_relation.rb +++ b/lib/relaton_bib/document_relation.rb @@ -39,24 +39,22 @@ class DocumentRelation # @param description [RelatonBib::FormattedString, nil] # @param bibitem [RelatonBib::BibliographicItem, # RelatonIso::IsoBibliographicItem] - # @param locality [Array] + # @param locality [Array] + # @param locality_stack [Array] # @param source_locality [Array] - def initialize(type:, bibitem:, description: nil, locality: [], - source_locality: []) + def initialize(type:, bibitem:, **args) type = "obsoletes" if type == "Now withdrawn" unless self.class::TYPES.include? type Util.warn "Invalid relation type: `#{type}`" end @type = type - @description = description - @locality = locality - @source_locality = source_locality + @description = args[:description] + @locality = args[:locality] || args[:locality_stack] || [] + @source_locality = args[:source_locality] || args[:source_locality_stack] || [] @bibitem = bibitem end - # rubocop:disable Metrics/AbcSize - # @param builder [Nokogiri::XML::Builder] def to_xml(builder, **opts) opts.delete :bibdata @@ -68,13 +66,16 @@ def to_xml(builder, **opts) source_locality.each { |l| l.to_xml builder } end end - # rubocop:enable Metrics/AbcSize # @return [Hash] def to_hash # rubocop:disable Metrics/AbcSize hash = { "type" => type, "bibitem" => bibitem.to_hash(embedded: true) } hash["description"] = description.to_hash if description - hash["locality"] = single_element_array(locality) if locality&.any? + locality.each_with_object(hash) do |l, obj| + k, v = l.to_hash.first + hash[k] ||= [] + hash[k] << v + end if source_locality&.any? hash["source_locality"] = single_element_array(source_locality) end diff --git a/lib/relaton_bib/document_relation_collection.rb b/lib/relaton_bib/document_relation_collection.rb index f45914f..aab6d07 100644 --- a/lib/relaton_bib/document_relation_collection.rb +++ b/lib/relaton_bib/document_relation_collection.rb @@ -12,11 +12,9 @@ class DocRelationCollection # @option relation [String] :type # @option relation [String] :identifier # @option relation [String, NIllClass] :url (nil) - # @option relation [Array] :locality - # @option relation [Array] :source_locality - # @option relation [RelatonBib::BibliographicItem, NillClass] :bibitem (nil) + # @option relation [Array] :locality + # @option relation [Array] :source_locality + # @option relation [RelatonBib::BibliographicItem, nil] :bibitem (nil) def initialize(relation) @array = relation.map { |r| r.is_a?(Hash) ? DocumentRelation.new(**r) : r } end diff --git a/lib/relaton_bib/extent.rb b/lib/relaton_bib/extent.rb new file mode 100644 index 0000000..7061b8a --- /dev/null +++ b/lib/relaton_bib/extent.rb @@ -0,0 +1,39 @@ +module RelatonBib + class Extent + attr_accessor :locality + + # + # @param [Array] locality + # + def initialize(locality) + @locality = locality + end + + def to_xml(builder) + builder.extent do |b| + locality.each { |l| l.to_xml(b) } + end + end + + def to_hash + hash = Hash.new { |h, k| h[k] = [] } + locality.each_with_object(hash) do |l, obj| + k, v = l.to_hash.first + obj[k] << v + end + end + + def to_asciibib(prefix = "", count = 1) + pref = prefix.empty? ? "extent" : "#{prefix}.extent" + out = count > 1 ? "#{pref}::\n" : "" + locality.each do |l| + out += l.to_asciibib(pref, locality.size) + end + out + end + + def to_bibtex(item) + locality.map { |l| l.to_bibtex(item) }.join + end + end +end diff --git a/lib/relaton_bib/hash_converter.rb b/lib/relaton_bib/hash_converter.rb index 381e268..81ce265 100644 --- a/lib/relaton_bib/hash_converter.rb +++ b/lib/relaton_bib/hash_converter.rb @@ -1,11 +1,9 @@ module RelatonBib module HashConverter extend self - # rubocop:disable Metrics/MethodLength, Metrics/AbcSize - # @param args [Hash] # @return [Hash] - def hash_to_bib(args) + def hash_to_bib(args) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength return nil unless args.is_a?(Hash) ret = Marshal.load(Marshal.dump(symbolize(args))) # deep copy @@ -34,13 +32,21 @@ def hash_to_bib(args) keyword_hash_to_bib(ret) # ret[:keyword] = RelatonBib.array(ret[:keyword]) ret[:license] = RelatonBib.array(ret[:license]) + # editorialgroup_hash_to_bib ret + # ics_hash_to_bib ret + # structuredidentifier_hash_to_bib ret + # doctype_hash_to_bib ret + ext_has_to_bib ret + ret + end + + def ext_has_to_bib(ret) + doctype_hash_to_bib ret + ret[:subdoctype] = ret[:ext][:subdoctype] if ret.dig(:ext, :subdoctype) editorialgroup_hash_to_bib ret ics_hash_to_bib ret structuredidentifier_hash_to_bib ret - doctype_hash_to_bib ret - ret end - # rubocop:enable Metrics/MethodLength, Metrics/AbcSize def keyword_hash_to_bib(ret) ret[:keyword] = RelatonBib.array(ret[:keyword]).map do |keyword| @@ -52,18 +58,19 @@ def extent_hash_to_bib(ret) return unless ret[:extent] ret[:extent] = RelatonBib.array(ret[:extent]).map do |e| - locality e - # ret[:extent][i] = Locality.new(e[:type], e[:reference_from], - # e[:reference_to]) + RelatonBib::Extent.new locality(e) end end def locality(loc) if loc[:locality_stack] - LocalityStack.new(loc[:locality_stack].map { |l| locality(l) }) + RelatonBib.array(loc[:locality_stack]).map do |l| + LocalityStack.new locality(l) + end else - l = loc[:locality] - Locality.new(l[:type], l[:reference_from], l[:reference_to]) + RelatonBib.array(loc[:locality]).map do |l| + Locality.new(l[:type], l[:reference_from], l[:reference_to]) + end end end @@ -339,17 +346,17 @@ def copyright_hash_to_bib(ret) end # @param ret [Hash] - def relations_hash_to_bib(ret) + def relations_hash_to_bib(ret) # rubocop:disable Metrics/MethodLength,Metrics/AbcSize return unless ret[:relation] ret[:relation] = RelatonBib.array(ret[:relation]) - ret[:relation]&.each do |r| - if r[:description] - r[:description] = FormattedString.new(**r[:description]) - end - relation_bibitem_hash_to_bib(r) - relation_locality_hash_to_bib(r) - relation_source_locality_hash_to_bib(r) + ret[:relation]&.each do |rel| + rel[:description] = FormattedString.new(**rel[:description]) if rel[:description] + relation_bibitem_hash_to_bib(rel) + relation_locality_hash_to_bib(rel) + relation_locality_stack_hash_to_bib(rel) + relation_source_locality_hash_to_bib(rel) + relaton_source_locality_stack_hash_to_bib(rel) end end @@ -372,36 +379,54 @@ def bib_item(item_hash) # @param rel [Hash] relation # @return [RelatonBib::LocalityStack] def relation_locality_hash_to_bib(rel) - rel[:locality] = RelatonBib.array(rel[:locality])&.map do |bl| - LocalityStack.new locality_locality_stack(bl) + return unless rel[:locality]&.any? + + rel[:locality] = RelatonBib.array(rel[:locality]).map do |bl| + Locality.new(bl[:type], bl[:reference_from], bl[:reference_to]) end end - def locality_locality_stack(lls) - if lls[:locality_stack] - RelatonBib.array(lls[:locality_stack]).map do |lc| - l = lc[:locality] || lc - Locality.new(l[:type], l[:reference_from], l[:reference_to]) - end - else - [Locality.new(lls[:type], lls[:reference_from], lls[:reference_to])] + def relation_locality_stack_hash_to_bib(rel) + return unless rel[:locality_stack]&.any? + + rel[:locality_stack] = RelatonBib.array(rel[:locality_stack]).map do |ls| + LocalityStack.new relation_locality_hash_to_bib(ls) end end + # def locality_locality_stack(lls) + # if lls[:locality_stack] + # RelatonBib.array(lls[:locality_stack]).map do |lc| + # l = lc[:locality] || lc + # Locality.new(l[:type], l[:reference_from], l[:reference_to]) + # end + # else + # [Locality.new(lls[:type], lls[:reference_from], lls[:reference_to])] + # end + # end + # @param rel [Hash] relation def relation_source_locality_hash_to_bib(rel) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength - rel[:source_locality] = RelatonBib.array(rel[:source_locality])&.map do |sl| - sls = if sl[:source_locality_stack] - RelatonBib.array(sl[:source_locality_stack]).map do |l| - SourceLocality.new(l[:type], l[:reference_from], - l[:reference_to]) - end - else - l = SourceLocality.new(sl[:type], sl[:reference_from], - sl[:reference_to]) - [l] - end - SourceLocalityStack.new sls + return unless rel[:source_locality]&.any? + + rel[:source_locality] = RelatonBib.array(rel[:source_locality])&.map do |loc| + # sls = if sl[:source_locality_stack] + # RelatonBib.array(sl[:source_locality_stack]).map do |l| + # SourceLocality.new(l[:type], l[:reference_from], l[:reference_to]) + # end + # else + # l = SourceLocality.new(sl[:type], sl[:reference_from], sl[:reference_to]) + # [l] + # end + SourceLocality.new loc[:type], loc[:reference_from], loc[:reference_to] + end + end + + def relaton_source_locality_stack_hash_to_bib(rel) + return unless rel[:source_locality_stack]&.any? + + rel[:source_locality_stack] = RelatonBib.array(rel[:source_locality_stack]).map do |loc| + SourceLocalityStack.new relation_source_locality_hash_to_bib(loc) end end @@ -465,9 +490,10 @@ def parse_validity_time(val, period) # @param ret [Hash] def editorialgroup_hash_to_bib(ret) - return unless ret[:editorialgroup] + eg = ret.dig(:ext, :editorialgroup) || ret[:editorialgroup] # @todo remove ret[:editorialgroup] in the future + return unless eg - technical_committee = RelatonBib.array(ret[:editorialgroup]).map do |wg| + technical_committee = RelatonBib.array(eg).map do |wg| TechnicalCommittee.new WorkGroup.new(**wg) end ret[:editorialgroup] = EditorialGroup.new technical_committee @@ -475,16 +501,18 @@ def editorialgroup_hash_to_bib(ret) # @param ret [Hash] def ics_hash_to_bib(ret) - return unless ret[:ics] + ics = ret.dig(:ext, :ics) || ret[:ics] # @todo remove ret[:ics] in the future + return unless ics - ret[:ics] = RelatonBib.array(ret[:ics]).map { |ics| ICS.new(**ics) } + ret[:ics] = RelatonBib.array(ics).map { |item| ICS.new(**item) } end # @param ret [Hash] def structuredidentifier_hash_to_bib(ret) - return unless ret[:structuredidentifier] + struct_id = ret.dig(:ext, :structuredidentifier) || ret[:structuredidentifier] # @todo remove ret[:structuredidentifier] in the future + return unless struct_id - sids = RelatonBib.array(ret[:structuredidentifier]).map do |si| + sids = RelatonBib.array(struct_id).map do |si| si[:agency] = RelatonBib.array si[:agency] StructuredIdentifier.new(**si) end @@ -527,12 +555,10 @@ def formattedref(frf) end def doctype_hash_to_bib(ret) - return unless ret[:doctype] + doctype = ret.dig(:ext, :doctype) || ret[:doctype] # @todo remove ret[:doctype] in the future + return unless doctype - ret[:doctype] = if ret[:doctype].is_a?(String) - create_doctype(type: ret[:doctype]) - else create_doctype(**ret[:doctype]) - end + ret[:doctype] = doctype.is_a?(String) ? create_doctype(type: doctype) : create_doctype(**doctype) end def create_doctype(**args) diff --git a/lib/relaton_bib/version.rb b/lib/relaton_bib/version.rb index d30ce0d..30651cd 100644 --- a/lib/relaton_bib/version.rb +++ b/lib/relaton_bib/version.rb @@ -1,3 +1,3 @@ module RelatonBib - VERSION = "1.19.6".freeze + VERSION = "1.20.0".freeze end diff --git a/lib/relaton_bib/xml_parser.rb b/lib/relaton_bib/xml_parser.rb index 49177f1..68b41bb 100644 --- a/lib/relaton_bib/xml_parser.rb +++ b/lib/relaton_bib/xml_parser.rb @@ -219,11 +219,11 @@ def fetch_medium(item) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/Ab # # @param [Nokogiri::XML::Element] item item element # - # @return [Array] extent + # @return [Array] extent # def fetch_extent(item) - item.xpath("./extent").reduce([]) do |a, ex| - a + localities(ex) + item.xpath("./extent").map do |ex| + RelatonBib::Extent.new localities(ex) end end @@ -644,13 +644,13 @@ def locality(loc, klass = Locality) # @return [Array] def source_localities(rel) - rel.xpath("./sourceLocality|./sourceLocalityStack").map do |lc| - if lc[:type] - SourceLocalityStack.new [locality(lc, SourceLocality)] + rel.xpath("./sourceLocality|./sourceLocalityStack").map do |loc| + if loc.name == "sourceLocality" + # src_locs = loc.xapth("./sourceLocality").map { |sl| locality(sl, SourceLocality) } + # SourceLocalityStack.new src_locs + locality loc, SourceLocality else - sls = lc.xpath("./sourceLocality").map do |l| - locality l, SourceLocality - end + sls = loc.xpath("./sourceLocality").map { |l| locality l, SourceLocality } SourceLocalityStack.new sls end end diff --git a/relaton-bib.gemspec b/relaton-bib.gemspec index 91ed1f6..7f10a33 100644 --- a/relaton-bib.gemspec +++ b/relaton-bib.gemspec @@ -27,6 +27,6 @@ Gem::Specification.new do |spec| spec.add_dependency "bibtex-ruby" spec.add_dependency "htmlentities" spec.add_dependency "iso639" - spec.add_dependency "nokogiri", "~> 1.16" + spec.add_dependency "nokogiri", "~> 1.16.0" spec.add_dependency "relaton-logger", "~> 0.2.0" end diff --git a/spec/examples/asciibib.adoc b/spec/examples/asciibib.adoc index cf15274..260d857 100644 --- a/spec/examples/asciibib.adoc +++ b/spec/examples/asciibib.adoc @@ -120,6 +120,7 @@ place.region.name:: Region place.country.name:: Switzelznd place.country.iso:: CH place.country.recommended:: true +extent:: extent.locality:: extent.locality.type:: section extent.locality.reference_from:: Reference from @@ -127,7 +128,7 @@ extent.locality.reference_to:: Reference to extent.locality:: extent.locality.type:: chapter extent.locality.reference_from:: 4 -extent.locality_stack:: +extent:: extent.locality_stack.locality:: extent.locality_stack.locality.type:: page extent.locality_stack.locality.reference_from:: 10 diff --git a/spec/examples/bib_item.xml b/spec/examples/bib_item.xml index 5522449..ac55493 100644 --- a/spec/examples/bib_item.xml +++ b/spec/examples/bib_item.xml @@ -1,5 +1,5 @@ - 2024-01-10 + 2024-12-11 Geographic information Geographic information Information géographique @@ -172,19 +172,9 @@ ISO 19115:2003 - - - Reference from - - - - - 1 - - - 2 - - + + Reference from + 2 @@ -199,6 +189,20 @@ ISO 19115:2003/Cor 1:2006 + + + 1 + + + + + 2 + + + + Reference from + Reference to + @@ -254,8 +258,6 @@ Reference from Reference to - - 4 @@ -288,4 +290,4 @@ 2011-02-03 18:30 2011-03-04 09:00 - + \ No newline at end of file diff --git a/spec/examples/bib_item.yml b/spec/examples/bib_item.yml index 11e0b2c..3489c89 100644 --- a/spec/examples/bib_item.yml +++ b/spec/examples/bib_item.yml @@ -8,10 +8,6 @@ title: script: Latn type: standard -doctype: - type: Doctype - abbreviation: DCT -subdoctype: Subdoctype docid: - id: ISO TC 211 @@ -242,16 +238,10 @@ relation: bibitem: formattedref: ISO 19115:2003 locality: - - locality_stack: - type: section - reference_from: Reference from - - locality_stack: - - type: chapter - reference_from: "1" - - type: page - reference_from: "2" - source_locality: - source_locality_stack: + - type: section + reference_from: Reference from + source_locality_stack: + - source_locality: - type: volume reference_from: "2" - type: chapter @@ -263,6 +253,17 @@ relation: bibitem: type: standard formattedref: ISO 19115:2003/Cor 1:2006 + locality_stack: + - locality: + - type: chapter + reference_from: "1" + - locality: + - type: page + reference_from: "2" + source_locality: + - type: section + reference_from: Reference from + reference_to: Reference to - type: partOf bibitem: title: @@ -327,19 +328,17 @@ place: extent: - locality: - type: section + - type: section reference_from: Reference from reference_to: Reference to - - locality: - type: chapter + - type: chapter reference_from: "4" - locality_stack: - locality: - type: page + - type: page reference_from: "10" reference_to: "20" - - locality: - type: volume + - type: volume reference_from: "1" size: @@ -371,30 +370,37 @@ validity: ends: "2011-02-03 18:30" revision: "2011-03-04 09:00" -editorialgroup: - - name: Editorial group - number: 1 - type: Type - identifier: Identifier - prefix: Prefix - -ics: - - code: "01" - text: First - -structuredidentifier: - - type: type 1 - agency: - - agency 1 - - agency 2 - class: class 1 - docnumber: "123" - partnumber: "4" - edition: "1" - version: "2" - supplementtype: type 2 - supplementnumber: "5" - language: en - year: "2020" - - agency: agency 3 - docnumber: "456" +ext: + doctype: + type: Doctype + abbreviation: DCT + + subdoctype: Subdoctype + + editorialgroup: + - name: Editorial group + number: 1 + type: Type + identifier: Identifier + prefix: Prefix + + ics: + - code: "01" + text: First + + structuredidentifier: + - type: type 1 + agency: + - agency 1 + - agency 2 + class: class 1 + docnumber: "123" + partnumber: "4" + edition: "1" + version: "2" + supplementtype: type 2 + supplementnumber: "5" + language: en + year: "2020" + - agency: agency 3 + docnumber: "456" diff --git a/spec/examples/bibdata_item.xml b/spec/examples/bibdata_item.xml index d260074..0dcb33b 100644 --- a/spec/examples/bibdata_item.xml +++ b/spec/examples/bibdata_item.xml @@ -1,5 +1,5 @@ - 2024-01-10 + 2024-12-11 Geographic information Geographic information Information géographique @@ -172,19 +172,9 @@ ISO 19115:2003 - - - Reference from - - - - - 1 - - - 2 - - + + Reference from + 2 @@ -199,6 +189,20 @@ ISO 19115:2003/Cor 1:2006 + + + 1 + + + + + 2 + + + + Reference from + Reference to + @@ -254,8 +258,6 @@ Reference from Reference to - - 4 @@ -316,4 +318,4 @@ 456 - + \ No newline at end of file diff --git a/spec/examples/bibdata_item_fr.xml b/spec/examples/bibdata_item_fr.xml index 4146f5b..5d5ca0d 100644 --- a/spec/examples/bibdata_item_fr.xml +++ b/spec/examples/bibdata_item_fr.xml @@ -1,5 +1,5 @@ - 2024-01-10 + 2024-12-11 Information géographique https://www.iso.org/standard/53798.html https://www.iso.org/obp/ui/#!iso:std:53798:en @@ -167,19 +167,9 @@ ISO 19115:2003 - - - Reference from - - - - - 1 - - - 2 - - + + Reference from + 2 @@ -194,6 +184,20 @@ ISO 19115:2003/Cor 1:2006 + + + 1 + + + + + 2 + + + + Reference from + Reference to + @@ -249,8 +253,6 @@ Reference from Reference to - - 4 @@ -311,4 +313,4 @@ 456 - + \ No newline at end of file diff --git a/spec/examples/from_bibtex.xml b/spec/examples/from_bibtex.xml index a5edd2a..70cbd0e 100644 --- a/spec/examples/from_bibtex.xml +++ b/spec/examples/from_bibtex.xml @@ -91,18 +91,20 @@ Series Some address - - 4 - - - 10 - 20 - - - 1 + + + 4 + + + 10 + 20 + + + 1 + Type Mendeley tags Keyword Key Word - + \ No newline at end of file diff --git a/spec/examples/hash.yml b/spec/examples/hash.yml index c291a96..0bcc035 100644 --- a/spec/examples/hash.yml +++ b/spec/examples/hash.yml @@ -66,9 +66,9 @@ contributor: - content: division logo: image: - id: logo1 src: logo1.png mimetype: image/png + id: logo1 filename: logo1.png width: '200' height: 100% @@ -272,17 +272,8 @@ relation: content: ISO 19115:2003 format: text/plain locality: - - locality_stack: - - locality: - type: section - reference_from: Reference from - - locality_stack: - - locality: - type: chapter - reference_from: '1' - - locality: - type: page - reference_from: '2' + - type: section + reference_from: Reference from source_locality: - source_locality_stack: - type: volume @@ -298,6 +289,17 @@ relation: description: content: supersedes format: text/plain + locality_stack: + - locality: + - type: chapter + reference_from: '1' + - locality: + - type: page + reference_from: '2' + source_locality: + - type: section + reference_from: Reference from + reference_to: Reference to - type: partOf bibitem: title: @@ -376,19 +378,17 @@ place: recommended: true extent: - locality: - type: section + - type: section reference_from: Reference from reference_to: Reference to -- locality: - type: chapter + - type: chapter reference_from: '4' - locality_stack: - locality: - type: page + - type: page reference_from: '10' reference_to: '20' - - locality: - type: volume + - type: volume reference_from: '1' size: - :type: page @@ -415,33 +415,34 @@ keyword: - content: Key Word license: - License -doctype: - type: Doctype - abbreviation: DCT -subdoctype: Subdoctype -editorialgroup: -- name: Editorial group - number: 1 - type: Type - identifier: Identifier - prefix: Prefix -ics: -- code: '01' - text: First -structuredidentifier: -- docnumber: '123' - type: type 1 - agency: - - agency 1 - - agency 2 - class: class 1 - partnumber: '4' - edition: '1' - version: '2' - supplementtype: type 2 - supplementnumber: '5' - language: en - year: '2020' -- docnumber: '456' - agency: - - agency 3 +ext: + doctype: + type: Doctype + abbreviation: DCT + subdoctype: Subdoctype + editorialgroup: + - name: Editorial group + number: 1 + type: Type + identifier: Identifier + prefix: Prefix + ics: + - code: '01' + text: First + structuredidentifier: + - docnumber: '123' + type: type 1 + agency: + - agency 1 + - agency 2 + class: class 1 + partnumber: '4' + edition: '1' + version: '2' + supplementtype: type 2 + supplementnumber: '5' + language: en + year: '2020' + - docnumber: '456' + agency: + - agency 3 diff --git a/spec/relaton_bib/bibliographic_item_spec.rb b/spec/relaton_bib/bibliographic_item_spec.rb index b9c7f78..6449bc0 100644 --- a/spec/relaton_bib/bibliographic_item_spec.rb +++ b/spec/relaton_bib/bibliographic_item_spec.rb @@ -180,7 +180,7 @@ expect(subject).to receive(:respond_to?).with(:ext_schema).and_return(true).twice expect(subject).to receive(:ext_schema).and_return("v1.0.0").twice hash = subject.to_hash - expect(hash["ext"]).to eq "schema-version" => "v1.0.0" + expect(hash["ext"]["schema-version"]).to eq "v1.0.0" end end diff --git a/spec/relaton_bib/hash_converter_spec.rb b/spec/relaton_bib/hash_converter_spec.rb index 4477dc1..dd67e32 100644 --- a/spec/relaton_bib/hash_converter_spec.rb +++ b/spec/relaton_bib/hash_converter_spec.rb @@ -21,19 +21,19 @@ expect(ls).to be_instance_of RelatonBib::LocalizedString end - it "make localityStack from unwrapped loclaity" do - hash = { locality: [{ type: "section", reference_from: "1" }] } - RelatonBib::HashConverter.relation_locality_hash_to_bib hash - expect(hash[:locality].first).to be_instance_of RelatonBib::LocalityStack - end + # it "make localityStack from unwrapped loclaity" do + # hash = { locality: [{ type: "section", reference_from: "1" }] } + # RelatonBib::HashConverter.relation_locality_hash_to_bib hash + # expect(hash[:locality].first).to be_instance_of RelatonBib::LocalityStack + # end - it "make sourceLocalityStack from unwrapped sourceLoclaity" do - hash = { source_locality: [{ type: "section", reference_from: "1" }] } - RelatonBib::HashConverter.relation_source_locality_hash_to_bib hash - expect(hash[:source_locality].first).to be_instance_of( - RelatonBib::SourceLocalityStack, - ) - end + # it "make sourceLocalityStack from unwrapped sourceLoclaity" do + # hash = { source_locality: [{ type: "section", reference_from: "1" }] } + # RelatonBib::HashConverter.relation_source_locality_hash_to_bib hash + # expect(hash[:source_locality].first).to be_instance_of( + # RelatonBib::SourceLocalityStack, + # ) + # end it "parse validity time" do r = RelatonBib::HashConverter.parse_validity_time({ begins: 1999 }, :begins) @@ -118,7 +118,7 @@ context "create doctype" do it "from string" do - ret = { doctype: "Doctype" } + ret = { ext: { doctype: "Doctype" } } described_class.doctype_hash_to_bib ret expect(ret[:doctype]).to be_instance_of RelatonBib::DocumentType expect(ret[:doctype].type).to eq "Doctype" @@ -126,7 +126,7 @@ end it "from hash" do - ret = { doctype: { type: "Doctype", abbreviation: "DCT" } } + ret = { ext: { doctype: { type: "Doctype", abbreviation: "DCT" } } } described_class.doctype_hash_to_bib ret expect(ret[:doctype]).to be_instance_of RelatonBib::DocumentType expect(ret[:doctype].type).to eq "Doctype" diff --git a/spec/relaton_bib/xml_parser_spec.rb b/spec/relaton_bib/xml_parser_spec.rb index 81495b5..9e96e46 100644 --- a/spec/relaton_bib/xml_parser_spec.rb +++ b/spec/relaton_bib/xml_parser_spec.rb @@ -58,7 +58,7 @@ XML item = RelatonBib::XMLParser.from_xml xml expect(item.relation.first.source_locality.first).to be_instance_of( - RelatonBib::SourceLocalityStack, + RelatonBib::SourceLocality, ) end