ai/es (artificial intelligence / expert system) visual prolog: part 3 2012. fall. sme., pukyong nat...
TRANSCRIPT
![Page 1: AI/ES (Artificial Intelligence / Expert System) Visual Prolog: Part 3 2012. Fall. SME., Pukyong Nat l Univ. Kim, Minsoo](https://reader035.vdocuments.site/reader035/viewer/2022062303/5518c688550346b31f8b5802/html5/thumbnails/1.jpg)
AI/ES(Artificial Intelligence / Expert System)
Visual Prolog: Part 3
2012. Fall.SME., Pukyong Nat’l Univ.
Kim, Minsoo
![Page 2: AI/ES (Artificial Intelligence / Expert System) Visual Prolog: Part 3 2012. Fall. SME., Pukyong Nat l Univ. Kim, Minsoo](https://reader035.vdocuments.site/reader035/viewer/2022062303/5518c688550346b31f8b5802/html5/thumbnails/2.jpg)
Contents• Data Modeling in Prolog• A Minimal Database
![Page 3: AI/ES (Artificial Intelligence / Expert System) Visual Prolog: Part 3 2012. Fall. SME., Pukyong Nat l Univ. Kim, Minsoo](https://reader035.vdocuments.site/reader035/viewer/2022062303/5518c688550346b31f8b5802/html5/thumbnails/3.jpg)
Data Modeling in Prolog• How data is modeled in Prolog (PIE)
– Domain Field Data Type• char: one character between single quotes
– ‘a’, ‘b’, ‘\n’, ‘\t’, ‘\r’, ‘\\’, ‘\”’, …• string: a series of characters between double
quotes– “Hill”, “John”, “…\n…”
• integer: an integral signed number– +1, 1, -2, 5, 0, …
• unsigned: integral unsigned numbers– 3, 4, …
• real: numbers that may contain a decimal part– -3.5, +4.56, -1.23456789e+18, …
– Simple Domain vs. Complex Domain
![Page 4: AI/ES (Artificial Intelligence / Expert System) Visual Prolog: Part 3 2012. Fall. SME., Pukyong Nat l Univ. Kim, Minsoo](https://reader035.vdocuments.site/reader035/viewer/2022062303/5518c688550346b31f8b5802/html5/thumbnails/4.jpg)
Data Modeling in Prolog• Extending Family Theory Example
– Open & Execute ‘PIE’ Project• Load ‘FamilyTree(A1).PRO’ and reconsult.
brother and sister relations?
Need to express gender.
Modeling: ‘Relation’ vs.
‘Entity’
![Page 5: AI/ES (Artificial Intelligence / Expert System) Visual Prolog: Part 3 2012. Fall. SME., Pukyong Nat l Univ. Kim, Minsoo](https://reader035.vdocuments.site/reader035/viewer/2022062303/5518c688550346b31f8b5802/html5/thumbnails/5.jpg)
Data Modeling in Prolog– Define a ‘person’ predicate, change
others• person(“Bill”, “male”), person(“Pam”,
“female”).X
X
+
+
![Page 6: AI/ES (Artificial Intelligence / Expert System) Visual Prolog: Part 3 2012. Fall. SME., Pukyong Nat l Univ. Kim, Minsoo](https://reader035.vdocuments.site/reader035/viewer/2022062303/5518c688550346b31f8b5802/html5/thumbnails/6.jpg)
Data Modeling in Prolog– Now, test your family theory!
• ? brother(“Jane”, X), sister(“Jack”, Y).
John, M Lisa, F Jim, M
Jane, FBill, M Sue, F
Pam, F Jack, M
![Page 7: AI/ES (Artificial Intelligence / Expert System) Visual Prolog: Part 3 2012. Fall. SME., Pukyong Nat l Univ. Kim, Minsoo](https://reader035.vdocuments.site/reader035/viewer/2022062303/5518c688550346b31f8b5802/html5/thumbnails/7.jpg)
Data Modeling in Prolog• In Prolog (Horn clauses)
– rules: ‘Head’ is true if ‘Body’ is true.• Head :- Body
– facts: clauses with ‘empty’ bodies.• cat(“Tom”).• cat(“Tom”) :- true.
– functor: a fact builds up compound domain.• Usually to define entities with their properties.
– person(string Name, string Gender)• functor is not a function
– A functor has no computation within it.• You can declare a functor in PIE by simply
using it in your predicates.– VIP requires you to declare functor before you
use.
![Page 8: AI/ES (Artificial Intelligence / Expert System) Visual Prolog: Part 3 2012. Fall. SME., Pukyong Nat l Univ. Kim, Minsoo](https://reader035.vdocuments.site/reader035/viewer/2022062303/5518c688550346b31f8b5802/html5/thumbnails/8.jpg)
Data Modeling in Prolog• Try another family theory
– Load ‘FamilyTree(B1).PRO’ / Reconsult
person(Who, “male”).
parent(X, person(_, “female”).
grandFather(X, Y).
sibling(person(“Pam”, “female”), person(Sibling, Gender)).
sister(person(_, “male”), person(X, Y)).
brother(person(_, “female”), X).
ancestor(person(“Pam”, _), Who).
![Page 9: AI/ES (Artificial Intelligence / Expert System) Visual Prolog: Part 3 2012. Fall. SME., Pukyong Nat l Univ. Kim, Minsoo](https://reader035.vdocuments.site/reader035/viewer/2022062303/5518c688550346b31f8b5802/html5/thumbnails/9.jpg)
Data Modeling in Prolog– Think of these two different theories
vs.
![Page 10: AI/ES (Artificial Intelligence / Expert System) Visual Prolog: Part 3 2012. Fall. SME., Pukyong Nat l Univ. Kim, Minsoo](https://reader035.vdocuments.site/reader035/viewer/2022062303/5518c688550346b31f8b5802/html5/thumbnails/10.jpg)
Data Modeling in Prolog• How to model a theory?
– Modeling• The establishment of a relationship between
the subset of the outside real-world that is being tackled with the internal data structures of software.
• Focus on entities and their relationships.– Description of entity functor (complex
domain)– Description of relationship fact, rule
– Software building• Software will be only as good as allowed by
the modeled data.– Poor model poorly working (inefficient)
software• Use side effects to tackle goals or sub-goals.
![Page 11: AI/ES (Artificial Intelligence / Expert System) Visual Prolog: Part 3 2012. Fall. SME., Pukyong Nat l Univ. Kim, Minsoo](https://reader035.vdocuments.site/reader035/viewer/2022062303/5518c688550346b31f8b5802/html5/thumbnails/11.jpg)
A Minimal Database• A data bases on a file
– Person Entity in Table (Relational-Model)• Using fact’s OAV-tuple (Object-Attribute-Value)• Using functor person(ID, Name, Weight,
Length, IQ)
fact("John", "ID", 1).fact("John", "Weight", 85).fact("John", "Length", 185).fact("John", "IQ", 110).fact("Thomas", "ID", 2).fact("Thomas", "Weight", 78)....
person("1", "John", 85, 185, 110).person("2", "Thomas", 78, 190, 150).person("3", "Anna", 65, 175, 130).person("4", "Lidy", 55, 160, 123)....
![Page 12: AI/ES (Artificial Intelligence / Expert System) Visual Prolog: Part 3 2012. Fall. SME., Pukyong Nat l Univ. Kim, Minsoo](https://reader035.vdocuments.site/reader035/viewer/2022062303/5518c688550346b31f8b5802/html5/thumbnails/12.jpg)
A Minimal Database• Create ‘chap07db’ project
– Add ‘person’ package to the root Build!
![Page 13: AI/ES (Artificial Intelligence / Expert System) Visual Prolog: Part 3 2012. Fall. SME., Pukyong Nat l Univ. Kim, Minsoo](https://reader035.vdocuments.site/reader035/viewer/2022062303/5518c688550346b31f8b5802/html5/thumbnails/13.jpg)
A Minimal Database– Create ‘person’ class under person
package• person package New In Existing Package…
![Page 14: AI/ES (Artificial Intelligence / Expert System) Visual Prolog: Part 3 2012. Fall. SME., Pukyong Nat l Univ. Kim, Minsoo](https://reader035.vdocuments.site/reader035/viewer/2022062303/5518c688550346b31f8b5802/html5/thumbnails/14.jpg)
A Minimal Database– add code(class facts) to ‘person.pro’ file.
![Page 15: AI/ES (Artificial Intelligence / Expert System) Visual Prolog: Part 3 2012. Fall. SME., Pukyong Nat l Univ. Kim, Minsoo](https://reader035.vdocuments.site/reader035/viewer/2022062303/5518c688550346b31f8b5802/html5/thumbnails/15.jpg)
A Minimal Database– Add declaration to ‘person.cl’ file.
– Build again!
![Page 16: AI/ES (Artificial Intelligence / Expert System) Visual Prolog: Part 3 2012. Fall. SME., Pukyong Nat l Univ. Kim, Minsoo](https://reader035.vdocuments.site/reader035/viewer/2022062303/5518c688550346b31f8b5802/html5/thumbnails/16.jpg)
A Minimal Database– Add menu/menu-item and connect
• TaskMenu.mnu Database/FillDatabase• TaskWindow.win onDatabaseFilldatabase
![Page 17: AI/ES (Artificial Intelligence / Expert System) Visual Prolog: Part 3 2012. Fall. SME., Pukyong Nat l Univ. Kim, Minsoo](https://reader035.vdocuments.site/reader035/viewer/2022062303/5518c688550346b31f8b5802/html5/thumbnails/17.jpg)
A Minimal Database• Rebuild All / Execute
– (if error) ‘Rebuild All’ again / Press ‘F5’
![Page 18: AI/ES (Artificial Intelligence / Expert System) Visual Prolog: Part 3 2012. Fall. SME., Pukyong Nat l Univ. Kim, Minsoo](https://reader035.vdocuments.site/reader035/viewer/2022062303/5518c688550346b31f8b5802/html5/thumbnails/18.jpg)
A Minimal Database• Add more predicates & connect to
menu– In ‘person.pro’ file
• foreach condition do body end foreach.
listDatabaseFail() :- stdIO::write("=== person database ===\n"), person(ID, Name, Weight, Length, IQ), stdIO::write("ID: ", ID, ", Name: ", Name, ", Weight: ", Weight, ", Length: ", Length, ", IQ: ", IQ), stdIO::nl, fail.listDatabaseFail() :- stdIO::write("==================\n"). listDatabaseForEach() :- stdIO::write("=== person database ===\n"), foreach person(ID, Name, Weight, Length, IQ) do stdIO::write("ID: ", ID, ", Name: ", Name, ", Weight: ", Weight, ", Length: ", Length, ", IQ: ", IQ), stdIO::nl end foreach, stdIO::write("==================\n").
![Page 19: AI/ES (Artificial Intelligence / Expert System) Visual Prolog: Part 3 2012. Fall. SME., Pukyong Nat l Univ. Kim, Minsoo](https://reader035.vdocuments.site/reader035/viewer/2022062303/5518c688550346b31f8b5802/html5/thumbnails/19.jpg)
A Minimal Database– Add declaration to ‘person.cl’ file.
![Page 20: AI/ES (Artificial Intelligence / Expert System) Visual Prolog: Part 3 2012. Fall. SME., Pukyong Nat l Univ. Kim, Minsoo](https://reader035.vdocuments.site/reader035/viewer/2022062303/5518c688550346b31f8b5802/html5/thumbnails/20.jpg)
A Minimal Database– Add menu/menu-item and connect
• TaskMenu.mnu TaskWindow.win Build/Try!
![Page 21: AI/ES (Artificial Intelligence / Expert System) Visual Prolog: Part 3 2012. Fall. SME., Pukyong Nat l Univ. Kim, Minsoo](https://reader035.vdocuments.site/reader035/viewer/2022062303/5518c688550346b31f8b5802/html5/thumbnails/21.jpg)
A Minimal Database• Add Dialog to create a person record
– Create a ‘forms’ package to the project root.
– Add ‘addPerson’ Dialog to ‘forms’ package.
![Page 22: AI/ES (Artificial Intelligence / Expert System) Visual Prolog: Part 3 2012. Fall. SME., Pukyong Nat l Univ. Kim, Minsoo](https://reader035.vdocuments.site/reader035/viewer/2022062303/5518c688550346b31f8b5802/html5/thumbnails/22.jpg)
A Minimal Database– Edit ‘addPerson’ dialog
• Add ‘Static Text’ and ‘Edit Control’ Build All!
name_ctlweight_ctllength_ctliq_ctl
![Page 23: AI/ES (Artificial Intelligence / Expert System) Visual Prolog: Part 3 2012. Fall. SME., Pukyong Nat l Univ. Kim, Minsoo](https://reader035.vdocuments.site/reader035/viewer/2022062303/5518c688550346b31f8b5802/html5/thumbnails/23.jpg)
A Minimal Database– In ‘person.pro’ file.
• Add ‘addPerson’ predicate and ‘list’ library.
addPerson(Name, Weight, Length, IQ) :- findAll(ID, person(ID, _, _, _, _), IDList), NewID = toString(toTerm(maximum(IDList)) + 1), assertz(person(NewID, Name, Weight, Length, IQ)), stdIO::write("Person ", Name, " has been added with ID: ", NewID), stdIO::nl.
![Page 24: AI/ES (Artificial Intelligence / Expert System) Visual Prolog: Part 3 2012. Fall. SME., Pukyong Nat l Univ. Kim, Minsoo](https://reader035.vdocuments.site/reader035/viewer/2022062303/5518c688550346b31f8b5802/html5/thumbnails/24.jpg)
A Minimal Database– Add declaration to ‘person.cl’ file.
Build!
![Page 25: AI/ES (Artificial Intelligence / Expert System) Visual Prolog: Part 3 2012. Fall. SME., Pukyong Nat l Univ. Kim, Minsoo](https://reader035.vdocuments.site/reader035/viewer/2022062303/5518c688550346b31f8b5802/html5/thumbnails/25.jpg)
A Minimal Database– Add menu/menu-item and connect
• TaskMenu.mnu Database/Add Person• TaskWindow.win onDatabaseAddPerson Try!
![Page 26: AI/ES (Artificial Intelligence / Expert System) Visual Prolog: Part 3 2012. Fall. SME., Pukyong Nat l Univ. Kim, Minsoo](https://reader035.vdocuments.site/reader035/viewer/2022062303/5518c688550346b31f8b5802/html5/thumbnails/26.jpg)
A Minimal Database– Add ClickResponder to <OK> button
• addPerson.dlg OK-button Event
![Page 27: AI/ES (Artificial Intelligence / Expert System) Visual Prolog: Part 3 2012. Fall. SME., Pukyong Nat l Univ. Kim, Minsoo](https://reader035.vdocuments.site/reader035/viewer/2022062303/5518c688550346b31f8b5802/html5/thumbnails/27.jpg)
A Minimal Database– Build / Try!
• Change addPerson(person.pro) to prevent exception.
+
+
![Page 28: AI/ES (Artificial Intelligence / Expert System) Visual Prolog: Part 3 2012. Fall. SME., Pukyong Nat l Univ. Kim, Minsoo](https://reader035.vdocuments.site/reader035/viewer/2022062303/5518c688550346b31f8b5802/html5/thumbnails/28.jpg)
A Minimal Database• Add Dialog to delete a person record
– Add ‘deletePerson’ Dialog to ‘forms’ package.
![Page 29: AI/ES (Artificial Intelligence / Expert System) Visual Prolog: Part 3 2012. Fall. SME., Pukyong Nat l Univ. Kim, Minsoo](https://reader035.vdocuments.site/reader035/viewer/2022062303/5518c688550346b31f8b5802/html5/thumbnails/29.jpg)
A Minimal Database– Edit ‘deletePerson.dlg’ dialog
• Add ‘List Box’ and ‘Edit Control’ Build All!
nameListbox_ctl
idListbox_ctl
name_ctlid_ctl
ReadOnly:True
![Page 30: AI/ES (Artificial Intelligence / Expert System) Visual Prolog: Part 3 2012. Fall. SME., Pukyong Nat l Univ. Kim, Minsoo](https://reader035.vdocuments.site/reader035/viewer/2022062303/5518c688550346b31f8b5802/html5/thumbnails/30.jpg)
A Minimal Database– Add menu/menu-item and connect
• TaskMenu.mnu Database/Delete Person• TaskWindow.win onDatabaseDeletePerson
![Page 31: AI/ES (Artificial Intelligence / Expert System) Visual Prolog: Part 3 2012. Fall. SME., Pukyong Nat l Univ. Kim, Minsoo](https://reader035.vdocuments.site/reader035/viewer/2022062303/5518c688550346b31f8b5802/html5/thumbnails/31.jpg)
A Minimal Database– Add 4 predicates to ‘person.pro’ file.
getAllNames(NameList) :- findAll(Name, person(_, Name, _, _, _), NameList). getSomeIDs(Name, IDList) :- findAll(ID, person(ID, Name, _, _, _), IDList). getPerson(ID, Name, Weight, Length, IQ) :- person(ID, Name, Weight, Length, IQ), !.getPerson(_ID, "0", 0, 0, 0).
deletePerson(ID) :- retract(person(ID, Name, _, _, _)), !, stdIO::write("Person ", Name, " with ID: ", ID, " has been deleted.\n").deletePerson(_).
![Page 32: AI/ES (Artificial Intelligence / Expert System) Visual Prolog: Part 3 2012. Fall. SME., Pukyong Nat l Univ. Kim, Minsoo](https://reader035.vdocuments.site/reader035/viewer/2022062303/5518c688550346b31f8b5802/html5/thumbnails/32.jpg)
A Minimal Database– Add declaration to ‘person.cl’ file.
Build!
![Page 33: AI/ES (Artificial Intelligence / Expert System) Visual Prolog: Part 3 2012. Fall. SME., Pukyong Nat l Univ. Kim, Minsoo](https://reader035.vdocuments.site/reader035/viewer/2022062303/5518c688550346b31f8b5802/html5/thumbnails/33.jpg)
A Minimal Database– Change ‘deletePerson.pro’ file Rebuild!
new(Parent) :- dialog::new(Parent), generatedInitialize(), person::getAllNames(NameList), SingletonList = removeDuplicates(NameList), nameListbox_ctl:addList(SingletonList).
![Page 34: AI/ES (Artificial Intelligence / Expert System) Visual Prolog: Part 3 2012. Fall. SME., Pukyong Nat l Univ. Kim, Minsoo](https://reader035.vdocuments.site/reader035/viewer/2022062303/5518c688550346b31f8b5802/html5/thumbnails/34.jpg)
A Minimal Database– Edit ‘deletePerson.dlg’ dialog
• nameListbox_ctl SelectionChangeListener Event onNameListboxSelectionChanged
onNameListboxSelectionChanged(Source) :- [Name | _T] = Source:getSelectedItems(), person::getSomeIDs(Name, IDList), idListbox_ctl:clearAll(), id_ctl:setText(""), name_ctl:setText(""), idListbox_ctl:addList(IDList), !.onNameListboxSelectionChanged(_Source).
![Page 35: AI/ES (Artificial Intelligence / Expert System) Visual Prolog: Part 3 2012. Fall. SME., Pukyong Nat l Univ. Kim, Minsoo](https://reader035.vdocuments.site/reader035/viewer/2022062303/5518c688550346b31f8b5802/html5/thumbnails/35.jpg)
A Minimal Database• idListbox_ctl SelectionChangeListener Event
onIdListboxSelectionChanged
onIdListboxSelectionChanged(Source) :- [ID | _T] = Source:getSelectedItems(), person::getPerson(ID, Name, _, _, _), id_ctl:setText(ID), name_ctl:setText(Name), !.onIdListboxSelectionChanged(_Source).
![Page 36: AI/ES (Artificial Intelligence / Expert System) Visual Prolog: Part 3 2012. Fall. SME., Pukyong Nat l Univ. Kim, Minsoo](https://reader035.vdocuments.site/reader035/viewer/2022062303/5518c688550346b31f8b5802/html5/thumbnails/36.jpg)
A Minimal Database• OK-button ClickResponder Event onOkClick
![Page 37: AI/ES (Artificial Intelligence / Expert System) Visual Prolog: Part 3 2012. Fall. SME., Pukyong Nat l Univ. Kim, Minsoo](https://reader035.vdocuments.site/reader035/viewer/2022062303/5518c688550346b31f8b5802/html5/thumbnails/37.jpg)
A Minimal Database• Build / Try!
– Change ‘deletePerson.dlg‘• Cancel-button ClickResponder
onCancelClick
![Page 38: AI/ES (Artificial Intelligence / Expert System) Visual Prolog: Part 3 2012. Fall. SME., Pukyong Nat l Univ. Kim, Minsoo](https://reader035.vdocuments.site/reader035/viewer/2022062303/5518c688550346b31f8b5802/html5/thumbnails/38.jpg)
A Minimal Database• Add Dialog to change a person record
– Add ‘changePerson.dlg‘ under forms package.
![Page 39: AI/ES (Artificial Intelligence / Expert System) Visual Prolog: Part 3 2012. Fall. SME., Pukyong Nat l Univ. Kim, Minsoo](https://reader035.vdocuments.site/reader035/viewer/2022062303/5518c688550346b31f8b5802/html5/thumbnails/39.jpg)
A Minimal Database– Edit ‘changePerson.dlg‘
• Add ‘List Box’ and ‘Edit Control’ Build All!
nameListbox_ctlidListbox_ctl
name_ctlweight_ctllength_ctliq_ctl
id_ctl
ReadOnly:True
![Page 40: AI/ES (Artificial Intelligence / Expert System) Visual Prolog: Part 3 2012. Fall. SME., Pukyong Nat l Univ. Kim, Minsoo](https://reader035.vdocuments.site/reader035/viewer/2022062303/5518c688550346b31f8b5802/html5/thumbnails/40.jpg)
A Minimal Database– Add menu/menu-item and connect
• TaskMenu.mnu Database/Change Person• TaskWindow.win onDatabaseChangePerson
![Page 41: AI/ES (Artificial Intelligence / Expert System) Visual Prolog: Part 3 2012. Fall. SME., Pukyong Nat l Univ. Kim, Minsoo](https://reader035.vdocuments.site/reader035/viewer/2022062303/5518c688550346b31f8b5802/html5/thumbnails/41.jpg)
A Minimal Database– Add a predicate to ‘person.pro’ file.
changePerson(ID, Name, Weight, Length, IQ) :- retract(person(ID, _, _, _, _)), assertz(person(ID, Name, Weight, Length, IQ)), !, stdIO::write("Person ", Name, " with ID: ", ID, " has been changed."), stdIO::nl.changePerson(_, _, _, _, _).
![Page 42: AI/ES (Artificial Intelligence / Expert System) Visual Prolog: Part 3 2012. Fall. SME., Pukyong Nat l Univ. Kim, Minsoo](https://reader035.vdocuments.site/reader035/viewer/2022062303/5518c688550346b31f8b5802/html5/thumbnails/42.jpg)
A Minimal Database– Add declaration to ‘person.cl’ file.
Build!
![Page 43: AI/ES (Artificial Intelligence / Expert System) Visual Prolog: Part 3 2012. Fall. SME., Pukyong Nat l Univ. Kim, Minsoo](https://reader035.vdocuments.site/reader035/viewer/2022062303/5518c688550346b31f8b5802/html5/thumbnails/43.jpg)
A Minimal Database– Change ‘changePerson.pro’ file
Rebuild!
new(Parent) :- dialog::new(Parent), generatedInitialize(), person::getAllNames(NameList), SingletonList = removeDuplicates(NameList), nameListbox_ctl:addList(SingletonList).
![Page 44: AI/ES (Artificial Intelligence / Expert System) Visual Prolog: Part 3 2012. Fall. SME., Pukyong Nat l Univ. Kim, Minsoo](https://reader035.vdocuments.site/reader035/viewer/2022062303/5518c688550346b31f8b5802/html5/thumbnails/44.jpg)
A Minimal Database– Edit ‘changePerson.dlg’ dialog
• nameListbox_ctl SelectionChangeListener Event onNameListboxSelectionChanged
onNameListboxSelectionChanged(Source) :- [Name | _T] = Source:getSelectedItems(), person::getSomeIDs(Name, IDList), idListbox_ctl:clearAll(), id_ctl:setText(""), name_ctl:setText(""), weight_ctl:setText(""), length_ctl:setText(""), iq_ctl:setText(""), idListbox_ctl:addList(IDList), !.onNameListboxSelectionChanged(_Source).
![Page 45: AI/ES (Artificial Intelligence / Expert System) Visual Prolog: Part 3 2012. Fall. SME., Pukyong Nat l Univ. Kim, Minsoo](https://reader035.vdocuments.site/reader035/viewer/2022062303/5518c688550346b31f8b5802/html5/thumbnails/45.jpg)
A Minimal Database• idListbox_ctl SelectionChangeListener Event
onIdListboxSelectionChanged
onIdListboxSelectionChanged(Source) :- [ID | _T] = Source:getSelectedItems(), person::getPerson(ID, Name, Weight, Length, IQ), id_ctl:setText(ID), name_ctl:setText(Name), weight_ctl:setText(toString(Weight)), length_ctl:setText(toString(Length)), iq_ctl:setText(toString(IQ)), !.onIdListboxSelectionChanged(_Source).
![Page 46: AI/ES (Artificial Intelligence / Expert System) Visual Prolog: Part 3 2012. Fall. SME., Pukyong Nat l Univ. Kim, Minsoo](https://reader035.vdocuments.site/reader035/viewer/2022062303/5518c688550346b31f8b5802/html5/thumbnails/46.jpg)
A Minimal Database• OK-button ClickResponder Event onOkClick
onOkClick(_Source) = button::defaultAction :- ID = id_ctl:getText(), Name = name_ctl:getText(), Weight = toTerm(weight_ctl:getText()), Length = toTerm(length_ctl:getText()), IQ = toTerm(iq_ctl:getText()), person::changePerson(ID, Name, Weight, Length, IQ).
![Page 47: AI/ES (Artificial Intelligence / Expert System) Visual Prolog: Part 3 2012. Fall. SME., Pukyong Nat l Univ. Kim, Minsoo](https://reader035.vdocuments.site/reader035/viewer/2022062303/5518c688550346b31f8b5802/html5/thumbnails/47.jpg)
A Minimal Database• Rebuild All / Try!
![Page 48: AI/ES (Artificial Intelligence / Expert System) Visual Prolog: Part 3 2012. Fall. SME., Pukyong Nat l Univ. Kim, Minsoo](https://reader035.vdocuments.site/reader035/viewer/2022062303/5518c688550346b31f8b5802/html5/thumbnails/48.jpg)
A Minimal Database• Saving and consulting the database
– Internal database is a volatile storage.• Save an internal database to disk save/2
– Arguments: filename, internal database name– Give a name to internal database to save it!
– Change ‘person.pro’ file to name a database.
![Page 49: AI/ES (Artificial Intelligence / Expert System) Visual Prolog: Part 3 2012. Fall. SME., Pukyong Nat l Univ. Kim, Minsoo](https://reader035.vdocuments.site/reader035/viewer/2022062303/5518c688550346b31f8b5802/html5/thumbnails/49.jpg)
A Minimal Database– In ‘person.pro’ file.
• Add 2 predicates and ‘file’ library.
saveDatabase() :- file::existFile("personDB.txt"), !, file::delete("personDB.txt"), file::save("personDB.txt", personDB), stdIO::write("The database has been overwritten to file personDB.txt\n").saveDatabase() :- file::save("personDB.txt", personDB), stdIO::write("The database has been saved to file personDB.txt\n").
consultDatabase() :- file::consult("personDB.txt", personDB), stdIO::write("Records have been added from file personDB.txt"), stdIO::nl.
![Page 50: AI/ES (Artificial Intelligence / Expert System) Visual Prolog: Part 3 2012. Fall. SME., Pukyong Nat l Univ. Kim, Minsoo](https://reader035.vdocuments.site/reader035/viewer/2022062303/5518c688550346b31f8b5802/html5/thumbnails/50.jpg)
A Minimal Database– Add declaration to ‘person.cl’ file.
Build!
![Page 51: AI/ES (Artificial Intelligence / Expert System) Visual Prolog: Part 3 2012. Fall. SME., Pukyong Nat l Univ. Kim, Minsoo](https://reader035.vdocuments.site/reader035/viewer/2022062303/5518c688550346b31f8b5802/html5/thumbnails/51.jpg)
A Minimal Database– Add menu-items and connect
• TaskMenu.mnu Window.win
![Page 52: AI/ES (Artificial Intelligence / Expert System) Visual Prolog: Part 3 2012. Fall. SME., Pukyong Nat l Univ. Kim, Minsoo](https://reader035.vdocuments.site/reader035/viewer/2022062303/5518c688550346b31f8b5802/html5/thumbnails/52.jpg)
A Minimal Database• Build and Execute!