Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Text counting
#1
Hi,

I have this text, stored in a string. What i would like is to devide it in sentences and know how many there are. Afterwards I like to know how many words each sentence counts.

Anyone an idea of how i can realise this?

Thanks !
#2
Use function tok.

Macro Macro2429
Code:
Copy      Help
str s=
;I have this text, stored in a string. What i would like is to devide it in sentences and know how many there are. Afterwards I like to know how many words each sentence counts.
;
;Anyone an idea of how i can realise this?
;
;Thanks !

ARRAY(str) sentences words
int is iw
tok s sentences -1 ".?!" 0x2000
out "%i sentences" sentences.len
for is 0 sentences.len
,tok sentences[is] words -1 ""
,out words.len
,for(iw 0 words.len) out words[iw]
,
#3
Thank You!

How can I use the output for calculation? I want to calculate the avarage amount of words in a sentence.
#4
Macro Macro2431
Code:
Copy      Help
str s=
;I have this text, stored in a string. What i would like is to devide it in sentences and know how many there are. Afterwards I like to know how many words each sentence counts.
;
;Anyone an idea of how i can realise this?
;
;Thanks !

ARRAY(str) sentences words
int is iw
tok s sentences -1 ".?!" 0x2000
out "%i sentences" sentences.len
int totalWords
for is 0 sentences.len
,tok sentences[is] words -1 ""
,;out words.len
,totalWords+words.len
,;for(iw 0 words.len) out words[iw]
out "average words/sentence: %i" totalWords/sentences.len
#5
Is it possible to not eliminate special characters that go with the words when tokenizing? Like this example:

Macro Macro248
Code:
Copy      Help
str s=
;I have 2 balloons: one is "red" and one is "blue". My brother has 2 cars. Car #1 is white and car #2 is grey.
;
;I complete 80% of my homework. My email is AbcDef@yahoo.com. I have one $20 bill in my wallet ^-^.
;
;I have a Black&Decker power drill tool.
I would like to see that those words still exist after tokenizing:
balloons:
"red"
"blue"
#1
#2
80%
AbcDef@yahoo.com
$20"^-^
Black&Decker
#6
tok sentences[is] words -1 " [9][],;"
#7
Works like a charm. Big Grin
Thanks a lot.


Forum Jump:


Users browsing this thread: 1 Guest(s)