Solved

Remove Non-Words

Posted on 2010-09-16
2
281 Views
Last Modified: 2012-05-10
Hi,

I'm looking for a way to remove non-english dictionary words from a file that has 3 fields:

Example:

word      xxword      x      xa      worlds

I'm looking to output only dictionary words:

word      hello        worlds

I'm pretty sure this would be possible to accomplish by using a dictionary that comes with Unix by overlapping the two files and outputting matches and formatting.


IThank you
0
Comment
Question by:faithless1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 8

Accepted Solution

by:
shanikawm earned 450 total points
ID: 33699184
You can use php Pspell functions.

e.g.:

cat file.txt

penn pencil eraser
black bleu red
monitor key muose

php spell.php

pencil eraser
black red
monitor key

<?php
$pspell_link = pspell_new("en");
$lines=file('file.txt');
foreach ($lines as $line)
{
        $words=preg_split('/[ \s]+/',trim($line));
        foreach ($words as $word)
        {
                if(pspell_check($pspell_link,$word))
                {
                        echo $word,' ';
                }
        }
        echo "\n";
}
?> 

Open in new window

0
 
LVL 110

Assisted Solution

by:Ray Paseur
Ray Paseur earned 50 total points
ID: 33701333
See the notes here:
http://us.php.net/manual/en/pspell.installation.php

You can run this script to find out if you've got pSpell:
<?php phpinfo(); ?>

This search may have some good examples if you do not have the extension installed.
http://lmgtfy.com?q=PHP+spell+checking
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article discusses how to create an extensible mechanism for linked drop downs.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question