Executable English / Internet Business Logic Tutorial, Part 3

Adrian Walker    internet.business.logic@gmail.com    

 

       In Part 2 of the tutorial, you saw how to write and run a simple agent. In this part, you will see, step by step, how to write and run a business case agent -- one that accepts estimates from various departments of an organization, and that produces various forecasts of revenue. In writing the business case agent, we will see how to use some more advanced features of the Executable English / Internet Business Logic system (IBL). Once you know how to use these more advanced features, you will be able to use the full power of the IBL to write and run your own agents.

In this part of the tutorial, you will learn how to use the following features of the IBL:

All of these features are used in the agent program called Reengineering, a fictitious business case forecast for the years 2020 and 2021. This is one of the agents that you can look at and run, using the IBL demo ID.

Let's suppose we want a business scenario for the Reengineering company for the years 2020 and 2021. We can say that we are considering just those two years, like this.


  this-year is a year under consideration for estimates  
  =====================================================  
   2020   
   2021



Suppose further that the company does business in two zones, namely the EEC and NAFTA.


  the Reengineering company does business in this-zone  
  ====================================================  
                                             EEC
                                             NAFTA



In each zone, the company has two departments



  each international zone of Reengineering has this-dept
  ===============================================================  
                                            Intellectual Property
                                            Consulting



We could picture the business zones and departments like this:


  EEC
      Intellectual Property  
      Consulting
   NAFTA
      Intellectual Property
      Consulting


Later in this tutorial, we shall see how to produce that kind of picture as an IBL answer table containing another table.

In building the business case, each department in each zone is asked to forecast its net income for each year. So far we only have two estimates, as shown in this table.



  for the year this-year the zone this-zone dept this-dept estimates net income $M this-new-amount
  =================================================================================================  
               2020               EEC            Consulting                        3
               2020               EEC            Intellectual Property             4



We have in mind to summarize the incomes from the zones and departments, but we have no data for NAFTA, and no data for the year 2021. Yet, maintaining a department is going to cost something. So, we will assume that a department that has not yet sent in an estimate will cost us a million dollars a year. We can say this with the following rule.


  some-year is a year under consideration for estimates
  in some-zone the Reengineering company has a dept some-dept
  not : for the year that-year the zone that-zone dept that-dept has a net income estimate on record
  --------------------------------------------------------------------------------------------------  
  the net income in $M for that-year to be contributed by that-zone that-dept is -1


Line 1 of the rule refers to one of our tables. Line 2 of the rule is a sentence we have not said anything about yet, but we can say what it means by writing this rule.


  the Reengineering company does business in some-zone
  each international zone of Reengineering has some-dept
  -----------------------------------------------------------  
  in that-zone the Reengineering company has a dept that-dept


Line 3 (the one about having a net income estimate on record) has "not : " at the front. That is how you say to the IBL that you only want a rule to succeed if the rest of the line is not true.

We also need some rules to say what we mean in the third line, the one about having a net income estimate on record. We'll actually do this in a slightly roundabout way to illustrate how one can use the IBL to keep track of row numbers in a table.


  table row some-n says for some-year the zone some-zone dept some-dept estimates net income $M some-amount
  ---------------------------------------------------------------------------------------------------------  
  for the year that-year the zone that-zone dept that-dept has a net income estimate on record

  row some-n : for the year some-year the zone some-zone dept some-dept estimates net income $M some-amount
  ---------------------------------------------------------------------------------------------------------
  table row that-n says for that-year the zone that-zone dept that-dept estimates net income $M that-amount


The first rule gives us a sentence about an estimate being on record. That's the sentence we need for the rule that tells us to assume that a department that has not yet turned in estimate will cost us a million dollars a year. The premise of the first rule is the conclusion of the second rule.

The second rule uses our table of the estimates so far, prefixed with "row some-n". So, in the conclusion of the rule we can mention which row of the table the estimate came from.

We can see how the two rules get us from the table to the estimate on record, like this:
    Table of data:  for the year some-year the zone some-zone dept some-dept estimates net income $M some-amount

    Step 1:  row some-n : for the year some-year the zone some-zone dept some-dept estimates net income $M some-amount

    Step 2:  table row that-n says for that-year the zone that-zone dept that-dept estimates net income $M that-amount 

    Step 3:  for the year that-year the zone that-zone dept that-dept has a net income estimate on record



