treat icon indicating copy to clipboard operation
treat copied to clipboard

undefined method `children' for nil:NilClass (NoMethodError)

Open gabro opened this issue 11 years ago • 21 comments

I'm trying to parse a document, but I get this error. Here's my code attempt

require 'treat'
include Treat::Core::DSL

rovio_privacy = document 'http://www.rovio.com/privacy'
rovio_privacy.apply :chunk, :segment, :tokenize, :parse

And here's the stacktrace

/Users/gabro/.rvm/gems/ruby-1.9.3-p448/gems/treat-2.0.7/lib/treat/core/dsl.rb:17:in `method_missing': undefined method `children' for nil:NilClass (NoMethodError)
    from /Users/gabro/.rvm/gems/ruby-1.9.3-p448/gems/treat-2.0.7/lib/treat/workers/processors/parsers/stanford.rb:57:in `recurse'
    from /Users/gabro/.rvm/gems/ruby-1.9.3-p448/gems/treat-2.0.7/lib/treat/workers/processors/parsers/stanford.rb:50:in `parse'
    from /Users/gabro/.rvm/gems/ruby-1.9.3-p448/gems/treat-2.0.7/lib/treat/entities/entity/delegatable.rb:66:in `call_worker'
    from /Users/gabro/.rvm/gems/ruby-1.9.3-p448/gems/treat-2.0.7/lib/treat/entities/entity/delegatable.rb:40:in `block (2 levels) in add_workers'
    from /Users/gabro/.rvm/gems/ruby-1.9.3-p448/gems/treat-2.0.7/lib/treat/entities/entity/applicable.rb:41:in `do_task'
    from /Users/gabro/.rvm/gems/ruby-1.9.3-p448/gems/treat-2.0.7/lib/treat/entities/entity/applicable.rb:49:in `block in do_task'
    from /Users/gabro/.rvm/gems/ruby-1.9.3-p448/gems/treat-2.0.7/lib/treat/entities/entity/applicable.rb:48:in `each'
    from /Users/gabro/.rvm/gems/ruby-1.9.3-p448/gems/treat-2.0.7/lib/treat/entities/entity/applicable.rb:48:in `do_task'
    from /Users/gabro/.rvm/gems/ruby-1.9.3-p448/gems/treat-2.0.7/lib/treat/entities/entity/applicable.rb:49:in `block in do_task'
    from /Users/gabro/.rvm/gems/ruby-1.9.3-p448/gems/treat-2.0.7/lib/treat/entities/entity/applicable.rb:48:in `each'
    from /Users/gabro/.rvm/gems/ruby-1.9.3-p448/gems/treat-2.0.7/lib/treat/entities/entity/applicable.rb:48:in `do_task'
    from /Users/gabro/.rvm/gems/ruby-1.9.3-p448/gems/treat-2.0.7/lib/treat/entities/entity/applicable.rb:49:in `block in do_task'
    from /Users/gabro/.rvm/gems/ruby-1.9.3-p448/gems/treat-2.0.7/lib/treat/entities/entity/applicable.rb:48:in `each'
    from /Users/gabro/.rvm/gems/ruby-1.9.3-p448/gems/treat-2.0.7/lib/treat/entities/entity/applicable.rb:48:in `do_task'
    from /Users/gabro/.rvm/gems/ruby-1.9.3-p448/gems/treat-2.0.7/lib/treat/entities/entity/applicable.rb:22:in `block in apply'
    from /Users/gabro/.rvm/gems/ruby-1.9.3-p448/gems/treat-2.0.7/lib/treat/entities/entity/applicable.rb:6:in `each'
    from /Users/gabro/.rvm/gems/ruby-1.9.3-p448/gems/treat-2.0.7/lib/treat/entities/entity/applicable.rb:6:in `apply'
    from test.rb:10:in `<main>'

I used the automatic installer and manually installed Enju, which is in my PATH.

Any idea on why I'm getting such error?

gabro avatar Oct 01 '13 20:10 gabro

I'm seeing the same thing. Did you find a solution to this?

acrookston avatar Dec 07 '13 08:12 acrookston

I can't reproduce with my p392. Will investigate with the newer version...

louismullie avatar Dec 07 '13 21:12 louismullie

It looks like something with the latest StanfordCoreNLP. I'm not sure at this point but I did try to install your other gem (sfanford-core-nlp) and it took a lot of odd manual configuration to get running.

I'll post a better report when I get to my computer (versions, os etc)

acrookston avatar Dec 08 '13 09:12 acrookston

I just got this with treat (2.0.7) with the automatic installer.

towski avatar Jan 11 '14 07:01 towski

has anyone managed to fix this one?

nettofarah avatar Mar 03 '14 05:03 nettofarah

still not working.

2.1.2 :001 > require 'treat' => true 2.1.2 :002 > require 'stanford-core-nlp' => true 2.1.2 :003 > sent = "This is an English sentence, prove it to me!" => "This is an English sentence, prove it to me!" 2.1.2 :004 > sent.apply(:parse).print_tree NoMethodError: undefined method children' for nil:NilClass from /home/shadowserv/.rvm/gems/ruby-2.1.2/gems/treat-2.1.0/lib/treat/workers/processors/parsers/stanford.rb:57:inrecurse' from /home/shadowserv/.rvm/gems/ruby-2.1.2/gems/treat-2.1.0/lib/treat/workers/processors/parsers/stanford.rb:50:in parse' from /home/shadowserv/.rvm/gems/ruby-2.1.2/gems/treat-2.1.0/lib/treat/entities/entity/delegatable.rb:66:incall_worker' from /home/shadowserv/.rvm/gems/ruby-2.1.2/gems/treat-2.1.0/lib/treat/entities/entity/delegatable.rb:40:in block (2 levels) in add_workers' from /home/shadowserv/.rvm/gems/ruby-2.1.2/gems/treat-2.1.0/lib/treat/entities/entity/applicable.rb:41:indo_task' from /home/shadowserv/.rvm/gems/ruby-2.1.2/gems/treat-2.1.0/lib/treat/entities/entity/applicable.rb:22:in block in apply' from /home/shadowserv/.rvm/gems/ruby-2.1.2/gems/treat-2.1.0/lib/treat/entities/entity/applicable.rb:6:ineach' from /home/shadowserv/.rvm/gems/ruby-2.1.2/gems/treat-2.1.0/lib/treat/entities/entity/applicable.rb:6:in apply' from /home/shadowserv/.rvm/gems/ruby-2.1.2/gems/treat-2.1.0/lib/treat/proxies/proxy.rb:14:inmethod_missing' from (irb):4 from /home/shadowserv/.rvm/rubies/ruby-2.1.2/bin/irb:11:in `

' 2.1.2 :005 > sent.apply(:tag => :stanford) => Sentence (77529910) --- "This is an [...] to me!" --- {:tag_set=>nil, :tag=>"S"} --- []

ls $GEM_HOME/gems/stanford-core-nlp-0.5.1/bin AnnotationBridge.java bridge.jar joda-time.jar jollyday.jar stanford-corenlp.jar stanford-parser.jar stanford-segmenter.jar xom.jar

mikirawr avatar Sep 26 '14 13:09 mikirawr

Are you using the latest version of StanfordCoreNLP files from the Stanford website, or are you downloading from my website (linked in the Manual)?

louismullie avatar Sep 29 '14 20:09 louismullie

Also, can you please test on 1.9.3.xxx and let me know if the bug reproduces there?

louismullie avatar Sep 29 '14 20:09 louismullie

I get the same thing with ruby 1.9.3:

1.9.3-p547 :001 > require 'treat'
 => true
1.9.3-p547 :002 > include Treat::Core::DSL
 => Object
1.9.3-p547 :003 > 'A strong wind would take you away'.apply(:parse).print_tree
NoMethodError: undefined method `children' for nil:NilClass
    from /Users/brian/.rvm/gems/ruby-1.9.3-p547/gems/treat-2.1.0/lib/treat/core/dsl.rb:17:in `method_missing'
    from /Users/brian/.rvm/gems/ruby-1.9.3-p547/gems/treat-2.1.0/lib/treat/workers/processors/parsers/stanford.rb:57:in `recurse'
    from /Users/brian/.rvm/gems/ruby-1.9.3-p547/gems/treat-2.1.0/lib/treat/workers/processors/parsers/stanford.rb:50:in `parse'
    from /Users/brian/.rvm/gems/ruby-1.9.3-p547/gems/treat-2.1.0/lib/treat/entities/entity/delegatable.rb:66:in `call_worker'
    from /Users/brian/.rvm/gems/ruby-1.9.3-p547/gems/treat-2.1.0/lib/treat/entities/entity/delegatable.rb:40:in `block (2 levels) in add_workers'
    from /Users/brian/.rvm/gems/ruby-1.9.3-p547/gems/treat-2.1.0/lib/treat/entities/entity/applicable.rb:41:in `do_task'
    from /Users/brian/.rvm/gems/ruby-1.9.3-p547/gems/treat-2.1.0/lib/treat/entities/entity/applicable.rb:22:in `block in apply'
    from /Users/brian/.rvm/gems/ruby-1.9.3-p547/gems/treat-2.1.0/lib/treat/entities/entity/applicable.rb:6:in `each'
    from /Users/brian/.rvm/gems/ruby-1.9.3-p547/gems/treat-2.1.0/lib/treat/entities/entity/applicable.rb:6:in `apply'
    from /Users/brian/.rvm/gems/ruby-1.9.3-p547/gems/treat-2.1.0/lib/treat/proxies/proxy.rb:14:in `method_missing'
    from (irb):3
    from /Users/brian/.rvm/rubies/ruby-1.9.3-p547/bin/irb:12:in `<main>'

cheerfulstoic avatar Oct 08 '14 12:10 cheerfulstoic

(and 2.1.2, which is what I tried first)

cheerfulstoic avatar Oct 08 '14 12:10 cheerfulstoic

Getting this same error, did anyone find a solution yet?

dstarh avatar Jan 15 '15 18:01 dstarh

I ended up using https://github.com/louismullie/stanford-core-nlp directly

cheerfulstoic avatar Jan 16 '15 05:01 cheerfulstoic

@cheerfulstoic I just downloaded that myself

dstarh avatar Jan 16 '15 14:01 dstarh

Same issue. I can get Stanford Core NLP running on my machine, but unfortunately I can't get Treat to parse on either 1.9.3 or 2.1.4.

Here's what I'm seeing:

2.1.4 :001 > require 'treat'
2.1.4 :002 > sent = "This is an English sentence, prove it to me!"
2.1.4 :003 > sent.apply(:parse).print_tree
NoMethodError: undefined method `children' for nil:NilClass
from ~/.rvm/gems/ruby-2.1.4@nlp/gems/treat-2.1.0/lib/treat/workers/processors/parsers/stanford.rb:57:in `recurse'
~/.rvm/gems/ruby-2.1.4@nlp/gems/treat-2.1.0/lib/treat/workers/processors/parsers/stanford.rb @ line 50 Treat::Workers::Processors::Parsers::Stanford.parse:

Specifically, I think the failure occurs a little further up the chain at Treat::Workers::Processors::Parsers::Stanford#parse on line 48-49 of stanford.rb (above):

48:  text = parser.apply(list)
49:  recurse(text.children[0], entity, tag_set)

Since parser.apply(list) returns an empty Rjb::Rjb_JavaProxy, calling text.children results in an empty array [], and text.children[0] results in a nil that eventually ends up in the #recurse method with undefined method 'children' for nil:NilClass.

I'm unclear whether it's a problem with the list variable or whether it's something that's occurring in either the bind-it or rjb gems that send the data to the parser.

Any ideas why parser.apply(list) would be returning an empty object?

ojak avatar Feb 25 '15 20:02 ojak

Ok, so this is interesting. If I tokenize first, then parsing appears to be working. For example:

FAILS: Calling parse directly on the string.

2.1.4 :001 > 'This is an English sentence, prove it to me!'.parse.print_tree
NoMethodError: undefined method `children' for nil:NilClass
from ~/.rvm/gems/ruby-2.1.4@nlp/gems/treat-2.1.0/lib/treat/workers/processors/parsers/stanford.rb:57:in `recurse'

WORKS: Adding tokenize before the parse method.

2.1.4 :001 > 'This is an English sentence, prove it to me!'.tokenize.parse.print_tree
+ Sentence (70142349342820)  --- "This is an [...] to me!"  ---  {:tag_set=>:penn}   --- []
|
+--+ Phrase (70142349274320)  --- "This"  ---  {:tag=>"NP"}   --- []
...
+--> Punctuation (70142352605260)  --- "!"  ---  {:tag=>"."}   --- [

Not sure why, but that seems to work.

ojak avatar Feb 25 '15 21:02 ojak

@ojak - indeed, as per the manual the parser requires tokenization. However it seems like the OP was appropriately tokenizing the sentences and still running into issues.

louismullie avatar Feb 25 '15 23:02 louismullie

@louismullie - I see, so the OP's problem is different from the others (and mine).

FYI, I was also unable to reproduce the OP's error on ruby 2.1.4, treat 2.1.0, and stanford-core-nlp 0.5.1 with the complete JAR installed under RVM.

ojak avatar Feb 26 '15 00:02 ojak

@gabro @acrookston - Does stanford-core-nlp work for you outside of treat? From IRB, can you run the following without receiving an error (to ensure that the JAR's are working for you):

2.1.4 :001 > require 'stanford-core-nlp'
2.1.4 :002 > pipeline = StanfordCoreNLP.load(:tokenize, :ssplit, :pos, :lemma, :parse, :ner, :dcoref)

ojak avatar Feb 26 '15 00:02 ojak

Seeing this issue too.

maccman avatar Aug 06 '15 21:08 maccman

same here

sent = "Just a test"
sent.apply(:parse).print_tree
NoMethodError: undefined method `children' for nil:NilClass
    from /Users/christinebooher/.rvm/gems/[email protected]/gems/treat-2.1.0/lib/treat/core/dsl.rb:17:in `method_missing'
    from /Users/christinebooher/.rvm/gems/[email protected]/gems/treat-2.1.0/lib/treat/workers/processors/parsers/stanford.rb:57:in `recurse'

tbbooher avatar Oct 10 '15 10:10 tbbooher

I had the same problem, and preforming tokenization before parsing did resolved the problem. That makes sense as a pipeline, but as is the documentation doesn't explain it. On the contrary, it propose the example which was pasted here several time which skip the tokenization.

The code should seamlessly run tokenize if needed and possible when the entity is parsed, so the documentation would be correct. Or an other option would be to let the documentation as is and catch this kind of exception when attempting to parse and throw relevant information about the mandatoriness of tokenizing before parsing.

psychoslave avatar Jul 27 '17 14:07 psychoslave