Question: Write the following program in Python(with comments #) , thanks. Program : Write a Horn clause inference( More detail Image on this is provided below
Write the following program in Python(with comments #), thanks.
Program: Write a Horn clause inference(More detail Image on this is provided below) engine which accepts a filename from the user, reads Horn clauses from that file, and then makes all possible deductions using forward chaining. The format of the input file will be one Horn clause per line in PROLOG notation(Image provided below). For example, if the data file contains B:-A. D:-B,C. A. C. then the program will deduce B and D are true.
Forward Chaining algorithm:

Horn Clause(Fig 7.14 pseudocode):

Note: If this info isn't enough, then you can also google about it, anything that can help you out. Thanks.
function PL-FC-ENTAILS?(KB, q) returns true or false inputs: KB, the knowledge base, a set of propositional definite clauses g, the query, a proposition symbol count a table, where count [c] is the number of symbols in c's premise inferred a table, where inferred[s] is initially false for all symbols agenda a queue of symbols, initially symbols known to be true in KB while agenda is not empty do p POP( agenda) if p = q then return true if inferredlp]-false then inferred[p] true for each clause c in KB where p is in c.PREMISE do decrement count[c] if count[c] 0 then add c.CONCLUSION to agenda return false Figure 7.15 The forward-chaining algorithm for propositional logic. The agenda keeps track of symbols known to be true but not yet "processed." The count table keeps track of how many premises of each implication are as yet unknown. Whenever a new symbol p from the agenda is processed, the count is reduced by one for each implication in whose premise p appears (easily identified in constant time with appropriate indexing.) If a count reaches zero, all the premises of the implication are known, so its conclusion can be added to the agenda. Finally, we need to keep track of which symbols have been processed; a symbol that is already in the set of inferred symbols need not be added to the agenda again. This avoids redundant work and prevents loops caused by implications such as Q and Q P
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