So far, we have said what the IBL is to do if an estimate is not turned in (remember the "not : " in front of the "estimate on record" sentence). If, on the other hand, a department has turned in an estimate, we can use it like this:


  some-year is a year under consideration for estimates
  in some-zone the Reengineering company has a dept some-dept
  table row some-n says for some-year the zone some-zone dept some-dept estimates net income $M some-amount  
  ---------------------------------------------------------------------------------------------------------
  the net income in $M for that-year to be contributed by that-zone that-dept is that-amount


To see how the rules work so far, go to the IBL Start Page, and pick the agent called Reengineering. Go to the question menu, and click on the sentence


  the net income in $M for some-year to be contributed by some-zone some-dept is some-amount  


A smaller window containing the sentence should pop up. Click on the Ask button in that window. You should see the answer


  the net income in $M for this-year to be contributed by this-zone this-dept is this-amount 
  ==========================================================================================  
                         2020                            EEC      Consulting               3
                         2020                            EEC      Intellectual Property    4
                         2020                            NAFTA    Consulting              -1
                         2020                            NAFTA    Intellectual Property   -1
                         2021                            EEC      Consulting              -1
                         2021                            EEC      Intellectual Property   -1
                         2021                            NAFTA    Consulting              -1
                         2021                            NAFTA    Intellectual Property   -1


Suppose there were many more years, zones and departments in the first three tables in this tutorial. Then the answer table would be like the one above, but it would be rather hard to read.

We could ask for portions of the answer by changing the question so that it has NAFTA in place of "some-zone", or by asking about Consulting for all zones, and so on.

However, we can also ask the IBL to show the above answer with tables inside other tables like this.


  the estimated income in $M in 2020
      EEC
        Consulting   3
        Intellectual Property   4
      NAFTA
        Consulting   -1
        Intellectual Property   -1

  the estimated income in $M in 2021  
      EEC
        Consulting   -1
        Intellectual Property   -1
      NAFTA
        Consulting   -1
        Intellectual Property   -1


We use a rule like this to specify the way we want the tables to appear.


  the net income in $M for some-year to be contributed by some-zone some-dept is some-amount
  ------------------------------------------------------------------------------------------  
  the estimated income in $M in that-year
    that-zone
        that-dept that-amount


The rule says that we would like the answer to be a table for each year, containing a table for each zone, containing in turn a table for a department and an amount. To see how the rule works, go to the question menu, and use it to ask the question


  the estimated income in $M in some-year  


As usual, when you get the answer, you can click on the button to the left of a row, and then ask for an explanation of how the row was found using the rules and facts.

If you would like another example of such "master-detail" tables, please run the agent program called SupplyChain1, and ask the question


  part some-partnumber some-name handled by buyer some-buyer has POs for vendor, date, qty reqd, and has a qty shipped  


In our Reengineering agent, we so far only have year 2020 estimates from the EEC departments. So, we need the departments concerned to start to add estimates for 2021 and NAFTA. We could just give the departments the "author" password and ask them to go to the "View or Change the Agent" page. There they could freely add information to the table:


  for the year this-year the zone this-zone dept this-dept estimates net income $M this-new-amount
  ================================================================================================  
               2020               EEC            Consulting                        3
               2020               EEC            Intellectual Property             4


However, for a project of any size, that would be a bad idea, since people could accidentally change or delete other people's estimates, and we would have no record of who had done this.

Instead, we will only give out the "user" password, and we will write some rules allowing users, who are not authors, to make transactions that change the table in a safer, more orderly way. We will also control which user IDs are allowed to make changes.

Here is a sample table we use for demonstration purposes:


  this-uid running with permission status this-perm is allowed to change the Reengineering estimates
  ==================================================================================================  
   anyuid                                 author
   anyuid                                 user


In real use, the table would contain actual user IDs.

So, we want to write a rule that checks who wants to make a change, and allows them to make the change if thay are so authorized. Then, the rule should write information to a log showing who made that change, when they made it, and what the change was.

