Posts: 97
Threads: 48
Joined: Sep 2010
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 !
Posts: 12,140
Threads: 142
Joined: Dec 2002
Use function tok.
Macro
Macro2429
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]
,
Posts: 97
Threads: 48
Joined: Sep 2010
Thank You!
How can I use the output for calculation? I want to calculate the avarage amount of words in a sentence.
Posts: 12,140
Threads: 142
Joined: Dec 2002
Macro
Macro2431
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
Posts: 133
Threads: 15
Joined: Jun 2014
Is it possible to not eliminate special characters that go with the words when tokenizing? Like this example:
Macro
Macro248
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 [email protected]. 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%
[email protected]
$20"^-^
Black&Decker
Posts: 12,140
Threads: 142
Joined: Dec 2002
tok sentences[is] words -1 " [9][],;"
Posts: 133
Threads: 15
Joined: Jun 2014
Works like a charm.

Thanks a lot.