ChatScript Advanced User Manual

40
7/26/2019 ChatScript Advanced User Manual http://slidepdf.com/reader/full/chatscript-advanced-user-manual 1/40 ChatScript Advanced User’s Manual © Bruce Wilcox, gowilcox@gmailcom   brilligunderstanding.com Revision 11/30/2014 cs4.8! "a#le o$ Contents Advanced Concepts % Advanced "opics % Advanced &atterns ' Advanced (utput )) Advanced *aria#les )+ Control (ver nput )+ (ut o$ Band Communication )+ Advanced -#uild %) .diting /on0topic 1iles %! Which Bot2 %3 Common Script dioms %4 5uestions67and0holding %+ .soterica and 1ine 8etail !9 Sel$0:e$lection !; A 1resh #uild !' Command line &arameters !4 Updating CS versions .asil< !+ "he 8ictionar< !+ 1

Transcript of ChatScript Advanced User Manual

Page 1: ChatScript Advanced User Manual

7/26/2019 ChatScript Advanced User Manual

http://slidepdf.com/reader/full/chatscript-advanced-user-manual 1/40

ChatScript Advanced User’s Manual

© Bruce Wilcox, gowilcox@gmailcom  brilligunderstanding.comRevision 11/30/2014 cs4.8!

"a#le o$ Contents

Advanced Concepts %

Advanced "opics %

Advanced &atterns '

Advanced (utput ))

Advanced *aria#les )+

Control (ver nput )+

(ut o$ Band Communication )+

Advanced -#uild %)

.diting /on0topic 1iles %!

Which Bot2 %3

Common Script dioms %4

5uestions67and0holding %+

.soterica and 1ine 8etail !9

Sel$0:e$lection !;

A 1resh #uild !'

Command line &arameters !4

Updating CS versions .asil< !+

"he 8ictionar< !+

1

Page 2: ChatScript Advanced User Manual

7/26/2019 ChatScript Advanced User Manual

http://slidepdf.com/reader/full/chatscript-advanced-user-manual 2/40

