I have a problem with my dictionary website, when people tried to search for a word which is in plural form, my script cannot find it. Is there any way that I could make the words put into singular so that it could be searched in the database?
but what will happen if the word naturally has "s" in the end like bus? And how about the singular form of mice? Oh man this is hard..
Yeah thats why i told u to add the % which if my memory is good will get any word that start with the query he made . you cant have a perfect dictionnary , except if you take all cases , all depend on how your db is made . but for the "S" cases if the users search for "discuss" and you remove the last "s" and in the query specify that you want to serach for "discus%" discuss should be returned (also any word that contain discusXXXX)
I do get your point commandos and I appreciate that. Take a look on this sample site here. If you searched for "mice" it will return using "mouse" same as with the "viri". My website is also using the same database(wordnet 3.0) so I guess it is on the php script? Here's my code how to search the query in the db: $word = preg_replace('%\ $%', '', $_REQUEST['w']); // Find the word $result = mysql_query('SELECT * FROM wn_synset WHERE [B]word="'.str_replace(' ', '_', $word).'"[/B] ORDER BY ss_type ASC'); $num_result = mysql_numrows($result); Code (markup): So what do you think guys?
Well from their FAQ : q.5.3 Can WordNet generate plural forms and other inflected forms? No. The morphological component of the WordNet library is unidirectional. Along with a set of irregular forms (e.g. children - child), it uses a sequence of simple rules, stripping common English endings until it finds a word form present in WordNet. Furthermore, it assumes its input is a valid inflected form. So, it will take "childes" to "child", even though "childes" is not a word
How come I haven't read that one? Anyway, if that is the case? how can you correct the words such us "mice" to "mouse" as what in their online sample? Alright this is the hard part, modifying my php code.. Is there tutorial on php wherein you can remove the "s" in the word just what you have said commandos? Thank for the help pal!
Yes I get it now, but I still need help on my php script. To make the queries found on the database is to delimit letters, for example "devastated" to become "devastate" or "divested" into "divest" and so on and so forth until to find a result in the database. I don't know how to write this in php, I am confused. Can you guys help me to start the editing of my code? Here's my php code for the queries: // Find the word $slashedword = stripslashes($_REQUEST['w']); $word = preg_replace('%\ $%', '', $slashedword); $result = mysql_query('SELECT * FROM wn_synset WHERE word="'.str_replace(' ', '_', $word).'" ORDER BY ss_type ASC'); Code (markup): In the $result variable, how should I make the mysql query check each word with delimited "s" "d" "ed" until to find a result?
well maybe make a loop for (i=0 till word.length) and each time remove the last char and make the query if it return something return it if it dont continue the loop and remove the last letter .
Thanks for the advices commandos, I will try that one. Also thanks to ikipei for the advice, how can I use the inflector_helper? Can you explain to me how can I will be able to integrate it? Like do I have something to install? Does the inflector_helper can also correct those terms in past tense?
Okay I am somehow succesful now and here's my solution: $slashedword = stripslashes($_REQUEST['w']); $neword = preg_replace('%\ $%', '', $slashedword); //reverse some plural forms to singular function trimplural($neword){ $plural_end='os'; $replace_singular='o'; if( substr($neword, -2) == $plural_end) { $neword = substr($neword, 0,strlen($neword)-2). $replace_singular; } $plural_end='ies'; $replace_singular='y'; if( substr($neword, -3) == $plural_end) { $neword = substr($neword, 0,strlen($neword)-3). $replace_singular; } $plural_end='xes'; $replace_singular='x'; if( substr($neword, -3) == $plural_end) { $neword = substr($neword, 0,strlen($neword)-3). $replace_singular; } $plural_end='oes'; $replace_singular='o'; if( substr($neword, -3) == $plural_end) { $neword = substr($neword, 0,strlen($neword)-3). $replace_singular; } $plural_end='ies'; $replace_singular='y'; if( substr($neword, -3) == $plural_end) { $neword = substr($neword, 0,strlen($neword)-3). $replace_singular; } $plural_end='ves'; $replace_singular='fe'; if( substr($neword, -3) == $plural_end) { $neword = substr($neword, 0,strlen($neword)-3). $replace_singular; } $plural_end='s'; $replace_singular=''; if( substr($neword, -1) == $plural_end && !(substr($neword, -2) == 'ss') ) { $neword = substr($neword, 0,strlen($neword)-1). $replace_singular; } return $neword; } $word = trimplural($neword); Code (markup): everything works fine now but I still have some problem. It still can't find words which plural form ended in "es" like "bosses" and also words that ended in "ves" like "thieves". I don't know how to fix it but it can now find queries such as "beasts" or "lives". Any help guys? It is almost done with some little problems that needs to fix. PS To test it you can use this url: http://www.defineitfast.com/browse/terms.html&new=1 Just change the bolded text into the word for queries. Should I still use loop here? or if functions? Thanks for the help guys!