Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Feb 2003
    Posts
    63
    Thanks
    0
    Thanked 0 Times in 0 Posts

    get count from each word

    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.

  • #2
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,093
    Thanks
    11
    Thanked 101 Times in 99 Posts
    if it were not for the quotes (which you could strip before they were entered) ... you could simply ..

    PHP Code:
    <?php
    $array 
    file'result.txt' ) ;
    print_rarray_count_values$array ) );
    ?>
    else you gonna have to (or similar)
    PHP Code:
    <?php
    $array 
    file'result.txt' ) ;
    foreach( 
    $file as $k=>$v ){
        
    $file[$k] = str_replace( array( "\"" "'" ) , '' $v ) ;
    }

    print_rarray_count_values$array ) );
    ?>
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #3
    New Coder
    Join Date
    Feb 2003
    Posts
    63
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #4
    New Coder
    Join Date
    Feb 2003
    Posts
    63
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #5
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,093
    Thanks
    11
    Thanked 101 Times in 99 Posts
    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' ?
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •