About Introduction Design Goals Tutorials Downloads

Using WordNet

(by Gary Dubuque)

If you haven't installed the WordNet dictionary, go to the Getting Started tutorial and add the dict folder to your installation.

To see if the dictionary is available type Ctrl-E to get the immediate execution of script dialog and in it type define success. You should get the definition of the word success displayed in the editor.

There are four script commands which rely on the dictionary for full functionality. They are define, words, synonyms and senses.

Define only displays information from WordNet. It is comparable to typing in the command from the DOS prompt for WordNet. This means it has many parameters to tailor the resulting report. I'll refer you to the system documentation for all the variations. For our tutorial, the define command is not the focus. It is just a nice feature to have.

We are more interested with how to use the remaining three commands to help write AIML.

Lets first start with finding the meanings of a word:

{defword}
make words,
"Input word?",$wrd,nl,
senses $wrd,
facts

This gives us a new case called "words" where we can see the results of our script processing. The frame asks for a word and then annotates it with all the word senses, that is, the meanings. The results are listed using the facts command.

An interesting variation would be to find all the synonyms for the word. So lets modify the frame a bit and add one for looping through each word sense:

{defword}
make words,
"Input word?",$wrd,nl,
senses $wrd,
$cnt = @MVCNT("$wrd") - 1,
:dosyn,
remove $cnt $wrd $s $t,
facts
{dosyn}
$s = "$s" & $cnt & "=$wrd(" & $cnt & ")",
submit $s,
$t = "synonyms $s" & $cnt,
submit $t,
$cnt = $cnt - 1,
[$cnt > 0] restart?,
nl

Now we have each word sense redefined as a predicate named s1 to s9 or however many word senses there are. Each of the word senses are annotated with the synonyms. Could we use this many possibilities for substitution of the given word? Maybe not, but it is interesting how much data a single word can generate.

What we could use is a way to suggest alternate words in a given pattern that can create new categories. The default script file – PU.txt – has these frames in it to do that. Lets ignore the {pickup} and {AskThat} frames since they just solicit the missing response to build a template. Once they have a template they call MorePatterns:

{MorePatterns}
$newpat = @UPPER($pat),
$newtmp = "<srai>" & $newpat & "</srai>",
$wrdtyp = "-n",
words "-xvarsfm" $newpat,
$newcnt = @MVCNT("$newpat"),
(tryadj)  [$newcnt <> 2] $wrdtyp = "-a",words "-xnvrsfm" $newpat,$newcnt = @MVCNT("$newpat")?,
(tryadv)  [$newcnt <> 2] $wrdtyp = "-r",words "-xnvasfm" $newpat,$newcnt = @MVCNT("$newpat")?,
(tryadj2) [$newcnt <> 2] $wrdtyp = "-a",words "-a" $newpat,$newcnt = @MVCNT("$newpat")?,
(tryadv2) [$newcnt <> 2] $wrdtyp = "-r",words "-r" $newpat,$newcnt = @MVCNT("$newpat")?,
(trynoun) [$newcnt <> 2] $wrdtyp = "-n",words "-n" $newpat,$newcnt = @MVCNT("$newpat")?,
(tryany)  [$newcnt <> 2] $wrdtyp = "-w",words "-xs" $newpat,$newcnt = @MVCNT("$newpat")?,
(oneword) [$newcnt <> 2] exit?,
$wrd = $newpat(1),
$owrd = @UPPER($wrd),
synonyms $wrdtyp $wrd,
$cnt = @MVCNT("$wrd"),
pin,
:EachNewPattern
{EachNewPattern}
(no more patterns) [$cnt < 2] exit?,
$cnt = $cnt - 1,
$nwrd = $wrd($cnt),
$nwrd = @UPPER($nwrd),
$nwrd = @CHANGE($nwrd,"-"," "),
(notnew) [$nwrd = $owrd] restart?,
$newpat = @UPPER($pat),
$newpat = @REPLACE($newpat,$owrd,$nwrd),
(add that) [$that <> ""][AskThat(usethat)] $newpat = $newpat & "<that>" & $that?,
$BotDB Index = 0,
match $newpat,
(got it) [$BotDB Pattern = $newpat][$BotDB Index <> 0] restart?,
pin,"Would you like to include a match to """ $newpat """ for that response? ",$ans,erase,
(add new) ["y","Y","yes","YES"] category $newpat $newtmp?,
(quit) ["q","Q","quit","QUIT"] exit?,
restart

The MorePatterns frame has to find good candidate words in the pattern to substitute with synonyms. It uses the words script command with a filter. The first attempt selects only nouns and excludes the rest. If it doesn't find any, it tries adjectives, adverbs, until just any word. If one of these attempts results in a single word being picked through the filters, then we are set for substituting.

The EachNewPattern frame finds synonyms for our single word and offers the substitution in the pattern as a choice for the botmaster to use in making another category. It does do a match script command to make sure the new proposed category is not an already existing pattern.


(Edited for the SourceForge site by Stefan Zakarias)

About Introduction Design Goals Tutorials Downloads