Prolog Recursion A3

1) More Prolog Recursion, 5 marks.

This link shows you the start of a prolog source file consisting of family (parent/child) relationships starting from someone you know. In your prior work for A2, you used parent and grandparent relationships. You may or may not have gone further back, but in case you did not, your grandparent’s parents are great-grandparents, their parents are great-great-grandparents and so on. The data in this file goes much (much) deeper than this. For this question, I am asking you to write a predicate greatcount(Person1,Person2,N) and add it to this source file. You may also write supporting predicates that you need, but you may not add any new facts to the source file. The three items participating in the greatcount() relationship are two symbols (persons in this system) and an integer, respectively. The purpose of greatcount is to count the number of greats in a relationship between the first person (the older person) and the second person (the younger or more recent person). For example, if X is Y’s great-great-grandparent, greatcount(X,Y,N) should produce N=2 if N is unbound. Similarly, in the same setting, greatcount(X,Y,2) should produce Yes. If X is not in a great-…-great grandparent relationship with Y (this includes if x and y were reversed in the above queries), then the predicate should produce No. A No result would also happen, for example, if x was only y’s grandparent, or if they were not related at all (e.g. if you picked a name that was not in this system for a query). Your predicate is NOT expected to bind N to 0 in those cases – simply producing No is fine (taking care of 0 for someone that is only a grandparent or parent is more difficult, so I am asking you to ignore that).

Your predicate should work for any combination of constants or variables. So, greatcount(N,fred,2) would find person(s) that are fred’s great-great grandparent, greatcount(fred,Y,3) would find Y= fred’s great-great-great grandchild(ren), greatcount(N,fred,M) would find all the great- possibilities for fred’s ancestry, along with the number of greats for each, and greatcount(X,Y,Z) with all variables unbound would find all persons in any number of greats-grandparent relationship along with the count of greats. You are NOT allowed to use bagof or setof in this, or any equivalent that processes results en mass: let one result be found at a time and hit ; as usual to get others. You do not need cut, fail, or any built-in predicate to see if a variable is bound or not for this: just basic recursion and simple prolog mathematics.

Add your predicate definitions to the source file provided in the above link, and test this thoroughly, covering the various possibilities of bound and unbound variables. Make sure you include in your tests finding the number of greats in the relationship between the following:

Ragnar Lothbrok (ragnarLothbrok – yes, that guy from the popular TV series Vikings, and John Anderson (johnAnderson – yes, that guy).

Brynhildr The Valkyrie (brynhildrTheValkyrie – yes, that character from Wagner’s Ring Cycle, Der Ring des Niebelungen) and John Anderson (johnAnderson – yes, that guy).

Odin (odin – yes, that guy from the scandinavian pantheon and minor MCU character played by Anthony Hopkins) and John Anderson (johnAnderson – yes, played by that guy). When you are satisfied with your predicate testing, paste the text of your queries and results of tests into the source file as a comment to show your output. Like A2, remember to make sure you try reloading the file to make sure your comment is closed properly and does not affect how the code runs.

2) The main assignment, A Prototype Knowledge-Based System – 20 marks

This main part of this assignment involves developing the basics of a knowledge-based system in Prolog (all code must be yours – you cannot use a shell/add-on or components written by someone else). The specific domain is left up to you, but to make life easy on yourself it should be something that involves a natural goal-directed (backward) search, since this is what Prolog wants to do by default. You are certainly welcome to write your own more advanced search routines to do forward reasoning in Prolog as part of this question if you so desire, but this is not necessary. You are responsible for identifying the knowledge to collect about your topic area, for representing this knowledge, and for performing searches against that knowledge. Your system should be more than a trivial taxonomy/identification system like the rule-based example we went over in class (that is, it needs to be more complex than having a single obvious answer to any query that’s asked of it, where that answer can be seen easily before anybody even runs the system). It should have some sort of uncertainty inherent in the domain itself (most domains that are even semi-realistic do!).

It will be understood that you will not necessarily have in-depth knowledge of many sophisticated domains (e.g. medicine) but you each do have hobbies and interests that could be adapted to a knowledge-based system (and are likely experts in things related to computer science!). The knowledge you use should not be entirely arbitrary or made up on your own – that is, the markers should be able to see that the system is working properly based on knowledge that is pubicly available if they wanted to look it up.

A basic knowledge-based system that does not include any additional processing or more complex knowledge engineering will receive a minimal grade. To improve the quality of the processing, you could include additional features such as default rules, certainty factors, a structured representation (look further ahead in the text on this), or a simple explanation facility. Choosing problems that Prolog does not naturally support (i.e. writing your own search routines) is also worth extra credit. The quality of the knowledge engineering will also be a factor in the grading of the assignment.

Your handin should include tests of your system: please run these and paste them back into the source file as a comment. In addition, and also in a comment in your document, I would like you to produce a short write-up that describes what is inadequate about the system you’ve done, and some ideas on how to extend it to do those things in Prolog.

Handing In Your Assignment

Both of these questions involve a single prolog source file with output copied back into your source as comments. There will be two handins on the course website, one for each of the above questions. As per the other assignments, please do not leave this until the last minute, as the forms will disappear at the precise system time of the handin deadline.