Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(URGENT) Crash on processing BSI bibliographic item when it does not have contact information, but only a URI #21

Closed
opoudjis opened this issue Feb 25, 2023 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@opoudjis
Copy link

bundle exec relaton fetch "BSI BS EN ISO 19650-2"

works fine, but when I fetch that document from within Metanorma, I'm getting:

[relaton-bsi] ("BS EN ISO 19650-2") fetching...
[relaton-bsi] ("BS EN ISO 19650-2") found BS EN ISO 19650-2:2018 & Revised NA
Fatal Error: undefined method `to_xml' for {:uri=>"https://www.bsigroup.com/"}:Hash

      contact.each { |contact| contact.to_xml builder }
                                      ^^^^^^^
Did you mean?  to_yaml
bundler: failed to load command: asciidoctor (/Users/nickn/.rbenv/versions/3.1.3/bin/asciidoctor)
/Users/nickn/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/relaton-bib-1.14.5/lib/relaton_bib/contributor.rb:204:in `block in to_xml': undefined method `to_xml' for {:uri=>"https://www.bsigroup.com/"}:Hash (NoMethodError)

      contact.each { |contact| contact.to_xml builder }
                                      ^^^^^^^
Did you mean?  to_yaml
	from /Users/nickn/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/relaton-bib-1.14.5/lib/relaton_bib/contributor.rb:204:in `each'
	from /Users/nickn/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/relaton-bib-1.14.5/lib/relaton_bib/contributor.rb:204:in `to_xml'

@opoudjis opoudjis added the bug Something isn't working label Feb 25, 2023
@ronaldtse ronaldtse changed the title Crash on processing URI-only contacts in BSI (URGENT) Crash on processing URI-only contacts in BSI Feb 25, 2023
@ronaldtse ronaldtse changed the title (URGENT) Crash on processing URI-only contacts in BSI (URGENT) Crash on processing BSI bibliographic item when it does not have contact information, but only a URI Feb 25, 2023
@andrew2net
Copy link
Contributor

andrew2net commented Feb 25, 2023

@opoudjis it means the contributor's contact is an array of Hashes, instead of RelatonBib::Addresses or RelatonBib::Contacts.

    # @param url [String, nil]
    # @param contact [Array<RelatonBib::Address, RelatonBib::Contact>]
    def initialize(url: nil, contact: [])
      @uri = URI url if url
      @contact = contact
    end

We need to fidn where the contributor is created and fix it.

@andrew2net
Copy link
Contributor

@opoudjis I don't have this error with relaton-iso v1.15.0, relaton-iso-bib v1.14.0, and relaton-bib v1.14.5

$ relaton fetch 'BSI BS EN ISO 19650-2'
[relaton-bsi] ("BSI BS EN ISO 19650-2") fetching...
[relaton-bsi] ("BSI BS EN ISO 19650-2") found BS EN ISO 19650-2:2018 & Revised NA
<bibdata type="standard" schema-version="v1.2.1">
  <fetched>2023-03-08</fetched>
  ...

@opoudjis
Copy link
Author

opoudjis commented Mar 9, 2023

@andrew2net Reread the first line of the ticket:

bundle exec relaton fetch "BSI BS EN ISO 19650-2"
works fine, but when I fetch that document from within Metanorma, I'm getting:

You have not addressed my request.

Specifically I am doing the following, and I require you to debug it so that it does not crash, which it is now doing:

# item = Relaton-Fetch("BSI BS EN ISO 19650-2")
ret = RelatonBib::XMLParser.from_xml(item)
old = ret.to_hash.symbolize_all_keys # converts all hash keys from strings to symbols
out = RelatonBib::HashConverter.hash_to_bib(@old)
RelatonBib::BibliographicItem.new(**out).to_xml

I am needing to do this, because I am substituting elements of the bibitem with replacement elements.

The contact encoding discrepancy is in RelatonBib::HashConverter :

old: result of ret.to_hash

 :contributor=>
  [{:organization=>
     {:name=>[{:content=>"British Standards Institution"}], :abbreviation=>{:content=>"BSI"}, :contact=>[{:uri=>"https://www.bsigroup.com/"}]},
    :role=>[{:type=>"publisher"}]}],
 :copyright=>
  [{:owner=>
     [{:name=>[{:content=>"British Standards Institution"}],
       :abbreviation=>{:content=>"BSI"},
       :contact=>[{:uri=>"https://www.bsigroup.com/"}]}],
    :from=>"2021"}],

out: result of RelatonBib::HashConverter.hash_to_bib

 :contributor=>
  [{:role=>[{:type=>"publisher", :description=>[]}],
    :entity=>
     {:name=>[{:content=>"British Standards Institution"}],
      :abbreviation=>{:content=>"BSI"},
      :contact=>[#<RelatonBib::Contact:0x00000001152ceaa0 @type="uri", @value="https://www.bsigroup.com/">],
      :identifier=>[],
      :subdivision=>[]}}],


 :copyright=>
  [{:owner=>
     [{:name=>[{:content=>"British Standards Institution"}],
       :abbreviation=>{:content=>"BSI"},
       :contact=>[{:uri=>"https://www.bsigroup.com/"}]}],
    :from=>"2021"}],

When I do .to_xml on the result, contributor converts fine, because its contact is a RelatonBib::Contact object. But the copyright element crashes, because its contact is a raw hash, not a RelatonBib::Contact object.

So RelatonBib::HashConverter.hash_to_bib needs to treat copyright.owner.contact the same way it treats contributor.entity.contact, encoding the contact element as an instance of RelatonBib::Contact.

https://github.com/relaton/relaton-bib/blob/main/lib/relaton_bib/hash_converter.rb:

def copyright_hash_to_bib(ret)
        return unless ret[:copyright]

        ret[:copyright] = RelatonBib.array(ret[:copyright]).map do |c|
          c[:owner] = RelatonBib.array(c[:owner])
          c
        end
      end

You need to add something like:

c[:owner].each do |x|
  x[:contact] = contacts_hash_to_bib(x)
end

andrew2net added a commit to relaton/relaton-bib that referenced this issue Mar 9, 2023
@andrew2net
Copy link
Contributor

@opoudjis fixed in the relaton-bib v 1.14.6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants