The DBGene sample application uses a classic Prolog application idea to illustrate how the Amzi! Logic Server can be used to provide the services of Prolog in conventional application environments. Given a genealogical database of information about people, the application lets you pose queries about various relationships, such as sister, uncle, grandparent, and ancestor.
This implementation was built with three tools:
To learn more see:
Using DBGene as stand-alone Prolog - How to run just the Prolog program.
Using DBGene with C++ front-end - How to use the sample, and how to put in your own family database.
Application Architecture - Details on the implementation, including annotated source code.
www.amzi.com - Additional demos, articles, freeware, evaluation copies and information about Amzi! Prolog + Logic Server.
We welcome any and all comments about this demo. Contact us at www.amzi.com
Simply open the project in Eclipse and run the project, either interpreted or compiled. The dbgene.pro file can also be run as a single file. Follow the prompts.
Running an Prolog program that uses ODBC requires two things: 1) to load the LSX amzi/bin/aodbc.lsx; and 2) to load the PLM amzi/abin/aodbc.plm. These can be done directly in the source code of the application file:
% Load the LSX that provides the extended predicates % for the ODBC interface. This could also be done % from amzi.cfg, or from a Logic Server host language % program.
:- loadlsx('aodbc.lsx').
% Make user the Prolog portion of the ODBC library, % which provides a Prolog-like interface to the % database, is loaded, and that its predicates are % imported.
:- ensure_loaded(aodbc). :- import(aodbc).
AODBC.LSX could also be loaded using amzi.cfg, but the direct loading method above is easier. See Amzi! runtime documentation for details on using amzi.cfg for loading LSXs.
AODBC.PLM could be linked with the program, which is preferred for running a compiled application. When that is done, the .plm is linked into the application .xpl file.
In the Eclipse project for DBGENE, you can also specify in the project properties that AODBC LSX and PLM are needed, and then, when running or building in Eclipse, the correct files will be loaded. Note that using ensure_loaded/1 means that aodbc.plm will be loaded only if it hasn't already been loaded, say by Eclipse or being linked into a .xpl file.
To run it you need:
DBGene automatically loads the ODBC database, 'gene' and the logic base, 'dbgene'. The middle listbox contains the names of the people in the gene database. The left hand listbox contains a list of the relations the dbgene logic base knows about. If you select a relation and an individual and push the 'Query' button, the names of the people who satisfy that relation appear in the right hand box.
If you have the tools to modify the database, which was created using Microsoft Access, you can fill it with individuals from your own family tree. Or you can replace the gene database with an ODBC database of your own choosing.
The logic base contains rules that define relationships based on the database. These are rules that express what it means to be a sibling, uncle, ancestor, etc. At the base of each of these rules are Prolog predicates that map directly to the database, using the Logic Server ODBC extension.
The user interface contains list boxes that present the pertinent information from the logic base. That information is obtained from a C++ class that encapsulates the logic base services.
There are two tables in the database defined as follows.
Person
*pid number (key) *surname text[40] (indexed) *midname....text[40] *name text[40] *gender text[1] m/f *mother number (indexed) (a pid) *father number (indexed) (a pid) dob text[10] (date yyyy-mm-dd) dod text[10] (date yyyy-mm-dd) birthplace text[50] nation text[40] note text[255]Marriage
*husband number (indexed) (a pid) *wife number (indexed) (a pid) married text[10] (date yyyy-mm-dd) divorced text[10] (date yyyy-mm-dd) note text[255]* - Fields that are used in this demonstration. Other fields are ignored.
Individuals with the same middle and last name are the top of the ancestral tree and also have parents indicated by the PersonID 0.
The code consists of these primary sections:
Some of the files in the application are pure boiler plate generated by the application wizard of Visual C++. That code is not included here. The code listed is:
progene.h - the header file for the class that encapsulates the Prolog services, based on the Logic Server C++ wrapper class.
progene.cpp - the implementation file for the ProGene class. Its primary function is to take one of the three list boxes of the application as input and fill it with the appropriate information derived from the Logic Base. API calls that loop through lists and queries are used to generate all the information required for each list box.
dbgendlg.cpp - the main dialog implementation that use the ProGene services. The OnInitDialog function calls ProGene to fill up the relations and individuals list boxes, and the OnQuery function passes the selected name and relation to ProGene, which then fills in the answers list box.
Copyright ©1987-2004 Amzi! inc. All Rights Reserved. Amzi! is a registered trademark and Logic Server and e-Prolog are trademarks of Amzi! inc.