jekyll / classifier-reborn

A general classifier module to allow Bayesian and other types of classifications. A fork of cardmagic/classifier.
https://jekyll.github.io/classifier-reborn/
GNU Lesser General Public License v2.1
552 stars 109 forks source link

TypeError: no implicit conversion from nil to integer in /classifier-reborn-2.2.0/lib/classifier-reborn/lsi.rb:313:in `sort' #184

Open stephenhmarsh opened 5 years ago

stephenhmarsh commented 5 years ago
terms = %w(artist_name artist_years art_title signature_info medium dimensions dimensions art_created_year) 

lsi = ClassifierReborn::LSI.new

array = ["Jean Arp", "1886 - 1966", "FIGURE-GERME DITE \"L'APRÈS-MIDINETTE\"", "Stamped with the raised initials HA and numbered V/V (on the interior)", "Bronze", "Height: 32 in.", "81.3 cm", "Conceived in 1958-59; this example cast by Georges Rudier in 1964."]

array.each_with_index do |text, index|
  lsi.add_item(text, terms[index])
end

throws:

TypeError: no implicit conversion from nil to integer
from /Users/stephen/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/classifier-reborn-2.2.0/lib/classifier-reborn/lsi.rb:313:in `sort'

trace:

wtf?
Exception: TypeError: no implicit conversion from nil to integer
--
0: /Users/stephen/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/classifier-reborn-2.2.0/lib/classifier-reborn/lsi.rb:313:in `sort'
1: /Users/stephen/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/classifier-reborn-2.2.0/lib/classifier-reborn/lsi.rb:313:in `build_reduced_matrix'
2: /Users/stephen/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/classifier-reborn-2.2.0/lib/classifier-reborn/lsi.rb:143:in `build_index'
3: /Users/stephen/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/classifier-reborn-2.2.0/lib/classifier-reborn/lsi.rb:77:in `add_item'
4: (pry):130:in `block in __pry__'
5: (pry):129:in `each'
6: (pry):129:in `each_with_index'
7: (pry):129:in `__pry__'
8: /Users/stephen/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/pry-0.12.2/lib/pry/pry_instance.rb:387:in `eval'
9: /Users/stephen/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/pry-0.12.2/lib/pry/pry_instance.rb:387:in `evaluate_ruby'

object:

lsi
=> #<ClassifierReborn::LSI:0x00007f98966163f0
 @auto_rebuild=true,
 @built_at_version=-1,
 @cache_node_vectors=nil,
 @items=
  {"Jean Arp"=>#<ClassifierReborn::ContentNode:0x00007f98953ad5b0 @categories=["artist_name"], @lsi_norm=nil, @lsi_vector=nil, @raw_norm=Vector[0.7071067811865475, 0.7071067811865475, 0.0, 0.0], @raw_vector=Vector[1.0, 1.0, 0.0, 0.0], @word_hash={:jean=>1, :arp=>1}>,
   "1886 - 1966"=>
    #<ClassifierReborn::ContentNode:0x00007f98953ad290 @categories=["artist_years"], @lsi_norm=nil, @lsi_vector=nil, @raw_norm=Vector[0.0, 0.0, 0.7071067811865475, 0.7071067811865475], @raw_vector=Vector[0.0, 0.0, 1.0, 1.0], @word_hash={:"1886"=>1, :"1966"=>1}>},
 @language="en",
 @version=2,
 @word_list=#<ClassifierReborn::WordList:0x00007f98953ad240 @location_table={:jean=>0, :arp=>1, :"1886"=>2, :"1966"=>3}>>
Ch4s3 commented 5 years ago

@stephenhmarsh This is a bug that has existed since the original implementation that as resisted numerous attempts to fix it. I could be because you input is too short for lsi, but I'm not sure.

otaviogaiao commented 5 years ago

I'm facing this bug too. Any idea on what to do?