The following rule does most of what we want, but we will see that we will also want another similar rule saying what the default estimate should be. Take a look at the rule, then we will go over it line by line to see how it makes a transaction.


  the current user is some-person with userid some-uid and with permission status some-perm
  anyuid running with permission status that-perm is allowed to change the Reengineering estimates
  the present date and time is some-year/month/day some-time
  some-year is a year under consideration for estimates
  in some-zone the Reengineering company has a dept some-dept
  the net income in $M for that-year to be contributed by that-zone that-dept is some-old-amount
  del : for the year that-year the zone that-zone dept that-dept estimates net income $M some-old-amount
  add : for the year that-year the zone that-zone dept that-dept estimates net income $M a-new-amount
  the next log number is some-num
  add : log that-num userid that-uid on that-year/month/day that-time added that-year that-zone that-dept that-new-amount  
  ------------------------------------------------------------------------------------------------------------------------
  Change the estimated net income for that-year that-zone for that-dept from that-old-amount to that~new-amount


Let's look at the rule line by line. Line 1 is a sentence that is "predefined" in the IBL. If a sentence is "predefined", the agent need not contain a rule or table that defines what the sentence means. Indeed, if we try to write such a rule or table, the IBL will send us a warning on the Check page.

Line 2 is a place holder for a later real permissions check, in which "anyuid" would be replaced with "that-uid", to refer to the ID found in line 1.

Line 3 is defined by several rules that we will look at later. Those rules use another predefined sentence that allows us to look up the current date and time on the IBL server.

Lines 4,5 and 6 use tables that we looked at before.

Lines 7 and 8 delete an old row from a table and add a new one.

Line 9 finds a new log number, using some rules that we will look at later.

Line 10 adds information to a log table.

Finally, the conclusion of the rule is a sentence that will appear in the question menu. In the sentence, "that~new-amount" is a new kind of place holder, indicated by using a "~" symbol where there would normally be a dash. When we run the rule, the place holder will be filled in with a default amount, but we will be able to change that to a different amount before making a transaction.

You may like to look at the above rule in the IBL, by choosing Reengineering and "Go to View or Change the Agent". There, you will see another rule, which is almost the same as the one above, saying that the default amount is actually just the old amount of the estimate.

So, now you will be able to:
  1. Ask what estimates are available for changes

  2. Get an answer table in which a row shows a "change" from, say, the amount 3 to the default amount 3

  3. In the answer table, change the default amount 3 to, say, 7

  4. Select "Make these changes to the Agent Data"

At this point, you may like to try running the Reengineering agent, and making a change like the one just described. After the change is made, you may like to ask the questions


  for the year some-year the zone some-zone dept some-dept estimates net income $M some-new-amount

  log some-num userid some-uid on some-year/month/day some-time added some-year some-zone some-dept some-amount  


You will see that your change has been made, and that the log table has been updated to show who made the change. Note that the log also shows the date and time of the change. The date and time are the ones at the IBL server on the West Coast of the USA, so of course your time zone may be different.

We said that line 3 of our transaction rule is defined by several rules. Those rules use a predefined sentence like this.


  the present date is some-year some-month some-day and the time is some-hour some-minute some-second  


The sentence allows us to look up the current date and time on the IBL server. However, we want a row of the log table to contain one entry called some-year/month/day, and another entry some-time. We can arrange this by writing a rule as follows.



  the present date is some-year some-month some-day and the time is some-hour some-minute some-second
  that-year followed by that-month separated by a symbol /  = some-year/month
  that-year/month followed by that-day separated by a symbol / = some-year/month/day
  that-minute with a leading zero if needed is some-0minute
  that-hour followed by that-0minute separated by a symbol : = some-time
  ---------------------------------------------------------------------------------------------------  
  the present date and time is that-year/month/day that-time


Line 1 of the rule is the "present date" predefined sentence. Lines 2, 3 and 5 use another predefined sentence that allows us to gather up the numbers we want, separated by symbols such as "/" and ":". We need line 4 because of the convention that a time of the form 12:01 is written with a zero in front of the minute, not as 12:1.

The sentence used in Line 4 is in turn defined by these two rules.


  some-minute consists of some-length symbols letters and digits
  that-length is less than 2
  0 followed by that-minute = some-0minute
  ---------------------------------------------------------
  that-minute with a leading zero if needed is that-0minute


  some-minute consists of some-length symbols letters and digits  
  that-length is greater than 1
  ---------------------------------------------------------
  that-minute with a leading zero if needed is that-minute


The two rules use some further predefined sentences that allow us to talk about "less than", "greater than" and "followed by".

Line 9 of the transaction rule was the sentence


  the next log number is some-num  


