louismullie / treat

Natural language processing framework for Ruby.
Other
1.36k stars 128 forks source link

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

Open gabro opened 10 years ago

gabro commented 10 years ago

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 commented 10 years ago

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

louismullie commented 10 years ago

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

acrookston commented 10 years ago

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 commented 10 years ago

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

nettofarah commented 10 years ago

has anyone managed to fix this one?

mikirawr commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

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

cheerfulstoic commented 9 years ago

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 commented 9 years ago

(and 2.1.2, which is what I tried first)

dstarh commented 9 years ago

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

cheerfulstoic commented 9 years ago

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

dstarh commented 9 years ago

@cheerfulstoic I just downloaded that myself

ojak commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

@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 commented 9 years ago

@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 commented 9 years ago

@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 commented 9 years ago

Seeing this issue too.

tbbooher commented 8 years ago

same here

sent = "Just a test"
sent.apply(:parse).print_tree
NoMethodError: undefined method `children' for nil:NilClass
    from /Users/christinebooher/.rvm/gems/ruby-2.2.2@improvement.rocks/gems/treat-2.1.0/lib/treat/core/dsl.rb:17:in `method_missing'
    from /Users/christinebooher/.rvm/gems/ruby-2.2.2@improvement.rocks/gems/treat-2.1.0/lib/treat/workers/processors/parsers/stanford.rb:57:in `recurse'
psychoslave commented 7 years ago

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.