Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Dec 2006
    Thanked 1 Time in 1 Post

    How to count frequencies of a word appearing in a paragraph?

    Say I have a block of text and I want to count "important" words in the block of text -- what's the best way to do this?

    "important" means operative words (excluding "the" "a" "because" "for" "this" "that").

    I want to count each "important" word and then record the number of times each word appears in the block of text.

    Has anyone does this before?

  2. #2
    Regular Coder ralph l mayo's Avatar
    Join Date
    Nov 2005
    Thanked 31 Times in 29 Posts
    The exceptions you list are part of a group commonly called "stop words," you can get a list here. If you're doing this purely in PHP it's going to be slow regardless of how you implement it, but you might have luck splitting the target text into an array of words and loading the stop words as another array, and using array_diff to remove the stop words. From there you're an array_count_values away from the answer.


Posting Permissions

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