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

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

Open
gabro opened this issue Oct 1, 2013 · 21 comments
Open

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

gabro opened this issue Oct 1, 2013 · 21 comments

Comments

@gabro
Copy link

gabro commented Oct 1, 2013

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?

@acrookston
Copy link

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

@louismullie
Copy link
Owner

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

@acrookston
Copy link

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)

@towski
Copy link

towski commented Jan 11, 2014

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

@nettofarah
Copy link

has anyone managed to fix this one?

@mikirawr
Copy link

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

@louismullie
Copy link
Owner

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
Copy link
Owner

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

@cheerfulstoic
Copy link

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
Copy link

(and 2.1.2, which is what I tried first)

@dstarh
Copy link

dstarh commented Jan 15, 2015

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

@cheerfulstoic
Copy link

@dstarh
Copy link

dstarh commented Jan 16, 2015

@cheerfulstoic I just downloaded that myself

@ojak
Copy link
Contributor

ojak commented Feb 25, 2015

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
Copy link
Contributor

ojak commented Feb 25, 2015

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.

@louismullie
Copy link
Owner

@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.

@ojak
Copy link
Contributor

ojak commented Feb 26, 2015

@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
Copy link
Contributor

ojak commented Feb 26, 2015

@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)

@maccman
Copy link

maccman commented Aug 6, 2015

Seeing this issue too.

@tbbooher
Copy link

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'

@psychoslave
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests