in reply to Re: problem count the number of words
in thread problem count the number of words
Hi bro
i have 2 files that include a lot of sentences and also i have 2 files include negative words and positive words and i want to count the number use of these 2 type of words in the sentences , my sentences are $pt = '/root/Positive.txt' , $nt = '/root/Negative.txt' so my words are $pwt = '/root/Positive2.txt' , $ntw = '/root/Negative2.txt' , now i want to count the number of words in 2 sentences by this code
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: problem count the number of words (updated)
by AnomalousMonk (Archbishop) on Dec 27, 2018 at 20:16 UTC | |
Here's an example of counting defined sets of "words" (which can be tricky to define) based on the technique described in the Building Regex Alternations Dynamically article by haukex. If you can figure out how to get the contents of your positive and negative word data files into the corresponding arrays (and if my notion of what you want is anywhere near what you actually want), you may be on your way. Note that the code is set up for case-insensitive matching and counting: the negative word "fourscore" matches "FoUrScOrE" in the example sentence, and so on. Note, again, that the concept of a "word" can be slippery, so the use of the \b boundary assertion, among other details, may not be appropriate.
Update: In the make_regex() function, the lines Give a man a fish: <%-{-{-{-< | [reply] [d/l] [select] |
by GHMON (Novice) on Dec 28, 2018 at 09:37 UTC | |
Hi TNX bro i could find the my problem , my problem was about these section *foreach (my $word = <$inwp>) { $countp{$word}++ ; }* , *foreach (my $word = <$nwt>) {$countn{$word}++ ; }* because i split the words by /\n/ that my code didn't need to this separator my new code
| [reply] [d/l] |
by poj (Abbot) on Jan 01, 2019 at 17:06 UTC | |
You appear to be just counting the words in the words file Positive2.txt and I can't see where you are spitting the sentences in Positive.txt into words. Perhaps this will help you progess poj | [reply] [d/l] [select] |