8-Bit Software Online Conversion
Sentence Generator. Sentenc - Listing
10REM >Sentenc
20REM by Steven Flintham
30REM
40REM Friday 15th April 1994
50REM Saturday 16th April 1994
60REM
70REM This is a completely new versio
n and is based entirely on
80REM 'phrase substitution'
90:
100MODE 7:width%=39
110PROCinit
120REPEAT
130PROCgenerate`sentence
140UNTIL FALSE
150END
160:
170DEF PROCinit
180LOCAL read%,clear%
190DIM template$(100),component$(800,3
),variable%(26),match%(5):REM CHANGED FR
OM 2000 TO 800 BY CJR
200FOR clear%=1 TO 26:variable%(clear%
)=0:NEXT
210PRINT "Please wait, reading templat
es..."
220RESTORE 1410:num`templates%=0
230REPEAT
240num`templates%=num`templates%+1
250READ template$(num`templates%)
260UNTIL template$(num`templates%)="ZZ
Z"
270num`templates%=num`templates%-1
280PRINT "Please wait, reading compone
nts..."
290RESTORE 1460:num`components%=0
300REPEAT
310num`components%=num`components%+1
320FOR read%=1 TO 3
330READ component$(num`components%,rea
d%)
340NEXT
350UNTIL component$(num`components%,1)
="ZZZ"
360num`components%=num`components%-1
370PRINT "Please wait, sorting compone
nts..."
380PROCsort`components
390CLS
400ENDPROC
410:
420DEF PROCsort`components
430LOCAL outer%,inner%,first$,second$
440IF num`components%=1 THEN ENDPROC
450FOR outer%=1 TO num`components%-1
460FOR inner%=outer%+1 TO num`componen
ts%
470IF component$(outer%,1)>component$(
inner%,1) THEN PROCswap(outer%,inner%)
480NEXT
490NEXT
500ENDPROC
510:
520DEF PROCswap(outer%,inner%)
530LOCAL temp$,sub%
540FOR sub%=1 TO 3
550temp$=component$(outer%,sub%):compo
nent$(outer%,sub%)=component$(inner%,sub
%):component$(inner%,sub%)=temp$
560NEXT
570ENDPROC
580:
590DEF FNS="Sentenc"
600:
610DEF PROCgenerate`sentence
620LOCAL sentence$
630IF num`templates%=1 THEN sentence$=
FNsubstitute(template$(1)) ELSE sentence
$=FNsubstitute(template$(RND(num`templat
es%)))
640PROCpretty`print(sentence$)
650ENDPROC
660:
670DEF FNsubstitute(line$)
680LOCAL left$,right$,mid$
690IF INSTR(line$,"<")=0 THEN =line$
700left$=LEFT$(line$,INSTR(line$,"<")-
1)
710right$=MID$(line$,INSTR(line$,">")+
1)
720mid$=MID$(line$,INSTR(line$,"<")+1,
INSTR(line$,">")-INSTR(line$,"<")-1)
730line$=left$+FNhandle`subst`comp(mid
$)+right$
740=FNsubstitute(line$)
750:
760DEF FNhandle`subst`comp(subst$)
770LOCAL match%,return$,var`num%
780match%=FNfind`subst(subst$)
790IF match%=0 THEN PRINT "Substitutio
n component '";subst$;"' not recognised.
":END
800IF component$(match%,2)="" THEN ret
urn$=FNget`at`random(component$(match%,3
))
810IF LEN(component$(match%,2))>=3 THE
N var`num%=ASC(LEFT$(component$(match%,2
),1))-64:variable%(var`num%)=VAL(MID$(co
mponent$(match%,2),3)):return$=FNget`at`
random(component$(match%,3))
820IF LEN(component$(match%,2))=1 THEN
var`num%=ASC(component$(match%,2))-64:r
eturn$=FNget`item(component$(match%,3),v
ariable%(var`num%))
830=return$
840:
850DEF FNfind`subst(subst$)
860LOCAL lower%,upper%,pos%,match%,cle
ar%,match`num%
870lower%=1
880upper%=num`components%
890match%=FALSE
900REPEAT
910pos%=(upper%-lower%)/2+lower%
920IF component$(pos%,1)=subst$ THEN u
pper%=pos%:lower%=pos%:match%=TRUE
930IF component$(pos%,1)>subst$ THEN u
pper%=pos%
940IF component$(pos%,1)<subst$ THEN l
ower%=pos%
950UNTIL match% OR upper%-lower%<=1
960IF NOT match% THEN pos%=upper%+1:RE
PEAT:pos%=pos%-1:UNTIL component$(pos%,1
)=subst$ OR pos%=0
970IF pos%=0 THEN =0
980REPEAT:pos%=pos%-1:UNTIL component$
(pos%,1)<>subst$:pos%=pos%+1
990FOR clear%=1 TO 5:match%(clear%)=0:
NEXT:match`num%=0
1000REPEAT
1010IF component$(pos%,1)=subst$ THEN m
atch`num%=match`num%+1:match%(match`num%
)=pos%
1020pos%=pos%+1
1030UNTIL pos%>num`components% OR compo
nent$(pos%,1)<>subst$
1040IF match`num%=0 THEN =0
1050IF match`num%=1 THEN =match%(1)
1060=match%(RND(match`num%))
1070:
1080DEF FNget`at`random(list$)
1090LOCAL num`in`list%
1100num`in`list%=FNnum`in`list(list$)
1110IF num`in`list%=1 THEN =FNget`item(
list$,1) ELSE =FNget`item(list$,RND(num`
in`list%))
1120:
1130DEF FNnum`in`list(list$)
1140LOCAL count%,offset%
1150IF INSTR(list$,"÷")=0 THEN =1
1160count%=0:offset%=1
1170REPEAT
1180count%=count%+1
1190offset%=INSTR(list$,"÷",offset%)+1
1200UNTIL offset%=1
1210=count%
1220:
1230DEF FNget`item(list$,pos%)
1240LOCAL skip%
1250IF INSTR(list$,"÷")=0 THEN =list$
1260IF pos%=1 THEN =LEFT$(list$,INSTR(l
ist$,"÷")-1)
1270FOR skip%=1 TO pos%-1
1280list$=MID$(list$,INSTR(list$,"÷")+1
)
1290NEXT
1300IF INSTR(list$,"÷")=0 THEN =list$
1310=LEFT$(list$,INSTR(list$,"÷")-1)
1320:
1330DEF PROCpretty`print(T$)
1340LOCAL A%
1350REPEAT
1360IF LEN(T$)<width% THEN PRINT T$:T$=
"" ELSE A%=INSTR(T$," ",width%+1):A%=A%+
(A%=0)*-width%:REPEAT:A%=A%-1:UNTIL MID$
(T$,A%,1)=" ":PRINT LEFT$(T$,A%):T$=MID$
(T$,A%+1)
1370UNTIL T$=""
1380ENDPROC
1390:
1400REM Templates
1410DATA "<Person> <enjoyed> <enjoyable
thing>."
1420DATA "If there was one thing <perso
n> <did not like>, it was <unpleasant th
ing>."
1430DATA ZZZ
1440:
1450REM Components
1460DATA "Person",,"<Man>÷<Woman>"
1470DATA "Man","S=1","He÷Steven÷Fred÷Ch
ris÷Michael"
1480DATA "Woman","S=2","She÷Helen÷Linds
ey÷Caroline"
1490DATA "person",,"<man>÷<woman>"
1500DATA "man","S=1","he÷Steven÷Fred÷Ch
ris÷Michael"
1510DATA "woman","S=2","she÷Helen÷Linds
ey÷Caroline"
1520DATA "his/her","S","his÷her"
1530DATA "he/she","S","he÷she"
1540:
1550DATA "enjoyed",,"enjoyed÷liked÷love
d"
1560DATA "did not like",,"did not like÷
hated÷could not stand"
1570:
1580DATA "enjoyable thing",,"reading th
e latest edition of 8BS÷going to work÷wr
iting <(brilliant )>programs to send in
to 8BS÷the mindless tedium of backing up
<his/her> collection of discs"
1590DATA "enjoyable thing",,"programmin
g <his/her> computer÷sleeping late at we
ekends÷laughing at people who said that
<his/her> 8-bit BBC was outdated"
1600DATA "unpleasant thing",,"backing u
p <his/her> discs÷talking to people who
owned Amigas÷power failures just as the
latest version of <his/her> program was
being saved"
1610:
1620DATA "(brilliant )",,"÷brilliant ÷g
reat ÷novel "
1630:
1640DATA ZZZ,ZZZ,ZZZ