...

View Full Version : get count from each word



kenny873
10-28-2003, 07:35 AM
if I have a file (result.txt) that contains :

egg
apple
egg
orange
banana
"chinese word"
"italian word"
"chinese word"

and I would like to count the frequecy of each term, do you know how? because I have a site provide search, every keyword search is stored in a table and now I would like to see which word is most frequent requested.

do I need to use trim() or other functions also to remove the white space and double quote?

thank you.

firepages
10-28-2003, 09:17 PM
if it were not for the quotes (which you could strip before they were entered) ... you could simply ..



<?php
$array = file( 'result.txt' ) ;
print_r( array_count_values( $array ) );
?>


else you gonna have to (or similar)


<?php
$array = file( 'result.txt' ) ;
foreach( $file as $k=>$v ){
$file[$k] = str_replace( array( "\"" , "'" ) , '' , $v ) ;
}

print_r( array_count_values( $array ) );
?>

kenny873
10-29-2003, 02:48 AM
thanks...however, I tried...but it is always timeout...it is because

1) I have a record of more than 100,000....this is a headache.

And 2), how can I group likely terms as follow:

hithway 200
hithway 300
hithway special
hithway

Any clue? thanks for you help again.

kenny873
10-29-2003, 02:56 AM
Actually, I am trying to output the data from Oracle database..

each day there may be 10,000 + entries to the search field with different words in different patterns.

I would like to count the top 10 frequent words and also count the rest in descending orders. Therefore I tried to spool all the output into a file, but it tooks hours and the txt file is huge, which is not efficient.

Does anyone know any SQL command that will do my task? OR if using PHP. how to be more effective?

thanks

firepages
10-29-2003, 05:05 AM
if it were a mysql database I would ..

"SELECT word , COUNT(word) FROM table GROUP BY word"

but an Oracle database ? , you have so many other options , and would depend on where and how you are storing the data in the first place , eg can you not just trigger a stored procedure to update a keyword table as and when the data is 'collected' ?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum