inukshuk / citeproc-ruby

A Citation Style Language (CSL) Cite Processor
101 stars 22 forks source link

deep_fetch error with articles #20

Closed ghost closed 10 years ago

ghost commented 10 years ago

I have updated to citeproc-ruby 1.0.0 and run into a problem rendering articles in IEEE style, whereas other kinds of bibtex entry, such as 'inproceedings' or 'book', render correctly in both APA and IEEE styles.

The error message is:

NoMethodError: undefined method `deep_fetch' for nil:NilClass
    from /home/peter/.rvm/gems/ruby-2.0.0-p247/gems/citeproc-1.0.0/lib/citeproc/abbreviate.rb:27:in `abbreviate'

This problem was not present in citeproc-ruby 0.0.6.

e.g. for the following biblio.bib

@article{Chase73,
  author = {W. G. Chase and H. A. Simon},
  title = {Perception in chess},
  journal = {Cognitive Psychology},
  volume = {4},
  pages = {55-81},
  year = {1973}
}

@book{Newell72,
    author = {A. Newell and H. A. Simon},
    title = {Human Problem Solving},
    address = {Englewood Cliffs, NJ},
  publisher = {Prentice-Hall},
    year = {1972}
}  

I get the following results in irb:

Everything works fine for apa style:

2.0.0p247 :037 > cp = CiteProc::Processor.new style: 'apa', format: 'text'
 => #<CiteProc::Processor style="apa" locale="en-US" items=[0]> 
2.0.0p247 :038 > cp.import BibTeX.open('/home/peter/biblio.bib').to_citeproc
 => #<CiteProc::Processor style="apa" locale="en-US" items=[2]> 
2.0.0p247 :039 > cp.render :bibliography, id: 'Newell72'
 => ["Newell, A., & Simon, H. A. (1972). Human Problem Solving. Englewood Cliffs, NJ: Prentice-Hall."] 
2.0.0p247 :040 > cp.render :bibliography, id: 'Chase73'
 => ["Chase, W. G., & Simon, H. A. (1973). Perception in chess. Cognitive Psychology, 4, 55–81."] 

But articles fail to render for ieee style:

2.0.0p247 :041 > cp2 = CiteProc::Processor.new style: 'ieee', format: 'text'
 => #<CiteProc::Processor style="ieee" locale="en-US" items=[0]> 
2.0.0p247 :042 > cp2.import BibTeX.open('/home/peter/biblio.bib').to_citeproc
 => #<CiteProc::Processor style="ieee" locale="en-US" items=[2]> 
2.0.0p247 :043 > cp2.render :bibliography, id: 'Newell72'
 => ["A. Newell and H. A. Simon, Human Problem Solving. Englewood Cliffs, NJ: Prentice-Hall, 1972."] 
2.0.0p247 :044 > cp2.render :bibliography, id: 'Chase73'
NoMethodError: undefined method `deep_fetch' for nil:NilClass
    from /home/peter/.rvm/gems/ruby-2.0.0-p247/gems/citeproc-1.0.0/lib/citeproc/abbreviate.rb:27:in `abbreviate'
inukshuk commented 10 years ago

That's a good one, thanks for reporting!

I think you can workaround the problem by calling cp2.abbreviations once before rendering as this would create the default abbreviations hash. In the 1.0.0 release there must have been a stray delegator or method alias, because calling the method on the processor engine as opposed to the processor (which is what the renderer does) returned nil.

This is also fixed in the 1.0.1 release. So if you do gem i citeproc citeproc-ruby (you need to update both) it should work out of the box.

ghost commented 10 years ago

Thanks, release 1.0.1 seems to have solved the problem.