Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Count unique words
#1
Hello,

I have a question Smile
Is it possible to let QM count the unique words from a string. If a word is used more than 1 time, the output should count +1 for each usage.

Like this:
"This is an example to show what i want. This test is a test to see how this can be done."

The words "This", "to" and 'test' should be counted as
This (3)
To (2)
Test (2)
All the other unique words as 1

Can this be done?

TIA
Sonic
#2
Macro Macro1805
Code:
Copy      Help
str s=
;This is an example to show what i want. This test is a test to see how this can be done.

;split s into words and add to array
ARRAY(str) a
tok s a

;add unique words to string map
IStringMap m=CreateStringMap(1)
int i n
for i 0 a.len
,str& r=a[i]
,if(m.IntGet(r n)) m.IntSet(r n+1); else m.IntAdd(r 1)

;results
m.GetList(s)
out s
#3
Thank You!

One more question if i may?

Is it possible to sort the output?
And can the 'hits' which are only found 1 time be excluded?
#4
GetList gets sorted.

insert this after m.GetList(s):
s.replacerx("^.+ 1[]" "" 8)


Forum Jump:


Users browsing this thread: 1 Guest(s)