The sentence is defined like this.


  this-num is a log number
  ========================
   0

  log some-num userid some-uid on some-year/month/day some-time added some-year some-zone some-dept some-amount
  -------------------------------------------------------------------------------------------------------------  
  that-num is a log number

  max some-num : that-num is a log number = some-lastnum
  that-lastnum + 1 = some-newnum
  ------------------------------------------------------
  the next log number is that-newnum


If there are no entries in the log, then the next log number will be 1, based on the table and the last rule. On the other hand, if there are entries in the log, then the last rule will find the largest log number so far, and will add 1 to it to get the next log number.

This completes our look at the Reengineering agent. In the agent, the tables of data are small and they have been handled directly by the IBL. Suppose that the tables contained a lot of data, or that the tables were already stored in a DBMS (such as Oracle). Then there would be no tables with the ==== underlines in the Reengineering agent. Instead there would be six rules like this:


  url:12.345.67.89  dbms:9i  dbname:ibldb  tablename:YR_CONS  port:1521  id:anonymous  password:oracle
  -----------------------------------------------------------------------------------------------------
  some-year is a year under consideration for estimates


  url:12.345.67.89  dbms:9i  dbname:ibldb  tablename:YZD_NET  port:1521  id:anonymous  password:oracle
  -----------------------------------------------------------------------------------------------------
  for the year some-year the zone some-zone dept some-dept estimates net income $M some-amount


  url:12.345.67.89  dbms:9i  dbname:ibldb  tablename:BUS_ZONE  port:1521  id:anonymous  password:oracle
  -----------------------------------------------------------------------------------------------------
  the Reengineering company does business in some-zone


  url:12.345.67.89  dbms:9i  dbname:ibldb  tablename:ZONE_DEPT  port:1521  id:anonymous  password:oracle
  -----------------------------------------------------------------------------------------------------
  each international zone of Reengineering has some-dept


  url:12.345.67.89  dbms:9i  dbname:ibldb  tablename:UID_PERM  port:1521  id:anonymous  password:oracle
  -----------------------------------------------------------------------------------------------------
  some-uid running with permision status some-perm is allowed to change the Reengineering estimates


  url:12.345.67.89  dbms:9i  dbname:ibldb  tablename:ESTIM_LOG  port:1521  id:anonymous  password:oracle
  ------------------------------------------------------------------------------------------------------------  
  log some-num userid some-uid on some-year/month/day some-time added some-year some-zone some-dept some-amount


Then, the agent would work as before, but most of the reasoning would be done in the DBMS. The main task of the IBL system would be to automatically generate and run the necessary SQL queries and transactions.

Please note that, if you wish to use the IBL system with your own Oracle or other DBMS, you will need to specify the URL of your machine in the first line of each of the rules like the ones above. You will also need to change each such line to describe the actual dbms, the name of the database, the table name, the port to use, and the ID and password. Then, it may be best to work with your database administrator to set the appropriate DBMS permissions on the tables that will be used. In most cases, you will also need to ask your system administrator to allow the www.executable-english.com server to send SQL queries through your firewall to the DBMS, and to allow the results to be sent back.

You have now completed the Part 3 of the IBL tutorial. You have learned how to use the following features of the IBL: To see a complete list of the predefined sentences that the IBL provides, please click on the Help button on the Agent page and then on the link "Predefined sentences". You can also see examples of how the Predefined sentences work by running the Agent called "Predefined".

Now that you know how to write and run a useful agent, you may like to try out some of the other agents provided on the free community "demo" ID. Then, you can use the same ID to write and run agents that are useful to you in your work.

Remember that an easy way to write a new agent is to first make a copy of an existing agent, using the choice "Save a Copy of the Selected Agent As..." on the Start page. Then, make small changes, one by one, running the agent each time to see your changes working. It is a good idea to save your changes from time to time by again making another copy of your agent-in-progress. You can also copy and paste your agent from your browser into an editor window on your own machine.

Please remember that the community "demo" ID is shared, and that the number of simultaneous authors and users is limited. So, you may like to register your own private ID. To do this, please go to the Login page , and fill in the New User registration information. Please be sure to also read the Terms and Conditions for using the IBL.

If you would like to make an agent you have written on your private ID available on the public community "demo" ID, please let us know. Or, you can open two browser windows at once, and copy and paste from your private ID to the demo ID.

Your questions and comments about this tutorial, and about the IBL system, are much appreciated. Please e-mail them to internet.business.logic@gmail.com. Thank you!