Author |
Message |
Ares
Joined: 28 Mar 2007 Posts: 24
|
Posted: Sun Apr 15, 2007 8:39 am Post subject: Allowing wildcards in TC answers |
|
|
is this supported yet? the wildcards would be entered on the admin side
so, instead of:
Quote: | What is the best country in the world?
usa
u.s.a.
united states of america |
you could do something like
Quote: | What is the best country in the world?
u*s*a
united*states*america |
where the *'s are wildcards that can be anything (.'s, in this case). |
|
|
admin Site Admin
Joined: 18 Apr 2006 Posts: 805 Location: Saint-Petersburg, Russia
|
Posted: Wed Apr 18, 2007 4:02 am Post subject: |
|
|
Thanks for suggestion, but I'm afraid I don't like implementing it. Wilcards complicate the code, but I want to keep it as simple as possible. _________________ Oleg Parashchenko, bbAntiSpam
Do you love our tools? Please sponsor further development! |
|
|
Ares
Joined: 28 Mar 2007 Posts: 24
|
Posted: Sun Apr 22, 2007 12:28 pm Post subject: |
|
|
in tc_hook_register(), in functions_tc.php:
Original
Code: |
//
// Check if the answer is correct
//
$as = preg_split("/\n/", $answers, -1, PREG_SPLIT_NO_EMPTY);
foreach ($as as $a) {
$a = trim($a);
if (strtolower($a) == strtolower($answer)) {
return;
}
}
tc_bad_answer();
|
New, supports wildcards
Code: |
//
// Check if the answer is correct
//
$as = preg_split("/\n/", $answers, -1, PREG_SPLIT_NO_EMPTY);
foreach ($as as $a) {
$regexp=$a;
// add code to filter out chars used by regexp?
// such as "()\/+?"
// well, most *normal* admins are never going to use those types of chars
// in their answers anyway...but str_replace's/etc are easily added ;)
$re2=explode("*",$regexp);
$regexp=""; $i=0;
foreach ($re2 as $re1) {
if ($i>0) $regexp.=".*?";
$regexp.="(".trim($re1).")";
$i++;
}
if (preg_match ("/".$regexp."/is", $answer))
return;
}
tc_bad_answer();
|
all the ~6 extra lines do is build a simple regular expression (the regexp equivalent of * is .*?, lol), then test to see if the user's answer matches that regexp provided by the admin (which can just be a plain old string, as well)
most intelligent admins aren't going to have regexp-style chars as part of their answers anyway, but it would still be good to filter them anyhow.
i'm currently testing it out on my site...ideally, it turns an answer sheet from this
Quote: | <b>Who is Captain Kirk's Vulcan companion?</b>
spock
mr spock
mr. spock
mister spock
<b>Enter the name of one nation that qualifies as a superpower</b>
usa
u.s.a.
america
united states
united states of america
<b>Finish the sentence:</b><ul>Captain Jean-Luc __________</ul>
picard
piccard
<b>Name one Star Wars droid</b>
r2d2
r2-d2
r2 d2
artoo deetoo
artoo-deetoo
C-3p0
c3p0
threepio |
to this
Quote: |
<b>Who is Captain Kirk's Vulcan companion?</b>
*spock
<b>Enter the name of one nation that qualifies as a superpower</b>
*america
u*s*a*
<b>Finish the sentence:</b><ul>Captain Jean-Luc __________</ul>
pic*ard
<b>Name one Star Wars droid</b>
r2*d2
artoo*
c*3p0
*three*p*o* |
the bottom line, is that wildcards will allow admins to give the users the slightest bit of increased flexibility in answering TC questions. If you were asked "Name One Star Wars Droid", and you had to get a correct answer on the first try, what would you try? R2D2? R2-D2? R2 D2? C3P0? C-3P0?
i think wildcards could help reduce confusion for users, because even if they slightly mispell a word, it will still be "right", as long as the admin was smart about having a decent wildcard answer for them. especially for the users who will say to their admins "WTF? i answered the question right!", which I know has happened more than once
and heck, people may not even use it to begin with. but those admins who get tired of typing in all 15 different variations and common misspellings of their answers may thank you for it. |
|
|
admin Site Admin
Joined: 18 Apr 2006 Posts: 805 Location: Saint-Petersburg, Russia
|
Posted: Wed Apr 25, 2007 4:24 am Post subject: |
|
|
Well, seems easy. Yet another condidate to the folder "contrib". By the way, I'd rewrite regexp construction in this way:
Code: |
$tmp = explode('*', $a);
$tmp = array_map(preg_quote, $tmp);
$regexp = implode('.*', $tmp);
|
_________________ Oleg Parashchenko, bbAntiSpam
Do you love our tools? Please sponsor further development! |
|
|
Ares
Joined: 28 Mar 2007 Posts: 24
|
Posted: Fri Apr 27, 2007 12:45 am Post subject: |
|
|
glad I could help, let me know if you need any assistance with anything else related to php
at the other voters:
if I may, can I lol @ the people (aside from oleg) who voted "no" to wildcards. Oleg has an excuse (he is busy out the ass, supporting TC/ATC), you other people don't. It's like saying "no, don't make my life easier". i don't understand it. |
|
|
Ok.