robertjwhitney / programr

Ruby interpreter for the AIML as an updated rubygem
http://aiml-programr.rubyforge.org/
MIT License
36 stars 21 forks source link

Problem with some tags #1

Open dreamingechoes opened 10 years ago

dreamingechoes commented 10 years ago

Hello,

I discovered this gem a few days ago, and I use it for a project but I'm having trouble because some tags (like "srai" and "sr") do not work properly, simply do not return any response. Am I the only one with this error?

robertjwhitney commented 10 years ago

Hi,

I also discovered some tags were presenting problems during my tests. For instance, I had to create a subset of the ALICE AML ( located here: https://github.com/robertjwhitney/alice-programr ).

I didn't end up with enough time to patch it, but I'm happy to assist if you track it down or accept a patch if you want to submit a pull request.

Thanks!

dreamingechoes commented 10 years ago

Hello,

I have been analyzing the source code of the gem, and I think I know what happens (at least with Srai tag). In the "AIML Parser", in the three blocks concerning the tag, the first initialize an object (currentSrai = Srai.new), and add to "openLabels" that object. But in the second block, create a new one, and the text is added to the new object, which is not the one in "openLabels" so that reference is lost. I just commented the line of code where you create a new object Srai, and has worked for me. I dont know if this happens with more tags, as I focused on the tag Srai.

Piece of code (lib/programr/aiml_parser.rb, lines 185 et seq):

srai

@parser.listen(%w{ srai }){|uri,localname,qname,attributes|
  currentSrai = Srai.new
  openLabels[-1].add(currentSrai)
  openLabels.push(currentSrai)
}

@parser.listen(:characters, %w{ srai }){|text|
  # currentSrai = Srai.new  <========= ¡¡¡¡ Problem here !!!!
  currentSrai.add(text)
}

@parser.listen(:end_element, %w{ srai }){
  currentSrai = nil
  openLabels.pop
}

end srai

I hope you find it helpful.

Greetings!

robertjwhitney commented 10 years ago

@dreamingechoes great. I didn't really write the library just ported it over to a gem.

robertjwhitney commented 10 years ago

hey @dreamingechoes I will accept a pull-request if you think you have a fix.

drusepth commented 8 years ago

I submitted a PR for srai.

Looks like there's still an off-by-one error in random to hunt down (AFAICT it never selects the last li).

boykoc commented 7 years ago

Both of these issues are addressed in the following PRs: #7 #5. See these for updated code.

decampj4 commented 6 years ago

@robertjwhitney - when you get a chance, could you publish a release with these patches please?

robertjwhitney commented 6 years ago

@decampj4 no problem, published it just now

decampj4 commented 6 years ago

@robertjwhitney thank you very much!