FEUZRUNV Introduction to the Database functionality Revision 1.3, 12 September 2001 2001 by empolis knowledge management GmbH
Copyright by empolis knowledge management GmbH. All rights reserved. This document is subject to change without notice Disclaimer: THIS DOCUMENT IS PROVIDED FOR INFORMATIONAL PURPOSES ONLY. The information contained in this document represents the current view of empolis knowledge management on the issues discussed as of the date of publication. INFORMATION PROVIDED IN THIS DOCUMENT IS PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND FREEDOM FROM INFRINGEMENT. Thanks to Pól McNulty, Interactive Multimedia Systems, Clara House, Glenageary Park, Glenageary, Co. Dublin, Ireland, for the first version of this document! empolis knowledge management Sauerwiesen 2 D-67661 Kaiserslautern Tel: + 49 6301 606 400 Fax: + 49 6301 606 409 cbrworks@empolis.com support@empolis.com www.empolis.com
To make it easier to create CBR-systems, CBR-Works supports to import information from a database. This information can be used to quickly define concepts, types, their range and also cases. Setting up the connection to a database and importing elements of it will be the focus of this tutorial. 3
1 Introduction for database access with CBR-Works 1.1 Setting up the ODBC Data Source Communication between CBR-Works and the database takes place using a 32 bit ODBC driver. This is our first step. To create a ODBC (Open DataBase Connectivity), complete the following: 1. Open your 32 bit ODBC in the control panel. This opens the ODBC data source administrator. Introduction for database access with CBR-Works 4
2. Select the User DSN tab. 3. To add a new data source select the Add button. This prompts the Create New Data Source dialog box. Here you select the necessary application driver. For our tutorial purpose select the Microsoft Access driver. 4. Push the Finish button 5. In the ODBC Microsoft Access set-up box, you now have to enter a name for this data source (so you can refer to it in CBR-Works), also you have to inform the driver of the location of the database file. To name the data source insert Tutorial in the Data Source_Name field. To inform the driver of the location of the database (Tutorial.mdb), press the Select button. In the pop-up box, navigate through the folders until you locate the file. Select it and click the OK button. When you return Introduction for database access with CBR-Works 5
to the set-up box click OK and then exit the Administrator application. 6. You now have created the data source. 1.2 Establishing a connection As the data source has been created we now connect CBR-Works to the database. Follow these steps: 1. Create a new blank CBR application in CBR- Works. 2. Click on the File->Preferences menu and select Database options (File->Preferences- >Database). This prompts the Database Options dialog box. 3. If your database is password protected it is necessary to include your user name (if any) and the password in their respective fields. 4. In the Data Source field enter the name of the data source created before, i.e., Tutorial. 5. Press OK 6. If you return to the default screen in CBR- Works, then you have been connected to the database, otherwise repeat these steps as an error Introduction for database access with CBR-Works 6
occurred and the connection could not be established. 1.3 Importing types into the Model Since your connection has been established you have to choose the way importing the types for your CBR-Application. First you can follow the this section if you prefer to import all types before importing any concept or second you can import a type with each concept you have defined (see Importing Concepts on page 11). Now, you want to import the types, select the Type button in the top right hand corner of the screen. To start: 1. Select Create Types from Database in the Edit menu. 2. This prompts the Table Wizard. At first the wizard appears to be empty, but don t fret. First click on the drop-down Table field and select the table named Table1. 3. The Column field now shows the attribute Reference, the typename listing Reference (which you can change), and the Super Type which shows the assumed parent type: Symbol is not correct. Change it to String by clicking on the Super Type pull-down box. Then press OK. This will close the Type Wizard and create the type as specified. 4. You have to repeat steps 1 through 3 for each Type you need to import from the Database and Introduction for database access with CBR-Works 7
in this case we want to import all of them. There are a few things to pay attention to: Each time you enter the Type Wizard you will be presented with this blank page. Therefore each time you wish to import another type you must select Table, from the Table pulldown menu. By Default the Type wizard will automatically load the first column, in this case: reference. You must navigate down the Column pulldown menu to select the next type to import. On the second turn it will be Accommodation, on the third Bedrooms and so on. Introduction for database access with CBR-Works 8
Each time you select a type from the Column field, the typename & Supertype also changes Also ensure that the correct SuperType is specified. Consult Table One of the tutorial document to check. One problem with the Type wizard is that it does not allow you to specify types as symbol sets, because most databases do not support sets. We shall change these settings later. In the picture above you can see the range of places listed. Error my occur here if there are mistakes in your Database. Remember to consult Table One from the tutorial document, ensure that the correct ranges are entered. For example view figure 5. If you look at Table One you will see that the range specified for the being attribute Bedrooms was from 0 to 9. However, below you can see that the Type wizard misinterpreted these values as an enumeration rather than a interval. To correct this error click on the interval radio button. The range section then alters to allow you to specify the minimum (0) and maximum (9) range. The same kind of problem will occur when importing the rental_price Type. Use these principle to fix that problem too. Importing the location type will also bring problems. The SuperType is wrong for a start, as w wish it to be a TaxonomySymbol. Change it. Introduction for database access with CBR-Works 9
When you have selected the TaxonomySymbol the range interface changes. Here you should see the difference between the layout of the taxonomy in the tutorial section and the one Introduction for database access with CBR-Works 10
here. Here all the districts are Sons of the Root directory instead of being the Sons of the North_Side and the South_Side. This is because the database contains no information on the layout of the structure of the Taxonomy. Therefore you must define it. In order to do this you will have to consult Table 1 in the tutorial document. First, you must add the two categories these districts come under. I.E. North_Side or South_Side. To begin... Click on the Root directory Type in North_Side in the new value field Introduction for database access with CBR-Works 11
Click Add as Son Then ensure that North_Side (NS) is selected and type South_Side (SS) and press Add as Brother Now that you have defined the two categories of the root you must make all the districts son s of their respective categories (Either NS or SS). Consult the tutorial for this. To add, click on a district and drag it over it s parent (e.g. Click on Donnybrook and drag it over the South_Side ) and release your mouse button. This adds Donnybrook as a sub-range of South_Side. Repeat this for all districts. Click OK when you have finished. Now that you have imported this taxonomy you will have to recreate the similarity matrix. To do this, return to point 7 onwards in Creating a taxonomy symbol in your tutorial document. Problems will also occur when you are importing types that are to be symbol sets. The Type Wizard will not allow you to define these kind of types. Therefore in order to fix this we must follow these steps: Instead of defining these types as symbol sets we shall instead define them as symbols. (We ll convert them later). Now, the problem with this is that the type Wizard will not realise that two words in the same field are two separate ranges, rather it will believe that any combination is a range in Introduction for database access with CBR-Works 12
itself. Therefore anytime there is a repeat of a range or a list of them please delete them by clicking on them and clicking Remove. If you consult Table 1 you will be able to see the ranges that should be there. When you have imported everything from the Type Wizard, go to the Type window. Click on the field that you wish to convert from symbols to symbol set. Using the right-mouse button, click on the Type, and select convert type from the menu. The Type Wizard will re-appear and if you click on the SuperType pull-down menu, you will see the option to convert to Symbol set. Once Symbol set is chosen, click OK to convert. Repeat this for all the symbols that need to be converted. I 1.4 Importing Concepts You may prefer to firstly import the concepts of your CBR-application. Start by selecting the concepts button on the top right-hand corner. Then select 'Create concepts from Database' from the edit menu. This prompt the Concept wizard. The Concept Wizard consists of two parts. The left-hand screen shows the name of the database, i.e. Table1. If you click on it, the Concept Wizard loads all of the table attributes. To import : Introduction for database access with CBR-Works 13
Select the Primary Key of your table (a primary key is a column which values identify a row unique). The column Reference is such a key, the values enumerate the rows in form of Place<x>. Your concept wizard should look like that Click on 'Create Concept' and then click 'Done' to import the concept and it's attributes. Introduction for database access with CBR-Works 14
1.5 Defining your new concept as the Case After completing these steps you will be returned to the concept window. If you look to the left-side of the screen you will see that there is now two concepts. However, only one of these may be the Case concept. Currently it is the wrong one, the concept named "Case" (the Case Concept is denoted by a a blue tab sticking out of the folder); See this picture: Click on the concept 'Table1' Select 'Define as Case', note that the blue tag has moved from 'Case' to 'Table1'. This illustrates that 'Table1' is now the Case Concept. As the other concept is of no use, it should be deleted. Click on the concept 'Case' and select Introduction for database access with CBR-Works 15
Delete Concept from the Edit menu. This leaves you with only one concept, the Case Concept Table1. The next step is to link all the types you imported to the attributes you imported, if you just have defined them. You have already seen how to link attributes to their respective types in the 'LINKING TYPES TO THEIR RESPECTIVE ATTRIBUTES' in the Tutorial document. Follow those procedures to accomplish this task. Perhaps you have not imported the types, then there is another possibility to do this now. Select the DataBase-card and select an attribute e.g. Reference. Introduction for database access with CBR-Works 16
Note that the type of Reference is Symbol. You could change this by selecting the button Create from DB. It is the short way, to get the Type Wizard for a concept. First you have to rename the Typename e.g. ReferenceStringType that the OK-button will be enabled. Selecting OK, your ReferenceStringType will be defined. The other types you could define in the same way, you need not to change the view to the Type Hierarchy. In the tutorial essay you will recall, altering the weights of attributes and disabling some attributes during the search phase ( i.e. the Introduction for database access with CBR-Works 17
Goto attribute). If you look at the table listing the attributes, you will see that the weights are all one and all the discriminant check-boxes are ticked. This must be updated. Consulting the WEIGHTS, HIDDEN ATTRIBUTES, & INTERNET LINKS section in the tutorial essay update these changes. One final thing is to note that the 'Reference' Attribute stores the name of the case and is therefore not necessary in the search procedure. Therefore, you must deselect the discriminant check box. Now that you have imported all your types & attributes, it is time to save the application and the carry on to importing our cases. 1.6 Importing our cases You are now ready to begin the final stage. Start by clicking on the Case Base Icon in the top right hand corner of the screen... To start importing the cases select Add Cases from database. When the Case Wizard appears to ask you to select a primary key, this will act as the name of the case. As the reference attribute serves as this, you will use this as your primary key. Click OK to close. Note: Transferring cases to case buffer is done automatically. The End. Introduction for database access with CBR-Works 18
This completes the tutorial of how to create a CBR- Works application from a database. To start a server and view over the web, consult the Tutorial.doc. I hope this is helpful. If there are any questions or comments, please contact support@empolis.com. Introduction for database access with CBR-Works 19
2 Advanced database access with CBR-Works 2.1 Audience This document assumes that you are already familiar with CBR-Works. You need to be familiar with the basic database access mechanisms of CBR- Works described in the Database.doc document. You also need a basic understanding of relational databases. 2.2 What you will learn This introduction shows you how to import data from a set of tables. 2.3 Relations in relational databases and CBR-Works In a relational database data is stored in tables. Tables have a set of columns. Every column has a name as well as a data type. CBR-Works stores data in concepts. Concepts have a set of attributes. Every attribute has a name and a type. So CBR-Works maps concepts to tables and columns to attributes. So far there is no fundamental difference between the organisation of data in databases and CBR- Works. However, when it comes to structured data things get more complicated. Advanced database access with CBR-Works 20
CBR-Works allows attributes to have complex types. If you want to model for example that cars have engines, where an "Engine" is a concept you can do this with CBR-Works by creating an attribute with type "Engine" within the Concept "Car". In the relational model however the type of a column is always atomic (Integer, String, Boolean etc.). So you can not model the relation between a whole, and its complex parts directly. This relations must be established by a SQL-statement that "joins" data from several tables. The result of the "JOIN" operation is a virtual table sometimes called a "view". This view contains columns from the tables that are joined together. Let s have a closer look at the "Join" operation. To understand this operation we need to understand the idea of "primary-keys". The problem is how to refer from one row in table X to another in table Y. This can be done by row identifiers. Typically, there is a single column called the "primary-key" in every table which allows to identify the rows of the table. No two rows of a table have the same value in the primary-key column. In some exotic cases the primarykey consists of more than one column. In which case no two rows of a table have the same values in these columns. Let s look at our example. Advanced database access with CBR-Works 21
We have two tables: The Car table: (The column EngineID refers to the Engine table) ID Price Colour EngineID 1 15000 Red 3 2 15000 Blue 2 3 17000 Green 3 And the Engine table: (The column ID is the primary key) ID Cylinders Horsepower 1 4 55 2 4 75 3 6 110 The following SQL-Statement builds our desired view: 6(/(&7&DU3ULFH&DU&RORXU (QJLQH&\OLQGHUV(QJLQH+RUVHSRZHU )520&DU,11(5-2,1(QJLQH 21&DU(QJLQH,' (QJLQH,' The FROM-Clause defines that rows are joined if the EngineID from the Car Table matches the ID from the Engine table. Price Colour Cylinders Horsepower 15000 Blue 4 75 15000 Red 6 110 17000 Green 6 110 Advanced database access with CBR-Works 22
Hence, the resulting view consists of a plain set of columns. There is no information about the wholepart structure. However the import mechanism of CBR-Works allows you to import Cars from the two tables without losing that structure. 2.4 How to establish the relations In order to make the data import as simply as possible CBR-Works creates the necessary SELECT Statement for you. However it needs some informations. The first thing it needs to know are the primary keys of your tables. That is, why you have to specify primary keys, when you create a Concept from the Database with the Concept-Wizard. Advanced database access with CBR-Works 23
Let s go back to our example. The Concept-Wizard creates an attribute for every column of the related table. So initially our Car Concept looks like this. When we have created our two concepts from the tables, CBR-Works can not know that an engine is a part of a car. You have to add an attribute to the Car Concept with type of Engine in order to do so. Also, when you are not interested in some of the columns, you can simply remove the related attributes. In our example we are neither interested in the CarID, nor in the EngineID of the car, so we simply remove Advanced database access with CBR-Works 24
these attributes. Our Car Concept now looks like this: Advanced database access with CBR-Works 25
When we switch to the database pane we see four attributes : For attributes with atomic types the DataBase pane shows the mapping from attribute name to column name. You may edit that mapping. For complex attributes CBR-Works knows that it has to perform a JOIN in order to import the data correctly. It also knows the primary-keys that are needed for that join. In our case it knows that the attribute "engine" has the type "Engine" and "Engine" has the primarykey "ID". However it doesn t know which column of the concept "Car" refers to that primary key of "En- Advanced database access with CBR-Works 26
gine". When you click on the "engine" attribute the editor shows a field where you can enter the foreignkey of "Car" which refers to "Engine". In our case the foreign-key is EngineID. When the primary-key consists of more than one column you have to enter here which (foreign) columns of the "whole-concept" refer to the primary-columns of the "part-concept". The whole-part import feature is not limited in depth. A part can have many parts, which in turn have many parts and so on. Advanced database access with CBR-Works 27
2.5 Remarks People that are familiar with databases may note, that there are a lot more possibilities to join tables than described above. This is true. We leave more complex JOIN operations to the database system itself. Now you may ask: "Why did you implement this kind of JOIN operations then?". A similar question would be: "Why don t we join the data in the database and than import data from a single view?. This would be much simpler!". If you have read the above text carefully you already know the answer. If CBR-Works would leave all JOIN operations to the database system, it could import data only from a single table. That means the whole-part structure is lost. Since this structure is helpful for the understanding of the domain, CBR-Works provides that information for you. Advanced database access with CBR-Works 28