Page 1 of 1

I need help with my final assignment, here is the question I am struggling with: The prolog_structures file looks like t

Posted: Sun May 15, 2022 1:10 pm
by answerhappygod
I need help with my final assignment, here is the question I am
struggling with:
I Need Help With My Final Assignment Here Is The Question I Am Struggling With The Prolog Structures File Looks Like T 1
I Need Help With My Final Assignment Here Is The Question I Am Struggling With The Prolog Structures File Looks Like T 1 (54.38 KiB) Viewed 78 times
The prolog_structures file looks like this:
I Need Help With My Final Assignment Here Is The Question I Am Struggling With The Prolog Structures File Looks Like T 2
I Need Help With My Final Assignment Here Is The Question I Am Struggling With The Prolog Structures File Looks Like T 2 (106.21 KiB) Viewed 78 times
I Need Help With My Final Assignment Here Is The Question I Am Struggling With The Prolog Structures File Looks Like T 3
I Need Help With My Final Assignment Here Is The Question I Am Struggling With The Prolog Structures File Looks Like T 3 (113.92 KiB) Viewed 78 times
I Need Help With My Final Assignment Here Is The Question I Am Struggling With The Prolog Structures File Looks Like T 4
I Need Help With My Final Assignment Here Is The Question I Am Struggling With The Prolog Structures File Looks Like T 4 (91.33 KiB) Viewed 78 times
Please help
final.py 102 103 104 105 Problem 4 Following the Abstract interpreter pseudocode in the lecture note Control in Prolog to implement a nondeterministic Prolog interpreter. 106 107 108 109 nondet_query (program, goal) where the first argument is a program which is a list of Rules. the second argument is a goal which is a list of Terms. 110 111 112 The function returns a list of Terms (results), which is an instance of the original goal and is a logical consequence of the program. See the tests cases (in src/main.py) as examples. 113 114 115 E def nondet query(self, program: List[Rule), eggalni List[Term]) -> List[Term]: return [] 116 117

prolog_structures.py # Data structures to represent Prolog terms. 2 3 # Every clause in a prolog program is encoded as a rule # A fact is a rule with empty body. 5 class Rule: 6 # head is a function 7 # body is a list* of functions (see RuleBody) 8 def __init__(self, head, body):... 4 13 def _str__(self): return str(self.head) + 14 ' :- ' + str(self.body) 15 16 of def Leq__(self, other): if not isinstance (other, Rule): return NotImplemented return self.head == other.head and self.body == other.body of def __hash__(self): return hash(self.head) + hash(self.body) 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 # Rule body is a list of functions (terms). class RuleBody: def __init__(self, terms): assert isinstance(terms, list) self.terms = terms def separator(self): return ',' of def _._str__(self): return '(' + (self.separator() + ' ').join( list (map(str, self.terms))) + ')' 36 37 38 39 of def Leq__(self, other): if not isinstance (other, RuleBody): return NotImplemented return self.terms == other. terms 40 41 42 43 of def_hash__(self): return hash(self.terms) 44 45

prolog_structures.py 47 ol class Term: 48 pass 49 50 51 52 53 # A function is, for example, father(rickard, ned). class Function (Term): def _init__(self, relation, terms): self.relation = relation # function name 모 self.terms = terms # funcion parameters 54 55 56 57 58 o 59 def str _str__(self): str_rel = str(self.relation) if not self.terms: # print (f'function {str_rel}') return str_rel # print (f'Function {str_rel}') return str_rel + 'C' +', '.join(map(str, self.terms)) + ')'. - 60 61 62 A 63 64 OTO 65 def __eq__(self, other): if not isinstance (other, Function): return Not Implemented return self.relation == other.relation and self.terms == other. terms 66 67 A 68 69 def __hash__(self): return hash(self.relation) + hash(self.terms) 70 71 72 73 74 # Prolog Variables, e.g. X, Y, ... class Variable(Term): def _init__(self, value): a self.value = value 75 76 77 78 of 79 def_str__(self): # print (f"Variable: {self.value} type {type(self.value)}") return self.value 80 A 81 82 o def is_anonym(self): return self.value[0] == 83 a 84 85 of def 86 Leq__(self, other): if not isinstance(other, Variable): return Not Implemented return self.value == other.value 87 88 부

prolog_structures.py 92 93 94 95 이 ol ol class Constant(Term): def _init__(self, value): self.value = value 96 97 98 ol of 99 def _str__(self): return str(self.value) 100 101 of 102 def __eq__(self, other): if not isinstance(other, Constant): return NotImplemented return self.value == other.value 103 104 105 106 def _hash__(self): return hash(self.value) 107 108 109 110 111 # Prolog Atoms, e.g. rickard, ned, ... Eclass Atom(Constant): def __init__(self, value): super()._init__(value) 112 113 114 of def 115 116 117 _str. (self): # print (f"Atom: {self.value} type {type(self.value)}") return str(self.value) 118 119 pass 120 121 122 123 # Prolog Numbers, e.g. 1, 2, ... class Number (Constant): def __init__(self, value): supero._init__(int(value)) 124 125 126 127 of 128 129 def __str_(self): # print (f"Number: {self.value} type {type(self.value)}") return str(self.value) 130 131 pass 132