Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
53
Task/Determine-sentence-type/CLU/determine-sentence-type.clu
Normal file
53
Task/Determine-sentence-type/CLU/determine-sentence-type.clu
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
% This iterator takes a string and yields one of 'E', 'Q',
|
||||
% 'S' or 'N' for every sentence found.
|
||||
% Because sentences are separated by punctuation, only the
|
||||
% last one can be 'N'.
|
||||
|
||||
sentence_types = iter (s: string) yields (char)
|
||||
own punct: string := "!?." % relevant character classes
|
||||
own space: string := " \t\n"
|
||||
own types: string := "EQS" % sentence type characters
|
||||
|
||||
prev_punct: bool := false % whether the previous character was punctuation
|
||||
last_punct: int := 0 % index of last punctuation character encountered
|
||||
sentence: bool := true % whether there are words since the last punctuation
|
||||
|
||||
for c: char in string$chars(s) do
|
||||
pu: int := string$indexc(c, punct)
|
||||
sp: int := string$indexc(c, space)
|
||||
if pu ~= 0 then
|
||||
prev_punct := true
|
||||
last_punct := pu
|
||||
elseif sp ~= 0 then
|
||||
if prev_punct then
|
||||
% a space after punctuation means a sentence has ended here
|
||||
yield(types[last_punct])
|
||||
sentence := false
|
||||
end
|
||||
prev_punct := false
|
||||
sentence := false
|
||||
else
|
||||
sentence := true
|
||||
end
|
||||
end
|
||||
|
||||
% handle the last sentence
|
||||
if prev_punct then yield(types[last_punct])
|
||||
elseif sentence then yield('N')
|
||||
end
|
||||
end sentence_types
|
||||
|
||||
% Test
|
||||
start_up = proc ()
|
||||
po: stream := stream$primary_output()
|
||||
test: string :=
|
||||
"hi there, how are you today? I'd like to " ||
|
||||
"present to you the washing machine 9001. You " ||
|
||||
"have been nominated to win one of these! Just " ||
|
||||
"make sure you don't break it"
|
||||
|
||||
% print the type of each sentence
|
||||
for c: char in sentence_types(test) do
|
||||
stream$putc(po, c)
|
||||
end
|
||||
end start_up
|
||||
Loading…
Add table
Add a link
Reference in a new issue