Welcome to the A.L.I.C.E. AI Foundation

Promoting the adoption and development of Alicebot and AIML free software.

A Personal Finance "Spreadsheet" in AIML

Dr. Richard S. Wallace

26 December 2001
© 2001 A.L.I.C.E. AI Foundation

Dr. Richard S. Wallace

1. Introduction

One of the critical requirements for the adoption of AIML technology as a standardized human-computer interface is the creation of a core set of application programming interfaces. For ALICE to become the primary mode of user interaction, she must have interfaces to a collection of common applications such as email, database, address book, calculator, and spreadsheet programs.

This report describes a first pass at the "spreadsheet" application for managing personal finances.

2. Sample Dialogue

The goal of this experiment is to produce a believable natural language interface to a trivial personal finance system. The following sample dialogue illustrates the flavor of conversations the bot should be able to handle:

Client: My checking account balance is 2300.
Robot: I got it. Do you have any more transactions?
Client: My savings account balance is 1000.
Robot: I got it. Anything else I can do for you?
Client: My visa card balance is 2100.
Robot: I got it. Thanks for the information.
Client: My citibank balance is 9000.
Robot: I got it. Is that it?
Client: I have 200 dollars in my wallet.
Robot: Alright. Thanks for the information.
Client: I spent 10 on a taxi.
Robot: I got it. Anything else I can do for you?
Client: I charged 23 for lunch on my visa card.
Robot: I got it. Thanks for the information.
Client: My landlord is mr bill.
Robot: Rent is theft!
Client: No kidding my rent is 1410 a month.
Robot: Would I kid you? 1410 is the market rate.
Client: I paid the rent with check number 101.
Robot: I got it. Thanks for the information.
Client: what is my checking account balance.
Robot: Your checking balance is 890.
Client: I charged 120 on my Visa card for the hotel.
Robot: Ok. Anything else I can do for you?
Client: What is my Visa card balance.
Robot: Your visa balance is -2243.
Client: How much money do I have in my wallet?
Robot: Your wallet balance is 190.
Client: I bought a book for 10.
Robot: Yes. I have recorded your transaction.
Client: now how much is in my wallet?
Robot: Why now? Your wallet balance is 180.

3. The transactions

The preceding dialogue reduces to the transactions listed in this section.

The DEBIT and CREDIT transactions have exactly the same format, except that the DEBIT transaction has a payee where the CREDIT has a payer. In either case the program stores the transactions in a comma- delimited format, making for easy import into other financial applications.

Specifically, the transaction record format is a comma delimited string of the form:

DEBIT account, amount, date, number, payee, category, note, id.

or

CREDIT account, amount, date, number, payer, category, note, id.

The account field identifies the account as checking, savings, wallet or the name of another account. The amount is indicated in dollars, as a nonnegative integer. The date includes a time stamp to the resolution of seconds. The number field usually indicates a check number or transaction number, if any. Payer/payee indicates the source/destination accounts for the transaction. The category field helps create a budget report later, showing how our income and expenses break down by categories such as rent, medicine, food, utility bills and so on.

The "security" of the system is limited to recording the client id, in this case localhost.localdomain. If the bot is online, care should be taken so that unauthorized clients cannot initiate personal financial transactions.

The records do not include a unique identifier or row number. Uniqueness of the records is only guaranteed by the timestamp, using the AIML <date/> function. This is fine if the transaction rate is always less than one per second. But a more realistic application may also have to include record identifiers.

The most sophisticated language processing demonstrated in this experiment was the use of AIML predicates for "landlord" and "rent". This makes possible the transformation of sentences such as "I paid the rent with check number 101" into a transaction.

INITIALIZE BANK checking, 2300, Tue Dec 25 08:32:16 PST 2001, localhost.localdomain.
CREDIT checking, 2300, tue dec 25 08 32 16 pst 2001, none, unknown, unknown, none, localhost.localdomain.
INITIALIZE BANK savings, 1000, Tue Dec 25 08:32:24 PST 2001, localhost.localdomain.
CREDIT savings, 1000, tue dec 25 08 32 24 pst 2001, none, unknown, unknown, none, localhost.localdomain.
INITIALIZE CREDT visa card, 2100, Tue Dec 25 08:32:32 PST 2001, localhost.localdomain.
DEBIT visa card, 2100, tue dec 25 08 32 32 pst 2001, none, unknown, unknown, none, localhost.localdomain.
INITIALIZE CREDT citibank, 9000, Tue Dec 25 08:32:51 PST 2001, localhost.localdomain.
DEBIT citibank, 9000, tue dec 25 08 32 51 pst 2001, none, unknown, unknown, none, localhost.localdomain.
INITIALIZE BANK wallet, 200, Tue Dec 25 08:33:01 PST 2001, localhost.localdomain.
CREDIT wallet, 200, tue dec 25 08 33 01 pst 2001, none, unknown, unknown, none, localhost.localdomain.
DEBIT wallet, 10, tue dec 25 08 33 23 pst 2001, none, a taxi, unknown, none, localhost.localdomain.
DEBIT visa, 23 for lunch, tue dec 25 08 33 34 pst 2001, none, unknown, unknown, none, localhost.localdomain.
DEBIT checking, 1410, tue dec 25 08 34 07 pst 2001, number 101, mr bill, rent, none, localhost.localdomain.
DEBIT visa, 120, tue dec 25 08 35 00 pst 2001, none, unknown, the hotel, none, localhost.localdomain.
DEBIT wallet, 10, tue dec 25 08 35 28 pst 2001, none, unknown, a book, none, localhost.localdomain.

4. The AIML Categories

The dialogue in section 2 resulted from the contents of the ALICE brain, plus the following set of "spreadsheet" categories. The basic idea is to reduce every financial statement into a transaction of the form CREDIT, DEBIT or INITIALIZE. There are two types of accounts, CREDIT accounts, mainly for CREDIT cards, and BANK accounts, which can include wallets, piggybanks, safes and other money containers, as well as regular bank DEBIT accounts like checking and savings.

The purpose of the INITIALIZE statement is to set an initial balance, open a new account, or override the spreadsheet's calculated balance for an account. CREDIT accounts are opened with a negative balance, initiated with a DEBIT transaction. BANK accounts are opened with a positive balance, initiated using a CREDIT transaction.

All of the DEBIT and CREDIT transactions are recorded in the default gossip file. This may not be the best place, but it made for a simpler pedagogical example. The program balance.sh calculates the account balances as need (see next section).

The following AIML categories represent a first-pass attempt to create the simple "spreadsheet". Not a true double-entry bookkeeping system, the categories nonetheless demonstrate the feasibility of building a personal finance application in AIML.

