Automatic question generator libs in Ruby Language

is there any Automatic question generator libraries in Ruby Language ?

class QuestionGenerator
def self.generate
“Huh?”
end
end

On Thu, Feb 24, 2011 at 6:04 PM, Sniper A. <

Sniper,

Could you be a little more specific?
What is a “question generator”?
Perhaps we could help you.

Best regards,
Abinoam Jr.

On Sat, Feb 26, 2011 at 6:55 PM, Sniper A.
[email protected] wrote:

suppose if i have a paragraph (arround 250 words)

i want to get all the possible question from that paragraph

?! all possible questions ?

“Why are there some many 3-character words in this language?”
“Was this bozo drunk when he wrote this?”
“Why doesn’t the outside part of an ‘e’ go all the way around?”
“This is really – wait, where did I put my car keys?”

def all_possible_questions
?
end

i don’t know were hit the sauce,bozo you type the letter with an e
awersome cookie

suppose if i have a paragraph (arround 250 words)

i want to get all the possible question from that paragraph

Thanks

On Tue, 1 Mar 2011 19:31:36 +0900, Shadowfirebird wrote:

    ans << sn if sn ~= /\? $/
end

return ans

end

(That won’t cope with brackets.) Said the Vicar: “Or quotes.” But
it’s a starting point – assuming that that was what you meant.

Presumably someone smarter than me could do better with a single
regex.

def questions(para)
para.scan(/([^!.]+??|.+?[!.])\w*/m).flatten.select { |m| m[-1] == ??
}.map &:strip
end

ruby-1.9.2-p136 :063 > str
=> “This is a sentence? Yes. And this too? Definitely!\n”
ruby-1.9.2-p136 :064 > questions(str)
=> [“This is a sentence?”, “And this too?”]

On Tue, Mar 1, 2011 at 10:55 AM, Peter Z.
[email protected]wrote:

This could be a long rabbit hole.

questions(“What does ‘?’ mean?”) #=> [“What does '?”, “’ mean?”]

On Tue, 1 Mar 2011 20:02:13 +0900, Adam P. wrote:

This could be a long rabbit hole.

Well, you’ve started this. Now I shall show you what a rabbit hole is
:wink:

#encoding:utf-8

requires 1.9

QUESTION_REGEXP = Regexp.compile(<<‘END’.strip, Regexp::EXTENDED |
Regexp::MULTILINE)
(?\g[!?.]?\s*){0}(?\g[!?.]\s*){0}(?[^!.?’]+?){0}
(?(?["’])\g\k<pq+0>\g|«\g»\g|\g\g|){0}
\g
END

def questions(para)
questions = []
while para =~ QUESTION_REGEXP
para = $’
questions << $& if $&.strip[-1] == ??
end
questions
end

TEXT = <<‘END’
Nested ‘questions?’ are supported.
This is a text. A question?
This «kind?» is supported too, really?
The quotes «“shall 'be” matching?’»?
END

p questions(TEXT)


WBR, Peter Z…

P.S. You definitely should run the code on a real ruby. It is
somehow… curious.

i want to get all the possible question from that paragraph

Do you mean that you want to extract all the sentences that end in a
question mark?

Untested (so don’t laugh, all you Ruby grownups):

def questions(para)
ans = []
para.split(/[.?!] /).each do |sn|
ans << sn if sn ~= /? $/
end

return ans

end

(That won’t cope with brackets.) Said the Vicar: “Or quotes.” But
it’s a starting point – assuming that that was what you meant.

Presumably someone smarter than me could do better with a single regex.

On Tue, Mar 1, 2011 at 12:28 PM, Peter Z.
[email protected]wrote:

Hm!

opine = “You think ’ is an excellent grapheme?” # arguably this is a
valid
fully-formed question…

questions(opine) # endless loop!

On Tue, 1 Mar 2011 22:15:45 +0900, Adam P. wrote:

is :wink:
questions(opine) # endless loop!
A debug modification has accidentally slipped through. The regexp
should have been defined this way:

QUESTION_REGEXP = Regexp.compile(<<‘END’.strip, Regexp::EXTENDED |
Regexp::MULTILINE)
(?\g[!?.]?\s*){0}(?\g[!?.]\s*){0}(?[^!.?]+?){0}
(?(?["’])\g\k<pq+0>\g|«\g»\g|\g\g|){0}
\g
END

(look at the last [] in first line: it has ’ removed).

I am aware of this problem. (I hadn’t written about it because of
several reasons: I don’t know what exactly causes it, and I wanted to
see if someone would trigger it — congratulations. Given the time this
regexp executes even on a simple strings, the code is already not
suited
for production, and this small misinformation would not hurt the OP.)

I’ve triggered it several times while trying different forms of the
regexp, and sometimes it occurs when using one of seemingly equivalent
constructs, but does not occur with other one. A quick look at some
backtraces taken at random times during the execution suggests that it
really loops (and not just executes for a lot of time), but oniguruma
is
really huge and complex, and I don’t have enough time to debug this.

Also, as I am not a regular expression guru, it may contain blatant
errors. (I’ve seen once a book on optimizing regexps. It was scary.)
I’ve tried to use my experience with LALR parsers here, but sometimes
oniguruma behaves in a completely different way. E.g. at the some point
I’ve tried to replace an empty token at the end of (?…) group
with a plain \g, which of course includes empty string, it would
not compile due to indefinite recursion. It works perfectly with
current variant. The (?…) token always was a terminal, of
course.

The ideal way of accomplishing this task would be using a lexer and a
parser; it is easy enough to write them manually in this case (as
opposed to using a tool like RACC). Thus, one would create a finite
state machine, which is what regular expression compiler does, too, but
the former will be optimized properly.

I’ll leave this as a homework to someone else :slight_smile:


WBR, Peter Z…

P.S. Given that Oniguruma RE can compile a full LALR parser, I wonder
how a regular expression matching a regular expression look like. And
the amount of time and memory it will use.

opine = “You think ’ is an excellent grapheme?” # arguably this is a valid
fully-formed question…

questions(opine) # endless loop!

So is: “What is the capital of Tunisia!”

Unless you can get Ruby to understand English, the parsing will always
be imperfect.

On Tue, Mar 1, 2011 at 8:59 AM, Shadowfirebird
[email protected]wrote:


Majorities, of course, start with minorities.
– Robert Moses

But that’s not a question! It’s an exuberant and wrong statement about a
fictitious city named “What”! (cue Abbott and Costello)

On Tue, Mar 1, 2011 at 1:59 PM, Shadowfirebird
[email protected]wrote:

opine = “You think ’ is an excellent grapheme?” # arguably this is a
valid
fully-formed question…

So is: “What is the capital of Tunisia!”

Unless you can get Ruby to understand English, the parsing will always be
imperfect.

Sure. Although my opine-variable question is more syntactic, I think, in
question-ness than the semantic-focused Tunisia one. But yes, I agree;
it’s
really just about coverage of needs.

But that’s not a question! It’s an exuberant and wrong statement about a
fictitious city named “What”! (cue Abbott and Costello)

Imagine a very angry teacher. And remember that you can’t end a
sentence with ‘?!’.

On Tue, Mar 1, 2011 at 5:03 PM, Shadowfirebird
[email protected] wrote:

But that’s not a question! It’s an exuberant and wrong statement about a
fictitious city named “What”! (cue Abbott and Costello)

Imagine a very angry teacher. And remember that you can’t end a sentence with
‘?!’.

Even an angry teacher will state a question (a rising inflection on
the last word/syllable of a sentence).

Punctuation reflects these changes in inflection/speech patterns (like
periods signaling long breaks, as are common to end a sentence, comma
signaling shorter pauses within a sentence which usually imply
additional information about the preceding topic, and so on).

TL;DR: Parsing a natural language is hard.


Phillip G.

Though the folk I have met,
(Ah, how soon!) they forget
When I’ve moved on to some other place,
There may be one or two,
When I’ve played and passed through,
Who’ll remember my song or my face.

On Wed, 2 Mar 2011 01:22:11 +0900, Phillip G. wrote:

the last word/syllable of a sentence).

Punctuation reflects these changes in inflection/speech patterns
(like
periods signaling long breaks, as are common to end a sentence, comma
signaling shorter pauses within a sentence which usually imply
additional information about the preceding topic, and so on).

TL;DR: Parsing a natural language is hard.

Indeed, this is the second derivative of original question.

Indeed, this is the second derivative of original question.

ROFL – indeed. We don’t really know what the OP actually wants as
yet. And if it’s difficult for people to parse a question…!

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs