Jump to content

comparing arrays containing strings-> stopword removal-> code help not working!


underwinefx

Recommended Posts

I need a stopword removal implementation. I am flabbergasted with few issues.

For eg:
[quote]
stopword.txt
is
the
that
this
[/quote]
[code]
<?
//loading the stopword from a text file 'stopword.txt' which contains a list of words containing one word per line and entered by pressing the ENTER key after every word

$stopword=array('is', 'the', 'that', 'this',);//I assume that the previous line gives the same effect as this line...am I wrong? and this LINE would NOT be in the code..since I will be using
$text="this is a quote to say that anything is possible";//contains stopwords that need to be removed.
//using explode to make the text string into separate array elements using <space> as the delimiter.
$keyword=explode(" ",$text);
$keyword=array_diff($keyword,$stopword);
?>
[/code]

The above code works...

[code]
<?
$myFile = "stopword.txt";//the file containing the stopwords
//opening the stopword.txt file
$fh = fopen($myFile, 'r');

//reading the stopword.txt file
$theData = fread($fh, filesize($myFile));

//to get the data from the text file as separate array elements using explode
//$stopword=explode("\n",$theData);
$keyword=explode(" ",$text);
$keyword=array_diff($keyword,$stopword);
[/code]

The above code does NOT work..why?

And I would Like to know what else can be done? To compare each element from one array to the other element and unset/remove it?

Should I use looping? I am a starter and I am at loss how to implement this ..

[quote][b]In brief:[/b]
1. load the stopword list from stopword.txt into stopword array
2. separate the string into keywords by using space as delimiter.
3. compare each word of stopword array with each element in the keyword array
4. remove the elements from keyword array which are present in stopword array
5. return results of new keyword array without the stopwords for further coding
[/quote]

How to implement this?

Regards,
Underwinefx
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.