A8*A/C.8 C(/C.&"S

Concepts can have part of speech information attached to them (using dictionar!sstem.h values". #g.

concept$ %mnouns &'& &'&)*+&,-R (bodead fotrot"

concept$ %madectives #C+# #C+#)5*+C (moon di6cious"*ince the script compile issues 7arning messages on 7ords it doesnt recogni6e9 in caseou misspelled them9 ou can also add +,&'R#*:#--+&, as a flag on the concept$

concept$ %un;no7n7ords +,&'R#*:#--+&, (asl daghh"and ou can combine pos declarations and ignorespelling.

 &ormall if ou declare a concept a second time9 the sstem considers that an error. +fou add the mar;er <'R# to its definition9 it 7ill allo7 ou to augment an eisting list.  concept$ %cit <'R# (o;o"

A8*A/C.8 "(&CS

here are several things to ;no7 about advanced topics.

"opic .xecution

=hen a topic is eecuting rules9 it does not stop ust because a rule matches. +t 7ill ;eepeecuting rules until some rule generates ouput for the user or something issues anappropriate >end or >fail call. *o ou can do things li;e this$

u$ (+ love" ?userloves @ trueu$ ( dog " ?animal @ dogu$ ( love" ,lad to hear itu$ ( dog" + hate dogsand given A+ love dogsB9 the sstem 7ill set ?userloves and ?animal and output glad tohear it.

"opic Control 1lags

he first are topic flags9 that control a topics overall behavior. hese are placed bet7eenthe topic name and the ( ;e7ords list". ou ma have multiple flags. #.g.

topic: ~rust keep random [rust iron oxide]

he flags and their meanings are$

:andom -  search rules randoml instead of linearl/o:andom D (default" search rules linearl

=eep D do not erase responders ever. ,ambits (and reoinders" are not affected b this..rase D (default" erase responders that successfull generate output. (,ambits

automaticall erase unless ou suppress them specificall.

2

Page 3: ChatScript Advanced User Manual

7/26/2019 ChatScript Advanced User Manual

http://slidepdf.com/reader/full/chatscript-advanced-user-manual 3/40

/oSta< D do not consider this a topic to remain in9 leave it (ecept for reoinders".Sta< D (default" ma;e this a pending topic 7hen it generates output

:epeat ! allo7 rules to generate output 7hich has been output recentl/o:epeat D (default" do not generate output if it matches output made recentl

&riorit<! raise the priorit of this topic 7hen matching ;e7ords/ormal! (default" give this topic normal priorit 7hen matching ;e7ords8eprioriti>e D lo7er the priorit of this topic 7hen matching ;e7ords

S<stem D this is a sstem topic. +t is automaticall &o*ta9 Eeep. Eeep automaticallapplies to gambits as 7ell. he sstem never loo;s to these topics for gambits.*stem topics can never be considered pending (defined shortl". he can nothave themselves or their rules be enabled or disabled. heir status/data is neversaved to user files.

User ! (default" this is a normal topic.

/oBloc?ing ! $verif should not perform an bloc;ing tests on this topic

/o&atterns 0 $verif should not perform an pattern tests on this topic

/oSamples 0 $verif should not perform an sample tests on this topic

/o=e<s ! $verif should not perform an ;e7ord tests on this topic

More D &ormall if ou tr to redeclare a concept9 ou get an error. <'R# tells C* ouintend to etend the topic and allo7s additional ;e7ords for it.

Bot@name D if this is given9 onl named bots are allo7ed to use this topic. ou can namemultiple bots separated b commas 7ith no etra spaces. #.g.9

topic: ~mytopic bot=harry,,roman [mykeyword]o support multiple bots9 ou ma create multiple copies of a topic name9 7hich var intheir bot restrictions and content. he set of ;e7ords given for a topic is the union of the;e7ords of all copies of that topic name. ou should not name a topic ending in a periodand a number (that is used internall to represent multiple topics of the same name".

-#ot name ! here is also a top level command ou can put in a file to label all topicsthereafter 7ith a uniform bot restriction. $bot name 7ill do this9 unless the topic has aneplicit bot@ou can9 for eample9 put at the topic of simpletopic.top the command

 bot$ harr9georgiaand get all topics in that file restricted to the t7o bots named. here should be no spacesafter the comma. 'f course there are onl t7o bots in the first place9 so this doesntactuall accomplish anthing useful.

Share  &ormall9 if ou have multiple bots9 the all tal; independentl to the user. =hatone learns or sas is not available to the other bots. +t is possible to create a collection of

3

Page 4: ChatScript Advanced User Manual

7/26/2019 ChatScript Advanced User Manual

http://slidepdf.com/reader/full/chatscript-advanced-user-manual 4/40

 bots that all can hear 7hat has been said and share information. Share on a topic meansthat all bots 7ill have common access/modification of a topics state. *o if one bot usesup a gambit9 the other bots 7ill not tr to use that gambit themselvs. ll facts created7ill be visible to all bots. nd if ou create a permanent user variable 7ith the startingname ?share)9 then all bots can see and modif it. *o ?share)name becomes a common

variable. =hen sharing is in effect9 the state 7ith the user (7hat he said9 7hat bot said97hat turn of the volle this is9 7here the reoinder mar; is" is all common among the bots! the are advancing a oint conversation.

:ules that erase and repeat

 &ormall a rule that successfull generates output directl erases itself so it 7ont runagain. ,ambits do this and responders do this.

,ambits 7ill erase themselves even if the dont generate output. he are intended totell a stor or progress some action9 and so do their thing and then disappear

automaticall.

Reoinders dont erase individuall9 the disappear 7hen the rule the are controlled bdisappears. rule that is mar;ed ;eep 7ill not erase itself. &or 7ill responders in a topicmar;ed ;eep (but gambits still 7ill".

Responders that cause others to generate output 7ill not normall erase themselves$  u$ (F" respond(%reactor"

+f the above rule causes output to be generated9 this rule 7ont erase itself9 the ruleinvo;ed from the %reactor topic that actuall generated the output 7ill erase itself. 5ut9 ifthe rule generating the output is mar;ed ;eep9 then since someone has to pa the price for output9 it 7ill be this calling rule instead.

Repeat does not stop a rule from firing9 it merel suppresses its output. *o the rule fires9does an other effects it might have9 but does not generate output. Gor a responder9 if itdoesnt generate output9 then it 7ont erase itself. Gor a gambit9 it 7ill because gambitserase themselves regardless of 7hether the generate output or not.

=e<words vs Control Script

topic can be invo;ed as a result of its ;e7ords or b a direct call from the controlscript or some other topic. +f ou intend to call it from script9 then there is almost neveran reason to give it ;e7ords as 7ell9 because that ma result in it being called t7ice97hich is 7asteful9 or out of order9 if there 7as a reason for the point ou called it fromscript.

4

Page 5: ChatScript Advanced User Manual

7/26/2019 ChatScript Advanced User Manual

http://slidepdf.com/reader/full/chatscript-advanced-user-manual 5/40

&ending "opics

he second thing to ;no7 is 7hat ma;es a topic pending. Control flo7 passes throughvarious topics9 some of 7hich become pending9 meaning one 7ants to continue in thosetopics 7hen tal;ing to the user. opics that can never be pending are$ sstem topics9

 bloc;ed topics (ou can bloc; a topic so it 7onHt eecute"9 and nosta topics.

=hat ma;es a remaining topic pending is one of t7o things. #ither the sstem iscurrentl eecuting rules in the topic or the sstem previousl generated a user responsefrom the topic. =hen the sstem leaves a topic that didnHt sa anthing to the user9 it isno longer pending. 5ut once a topic has said something9 the sstem epects to continue inthat topic or resume that topic.

he sstem has an ordered list of pending topics. he order is$ 1st! being 7ithin that topiceecuting rules no79 2nd! the most recentl added topic (or revived topic" is the most pending.. ou can get the name of the current most pending topic (%topic"9 add pending

topics ourself (^addtopic(""9 and remove a topic off the list (^poptopic("".

:andom am#it

he third thing about topics is that the introduce another tpe9 the random gambit9 r:.

he topic gambit t: eecutes in seIuence forming in effect one big stor for the durationof the topic. ou can force them to be dished randoml b setting the random flag on thetopic9 but that 7ill also randomi6e the responders. nd sometimes 7hat ou 7ant is semi!randomness in gambits. hat is9 a topic treated as a collection of subtopics for gambit purposes.

his is r:  he engine selects an r: gambit randoml9 but an t: topic gambits that follo7it up until the net random gambit are considered AattachedB to it. he 7ill be eecutedin seIuence until the are used up9 after 7hich the net random gambit is selected.

opic: ~beach [beach sand ocean sand!castle]" subtopic about swimming r: #o you like the ocean$  t: like swimming in the ocean.  t: o&ten go to the beach to swim." subtopic about sand castles.r: 'a(e you made sand castles$

a: )~yes* +aybe sometime you can make some that can go see.a: )~no* admire those who make luxury sand castles.

  t: (e seen pictures o& some really grand sand castles.

his topic has a subtopic on s7imming and one on sand castles. +t 7ill select the subtopicrandoml9 then over time ehaust it before moving onto the other subtopic.

 &ote an t$ gambits occurring before the first r$ gambit9 7ill get eecuted linearl untilthe r$ gambits can fire.

J

Page 6: ChatScript Advanced User Manual

7/26/2019 ChatScript Advanced User Manual

http://slidepdf.com/reader/full/chatscript-advanced-user-manual 6/40

(verview o$ the control script

 &ormall ou start using the sstem 7ith the pre!given control script. 5ut its ust a topicand ou can modif it or 7rite our o7n.

he tpical flo7 of control is for the control script to tr to invo;e a pending reoinder.his allo7s the sstem to directl test rules related to its last output9 rules that anticipateho7 the user 7ill respond. nli;e responders and gambits9 the engine 7ill ;eep tringreoinders belo7 a rule until the pattern of one matches and the output doesnHt fail. &otfailing does not reIuire that it generate user output. <erel that it doesnHt return a failcode. =hereas responders and gambits are tried until user output is generated (or ou runout of them in a topic".

+f no output is generated from reoinders9 the sstem 7ould test responders. Girst in thecurrent topic9 to see if the current topic can be continued directl. +f that fails to generate

output9 the sstem 7ould chec; other topics 7hose ;e7ords match the input to see ifthe have responders that match. +f that fails9 the sstem 7ould call topics eplicitlnamed 7hich do not involve ;e7ords. hese are generic topics ou might have set up.

+f finding a responder fails9 the sstem 7ould tr to issue a gambit. Girst9 from a topic7ith matching ;e7ords. +f that fails9 the sstem 7ould tr to issue a gambit from thecurrent topic. +f that fails9 the sstem 7ould generate a random gambit.

'nce ou find an output9 the 7or; of the sstem is nominall done. +t records 7hat rulegenerated the output9 so it can see reoinders attached to it on net input. nd it recordsthe current topic9 so that 7ill be biased for responding to the net input. nd then thesstem is done. he net input starts the process of tring to find appropriate rules ane7.

here are actuall three control scripts (or one invo;ed multiple 7as". he first is the preprocess9 called before an user sentences are anal6ed. he main script is invo;ed foreach input sentence. he postprocess is invo;ed after all user input is complete. +t allo7sou to eamine 7hat 7as generated (but not to generate ne7 output".

K

Page 7: ChatScript Advanced User Manual

7/26/2019 ChatScript Advanced User Manual

http://slidepdf.com/reader/full/chatscript-advanced-user-manual 7/40

A8*A/C.8 &A"".:/S

=e<word &hrases

ou cannot ma;e a concept out 7ith a member 7hose string includes starting or trailing

 blan;s9 li;e A L A. *uch a 7ord could never match as a pattern9 since spaces are s;ippedover. 5ut ou can ma;e it respond to idiomatic phrases and multiple 7ords. ust put themin Iuotes. #.g.9 concept$ %remove ( Ata;e a7aB remove "

 &ormall in patterns ou can 7riteM$ ( do ou ta;e a7a cheese"

and the sstem 7ill match sentences 7ith those 7ords in order. +n =ord&et9 some 7ordsare actuall composite 7ords li;e $ )sho7. =hen ou do $prepare on what is your &a(orite - show ou 7ill discover that the engine has merged )sho7 into onecomposite 7ord. he sstem has no trouble matching inputs 7here the 7ords are splitapart

M$ (7hat is our favorite sho7 "5ut if ou tried a 7ord memori6e li;eM$ (7hat is our favorite F1 F1"

that 7ould fail because the first F1 memori6es -!show and there is therefore no second7ord to memori6e. -i;e7ise 7hen ou 7rite concept: ~(iewing )- show/ * thesstem can match that concept readil also. +n fact9 7henever ou 7rite the Iuoted;e7ord phrase9 if all its 7ords are canonical9 ou can match canonical and non!canonincal forms. A sho7B matchs - shows as 7ell as - show.

8ictionar< =e<word sets

+n Chat*cript9 =ord&et ontologies are invo;ed b naming the 7ord9 a %9 and the inde of the meaning ou 7ant.

concept: ~buildings [ shelter~0 li(ing!accomodations~0 building~1 ]he concept ~buildings represents NK0 general and specific building 7ords found in the=ord&et dictionar D an 7ord 7hich is a child of$ definition 1 of shelter9 definition 1 ofaccommodations9 or definition 3 of building in =ord&etHs ontolog. Oo7 7ould ou beable to figure out creating thisM his is described under :up in Word Commands later. 2uilding~1 and building~1n are eIuivalent. he first is 7hat ou might sa to refer to the3rd meaning of building. +nternall building~1n denotes the 3rd meaning and its a nounmeaning. ou ma see that in printouts from Chatscript. +f ou 7rite 3n ourself9 thesstem 7ill strip off the n mar;er as superfluous.

*imilarl ou can invo;e parts of speech classes on 7ords. 5 default ou get all ofthem. +f ou 7rite$ concept: ~beings [snake mother ]then a sentence li;e  like mothering my baby 7ould trigger this concept9 as 7ould 'e snaked his way through the grass.  5ut the engine has a dictionar and a part!of!speechtagger9 so it often ;no7s 7hat part of speech a 7ord in the sentence is. ou can use thatto help prevent false matches to concepts b adding ~n ~( ~a or ~b (adverb" after a 7ord.

concept: ~beings [snake~n mother~n]

N

Page 8: ChatScript Advanced User Manual

7/26/2019 ChatScript Advanced User Manual

http://slidepdf.com/reader/full/chatscript-advanced-user-manual 8/40

+f the sstem isnHt sure something is onl a noun9 it 7ould let the verb match still. hus auser single!7ord repl of snakes 7ould be considered both noun and verb.

he notation run%4K eists to represent a meaning. here is mild inherent danger that +might ;ill off some 7ord meaning that is problematic (eg if run%23 turned out mar; the

%curses set and + didnt 7ant the resulting confusion"9 said ;ill off might strand ourmeaning b renumbering into either non!eistence (in 7hich case the script compiler 7ill7arn ou" or into a different pos set (because our meaning 7as on the boundar ofmeanings of a different pos tpe". se of the specific meaning is hand in definingconcepts 7hen the meaning is a noun9 because =ordnet has a good noun ontolog. se of the specific meaning of other parts of speech is more Iuestionable9 as =ordnet does nothave much ontolog for them. he broader scope meaning restriction b part!of!speech (eg run%v" has much moreutilit. +t has its ris;s in that it depends on the parser getting it right (as ou have seen"97hich over time 7ill get better and better. +n <'* cases9 ou are better off 7ith the full

fledged unadorned 7ord9 7hich is parse!independent. his is particularl true 7hen ouare pattern matching adacent 7ords and so contet is firm. P run %app is a prett cleancontet 7hich does not need pos!certification. he topic on %drugs 7ould 7ant in its;e7ord list clean%a to allo7 Q+ve been clean for monthsQ to target it9 but not Q+ cleanm houseQ.

S<stem 1unctions

ou can call an predefined sstem function. +t 7ill fail the pattern if it returns an fail or end code. +t 7ill pass other7ise. he most li;el functions ou 7ould call 7ould be$

>Iuer D to see if some fact data could be found.<an functions ma;e no sense to call9 because the are onl useful on output and their behavior on the pattern side is unpredictable.

ou cannot omit the > prefi. he sstem has no 7a to distinguish it other7ise.

Macros

ust as ou can use sets to AshareB data across rules9 ou can also 7rite macros to sharecode. patternmacro is a top!level declaration that declares a name9 arguments that can be passed9 and a set of script to be eecuted Aas though the script code 7ere in place ofthe original callB. <acro names can be ordinar names or have a > in front of them. hearguments must al7as begin 7ith >. he definition ends 7ith the start of a ne7 top!leveldeclaration or end of file. #.g.

 patternmacro: ^3'4567875)^who*9[not ne(er][ 

) be ^who [blonde brunette redhead blond ] ;; *) what ^who hair color ;; *

 ]

8

Page 9: ChatScript Advanced User Manual

7/26/2019 ChatScript Advanced User Manual

http://slidepdf.com/reader/full/chatscript-advanced-user-manual 9/40

$: )^3'4567875)** 'ow would know your hair color$

he above patternmacro ta;es one argument (7ho 7e are tal;ing about". fter chec;ingthat the sentence is not in the negative9 it uses a choice to consider alternative 7as ofas;ing 7hat the hair color is. he first 7a matches are you a redhead . he second 7a

matches what is my hair color . he call passes in the value  (7hich 7ill also match mymine etc in the canonical form". #ver place in the macro code 7here >7ho eists9 theactual value passed through 7ill be used.

ou cannot omit the > prefi in the call. he sstem has no 7a to distinguish itother7ise.

=hereas most programming language separate their arguments 7ith commas becausethe are reserved to;ens in their language9 in Chat*cript a comma is a normal 7ord. *oou separate arguments to functions ust 7ith spaces.

$: ) ^<i(e4rg<unction) 0 1 my , word**

=hen a patternmacro ta;es a single argument and ou 7ant to pass in several9 ou can7rap them in parens to ma;e them a single argument. 'r sometimes brac;ets. #.g.9

$: ) ^#oou#ohis) )play > baseball* * * es do$: ) ^#oou#ohis) [swim sur& scuba di(e/] * es do

+f ou call a patternmacro 7ith a string argument9 li;e Ascuba diveB above9 the sstem7ill convert that to its internal single!to;en format ust as it 7ould have had it been partof a normal pattern. uoted strings to output macros are treated differentl and left instring form 7hen passed.

ou can also declare something dualmacro$ 7hich means it can be used in both patternand output contets.

iteral /ext

+f ou need to test a character that is normall reserved9 li;e ( or S9 ou can put a bac;slash in front of it.

 s: ) ?) > ?* * @hy are you saying that aside$

5uestion and exclamation 2 DE

 &ormall ou alread ;no7 that an input 7as a Iuestion because ou used the ruletpe M$ . 5ut reoinders do not have rule tpes9 so if ou 7ant to ;no7 if something 7as aIuestion or not9 ou need to use the M ;e7ord. +t doesnHt change the match position

t: #o you like germs$a: )$* @hy are you asking a Auestion instead o& answering me$a: )9$* appreciate your statement.

+f ou 7ant to ;no7 if an eclamation ended his sentence9 ust bac;slash a T so it 7onHt be treated as a not reIuest. his doesnHt change the match position.

 s: ) like ?* @hy so much excitement 

U

Page 10: ChatScript Advanced User Manual

7/26/2019 ChatScript Advanced User Manual

http://slidepdf.com/reader/full/chatscript-advanced-user-manual 10/40

More comparison tests F and 2

ou can use the logical and  bit!relation to test numbers. n non!6ero value passes. s: ) !~number !BC0* our number is odd.

M can be used in t7o 7as. s a comparison operator9 it allo7s ou to see if the item onthe left side is a member of a set on the right. #.g.

u$ ()%propernameM%bands"

s a standalone9 it allo7s ou to as; if a 7ildcard or variable is in the sentence. #.g.u$ ( )1M "u$ ( ?botM "

Comparison with CGG Hde$ine in dictionar<s<stemh

ou can name a constant from that file as the right hand side of a comparison test b prefiing its name 7ith V. #.g.9 s: ) !~number !B="D7ED*

*uch constants can be done an7here9 not ust in a pattern.

Current "opic I 

ou can as; if the sstem is currentl in a topic via %. his 7ill consult the pending topicslist9 and if the topic is there9 it is considered in that topic. #.g.9

u$ ( chocolate % " + love chocolate ice cream.he above does not match an use of chocolate9 onl one 7here 7e are alread in thistopic (li;e topic$ %ice)cream".

useful idiom is S%topicname %W. his allo7s ou to match if #+O#R the user gave;e7ords of the topic 'R ou are alread in the topic. *o$

u$ (PPchocolate S%ice)cream %W XX"7ould match if ou onl said AchocolateB 7hile inside the topic9 or if ou said Achocolateice creamB 7hile outside the topic.

&re$ix Wildcard Spelling and &ost$ix Wildcard Spelling

*ome 7ords ou ust ;no7 people 7ill get 7rong9 li;e *chrodingers cat or *agittarius.ou can reIuest a partial match b using an F to represent an number of letters (includig0". Gor eample

u$ ( *agF" his matches *agittarius in a variet of misspellings.u$ (Ftor" this matches AreactorB.

he F can occur in one or more positions and means 0 or more letters match. period can be used to match a single letter (but ma not start a 7ildcardprefi". #.g.9

u$ ( p.tF"can match pituitary or merel pit  or pat . ou cannot use a 7ildcard on the first letter ofthe pattern.

10

Page 11: ChatScript Advanced User Manual

7/26/2019 ChatScript Advanced User Manual

http://slidepdf.com/reader/full/chatscript-advanced-user-manual 11/40

u$ (.pF" is not legal because it ma not start 7ith a period.

ndirect pattern elements

<ost patterns are eas to understand because 7hat 7ords the loo; at is usuall staring

ou in the face. =ith indirection9 ou can pass patterndata from other topics9 at a cost ofobscurit. eclaring a macro does this. > normall means a macro call (if 7hat follo7sit is arguments in parens"9 or a macro argument. he contents of the macro argument areused in the pattern in its place. <acro arguments onl eist inside of macros. 5ut macrosdonHt let ou 7rite rules9 onl pieces of rules.

 &ormall ou use a variable directl. ??tmp @ nil clears the ??tmp variable9 forinstance9 7hile u: ) * FFtmp goes home 7ill output the value into the output stream.

he functional user argument lets ou pass pattern data from one topic to another. s: ) are you a !^F(ar *

he contents of ?var are used at that point in the pattern. <abe it is a set being named.<abe itHs a 7ord. ou can also do 7hole epressions9 but if ou do ou 7ill be at ris; because ou 7onHt have the script compiler protecting ou and properl formatting ourdata. *ee also dvanced ariables.

Setting Match &osition 0 @J!Y @J!!

ou can Abac; upB and continue matching from a prior match position using Z follo7ed b a match variable previousl set. #.g.u$ ()%pronoun F go Z)0Y often" his matches A+ often goB but not A+ goB

ust as P sets the position pointer to the start9 Z)0Y ma;es the pattern thin; it ustmatched that 7ildcard at that location in the sentence going for7ard.

 s: ) !is !~she *  V for input$ is mother going this sets !B to is and !0 to mother  s: ) G!0H going * V this completes the match of is mother going 

'E. *etting positional contet is reall obscure and probabl not for ou. *o 7h does iteistM +t supports shared code for pseudo parsing.

ou can match either for7ards or bac;7ards. &ormall matching is al7as donefor7ards. 5ut ou can set the direction of matching at the same time as ou set a position.Gor7ard matching is Z)nY and bac;7ard matching is Z)n!.

Bac?ward Wildcards

ou can reIuest n 7ords before the current position using F!n. Gor eampleu$ (+ love F X )F!1 " capture last 7ord of sentence

or< details a#out strings

11

Page 12: ChatScript Advanced User Manual

7/26/2019 ChatScript Advanced User Manual

http://slidepdf.com/reader/full/chatscript-advanced-user-manual 12/40

u$ ( + Ata;e chargeB " 'E.

=hen ou use Qta;e chargeQ it can match ta;ing charges9 ta;e charge9 etc. =hen ou useQta;ing chargeQ it can onl match that9 not Qta;ing charges. +f all 7ords in the string arecanonical9 it can cover all forms. +f an are not9 it can onl literall match.

 he Iuote notation is tpicall used in several situations...

1. ou are matching a recogni6ed phrase so Iuoting it emphasi6es that2. 7hat ou are matching contains embedded punctuation and ou dont 7ant to thin;about ho7 to to;eni6e it e.g.9 Q<rs. =atsonsQ !! is the period part of <rs9 is the part of=atson9 etc. #asier ust to use Iuotes and let the sstem handle it.3. ou 7ant to use a phrase inside SW or [\ choices. -i;e S li;e live Areall enoBW

+n actualit9 7hen ou Iuote something9 the sstem generates a correctl to;eni6ed set of7ords and oins them 7ith underscores into a single 7ord.nhere is no real difference

 bet7een Qgo bac;Q and go)bac; in a pattern.

 5ut compared to ust listing the 7ords in seIuence in our pattern9 a Iuoted epressioncannot handle optional choices of 7ords. ou cant 7rite Qgo [reall almost\ bac;Q7here that can match go back   or go almost back . *o there is that limitation 7hen using astring inside SW or [\. 5ut9 one can 7rite a pattern for that. =hile SW means a choice of7ords and [ \ means a choice of optional 7ords9 ( " means these things in seIuence. *oou could 7rite$

u$ ( S net before (go [almost reall\ bac;" W "and that 7ill be a more comple pattern. 'ne almost never has a real use for thatcapabilit9 but ou use (" notation all the time9 of course. +n fact9 all rules have animplied P F in front of the (". hats 7hat allo7s them to find a seIuence of 7ordsstarting an7here in the input. 5ut 7hen ou nest (" inside9 unless ou 7rite P F ourself9ou are committed to remaining in the seIuence set up.

s a side note9 the Iuoted epression is faster to match than the ( " one. hats becausethe cost of matching is linear in the number of items to test. nd a Iuoted epression (orthe ) eIuivalent" is a single item9 7hereas ( ta;e charge" is 4 items. *o the first rule 7ill belo7 7ill match faster than the second rule$

u$ ( A+ love ou toda 7henB"u$ (+ love ou toda 7hen"

5ut Iuoted epressions onl 7or; up to J 7ords in the epression (one rarel has a needfor more" 7hereas (" notation ta;es an number. nd using Iuotes 7hen it isnt acommon phrase is obscure and not 7orth doing.

enerali>ing a pattern word

=hen ou 7ant to generali6e a 7ord9 a hand thing to do is tpe $concepts 7ord and see7hat concepts it belongs to9 pic;ing a concept that most broadl epresses our meaning.he sstem 7ill sho7 ou both concepts and topics that encompass the 7ord. 5ecause

12

Page 13: ChatScript Advanced User Manual

7/26/2019 ChatScript Advanced User Manual

http://slidepdf.com/reader/full/chatscript-advanced-user-manual 13/40

topics are more unreliable (contain or ma in the future contain 7ords not appropriate toour generali6ation9 topics are al7as sho7n a % rather than the mere %name.

"he deep view o$ patterns

 ou normall thin; of the pattern matcher as matching 7ords from the sentence. +tdoesnt. +t matches mar;s. mar; is an arbitrar tet string that can be associated 7ith asentence location. he actual 7ords (but not necessaril the actual case ou use" are ustmar;s placed on the actual locations in the sentence 7here the 7ords eist. he canonicalforms of those 7ords are also such mar;s. s are the concept set names and topic names7hich have those 7ords as ;e7ords. nd all parser determined pos!tag and parser rolesof 7ords.

+t gets interesting because mar;s can also cover a seIuential range of locations. hatsho7 the sstem detects phrases as ;e7ords9 idioms from the parser li;e  am a little bitcraIy (7here a little bit  is an adverb covering 3 sentence locations" and contiguous

 phrasal verbs.

nd there are functions ou can call to set or erase mar;s on our o7n (>mar; and>unmar;".

:attern matching involves loo;ing at to;ens 7hile having a current sentence locationinde. nless ou are using a 7ildcard9 our to;ens must occur in contiguous order tomatch. s the match9 the current sentence location is updated. 5ut not necessarilupdated to the net adacent location. +t 7ill depend on the length of the mar; beingmatched. *o our to;en might be %adverb but that ma match a multiple!7ord seIuence9so the location inde 7ill be updated to the end of that inde.

nd ou can pla 7ith the location inde itself9 setting it to the location of a previouslmatched ) variable and setting 7hether matching should proceed for7ards or bac;7ardsthrough the sentence. Reall9 the actual capabilities of pattern matching are Iuiteoutrageous.

nteresting thing a#out match varia#les

nli;e user variables9 7hich are saved 7ith users9 match variables (li;e )0" are global toChat*cript. he are initiali6ed on startup and never destroed. he are over7ritten b arule that forces a match value onto them and b things li;e )0 @ >burst(.." or )3 @>first(Z0all". nd those ma overrun the needed number of variables b 1 to indicate theend of a seIuence. 5ut this means tpicall )10 and above are easil available as permanent variables that can hold values across all users etc. his might be hand in aserver contet and is definitel hand in $document mode 7here user memor can bever transient. 'f course remembering 7hat )10 means as a holding variable is harder9unli;e the ones bound to matches from input. *o ou can use

rename$ )bettername )12in a script before an uses of )bettername9 7hich no7 mean )12.

13

Page 14: ChatScript Advanced User Manual

7/26/2019 ChatScript Advanced User Manual

http://slidepdf.com/reader/full/chatscript-advanced-user-manual 14/40

A8*A/C.8 (U"&U"

*imple output puts 7ords into the output stream9 a magical place that Iueues up each7ord ou 7rite in a rule output. =hat + didnHt tell ou before 7as that if the rule failsalong the 7a9 an incomplete stream is canceled and sas nothing to the user.

Gor eample9t$ + love this rule. >fail(R-#":rocessing the above gambits successivel puts the 7ords A+B9 AloveB9 AthisB9 AruleB9 A.Binto the output stream of that rule. +f some7here along the 7a that rule fails (in thiscase b the call at the end"9 the stream is discarded. +f the rule completes and this is a toplevel rule9 the stream is converted into a line of output and stored in the responses list.=hen the sstem is finished processing all rules9 it 7ill displa the responses list to theuser9 in the order the 7ere generated (unless ou used >preprint or >insertprint togenerate responses in a different order". +f the output 7as destined for storing on avariable or becoming the argument to a function or macro9 then the output stream is

stored in the appropriate place instead.

+ also didnHt tell ou that the sstem monitors 7hat it sas9 and 7onHt repeat itself (even if from a different rule" 7ithin the last 20 outputs. *o if9 7hen converting the output streaminto a response to go in the responses list9 the sstem finds it alread had such a responsesent to the user in some recentl earlier volle9 the output is also discarded and the ruleAfailsB.

ctuall9 its a bit more complicated than that. -ets imagine a stream is being built up.nd then suddenl the rule calls another rule (>reuse9 >gambit9 >repond". =hat happensM#.g.9 u$ (some test" + li;e fruit and vegetables. >reuse(C'<<'&" nd so do ou.=hat happens is this! 7hen the sstem detects the transfer of control (the >reuse call"9 ifthere is output pending it is finished off and pac;aged for the user. he current stream iscleared9 and the rule is erased (if allo7ed to be". hen the >reuse(" happens. #ven if itfails9 this rule has produced output and been erased. ssuming the reuse doesnt fail9 it7ill have sent 7hatever it 7ants into the stream and been pac;aged up for the user. herest of the message for this rule no7 goes into the output stream (Aand so do ouB" andthen that too is finished off and pac;aged for the user. he rule is erased because it hasoutput in the stream 7hen it ends (but it 7as alread erased so it doesnt matter".

1ormatted dou#le Kuotes L1ormat String

5ecause ou can intermi program script 7ith ordinar output 7ords9 Chat*criptnormall autoformats output code. 5ut programming languages allo7 ou to controlour output 7ith format strings and Chat*cript is no eception. +n the case of Chat*cript9the functional string ^/xxx/ string is a format string. he sstem 7ill remove the > andthe Iuotes and put it out eactl as ou have it9 except 9 it 7ill substitute variables (7hichou learn about shortl" 7ith their values and it 7ill accept S W SW choice bloc;s. nd 7illallo7 function calls. ou cant do assignment statements or loops or if statements.

t: ^ like you./ puts out   like you.

14

Page 15: ChatScript Advanced User Manual

7/26/2019 ChatScript Advanced User Manual

http://slidepdf.com/reader/full/chatscript-advanced-user-manual 15/40

=hen ou 7ant special characters in the format string li;e S W and ( "9 ou need to bac;slash them9 7hich the format string removes 7hen it eecutes. Gor eample$

u: )* Ftmp = [ hi ^/there [ ] John/ ]the brac;ets inside the format string 7ill confuse the choices code of output unless ou protect it using ]S and ]W .

Gormat strings evaluate themselves as soon as the can. +f ou 7rite$u: )* Ftmp = ^/ his is F(ar output/

then ?tmp 7ill be set to the result of evaluating the format string. *imilarl9 if ou 7rite$u: )* Ftmp = ^my&unc)^/ his is F(ar output/*

then the format string is evaluated before being sent to >mfunc.

ou can continue a format string across multiple source lines. +t 7ill al7as have a singlespace representing the line change9 regardless of ho7 man spaces 7ere before or afterthe line brea;. #.g>Bthis is

  m lifeB ^ >Bthis is m lifeBregardless of 7hether there 7ere no spaces after is or 100 spaces after is. ou ma nothave comments at the ends of such lines (the 7ould be absorbed into the string".

1unctional Strings

=henever format strings are placed in tables9 the become a slightl different flavor9called functional strings. he are li;e regular output! the are literall output script.Gormatting is automatic and ou get to ma;e them do an ;ind of eecutable thing9 asthough ou 7ere staring at actual output script. *o ou lose the abilit to control spacing9 but gain full other output eecution abilities.

he have to be different because there is no user contet 7hen compiling a table. s aconseIuence9 if ou have table code that loo;s li;e this$

>createfact( >B his is ?var outputB"the functional string does &' evaluate itself before going to createfact. +t gets stored asits original self.

=e 7ill no7 learn functions that can be called that might fail or have interesting othereffects. nd some control constructs.

oop Construct

he loop allo7s ou to repeat script. +t ta;es an optional argument 7ithin parens9 7hichis ho7 man times to loop. +t eecutes the code 7ithin [ \ until the loop count epires oruntil a G+- or #& code of some ;ind is issued. Gail(rule" and #nd(rule" signal merelthe end of the loop9 not reall the rule9 and 7ill not cancel an pending output in theoutput stream. ll other return codes have their usual effect.

t: 'ello. loop )K* L me M

1J

Page 16: ChatScript Advanced User Manual

7/26/2019 ChatScript Advanced User Manual

http://slidepdf.com/reader/full/chatscript-advanced-user-manual 16/40

t: loop )* L his is &ore(er, not. &ail)5E8N*Mhe first gambit prints 'ello. me me me me me. he second loop 7ould print forever9 butactuall prints out his is &ore(er, not. because after starting output9 the loop isterminated. -oop also has a built in limit of 1000 so it 7ill never run forever.

$ Construct

he if allo7s ou to conditionall eecute bloc;s of script. he full snta is$ & ) test0 * L script0 M else i& ) testO * L scriptO M P else L script1 M

ou can omit the else i&  section9 having ust i& and else, and ou can omit the else section9having ust i&  or i& and else i& . ou ma have an number of else i&  sections.he test condition can be$

1. variable D if it is defined9 the test passes2. T variable D if it is not defined9 the test passes (same as relation variable @@ null"3. function call D if it doesnHt fail or return the values 0 or null or nil9 it passes4. relation D one of @@ T@ P P@ X X@ M TM

Gor the purposes of numeric comparison (P P@ X X@" a null value compared against anumber 7ill be considers as 0.ou ma have a series of test conditions separated b & and 'R. he failure of thetest condition can be an end  or &ail  code. +t does not affect outside the condition_ itmerel controls 7hich branch of the i& gets ta;en.

i& )F(ar* L M " i& F(ar has a (aluei& )F(ar == K and &oo)1** LM " i& F(ar is K and &oo)1* doesnt &ail

Comparison tests bet7een t7o tet strings is case insensitive.

5uoting

  &ormall output evaluates things it sees. his includes ?user variables9 7hich print outtheir value. 5ut if ou put Iuote in front of it9 it prints its o7n name. ?name 7ill print?name. he eception to this rule is that internal functions that process their o7narguments uniIuel can do 7hat the 7ant9 and the Kuer< function defines ?name tomean use the contents of ?name9 ust dont epand it if it is a concept or topic name asvalue.

*imilarl9 a function variable li;e >name 7ill pretend it 7as its content originall. hismeans if the value 7as ?var then9 had ?var been there in the output originall9 it 7ouldhave printed out its content. *o normall >name 7ill print out the contents of its content.gain9 ou can suppress 7ith using >name to force it to onl print its content directl.

(utputting underscores

 &ormal #nglish sentences do not contain underscores. =ordnet uses underscores incomposite 7ords involving spaces. Chat*cript9 therefore has a special use for underscoresinternall and if ou put underscores in our output tet9 7hen the are shipped to theuser the are converted to spaces. his doesnt appl to internal uses li;e storing onvariables. *o normall ou cannot output an underscore to a user. 5ut a 7eb address

1K

Page 17: ChatScript Advanced User Manual

7/26/2019 ChatScript Advanced User Manual

http://slidepdf.com/reader/full/chatscript-advanced-user-manual 17/40

might legitimatel contain underscores. *o9 if ou put t7o underscores in a ro79Chat*cript 7ill output a single underscore to the user.

(utput Macros

ust as ou can 7rite our o7n common routines for handling pattern code 7ith patternmacro:9 ou can do the same for output code. 7utputmacro: name )^arg0 ^argOP* and then our code. 'nl no7 ou use output script instead of pattern stuff. gain97hen calling the macro9 arguments are separated 7ith spaces and not commas.=hereas most programming language separate their arguments 7ith commas becausethe are reserved to;ens in their language9 in Chat*cript a comma is a normal 7ord. *oou separate arguments to functions ust 7ith spaces.

$: ) hi* ^<i(e4rg<unction) 0 1 my , word*

'utputmacros can return a value9 ust li;e a normal function. ou ust dump the tet asou 7ould a message to the user.

 outputmacro: ^mymac()  tested here

TOPIC: ~patterns keep repeat []

#! what tme s tu: ( "" what tme ) $test % ^mymac() &on(ok $test)

7ill print Ao;tested hereB.

dualmacro: name)...*  is eactl li;e outputmacro$9 but the function can be called on thenside or on the output side. picall this ma;es most sense for a function that performs afied >Iuer 7hich ou can see if it fails in pattern side or as a test on the output side orinside an if condition.

'utput macros can be passed sstem function names and output macro names9 allo7ingou to indirectl call things. #.g.9

outputmacro$ >indirect(>fn >value"??tmp @ >fn(>value"

he above 7ill evaluate >fn9 and if it finds that it is a function name9 7ill use that in acall. he onl tric; part is creating the name of the function to call in the first place. +fou ust 7rite a function name 7ith > in output9 the compiler 7ill complain about ourcall. *o ou have to snthesi6e the name someho7. Oere are t7o 7as$

outputmacro$ >mcall("??tmpfn @ >oin( >B]>B func"

>indirect(??tmpfn 34">indirect( >B]>funcB 34"

ou can also store function names on user and match variables and then call them. #.g.9??tmp @ >B]>funcB??tmp(34"

1N

Page 18: ChatScript Advanced User Manual

7/26/2019 ChatScript Advanced User Manual

http://slidepdf.com/reader/full/chatscript-advanced-user-manual 18/40

S<stem 1unctions

here are man sstem functions to perform specific tas;s. hese are enumerated in theChat*cript *stem Gunction manual and the Chat*cript Gacts manual.

:andomi>ed (utput :evisited NO

Remember this construct$$: )hi* ['ow are you &eeling$][@hy are you here$]

hese choices are pic;ed eIuall. 5ut mabe ou donHt 7ant some choices. ou can putan eistence test of a variable at the start of a choice to restrict it.

$: )hi* [Fready 'ow are you &eeling$][@hy are you here$]+n the above9 the first choice is controlled b ?read. +f it is undefined9 the choice cannot be used. ou can also use negative tests.

$: )hi* [9Fready this is a][his is b]+n the above onl if ?read is undefined can ou sa this is a

+f ou 7ant the variable to be a lead item in the actual output of a choice9 ou can do this$M$ (hi" S>eval(?read" is part of the outputW

or the more clun;$M$ (hi" )0 @ ?read S )0 is part of the outputW

Choices lead to issues 7hen ou 7ant reoinders. ou can label reoinder branches ofchoices. hose 7ithout labels default to a:

$: )what meat* [c: rabbit ] [e: steak] [ h: lamb] [pork]a: this reJoinders pork c: this reJoinders rabbit e: this reJoinders steak 

 &: this reJoinders on e:h: this reJoinders lamb

+n the above9 pork   reoinders at a:9 7hile the other choices name their reoinder value.#ach ne7 starting label needs to be at least one higher than the reoinder before it. hatallo7s the sstem to detect reoinders on reoinders from choice branches.

+f ou do both variable control and reoinder label9 the control comes first and label afterou have successful control.

$: )what meat* [Fready c: rabbit ] [e: steak] [ g: lamb] [pork]

18

Page 19: ChatScript Advanced User Manual

7/26/2019 ChatScript Advanced User Manual

http://slidepdf.com/reader/full/chatscript-advanced-user-manual 19/40

Advanced *aria#les

ndirection *aria#les

ou can9 of course9 merel refer to a variable in a script to set or get its value. 5ut ou

can also create a variable not eplicitl named in the script. ou can create a variablename simpl b using >oin(? " 7hich 7ould create the name ?. nd ou couldma;e that more dnamic b using a variable instead of 9 li;e

??tmp @ >oin(? )0"ou can set such variables using function notation >9 e.g.

>??tmp @ 2Jhe above sas ta;e the value of ??tmp9 treat it as the name of a variable9 and assign intoit. +f ou 7ant to get its value bac;9 ou can do

??val @ >eval(??tmp" V ??val becomes 2J

<an routines automaticall evaluate a variable 7hen using it as an argument9 li;e

>gambit(??tmp". 5ut if ou 7ant the value of the variable it represents9 then ou need toevaluate it another time.??tmp1 @ >??tmp>gambit(??tmp1"

ou currentl cannot use indirect directl in function calls9 so >gambit(>??tmp1" is notlegal.

*ee also +ndirect :attern #lements in dvanced :atterns.

Control (ver nput

he sstem can do a number of standard processing on user input9 including spellcorrection9 proper!name merging9 epanding contractions etc. his is managed b settingthe user variable ?to;en. he default one that comes 7ith Oarr is$$token % #'OIT*+,*CTIO-P.ITTI/ 0 #'O-12-TIT1T*-3-T*4 0 #'O142*+4*+/*0 #'OP+OP*+54*4*+/* 0 #'O-P*..C6*C7 0 #'OP5+-*

he V signals a named constant from the dictionar*stem.h file. 'ne can set thefollo7ing$hese enable various -+# files to perform substitutions on input$'O*--*TI5.- 8 per9orm .I*'5T5;systemessenta<s whch most<y strps o99 tra<n=punctuaton and sets correspondn= 9<a=s nstead>'O-12-TIT1T*- ? per9orm .I*'5T5;su@sttutes'OCOT+5CTIO- ? per9orm .I*'5T5;contractonsA eBpandn= contractons>

'OIT*+,*CTIO- ? per9orm .I*'5T5;nter&ectonsA chan=n= phrases tonter&ectons>'O2+ITI-6 ? per9orm .I*'5T5;@rtshA respe<<n= @rt words to 5mercan>'O-P*..I/ ? per9orms the .I*'5T5;spe<<n= 9<e (manua< spe<< correcton)'OT*TI/ ? per9orms the .I*'5T5;teBtn= 9<e (eBpand teBtn= notaton)'O-12-TIT1T*-3-T*4 ? do a<< .I*'5T5 9<e eBpansons

'OIT*+,*CTIO-P.ITTI/ ? @reak o99 <eadn= nter&ectons nto own sentence>'O142*+4*+/* ? mer=e mu<tp<e word num@ers nto one (D9our and twentyE)'OP+OP*+54*4*+/* ? mer=e mu<tp<e proper name nto one (D/eor=e 6arrsonE)

1U

Page 20: ChatScript Advanced User Manual

7/26/2019 ChatScript Advanced User Manual

http://slidepdf.com/reader/full/chatscript-advanced-user-manual 20/40

'O'5T*4*+/* ? mer=e month day and;or year seFuences (D,anuary GA HJE)

I9 any o9 the a@oKe tems a99ect the nputA they w<< @e echoed as Ka<ues ntoLtokenM<a=s so you can detect they happened>

The neBt chan=es do not echo nto LtokenM<a=s and re<ate to =rammar o9 nput:

'OPO-T5/ ? a<<ow pos8ta==n= (<a@e<s <ke ~noun ~Ker@ @ecome marked)'OP5+-* ? a<<ow parser (<a@e<s 9or word ro<es <ke ~mansu@&ect)'OCO'ITIO5.PO-T5/ ? per9orm pos8ta==n= on<y 9 a<< words are known> 5Kodswastn= tme on 9ore=n sentences n partcu<ar>O*+5-* ? where a su@sttuton wou<d de<ete a word entre<y as &unkA donNt>

orma<<y the system tres to out=uess the userA who cannot @e trusted to usecorrect punctuaton or casn= or spe<<n=> These @<ock that:-T+ICTC5-I/ ? eBcept 9or Hst word o9 a sentenceA assume user uses correct casn=on words>OIM*+1*-TIO ? the system w<< not try to set the 1*-TIO45+7 9<a= 9 theuser ddnNt nput a and the structure o9 the nput <ooks <ke a Fueston>'O-P*..C6*C7 8 per9orm nterna< spe<< checkn=O.3.O*+C5-* ? 9orce a<< nput (eBcept DIE) to @e <ower caseA re9use to

reco=nQe uppercase 9orms o9 anythn=

OI4P*+5TI* 8OIT6I 8O-*T*C**' 8

orma<<y the tokenQer @reaks apart some knds o9 sentences nto two> ThesepreKent that:O63P6**' ? donNt @reak apart a sentence a9ter a hyphenOCO.O*' ? donNt @reak apart a sentence a9ter a co<onO-*4ICO.O*' ? donNt @reak apart a sentence a9ter a sem8co<on

oteA you can chan=e $token on the 9<y and 9orce nput to @e reana<yQed Ka

^retry(-*T*C*)> I do ths when I detect the user s tryn= to =Ke hs nameA andmany 9ore=n names m=ht @e spe<<8corrected nto somethn= wron= and the user sun<ke<y to msspe<< hs own name> ,ust remem@er to reset $token @ack to norma<a9ter you are done> 6ere s one such wayA assumn= $stdtoken s set to your norma<token9<a=s n your @ot de9nton outputmacro:

#! my name s +o=r

s$ (name is )F"if (?to;en @@ ?stdto;en"[

?to;en @ V')+&#R#C+'&)*:-++&, `V')*5*+#)**#< ` V')&<5#R)<#R,# `

V'):R*#retr(*#&#&C#"\)0 is the name.?to;en @ ?stdto;en 

+f ou tpe Am name is RogrB into a topic 7ith this9 the original input is spell!correctedto Am name is RogerB9 but this 7ill change the ?to;en over to one 7ithout spellcorrection and redo the sentence9 7hich 7ill no7 come bac; 7ith Am name is RogrB and

20

Page 21: ChatScript Advanced User Manual

7/26/2019 ChatScript Advanced User Manual

http://slidepdf.com/reader/full/chatscript-advanced-user-manual 21/40

 be echoed correctl9 and ?to;en reset. hats assuming nothing else 7ould run differentland trap the response else7here. +f ou 7ere 7orried about that9 it 7ould be possible forthe script to save 7here it is using >getrule(tag" and modif our control script to returnimmediate control to here after input processing if ou had changed ?to;en.

=hile in general9 substitutions are defined in the -+# folder9 ou can define private substititions for our specific bot using the scripting language. ou can sa

replace: xxx yyyyy7hich defines a substitution ust li;e a livedata substitution file. +t actuall creates asubstitution file called pri(ateB.txt  or pri(ate0.txt in our ':+C folder. #ven then9 thosesubstitutions 7ill not be enacted unless ou eplicitl add to the ?to;en valueV'):R+#9 eg$token % #'OIT*+,*CTIO-P.ITTI/ 0 #'O-12-TIT1T*-3-T*4 0 #'O142*+4*+/*0 #'OP+OP*+54*4*+/* 0 #'O-P*..C6*C7 0 #'OP5+-* 0 #'OP+I5T*

(ut o$ #and Communication

Chat*cript can neither see nor act9 but it can interact 7ith sstems that do. heconvention is that out!of!band information occurs at the start of input or output9 and isencased in S W.

Chat*cript does not attempt to postag and parse an input sentence 7hich begins 7ith S.+t 7ill automaticall not tr to spellchec; that part also. +n fact9 the SW 7ill be split offinto its o7n sentence. ou can use normal C* rules to detect and react to incoming oobmessaging. #.g9 input li;e thisS speed@10 rate$ J0 W ser said thiscould be processed b our script. lthough the 2 data oob items are inconsistentl

sho7n9 the protocol ou use is entirel up to ou 7ithin the SW area.

''5 output needs to be first9 7hich means probabl delaing to one of the last thingsou do on the last sentence of the input9 and using >preprint(". #.g.

u$ (??outputgesture" >preprint( ]S ??outputgesture ]W "ou can hand author gestures directl on our outputs9 but then ou have to be certainou onl output one sentence at a time from our chatbot (lest a gesture command getsand7iched bet7een t7o output sentence". ou also have to be 7illing to hand author theuse of each gesture. + prefer to 7rite patterns for common things (li;e sha;e head no ornod es" and have the sstem automaticall generate gestures during postprocessing onits o7n output.

he stand!alone engine and the =#5+&#RGC#/5##R scripts automaticall handlethe follo7ing oob outputs$

Callbac;$ he 7ebpage or stand!alone engine 7ill 7ait for the designated millisecondsand if the user has not begun tping 7ill send in the oob message Scallbac;W to C*. +f user  begins tping before the timeout9 the callbac; is cancelled.e.g. Scallbac;@3000W 7ill 7ait 3 seconds.

21

Page 22: ChatScript Advanced User Manual

7/26/2019 ChatScript Advanced User Manual

http://slidepdf.com/reader/full/chatscript-advanced-user-manual 22/40

-oopbac;$ he 7ebpage or stand!alone engine 7ill 7ait for the designated millisecondsafter e(ery output from C* and if the user has not begun tping 7ill send in the oobmessage Sloopbac;W to C*. +f user begins tping before the timeout9 the loopbac; iscancelled for this output onl9 and 7ill resume counting on the net output.e.g. Sloopbac;@3000W 7ill 7ait 3 seconds after ever output.

larm$ he 7ebpage or stand!alone engine 7ill 7ait for the designated milliseconds andthen send in the oob message SalarmW to C*. +nput tping has no effect.e.g. Salarm@3000W 7ill 7ait 3 seconds and then send in the alarm.

C* can cancel an of these b sending an oob message 7ith a milliseconds of 0.e.g. Sloopbac;@0 callbac;@0 alarm@0W cancels any pending callbac;s into the future.

22

Page 23: ChatScript Advanced User Manual

7/26/2019 ChatScript Advanced User Manual

http://slidepdf.com/reader/full/chatscript-advanced-user-manual 23/40

Advanced -#uild

Build warning messages

5uild 7ill 7arn ou of a number of situations 7hich9 not illegal9 might be mista;es.+t has several messages about 7ords it doesnt recogni6e being used as ;e7ords in patterns and concepts. ou can suppress those messages b augmenting the dictionar'R ust telling the sstem not to tell ou-#uild 9 nospell

here is no problem 7ith these 7ords9 presuming that ou did in fact mean them and thedo not represent a tpo on our part.

ou can get etra spellchec;ing9 on our output 7ords9 7ith this$-#uild 9 outputspell run spellchec;ing on tet output of rules (see if tpos eist"

5uild 7ill also 7arn ou about repeated ;e7ords in a topic or concept. his means thesame 7ord is occurring under multiple forms. gain9 the sstem 7ill survive but it li;elrepresents a 7aste of ;e7ords. Gor eample9 if ou 7rite this$

topic$ %mtopic ( cheese Tcheese"ou contradict ourself. ou reIuest a 7ord be a ;e7ord and then sa it shouldnt be.he sstem 7ill not use this ;e7ord. 'r if ou 7rite this

topic$ %mtopic (cheese cheese%1"ou are saing the 7ord cheese or the 7ordnet path of cheese meaning V19 7hichincludes the 7ord cheese. ou dont need AcheeseB. 'r consider$

topic$ %mtopic (cheese cheese%n"

*ince ou have accepted all forms of cheese9 ou dont need to name cheese%n.

:eset User0de$ined

 &ormall9 a build 7ill leave our current user identit alone. ll state remainsunchanged9 ecept that topics ou have changed 7ill be reset for the bot (as though it hasnot et ever seen those topics". 5ut if ou 7ant to start over 7ith the ne7 sstem as a ne7user9 ou can reIuest this on the build command.

-#uild 9 reset reinit the current character from scratch (eIuivalent to $reset user"

Build a<ers

he build sstem has t7o laers9 0 and 1. =hen ou sa $build 09 the sstem loo;s in thetop level director for a file Afiles0.ttB. *imilarl 7hen ou sa $build 1 it loo;s forAfiles1.ttB. =hatever files are listed inside a Afiles.ttB are 7hat gets built. nd thelast character of the file name (e.g.9 files0" is 7hat is critical for deciding 7hat level to build on. +f the name ends in 09 it builds level 0. +f it doesnt9 it builds level 1. his meansou can create a bunch of files to build things an 7a ou 7ant. ou can imagine$$build common0 D shared data!source (level 0"

23

Page 24: ChatScript Advanced User Manual

7/26/2019 ChatScript Advanced User Manual

http://slidepdf.com/reader/full/chatscript-advanced-user-manual 24/40

$build george D george bot!specific (level 1"$build henr D henr bot!specific (level 1"$build all D does george and henr and others (level 1"

or 

$build sstem0 ! does -- files9 there is no level 1.

ou can build laers in either order9 and omit either.

/ote! +f ou ma;e something li;es files2.tt and do a $build 29 this does not add anotherlaer on top of level 1. +t replaces level 1. here are onl 2 levels. *o if our file does notdefine a bot and his topics and control script9 ou 7ipe out Oarr9 for eample9 and areleft 7ith nothing.

S?ipping a topic $ile

+f ou put in $Iuit as an item (li;e at the start of the file"9 then the rest of the file iss;ipped.

:enaming *aria#les, Sets, and nteger Constants

top level declaration in a script rename a match variablerename$ )bettername )12

 before an uses of )bettername9 7hich no7 mean )12. ou can put multiple rename pairsin the same declaration.

rename$ )bettername )12 )o;name )14and ou can provide multiple names9 so ou can later also sa

rename$ )name )12and both )name and )bettername refer to )12.

Renames can also rename concept sets$rename$ Zmset Z1

so ou can do$Zmset Y@ createfact( 1 2 3"

  ??tmp @ first(Zmsetsubect"

ou can also declare our o7n 32 or K4!bit integer constantsrename $ VVmconstant !J1J VVhisconstant 000004100

8e$ining private 5ueries see $act manual

24

Page 25: ChatScript Advanced User Manual

7/26/2019 ChatScript Advanced User Manual

http://slidepdf.com/reader/full/chatscript-advanced-user-manual 25/40

.diting /on0topic 1iles

 &on!topic files include the contents of +C and -+#.

8C" $iles

ou ma choose to edit the dictionar files. here are 3 ;inds of files. he facts0.tt filecontains hierarch relationships in 7ordnet. ou are unli;el to edit these. he dict.binfile is a compressed dictionar 7hich is faster to read. +f ou edit the actual dictionar7ord files9 then erase this file. +t 7ill regenerate ane7 7hen ou run the sstem again9revised per our changes. he actual dictionar files themselves ou might add a 7ordor alter the tpe data of a 7ord. he tpe information is all in dictionar*stem.h

*.8A"A $iles

he substitutions files consistof pairs of data per line. he first is 7hat to match.

+ndividual 7ords are separated b underscores9 and ou can reIuest sentence boundariesP and X . he output can be missing (delete the found phrase" or 7ords separated b plussigns (substitute these 7ords" or a 7ord 7hich names a sstem flag to be set (and theinput deleted". he output can also be prefied 7ith TSW 7here inside the brac;ets are alist of 7ords separated b spaces that must not follo7 this immediatel. +f one does9 thematch fails. ou can also use X as a 7ord9 to mean that this is &' at the end of thesentence. he files include$

interections.tt D remaps to % 7ords standing for interections or discourse actscontractions.tt D remaps contractions to full formattingsubstitutes.tt D (omittable" remaps idioms to other phrases or deletes them. british.tt D (omittable" converts british spelling to usspellfi.tt D (omittable" converts a bunch of common misspellings to correctteting.tt (omittable" converts common teting into normal english.sstemessentials.tt D things needed to handle end punctuationepandabbreviations.tt D does 7hat its name suggests

:rocessing done b various of these files can be suppressed b setting ?to;en differentl.*ee 6ontrol o(er nput.

he Iueries.tt file defines Iueries available to >Iuer. Iuer is itself a script. *ee thefile for more information.

he canonical.tt file is a list of 7ords and override canonical values. =hen the 7ord onthe left is seen in ra7 input9 the 7ord on the right 7ill be used as its canonical form.

he lo7ercasetitles.tt file is a list of lo7er!case 7ords that can be accepted in a title. &ormall lo7er case 7ords 7ould brea; up a title.

2J

Page 26: ChatScript Advanced User Manual

7/26/2019 ChatScript Advanced User Manual

http://slidepdf.com/reader/full/chatscript-advanced-user-manual 26/40

 W7C7 B("2

he sstem can support multiple bots cohabiting the same engine. ou can restrict topicsto be available onl to certain bots (see dvanced opics". ou can restrict rules to beingavailable onl to certain bots b using something li;e

M$ (?bot@harr "M$ (T?bot@harr ".t$ (?bot@harr" < name is harr.

he demo sstem has onl one bot9 Oarr. +f it had t7o bots in it9 harry and Qeorgia, oucould get ,eorgia b logging in as yourname:georgia. nd ou can confirm 7ho she is b as;ing what is your name.

ou specif 7hich bot ou 7ant 7hen ou login9 b appending :botname to our loginname9 e.g.9 bruce$harr . =hen ou donHt do that9 ou get the default bot. Oo7 does thesstem ;no7 7hat that isM +t loo;s for a fact in the database 7hose subect 7ill be the

default bot name and 7hose verb is de&aultbot . +f none is found9 the default bot is calledanonymous9 and probabl nothing 7or;s at all. efining the default bot is 7hat a tabledoes 7hen ou compile simplecontrol.top. +t has$

table$ defaultbot (>name">createfact(>name defaultbot defaultbot"$harr

picall 7hen ou build a level 1 topic base (e.g.9 $build ben or $build 1 or 7hatever"9that laer has the initiali6ation function for our bot(s" other7ise our bot cannot 7or;.his function is invo;ed 7hen a ne7 user tries to spea; to the bot and tells things li;e7hat topic to start the bot in and 7hat code processes the users input. ou need one ofthese functions for each bot9 though the functions might be pure duplicates (or might not be". +n the case of harr9 the function is

outputmacro$ harr(">addtopic(%introductions"?control)pre @ %control?control)main @ %control?control)post @ %control

*impleControl.top also has a function that declares 7ho the default bot is.  table: de&aultbot )^name*

^create&act)^name de&aultbot de&aultbot* #44:harry

ou can change default bots merel b reIuesting different build files that name thedefault9 or b editing our table.

o have multiple bots available9 one might start b ma;ing multiple folder copies ofOarr and changing them to separate bots 7ith separate files.tt . hats fine for building them as each stand!alone bots9 but if ou 7ant them to cohabit ou must have asingle files.tt file that names the separate bots folders! the must be built together.

2K

Page 27: ChatScript Advanced User Manual

7/26/2019 ChatScript Advanced User Manual

http://slidepdf.com/reader/full/chatscript-advanced-user-manual 27/40

'f course if ou merel cloned those folders9 the have topics all 7ith the same name9li;e %control and %introductions and %childhood. his is a problem. -i;el ou 7ould7ant onl one cop of %control that both bots used. nd either the should have differenttopic names for %introductions and %childhood 'R ou must put a bot restriction on eachof the duplicate topics9 naming 7hich bot can use it.

"opics B< Bot

ou should alread ;no7 that a topic can be restricted to specific bots. &o7 ou learnthat ou can create multiple copies of the same topic9 so different bots can have differentcopies. hese form a topic famil 7ith the same name. he rules are$

1. the topics share the union of ;e7ords2. $verif can onl verif the first cop of a topic it is allo7ed access to

=hen the sstem is tring to access a topic9 it 7ill chec; the bot restrictions. +f a topicfails9 it 7ill tr the net duplicate in succession until it finds a cop that the bot is allo7edto use. his means if topic 0 is restricted to ben and topicO is unrestricted9 ben 7ill use

topic0 and all other bots 7ill use topicO. +f the order of declaration is flipped9 then all botsincluding ben 7ill use topic O (7hich no7 precedes topic 0 in declaration".

ou can also use the $disable and $enable commands to turn off all or some topics for a personalit.

2N

Page 28: ChatScript Advanced User Manual

7/26/2019 ChatScript Advanced User Manual

http://slidepdf.com/reader/full/chatscript-advanced-user-manual 28/40

Page 29: ChatScript Advanced User Manual

7/26/2019 ChatScript Advanced User Manual

http://slidepdf.com/reader/full/chatscript-advanced-user-manual 29/40

'R tell >reuse to s;ip used rules b giving it a second argument (anthing". *o one 7ais$

t: '7E3N )* li(e in a small houseu: 3N8< )where > you > li(e* ^disable)5E8N 3N8<* ^reuse)'7E3N*

and the other 7a is$t: '7E3N )* li(e in a small houseu: )where > you > li(e* ^reuse)'7E3N skip*

<ean7hile9 in the original eample9 if the gambit eecutes first9 it disables itself9 but theresponder can still ans7er the Iuestion b saing it again.

 &o79 suppose ou 7ant to notice that ou alread told the user about the house so if heas;s again ou can sa something li;e$ ou &orgot$ li(e in a small house. Oo7 can oudo that. 'ne 7a to do that is to set a user variable from O'*# and test it from theresponder.

t: '7E3N )* li(e in a small house Fhouse = 0u: )where > you > li(e* [Fhouse ou &orgot$] ^reuse)'7E3N*+f ou 7anted to do that a lot9 ou might ma;e an outputmacro of it$

 outputmacro: ^he&orgot)^test* [^test ou &orgot$]t: '7E3N )* li(e in a small house Fhouse = 0u: )where > you > li(e* he&orgot)Fhouse * ^reuse)'7E3N*

'r ou could do it on the gambit itself in one neat pac;age.outputmacro: ^he&orgot)^test* [^test ou &orgot$] ^test = 0t: '7E3N )* he&orgot)Fhouse * li(e in a small house.u: )where > you > li(e* ^reuse)'7E3N*

2U

Page 30: ChatScript Advanced User Manual

7/26/2019 ChatScript Advanced User Manual

http://slidepdf.com/reader/full/chatscript-advanced-user-manual 30/40

5U.S"(/S67A/807(8/

his is a reference manual9 not a tutorial guide. <abe ou didnHt see ho7 to do 7hat ou7anted to do. <abe itHs possible at present and mabe itHs not.

Geel free to email 5ruce =ilco at go7ilcoZgmail.com and as; Iuestions. +f ou findsomething ou canHt do9 mabe +Hll 7hip up a ne7 release version in 7hich it is possible.

30

Page 31: ChatScript Advanced User Manual

7/26/2019 ChatScript Advanced User Manual

http://slidepdf.com/reader/full/chatscript-advanced-user-manual 31/40

.soterica and 1ine 8etail

Being $irst to converse

 &ormall 7hen ou log in in stand!alone mode9 this initiates a ne7 conversation and the

chatbot spea;s first. +f ou prefi our login name 7ith F9 ou get to spea; first and thiscontinues an prior conversation ou ma have had.

&re$ix la#eling in stand0alone mode

ou can control the label put before the botHs output and the userHs input prompt bsetting variables ?botprompt and ?userprompt. + set them in the botHs initiali6ation code9though ou can dnamicall change them. he values can be literal or a format string.he value is used as the prompt. Oence the follo7ing eample$

?userprompt @ >Q?login$ XQ?botprompt @ > QORR$ Q

he user prompt 7ants to use the userHs login name so it is a format string9 7hich is processed and stored on the user prompt variable. he botprompt 7ants to force a spaceat the end9 so it also uses a format string to store on the bot prompt variable.

 n color.tbl is there a reason that the color grey includes both building and ~building$

es. Rules often 7ant to distinguish members of sets that have supplemental data fromones that donHt. he set of ~musician has etra table data9 li;e 7hat the did and doesnHtinclude the 7ord musician itself. herefore a rule can match on ~musician and ;no7 ithas supplemental data available.

his is made clearer 7hen the set is named something list ~xxxlist . 5ut the sstemevolved and is not consistent.

 'ow are doubleRAuoted strings handled$

Girst9 note that ou are not allo7ed strings that end in punctuation follo7ed b a space.his string A+ love ou. A is illegal. here is no function adding that space serves.

*tring handling depends on the contet. +n input/pattern contet9 it means translate thestring into an appropriatel to;eni6ed entit. *uch contet happens 7hen a user tpes insuch a string$

  liked A=ar and :eaceB+t also happens as ;e7ords in concepts$

concept: ~test[ kick o(er/]and in tables$

 #44:Saris, <ranceB

and in patterns$u: )do you know/ what *

+n output contet9 it means print out this string 7ith its double Iuotes literall. #.g.

31

Page 32: ChatScript Advanced User Manual

7/26/2019 ChatScript Advanced User Manual

http://slidepdf.com/reader/full/chatscript-advanced-user-manual 32/40

u: )hello* @hat say you$  A V prints out A=hat sa ouM A

here are also the functional interpretations of strings_ these are strings 7ith > in front ofthem.

he donHt ma;e an sense on input or patterns or from a user9 but the are hand in atable. he mean compile the string (format it suitable for output eecution" and ou canuse the results of it in an >eval call.

'n the output side9 a >BstringB means to interpret the contents inside the string as aformat string9 substituting an named variables 7ith their content9 preserving all internalspacing and punctuation9 and stripping off the double Iuotes.

u: )test* ^/his F(ar is good./  V if ?var is ;id the result is his kid is good.

@hat really happens on the output side o& a rule$

=ell9 reall9 the sstem AevaluatesB ever to;en. *imple #nglish 7ords and punctuational7as evaluate to themselves9 and the results go into the output stream. *imilarl9 thevalue of a tet string li;e Athis is tetB is itself9 and so this is text/ sho7s up in theoutput stream. nd the value of a concept set or topic name is itself.

*stem function calls have specific uniIue evaluations 7hich affect the data of thesstem and/or add content into the output stream. ser!defined macros are ust script thatresides eternal to the script being evaluated9 so the are evaluated. *cript constructs li;e+G9 -'':9 assignment9 and relational comparison affect the flo7 of control of the script but donHt themselves put anthing into the output stream 7hen evaluated.

=henever a variable is evaluated9 its contents are evaluated and their result is put into theoutput stream. ariables include user variables9 function argument variables9 sstemvariables9 match variables9 and factset variables.

Gor sstem variables9 their values are al7as simple tet9 so that goes into the outputstream. nd match variables 7ill usuall have simple tet9 so the go into the outputstream. 5ut ou can assign into match variables ourself9 so reall the can holdanthing.

*o 7hat results from this$u: )x*

F(arO = applesF(ar0= Join)F (arO*  like F(ar0

?var2 is set to apples. +t stores the name (not the content" of ?var2 on ?var1 and then like is printed out and then the content of ?var1 is then evaluated9 so ?var2 getsevaluated9 and the sstem prints out apples.

his evaluation during output is in contrast to the behavior on the pattern side 7here thegoal is presence9 absence9 and failure. &aming a 7ord means finding it in the sentence.

32

Page 33: ChatScript Advanced User Manual

7/26/2019 ChatScript Advanced User Manual

http://slidepdf.com/reader/full/chatscript-advanced-user-manual 33/40

 &aming a concept/topic means finding a 7ord 7hich inherits from that concept eitherdirectl or indirectl. &aming a variable means seeing if that variable has a non!nullvalue. Calling a function discards an output stream generated and aside from other sideeffects means did the function fail (return a fail code" or not.

 'ow does the system tell a &unction call wTo ^ &rom Nnglish

+f li;e is defined as an output macro and if ou 7rite$t: like )somewhat* ice

ho7 does the sstem resolve this ambiguitM Oere9 7hite space actuall matters. Girst9 ifthe function is a builtin sstem function9 it al7as uses that. *o ou canHt 7rite this$

t: &ail )sort o&* at most things=hen it is a user function9 it loo;s to see if the ( of the argument list is contiguous to thefunction name or spaced apart. Contiguous is treated as a function call and apart is treatedas #nglish. his is not done for built!ins because itHs more li;el ou spaced it accidentlthan that ou intended it to be #nglish.

 'ow should go about creating a responder$

Girst ou have to decide the topic it is in and insure the topic has appropriate ;e7ords ifneeded.

*econd9 ou need to create a sample sentence the rule is intended to match. ou shouldma;e a VT comment of it. hen9 the best thing is to tpe $prepare follo7ed b oursentence. his 7ill tell ou ho7 the sstem 7ill to;eni6e it and 7hat concepts it 7illtrigger. his 7ill help ou decide 7hat the structure of the pattern should be and ho7general ou can ma;e important ;e7ords.

@hat really happens with rule erasure$

he sstemHs default behavior is to erase rules that put output into the output stream9 sothe 7onHt repeat themselves later. ou can eplicitl ma;e a rule erase 7ith >erase(" andnot erase 7ith >;eep(" and ou can ma;e the topic not allo7 responders to erase 7ithkeep as a topic flag. *o if a rule generates output9 it 7ill tr to erase itself. +f a ruleuses >reuse("9 then the rule that actuall generated the output 7ill be the called rule. +f for some reason it cannot erase itself9 then the erasure 7ill rebound to the caller9 7ho 7ill trto erase himself. *imilarl9 if a rule uses >refine("9 the actual output 7ill come from areoinder(". hese can never erase themselves directl9 so the erasure 7ill again reboundto the caller.

 &ote that a topic declared system &##R erases its rules9 neither gambits nor responders9even if ou put >erase(" on a rule.

 'ow can get the original input when ha(e a pattern like u: )~emogoodbye*

o get the original input9 ou need to do the follo7ing$

33

Page 34: ChatScript Advanced User Manual

7/26/2019 ChatScript Advanced User Manual

http://slidepdf.com/reader/full/chatscript-advanced-user-manual 34/40

u$ (%emogoodbe"??tmpto;en @ ?to;en?to;en @ 0>retr(*#&#&C#"

and at the beginning of our main program ou need a rule li;e this$u$ (??tmpto;en )F "?to;en @ ??tmpto;en. no7 that ou have the original sentence9 ou decide 7hat to do. mabe ou had set a flag to ;no7 7hat ou 7anted to do

&attern Matching Anomolies

 &ormall ou match 7ords in a sentence. 5ut the sstem sometimes merges multiple7ords into one9 either as a proper name9 or because some 7ords are li;e that. Goreample Ahere and thereB is a single 7ord adverb. +f ou tr to match A=e go here and

there about to7nB 7ithu$ (F here F" ou 7ill succeed. he actual to;ens are A7eB AgoB Ahere and thereB AaboutB Ato7nB. but the pattern matcher is allo7ed to pee; some into composite 7ords. =hen it doesmatch9 since the actual to;en is Ahere and thereB9 the position start is set to that 7ord(e.g.9 position 3"9 and in order to allo7 to match other 7ords later in the composite9 the position end is set to the 7ord before (e.g.9 position 2". his means if ou pattern is

u$ (F here and there F" it 7ill match9 b matching the same composite 7ord 3 times in a ro7. he anomalcomes 7hen ou tr to memori6e matches. +f our pattern is

u$ ()F and )F " then )0 is bound to 7ords 1 2 A7e goB9 and matches Ahere and thereB9 and )1 matchesthe rest9 Aabout to7nB. hat is9 the sstem 7ill &' position the position end before thecomposite 7ord. +f it did9 )1 7ould be Ahere and there about to7nB. +tHs not.

lso9 if ou tr to memori6e the match itself9 ou 7ill get nothing because the sstemcannot represent a partial 7ord. Oence

u$ (F )and F " 7ould memori6e the empt 7ord for )0.

+f ou donHt 7ant something 7ithin a 7ord to match our 7ord9 ou can al7as Iuote it.u$ (F and F"

does not match Ahere and there about to7nB.

he more interesting case comes 7hen a composite is a member of a set. *uppose$concept$ %mun; (and"u$ (F )%mun; F "

=hat happens hereM Girst9 a match happens9 because %mun; can match and inside thecomposite. *econd memori6ation cannot do that9 so ou memori6e the empt 7ord. +fou 7ant to not match at all9 ou can 7rite$

u$ (F )H%mun; F "

34

Page 35: ChatScript Advanced User Manual

7/26/2019 ChatScript Advanced User Manual

http://slidepdf.com/reader/full/chatscript-advanced-user-manual 35/40

+n this case9 the result is not allo7ed to match a partial 7ord9 and fails to match.Oo7ever9 given A < brothers are rare.B and these$

concept$ %mfamil (brother"u$ (F )H% mfamil F "

the sstem 7ill match and store )0 @ brothers. uoting a set merel means no partial

matches are allo7ed. he sstem is still free to canonicali6e the 7ord9 so brothers and brother both match. +f ou 7anted to '&- match brother9 ou could have Iuoted it inthe concept definition.

concept$ %mfamil (brother"

Bloc?ing a topic $rom accidental access

here ma be a topic ou dont 7ant code li;e >gambit(" to launch on its o7n9 foreample9 a stor. ou can bloc; a topic from accidental gambit access b starting it 7ith

t$ (T%" >fail(topic"+f ou are not alread in this topic9 it cannot start. 'f course ou need a 7a to start it.

here are t7o. Girst9 ou can ma;e a responder react (enabling the topic". #.g.9u$ (tal; about bees" >gambit(%"+f the topic 7ere bees and loc;ed from accidental start9 7hen this responder matches9 ouare immediatel 7ithin the topic9 so the gambit reIuest does not get bloc;ed.he other 7a to activate a topic is simpl >ddopic(%bees". topic being the currentone on the pending topics list is the definition of A%B. matching responder adds thetopic to that list but ou can do it manuall from outside and then ust sa>gambit(%bees".

3J

Page 36: ChatScript Advanced User Manual

7/26/2019 ChatScript Advanced User Manual

http://slidepdf.com/reader/full/chatscript-advanced-user-manual 36/40

Sel$0:e$lection

+n addition to reasoning about user input9 the sstem can reason about its o7n output.his is called reflection9 being able to see into ones o7n 7or;ings.

5ecause the control script that runs a bot is ust script and invo;es various enginefunctions9 it is eas to store notes about 7hat happened. +f ou called >reoinder and itgenerated output (response changed value" ou ;no7 the bot made a repl from areoinder. #tc.

o manage things li;e automatic pronoun resolution9 etc9 ou also 7ant the chatbot to beable to read and process its o7n output 7ith 7hatever scripts ou 7ant. he set ofsentences the chatbot utters for a volle are automaticall created as transient facts storedunder the verb AchatoutputB. he subect is a sentence uttered b the chatbot. he obectis a fact triple of 7hatever value 7as stored as 7h (default is A.B"9 the name of thetopic9 and the offset of the rule 7ithin the topic.

ou can prepare such a sentence ust as the sstem does an ordinar line of input bcalling >anal6e( value". his to;eni6es the content9 performs the usual parse and mar; of concepts and gets ou all read to begin pattern matching using some topic. ,enerall +do this during the post!process phase9 7hen 7e are done 7ith all user input. herefore9

t: ^Fuery(drectK chatoutput 8H R ) # =et the sentences<oop()S

$$prorutter % ^<ast(Rsu@&ect)^ana<yQe($$prorutter) # prepare ana<yss o9 what chat@ot sad 8

respond(~-e<9+e9<ect) 

Reflective information is available during main processing as 7ell. ou can set 7h to be a value and that value 7ill be associated 7ith an output generated thereafter. #.g.97h @ Iuibble.

he sstem also sets ?to;encontrol to results that happen from input processing.

3K

Page 37: ChatScript Advanced User Manual

7/26/2019 ChatScript Advanced User Manual

http://slidepdf.com/reader/full/chatscript-advanced-user-manual 37/40

A 1resh Build

ouve been building and chatting and something isnHt right but itHs all confusing. <abeou need a fresh build. Oere is ho7 to get a clean start.

0. uit chatscript.

1. #mpt the contents of our *#R folder9 but donHt erase the folder.

his gets rid of old histor in case ou are having issues around things ouHve said beforeor used from the chatbot before.

2. #mpt the contents of our ':+C folder9 but donHt erase the folder.

his gets rid of an funn state of topic builds.

3. $build 0 ! rebuild the common laer 4. $build D 7hatever file ou use for our personalit laer 

:robabl all is good no7. +f not Iuit chatscript. *tart up and tr it no7.

3N

Page 38: ChatScript Advanced User Manual

7/26/2019 ChatScript Advanced User Manual

http://slidepdf.com/reader/full/chatscript-advanced-user-manual 38/40

Command ine (ptions

<ost of the command line options are documented 7ith the server documentation9 because the affect that. Oere are general ones.

Memor< options-

Chatscript staticall allocates its memor and so (barring unusual circumstance" 7ill notallocate memor ever during its interactions 7ith users. hese parameters can controlthose allocations. one tpicall in a memor poor environment li;e a cellphone.

#u$$erQ); ! ho7 man buffers to allocate for general use (12 is default"#u$$erQ);xR9 D allocate 1J buffers of 80; btes each (default buffer si6e is 80;"

<ost chat doesnt reIuire huge output and buffers around 20; each 7ill be more thanenough. 12 buffers is generall enough too (depends on recursive issues in our scripts".

+f the sstem runs out of buffers9 it 7ill perform emergenc allocations to tr to get more9 but in limited memor environments (li;e phones" it might fail. ou are not allo7ed toallocate less than a 20E buffer si6e.

dictQn ! limit dictionar to this si6e entriestextQn  ! limit string space to this man btes$actQn  ! limit fact pool to this number of factshashQn   use this hash si6e for finding dictionar 7ords (bigger @ faster access"cacheQ)x;9 D allocate a J0E buffer for handling 1 user file at a time. server might7ant to cache multiple users at a time.

default version of Chat*cript 7ill allocate much more than it needs9 because it doesnt;no7 7hat ou might need. +f ou 7ant to use the least amount of memor (multipleservers on a machine or running on a mobile device"9 ou should loo; at the *# lineon startup and add small amounts to the entries (unless our application does unusualthings 7ith facts". +f ou 7ant to ;no7 ho7 much9 tr doing -show stats and then-source :.:.SS6#igregresstxt . his 7ill run our bot against a 7ide range of inputand the stats at the end 7ill include the maimum values needed during a volle. o be paranoid9 add beond those valuse. a;e our ma dict value and double it. *ame 7ithma fact. dd 10000 to ma tet. ust for reference9 for our most advanced bot9 theactual ma values used 7ere$ ma dict$ 34K ma fact$ K8U ma tet$ 380J2. nd themaimum rules eecuted to find an ans7er to an input sentence 7as 842K (not that oucontrol or care". pical rules eecuted for an input sentence 7as J00!2000 rules.

Gor eample9 add 1000 to the dict and fact used amounts and 10 (;b" to the string spaceto have enough normal 7or;ing room.

(utput options-

outputQnnn limits output line length for a bot to that amount (forcing ]r]n as needed". 0is unlimited.

38

Page 39: ChatScript Advanced User Manual

7/26/2019 ChatScript Advanced User Manual

http://slidepdf.com/reader/full/chatscript-advanced-user-manual 39/40

1ile options-

livedataQxxx name relative or absolute path to our o7n private -+# folder. onot add trailing / on this path. Recommended is ou useR=/ourbotfolder/-+#

to ;eep all our data in one place. ou can have our o7n live data9 et use Chat*criptsdefault -+#/**#< and -+#/#&,-+*O b providing paths to theAsstem@B and Aenglish@B parameters as 7ell as the Alivedata@B parameter.

usersQxxx   name relative or absolute path to 7here ou 7ant the *#R* folder to be.o not add trailing /.

logsQxxx   name relative or absolute path to 7here ou 7ant the -',* folder to be. onot add trailing /.

(ther options-

trace turn on all tracing.

language D set the language to this. &ormall the sstem defaults to english. ou can (ifimplemented" pic; other languages.

user$actsQn limit a user file to saving onl the n most recentl created facts of a user(this does not include facts stored in fact sets".

userlog 0 *tore a user!bot log in *#R* director (default".nouserlog 0 ont store a user!bot log.

loginQxxxx  ! he same as ou 7ould name 7hen as;ed for a login9 this avoids havingto as; for it. Can be login@george or login@george$harr or 7hatever.

3U

Page 40: ChatScript Advanced User Manual

7/26/2019 ChatScript Advanced User Manual

http://slidepdf.com/reader/full/chatscript-advanced-user-manual 40/40

Updating CS *ersions .asil<

Chat*cript gets updated often on a regular basis. nd ou probabl dont 7ant to have toreintegrate our files and its ever time. *o here is 7hat ou can do.

Create a folder for our stuff$ e.g. <*GG. =ithin it put our folder that ounormall ;eep in R= and our files.tt files normall at the top level ofChat*cript. nd if ou have our o7n hac;ed version of files from -+#9 put ourfolder there also.

hen create a folder 7ithin ours called Chat*cript and put the current Chat*criptcontents 7ithin that. ou can also create a batch file9 probabl 7ithin our folder9 thatdoes a Acd Chat*criptB to be in the right director9 and then runs Chat*cript 7ith thefollo7ing parameters$

Chat*cript livedata@../-+# english@-+#/#&,-+*Osstem@-+#/**#<

 &ormall 7hile ou might override various substitutes files9 ou 7ould not override the#&,-+*O and **#< folders.

*o no79 7hen ou 7ant to update to the latest version of Chat*cript9 merel unpac; the6ip into our Chat*cript folder9 over7riting files alread there.

"he 8ictionar<

here is the ,-'5- dictionar in +C and local dictionar per level in ':+C. ou can augment our dictionar locall b defining concepts 7ith properties$ concept$ %morenouns &'& &'&):R':#R)*+&,-R (:otsdam :aris"concept$ %verbaugment #R5 #R5)+&G+&++# (s7al; smea6le"

'ne can also directl edit the dictionar tt files in +C/#&,-+*O observing ho7 theseem to be formatted9 doing nothing cra69 and being careful 7ith consistenc ofmeaning values (if needed" and then ust delete dict.bin. +f ou 7ant to edit the 7ordnetontolog hierarch9 ou need to edit facts.tt and delete facts.bin he sstem 7ill rebuildthem 7hen ou run C*.