Jump to content

Use pspell to detect words on sentence


Rusty3

Recommended Posts

I want to turn this: "helloworld", into this: "hello world"

 

The idea is to use pspell to detect "hel loworld" is incorrect and "hello world" as correct.

 

The algorithm removes one char each loop and detect the smallest world, stores it and loops througth the remaining text again to do the same thing... or at least it was supposed to do that...

 

Of course "expertsexchange", should return "experts exchange" and "expert sex change".

 

Any help greatly appreciated. Thanks.

 

 

$sentence = "helloworld";  


for ($f = 0; $f < 5; $f++)   {  
list($firstword,$remaining) = extractfirstkeyword($sentence); 
echo  "Firstword:$firstword<br>"; 
echo  "Remaining:$remaining<br>";
echo  "<hr>"; 
$sentence =  $remaining;
}



function extractfirstkeyword($sentence) { 

$pspell_link = pspell_new("en"); 

$size = strlen($sentence);  
    for ($i = 0; $i < $size-1; $i++)   {
          
    $currentword = substr_replace($sentence ,"",($size - $i));
           if (pspell_check($pspell_link, $currentword))
            {   
            $firstword =  $currentword;  
            $remaining = substr($sentence, strlen($firstword));
            echo  "currentword:$currentword<br>"; 
            echo  "remaining:$remaining<br>";    
            }  
    }
return array($firstword,$remaining);
}

Link to comment
https://forums.phpfreaks.com/topic/167427-use-pspell-to-detect-words-on-sentence/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.