programr icon indicating copy to clipboard operation
programr copied to clipboard

Problem with some tags

Open dreamingechoes opened this issue 10 years ago • 9 comments

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?

dreamingechoes avatar Feb 13 '14 09:02 dreamingechoes

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!

robertjwhitney avatar Feb 13 '14 16:02 robertjwhitney

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!

dreamingechoes avatar Feb 13 '14 16:02 dreamingechoes

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

robertjwhitney avatar Feb 13 '14 19:02 robertjwhitney

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

robertjwhitney avatar Aug 26 '14 18:08 robertjwhitney

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

drusepth avatar Jan 09 '16 16:01 drusepth

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

boykoc avatar Jan 18 '17 14:01 boykoc

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

decampj4 avatar Nov 27 '17 20:11 decampj4

@decampj4 no problem, published it just now

robertjwhitney avatar Nov 28 '17 00:11 robertjwhitney

@robertjwhitney thank you very much!

decampj4 avatar Nov 28 '17 01:11 decampj4