treat icon indicating copy to clipboard operation
treat copied to clipboard

TypeError: no implicit conversion from nil to integer when tokenizing

Open aliw77 opened this issue 10 years ago • 3 comments

Running through a few examples from the manual, cannot get tokenize to work. Here is a paste from irb:

2.0.0p195 :005 > require 'treat'
 => false
2.0.0p195 :006 > include Treat::Core::DSL
 => Object
2.0.0p195 :007 > p = paragraph('A walk in the park. A trip on a boat.').segment
 => Paragraph (70247709531120)  --- "A walk in [...] a boat."  ---  {}   --- []
2.0.0p195 :023 > Treat.core.language.detect = true
 => true
2.0.0p195 :035 > sent = "This is an English sentence, prove it to me!"
 => "This is an English sentence, prove it to me!"
2.0.0p195 :036 > sent.apply(:tokenize, :parse).print_tree
TypeError: no implicit conversion from nil to integer
    from /Users/mac/.rvm/gems/ruby-2.0.0-p195/gems/treat-2.0.7/lib/treat/entities/entity/delegatable.rb:91:in `[]'
    from /Users/mac/.rvm/gems/ruby-2.0.0-p195/gems/treat-2.0.7/lib/treat/entities/entity/delegatable.rb:91:in `find_worker_for_language'
    from /Users/mac/.rvm/gems/ruby-2.0.0-p195/gems/treat-2.0.7/lib/treat/entities/entity/delegatable.rb:83:in `find_worker'
    from /Users/mac/.rvm/gems/ruby-2.0.0-p195/gems/treat-2.0.7/lib/treat/entities/entity/delegatable.rb:55:in `call_worker'
    from /Users/mac/.rvm/gems/ruby-2.0.0-p195/gems/treat-2.0.7/lib/treat/entities/entity/delegatable.rb:40:in `block (2 levels) in add_workers'
    from /Users/mac/.rvm/gems/ruby-2.0.0-p195/gems/treat-2.0.7/lib/treat/entities/entity/applicable.rb:41:in `do_task'
    from /Users/mac/.rvm/gems/ruby-2.0.0-p195/gems/treat-2.0.7/lib/treat/entities/entity/applicable.rb:22:in `block in apply'
    from /Users/mac/.rvm/gems/ruby-2.0.0-p195/gems/treat-2.0.7/lib/treat/entities/entity/applicable.rb:6:in `each'
    from /Users/mac/.rvm/gems/ruby-2.0.0-p195/gems/treat-2.0.7/lib/treat/entities/entity/applicable.rb:6:in `apply'
    from /Users/mac/.rvm/gems/ruby-2.0.0-p195/gems/treat-2.0.7/lib/treat/proxies/proxy.rb:14:in `method_missing'
    from (irb):36
    from /Users/mac/.rvm/rubies/ruby-2.0.0-p195/bin/irb:16:in `<main>'

aliw77 avatar Nov 23 '13 16:11 aliw77

This seems like it's the language detection feature causing the bug. Does the bug disappear if you remove Treat.core.language.detect = true ?

louismullie avatar Nov 26 '13 01:11 louismullie

I actually wanted to use the treat gem for language detection of user text input. Without language detection i get "english" for all sentences. e.g.

2.0.0p195 :009 > puts "El mundo de hoy no tiene sentido".language
english
 => nil

aliw77 avatar Nov 26 '13 22:11 aliw77

Has anyone found a solution to this? On my Mac language recognition doesn't seem to work:

Treat.core.language.detect = true
a = "I want to know God's thoughts; the rest are details. - Albert Einstein"
b = "El mundo de hoy no tiene sentido, así que ¿por qué debería pintar cuadros que lo tuvieran? - Pablo Picasso"
c = "Un bon Allemand ne peut souffrir les Français, mais il boit volontiers les vins de France. - Goethe"
d = "Wir haben die Kunst, damit wir nicht an der Wahrheit zugrunde gehen. - Friedrich Nietzsche"
puts a.language    # => nil
puts b.language    # => nil
puts c.language    # => nil
puts d.language    # => nil

Before that I did a

require 'treat'
Treat::Core::Installer.install
Treat::Core::Installer.install 'german'

Is there something else required for language recognition to work?

nightscape avatar Jan 09 '14 19:01 nightscape