Please help, I need this for my final assignment:
Here is what prolog_structure file looks like:
Please help! Thanks
final.py x 118 119 LUI 120 Challenge Problem 121 122 123 det_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. 124 125 126 127 The function returns a list of term lists (results). Each of these results is an instance of the original goal and is a logical consequence of the program. If the given goal is not a logical consequence of the program, then the result is an empty list. See the test cases (in src/main.py) as examples. 128 129 130 131 人口= def det.query(self, programu: List[Rule], pgoalu: List[Term]) -> List[List[Term]]: return [pgoal] 132 133 134 135 136
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
Please help, I need this for my final assignment: Here is what prolog_structure file looks like: Please help! Thanks
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
Please help, I need this for my final assignment: Here is what prolog_structure file looks like: Please help! Thanks
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!