<aiml>
    <category>
        <pattern>ACKNOWLEDGE TRANSACTION</pattern>
        <template>
            <random>
                <li>Ok.</li>
                <li>Yes.</li>
                <li>Alright.</li>
                <li>I got it.</li>
            </random>
            <random>
                <li>Is there anything else I can help you with?</li>
                <li>Do you have any more transactions?</li>
                <li>I have recorded your transaction.</li>
                <li>Anything else I can do for you?</li>
                <li>Thanks for the information.</li>
                <li>Is that it?</li>
            </random>
        </template>
    </category>
    <category>
        <pattern>CREDIT ACCT * AMT * DATE * NUMBER * PAYER * CATEGORY * NOTE *</pattern>
        <template>
            <srai>ACKNOWLEDGE TRANSACTION</srai>
            <think>
                <gossip>CREDIT <star/>, <star index="2"/>, <star index="3"/>, <star index="4"/>, <star index="5"/>, <star index="6"/>, <star index="7"/>, <id/>.</gossip>
            </think>
        </template>
    </category>
    <category>
        <pattern>DEBIT ACCT * AMT * DATE * NUMBER * PAYEE * CATEGORY * NOTE *</pattern>
        <template>
            <srai>ACKNOWLEDGE TRANSACTION</srai>
            <think>
                <gossip>DEBIT <star/>, <star index="2"/>, <star index="3"/>, <star index="4"/>, <star index="5"/>, <star index="6"/>, <star index="7"/>, <id/>.</gossip>
            </think>
        </template>
    </category>
    <category>
        <pattern>INITIALIZE BANK ACCT * AMT *</pattern>
        <template>
            <srai>ACKNOWLEDGE TRANSACTION</srai>
            <think>
                <gossip>INITIALIZE BANK <star/>, <star index="2"/>, <date/>, <id/>.</gossip>
                <srai>
                    CREDIT ACCT <star/> AMT <star index="2"/> DATE <date/>
                </srai>
            </think>
        </template>
    </category>
    <category>
        <pattern>INITIALIZE CREDT ACCT * AMT *</pattern>
        <template>
            <srai>ACKNOWLEDGE TRANSACTION</srai>
            <think>
                <gossip>INITIALIZE CREDT <star/>, <star index="2"/>, <date/>, <id/>.</gossip>
                <srai>
                    DEBIT ACCT <star/> AMT <star index="2"/> DATE <date/>
                </srai>
            </think>
        </template>
    </category>
    <category>
        <pattern>BALANCE ACCT *</pattern>
        <template>
            <system>sh /home/alicebot/balance.sh <star/>
            </system>
        </template>
    </category>
    <category>
        <pattern>HOW MUCH IS IN MY WALLET</pattern>
        <template>
            <srai>BALANCE ACCT WALLET</srai>
        </template>
    </category>
    <category>
        <pattern>HOW MUCH MONEY _ MY WALLET</pattern>
        <template>
            <srai>BALANCE ACCT WALLET</srai>
        </template>
    </category>
    <category>
        <pattern>HOW MUCH CASH _ I HAVE</pattern>
        <template>
            <srai>BALANCE ACCT WALLET</srai>
        </template>
    </category>
    <category>
        <pattern>WHO IS MY LANDLORD</pattern>
        <template>
            <get name="landlord"/>
        </template>
    </category>
    <category>
        <pattern>WHAT IS MY RENT</pattern>
        <template>
            <get name="rent"/> per month.</template>
    </category>
    <category>
        <pattern>MY RENT IS *</pattern>
        <template>
            <set name="rent"><star/></set> is the market rate.
        </template>
    </category>
    <category>
        <pattern>MY RENT IS * DOLLARS PER MONTH</pattern>
        <template>
            <srai>MY RENT IS <star/></srai>
        </template>
    </category>
    <category>
        <pattern>MY RENT IS * PER MONTH</pattern>
        <template>
            <srai>MY RENT IS <star/></srai>
        </template>
    </category>
    <category>
        <pattern>MY LANDLORD IS *</pattern>
        <template>
            <think>
                <set name="landlord">
                    <person/>
                </set>
            </think>
            Rent is theft!
            </template>
    </category>
    <category>
        <pattern>MY CHECKING ACCOUNT BALANCE IS *</pattern>
        <template>
            <srai>INITIALIZE BANK ACCT checking AMT <star/></srai>
        </template>
    </category>
    <category>
        <pattern>MY CITIBANK BALANCE IS *</pattern>
        <template>
            <srai>INITIALIZE CREDT ACCT citibank AMT <star/></srai>
        </template>
    </category>
    <category>
        <pattern>MY SAVINGS ACCOUNT BALANCE IS *</pattern>
        <template>
            <srai>INITIALIZE BANK ACCT savings AMT <star/></srai>
        </template>
    </category>
    <category>
        <pattern>MY VISA CARD BALANCE IS *</pattern>
        <template>
            <srai>INITIALIZE CREDT ACCT visa card AMT <star/></srai>
        </template>
    </category>
    <category>
        <pattern>I HAVE * IN MY WALLET</pattern>
        <template>
            <srai>INITIALIZE BANK ACCT wallet AMT <star/></srai>
        </template>
    </category>
    <category>
        <pattern>I HAVE * DOLLARS IN MY WALLET</pattern>
        <template>
            <srai>INITIALIZE BANK ACCT wallet AMT <star/></srai>
        </template>
    </category>
    <category>
        <pattern>WHAT IS MY * ACCOUNT BALANCE</pattern>
        <template>
            <srai>BALANCE ACCT <star/></srai>
        </template>
    </category>
    <category>
        <pattern>I HAVE * DOLLARS TO MY NAME</pattern>
        <template>
            <srai>INITIALIZE BANK ACCT wallet AMT <star/></srai>
        </template>
    </category>
    <category>
        <pattern>I HAVE * DOLLARS</pattern>
        <template>
            <srai>INITIALIZE BANK ACCT wallet AMT <star/></srai>
        </template>
    </category>
    <category>
        <pattern>WHAT IS MY * CARD BALANCE</pattern>
        <template>
            <srai>BALANCE ACCT <star/></srai>
        </template>
    </category>
    <category>
        <pattern>DEPOSIT * IN CHECKING ACCOUNT</pattern>
        <template>
            <srai>CREDIT ACCT checking AMT <star/></srai>
        </template>
    </category>
    <category>
        <pattern>I PAID MY RENT WITH CHECK *</pattern>
        <template>
            <srai>
                DEBIT ACCT checking AMT <get name="rent"/> DATE <date/> NUMBER <star/> PAYEE <get name="landlord"/> CATEGORY RENT
            </srai>
        </template>
    </category>
    <category>
        <pattern>I PAID THE RENT WITH CHECK *</pattern>
        <template>
            <srai>
                DEBIT ACCT checking AMT <get name="rent"/> DATE <date/> NUMBER <star/> PAYEE <get name="landlord"/> CATEGORY RENT
            </srai>
        </template>
    </category>
    <category>
        <pattern>I CHARGED * DOLLARS ON MY ATM AT * FOR *</pattern>
        <template>
            <srai>
                DEBIT ACCT checking AMT <star/> DATE <date/> NUMBER none PAYEE <star index="2"/> CATEGORY <star index="3"/>
            </srai>
        </template>
    </category>
</aiml>

The remainder of the AIML categories have been placed here due to considerations of length.

5. The shell script

There are an infinite number programs one could write to calculate account balances based on the DEBIT and CREDIT transaction recorded in the gossip file.

Ideally the AIML script should be tightly integrated with a real spreadsheet application. For now we use a simple shell script to stand in for the real application. The script uses awk to calculate sums. Its use of temporary files is unfortunate.

# the account balance shell script
# This example is for instructional purposes only.
# Usage: balance <account>
rm -f *.temp
echo 0 > credit.temp
echo 0 > debit.temp
echo "Your "$@" balance is"
grep DEBIT /home/alicebot/data/gossip.data | grep $@ | awk -F , '{print $2;
n-=$2; print n}' | tail -1 > debit.temp
grep CREDIT /home/alicebot/data/gossip.data | grep $@ | awk -F , '{print $2;
n+=$2; print n}' | tail -1 > credit.temp
cat credit.temp debit.temp | awk '{print $1; n+=$1; print n}' | tail -1

6. Conclusion

We have demonstrated the feasibility of a simple personal finance application with AIML. Despite its limitations, the program is adequate for a small set of personal finance needs.

To make this application more robust we should:

  1. Create a realistic double-entry bookkeeping system.
  2. Add a unique identifier to each transaction.
  3. Integrate the program more closely with a real financial application.
  4. Develop an expanded set of AIML patterns to capture a wider variety of transaction statements, including dollars and cents, international currencies, interest payments, and taxes.
  5. Enhance the security feature to prohibit unauthorized clients from making personal financial transactions.
  6. Substitute voice for text input. This is the kind of application you want to carry around with you, so you can utter "I spent 10 on a taxi", at the same time you pay the driver, and "I took out 100 from the ATM", while you are still at the cash machine.

More generally, we need to work on AIML APIs for a variety of everyday applications. These include, but are not limited to, address books, spreadsheets, databases, email, web browsers, word processors, and games. In the dream world of the future, the talking Star Trek/HAL-style computer will handle all of the applications we use now on WIMP (Windows, Icons, Menus, Pointing Device) computers.

Appendix A. AIML categories for personal finance

The appendix is provided here