PHP Classes

No pspell

Recommend this page to a friend!

      Word Solver  >  All threads  >  No pspell  >  (Un) Subscribe thread alerts  
Subject:No pspell
Summary:Using .txt dictionaries
Messages:13
Author:Beldar
Date:2012-03-16 17:16:19
Update:2012-05-16 16:32:34
 
  1 - 10   11 - 13  

  1. No pspell   Reply   Report abuse  
Picture of Beldar Beldar - 2012-03-16 17:16:19
It's possible to use a .txt word dictionary instead of pspell? To hard to install!

  2. Re: No pspell   Reply   Report abuse  
Picture of Arturs Sosins Arturs Sosins - 2012-03-16 18:38:25 - In reply to message 1 from Beldar
Yes, sure you can, you only need to extend this class and override atleast two methods, here's an example using custom_dixtionary.txt where each word is it new line:

//including original class
include("./word_solver.php");
//extending
class custom_word_solver extends word_solver
{
/****************************
* CUSTOM DICTIONARY FUNCTIONS
****************************/

//initialize dictionary
protected function dictionary_init(){
$str = file_get_contents("./custom_dictionary.txt");
$parts = explode("\r\n", $str);
foreach($parts as $part)
{
$this->dict[$part] = true;
}
}

//return false if word is incorrect
//or true if word is correct
protected function dictionary_check($word){
$ret = false;
if(strlen($word) > 2)
{
if(isset($this->dict[$word]))
{
$ret = true;
}
}
return $ret;
}
}

//use custom class as you would use original word_solver
$ws = new custom_word_solver();

  3. Re: No pspell   Reply   Report abuse  
Picture of Patrick Patrick - 2012-04-25 22:41:20 - In reply to message 2 from Arturs Sosins
I'm so close to getting your PHP class to work with a custom dictionary.
Are you certain that everything is working in that code snippet that you posted? For one thing, it wasn't wrapped in <?php tags, but that was easy. I've modified the html_example.php to include my new php file, which I named custom_ws.php. I then changed the line in the html_example.php file to call
$ws = new custom_word_solver();

I've got a custom dictionary as a text file with each word on its own line.
If I print_r ($str) in the custom_ws.php file I created, it shows all the words in the dictionary as expected.

The routine runs without throwing any errors, however, it doesn't show me any words.
It outputs
Array
(
)

Even when I type a word or letters that are clearly in the dictionary.
When I use the scripts as originally written -- with Pspell, on my site, they work just fine.
I just cannot get it to work with the custom dictionary, even after using the script you added.

BTW, if I never want to use Pspell -- always a custom dictionary, can't I just get rid of those functions in the original word_solver.php file? Why do an extend?

Any help you can provide me would be GREATLY appreciated. If you have PayPal donations set up, I'll be happy to contribute. Your script is doing just what I want, otherwise.

  4. Re: No pspell   Reply   Report abuse  
Picture of Arturs Sosins Arturs Sosins - 2012-04-26 08:20:02 - In reply to message 3 from Patrick
Hello,
I've uploaded a custom dictionary example:
webcodingeasy.com/my_classes/word_s ...

So you can check where you stuck, it seems to be working, but if not let me know. ;)

About extending class, well that is the concept of OOP, reusing something that is already coded. And that way, you don't have to mess with code that you didn't write, but only update it with your own.

But if you are feeling comfortable with editing classes code, sure you can implement this functions right into the class. ;)

  5. Re: No pspell   Reply   Report abuse  
Picture of Patrick Patrick - 2012-04-26 22:22:26 - In reply to message 4 from Arturs Sosins
Hi Arturs,

I was SO excited to see your prompt reply, but after uploading the files to my server (without making ANY changes) to test them, it appears to have the same issue that my script yesterday was having.
It simply is not using the dictionary.

Test this:
Type in a word you know is in your custom dictionary, such as "Abby".
Set "Use all letters" to yes or no -- it doesn't matter.
Make sure Return is set to "Valid Words" so it checks the dictionary.
Click Generate and all you get is:

Array
(
)

Empty...

If you do the same thing, but set it to Anagram mode, it will show you the array of permutations and you will see 'abby' right there at the top of the list.

If you look in the custom_dictionary.txt file you provided, you see 'abby' clearly is in the dictionary.

I don't know what's failing.

Do you have it working on your server?

You can test the files I uploaded to my server at
cadsoft-consult.com/solver/custom_h ...

As I mentioned, I simply uploaded the files you provided up to the server.
I have tried it on two different physical servers, one of which is running the latest version of PHP, so I don't think that could be an issue.

Any help you could provide would be WONDERFUL!

Thank you again.

Patrick

  6. Re: No pspell   Reply   Report abuse  
Picture of Arturs Sosins Arturs Sosins - 2012-04-27 07:12:24 - In reply to message 5 from Patrick
Ok there, seems to be a bug. It returns word baby, but doesn't return word abby.

I'll have a more thorough look on the weekend and let you know ;)

  7. Re: No pspell   Reply   Report abuse  
Picture of Patrick Patrick - 2012-04-30 18:49:46 - In reply to message 6 from Arturs Sosins
Any progress?

  8. Re: No pspell   Reply   Report abuse  
Picture of Arturs Sosins Arturs Sosins - 2012-05-02 10:10:27 - In reply to message 7 from Patrick
Hello,
sorry for not getting back earlier.
In Latvia, we had a holiday shift, meaning we had to work all weekend, so we can get a continuous holiday together with national holiday next week.

Long story short, I've deviated from the schedule, and haven't got any time to check it, but will try to devote some time as soon as possible.

  9. Re: No pspell   Reply   Report abuse  
Picture of Patrick Patrick - 2012-05-02 23:33:27 - In reply to message 8 from Arturs Sosins
No worries, Arturs.
I appreciate your help. I wish I was better with PHP. I've been trying to troubleshoot it myself and it just looks like it should be working and I can't figure out why it isn't.
I look forward to hearing from you when you have a chance.

Thank you!

Patrick

  10. Re: No pspell   Reply   Report abuse  
Picture of Arturs Sosins Arturs Sosins - 2012-05-13 14:54:57 - In reply to message 9 from Patrick
Hi,
I fixed the bug and uploaded new version including new example for custom dictionary. Please try them out, and see if they work for you. ;)

 
  1 - 10   11 - 13