From 082e633f946017940cbfd2f632106601825f6032 Mon Sep 17 00:00:00 2001 From: kingmalak <94921010+kingmalak@users.noreply.github.com> Date: Tue, 10 May 2022 16:38:10 +0200 Subject: [PATCH 1/5] Create Revision --- code/core/modules/Revision | 1 + 1 file changed, 1 insertion(+) create mode 100644 code/core/modules/Revision diff --git a/code/core/modules/Revision b/code/core/modules/Revision new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/code/core/modules/Revision @@ -0,0 +1 @@ + From 98a66799a6286bf09c219c4abee42369cf7399a6 Mon Sep 17 00:00:00 2001 From: kingmalak <94921010+kingmalak@users.noreply.github.com> Date: Tue, 10 May 2022 16:38:22 +0200 Subject: [PATCH 2/5] Delete Revision --- code/core/modules/Revision | 1 - 1 file changed, 1 deletion(-) delete mode 100644 code/core/modules/Revision diff --git a/code/core/modules/Revision b/code/core/modules/Revision deleted file mode 100644 index 8b13789..0000000 --- a/code/core/modules/Revision +++ /dev/null @@ -1 +0,0 @@ - From 46f51cae7c08178e30a75597fd24a418a8c7e9a1 Mon Sep 17 00:00:00 2001 From: kingmalak <94921010+kingmalak@users.noreply.github.com> Date: Tue, 10 May 2022 16:41:38 +0200 Subject: [PATCH 3/5] Create Context --- code/core/modules/Revision/Context | 52 ++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 code/core/modules/Revision/Context diff --git a/code/core/modules/Revision/Context b/code/core/modules/Revision/Context new file mode 100644 index 0000000..3cbb17a --- /dev/null +++ b/code/core/modules/Revision/Context @@ -0,0 +1,52 @@ +class Context: + + def __init__(self): + pass + + def __init__(self, name, hyps, id): + self.name = name + self.hyps = hyps + self.id = id + + + hyps: { + + "Beliefs" : "hanshoof" , + "Desires" : "hanshoof", + "Intentions" : "nshoof" + } + #set of props per attitude that were user asserted + #key 3obar 3an ints + def get_context(self): + return self._name + + def addtoContext(Proposition p, Attitude a): + hyps.update({a : p}) + + def isSupported(Proposition p, Attitude a): + ('a', p) in hyps.items() + + + + + # Attitudes = hyps.keys() + #def search(Attitudes, a): + # for i in range(len(Attitudes)): + # if Attitudes[i] == a: + # return True + # return False + + + + + #def contexttoString(self.id): + + + #def checkContradiction(Proposition p): + #def resolveContradiction(): + + + + + + From 01c902f307cf2b868a25e95c343c428adc897c64 Mon Sep 17 00:00:00 2001 From: kingmalak <94921010+kingmalak@users.noreply.github.com> Date: Tue, 10 May 2022 16:42:16 +0200 Subject: [PATCH 4/5] Add files via upload --- .../modules/Revision/ContextController.py | 37 ++++++++++++++++++ code/core/modules/Revision/PropositionSet.py | 23 +++++++++++ code/core/modules/Revision/Support.py | 38 +++++++++++++++++++ .../modules/Revision/SupportController.py | 16 ++++++++ 4 files changed, 114 insertions(+) create mode 100644 code/core/modules/Revision/ContextController.py create mode 100644 code/core/modules/Revision/PropositionSet.py create mode 100644 code/core/modules/Revision/Support.py create mode 100644 code/core/modules/Revision/SupportController.py diff --git a/code/core/modules/Revision/ContextController.py b/code/core/modules/Revision/ContextController.py new file mode 100644 index 0000000..3521908 --- /dev/null +++ b/code/core/modules/Revision/ContextController.py @@ -0,0 +1,37 @@ +class ContextController(Context): + + def __init__(self, contextSet, attitudeSet, id): + super().__init__(self, contextSet, attitudeSet) + + + + setOfAttitudes = ["Beliefs", "Desires", "Intentions", ] + + setOfContexts = [] + + +def removeContext(Context c): + setOfContexts.remove(c.id) + + +#helper method to get key + +def get_key(val): + for key, value in hyps.items(): + if val == value: + return key + + return "key doesn't exist" + + +def checkContext(Proposition p): + + keys = hyps.keys() + values = hyps.values() + if p in values: + get_key(p) + + + + + \ No newline at end of file diff --git a/code/core/modules/Revision/PropositionSet.py b/code/core/modules/Revision/PropositionSet.py new file mode 100644 index 0000000..dfd55df --- /dev/null +++ b/code/core/modules/Revision/PropositionSet.py @@ -0,0 +1,23 @@ +#from path to proposition +class PropositionSet(Proposition): + def __init__(self, id): + self.id = id + + + #creating list + + propSet = [] + + + #appending instances of class proposition to this proposition set + def addToPropSet(Proposition p): + propSet.append(p.id) + + def isEmpty(): + if len(propSet)==0: + print('the proposition set is empty') + + def remove(prop): + propSet.remove(p) + + \ No newline at end of file diff --git a/code/core/modules/Revision/Support.py b/code/core/modules/Revision/Support.py new file mode 100644 index 0000000..43b91a2 --- /dev/null +++ b/code/core/modules/Revision/Support.py @@ -0,0 +1,38 @@ +class Support: + def __init__(self, id, node): + self.id = id + self.node = node + + supportStruct: ({'Beliefs': 'Geeks', + 'Desires': 'For', + 'Intentions':'Geeks'}) + #props used to derive a propo for which this is a support + #attitude:support + + def createSupport(Proposition p, Attitude a): + + supportStruct = add_values_in_dict(supportStruct, 'a', p) + + if a not in supportStruct: + supportStruct[a] = p + + #3ayza ashoof law feeh key bel attitude da w law feeh azawed value, + #law mafeesh n update el dict + + #helper method to append multiple values to the same key + def add_values_in_dict(supportStruct, key , list_of_values): + if key in supportStruct: + supportStruct[key] = list() + supportStruct[key].extend(list_of_values) + return supportStruct + + + + def removePropFromSupports(Proposition p): + + allProps = supportStruct.values() + for i in allProps: + if allProps[i] == p: + allProps.remove(p) + + \ No newline at end of file diff --git a/code/core/modules/Revision/SupportController.py b/code/core/modules/Revision/SupportController.py new file mode 100644 index 0000000..e0c262c --- /dev/null +++ b/code/core/modules/Revision/SupportController.py @@ -0,0 +1,16 @@ +import itertools +class SupportController(Support,PropositionSet): + def __init__(self, id, node): + super().__init__(self, id, node) + + + def combineSupports(PropositionSet): + + for i in propSet: + xty + + + + + + #def removeFromSupports(PropositionSet): \ No newline at end of file From ed49b8beadfa87dff36fe0eccd9a33c2ae865432 Mon Sep 17 00:00:00 2001 From: kingmalak <94921010+kingmalak@users.noreply.github.com> Date: Mon, 6 Jun 2022 03:19:31 +0200 Subject: [PATCH 5/5] Add files via upload --- code/core/modules/Revision/Context.py | 196 ++++++++++++++++++ .../modules/Revision/ContextController.py | 51 ++--- code/core/modules/Revision/PropositionSet.py | 16 +- code/core/modules/Revision/Support.py | 135 +++++++++--- .../modules/Revision/SupportController.py | 84 +++++++- 5 files changed, 418 insertions(+), 64 deletions(-) create mode 100644 code/core/modules/Revision/Context.py diff --git a/code/core/modules/Revision/Context.py b/code/core/modules/Revision/Context.py new file mode 100644 index 0000000..946716c --- /dev/null +++ b/code/core/modules/Revision/Context.py @@ -0,0 +1,196 @@ +from Support.py import Support +from PropositionSet.py import PropositionSet +from operator import itemgetter +class Context: + + def __init__(self): + pass + + def __init__(self, name, hyps, id): + self.name = name + self.hyps = hyps + self.id = id + + + hyps: {} + # def populatehyps(): + # keys = range(len(attitudes)) + # values = PropositionSet(propset) #call constructor of proposition set + # for i in keys: + # hyps[i] = values(i) + # return hyps + + def generate_sets(sets_input): + + sets_input = re.sub(" ", "", sets_input) + sets_input = sets_input[1:-1] + + index1 = 0 + + for current_index, character in enumerate(sets_input): + if character == '[': + index1 = current_index + 1 + continue + + if character == ']': + result.append(get_set_from_comma_separated(sets_input[index1:current_index])) + + return result + + + def get_set_from_comma_separated(text): + generated_set = set() + + split_text = text.split(',') + for item in split_text: + generated_set.add(item) + + return frozenset(generated_set) + + def insert_into_dictionary(key, sets_array, dictionary): + if Context.getIndex(key) not in hyps: + hyps[Context.getIndex(key)] = set() + + for item in sets_array: + hyps[Context.getIndex(key)].add(item) + + + + + for i in range(0, 5): + input_key = input("Enter key") + + generated_sets = generate_sets(input("Enter sets")) + insert_into_dictionary(input_key, generated_sets, hyps) + + def get_context(self): + return self._name + + # def addtoContext(node, attitude): + # hyps[self.getIndex(attitude)].append(node) + + + def isSupported(node, attitude): + x = Support.supportStruct[node.supportset()] + if isinstance(x, dict): + + for i in x: + supps = list(Support.supportStruct[key]) + for j in hyps: + if supps <= list(hyps.get((Context.getIndex(attitude)))): + return True + + return False + # dictofsupports = dict(Support.supportStruct.get(key)) + # for i in dictofsupports: + # if key in Support.supportStruct.keys(): + # res = list(map(itemgetter(key), Support.supportStruct)) + + def setAttitudes(attitude): + setofattitudes = [ ] + input_string = input("Enter all attitudes separated by space ") + # Split string into words + family_list = input_string.split(" ") + for attitude in family_list: + setofattitudes.append(attitude) + + return setofattitudes + + x = setofattitudes + + + def setconsistentatts(consistentatts): + setofconistentatts = [ ] + n = int(input("Enter number of elements : ")) + + for i in range(0, n): + ele = [input(), int(input())] + setofconistentatts.append(ele) + return setofconistentatts + + y = setofconistentatts + + def getIndex(key): + for i in setofattitudes: + if setofattitudes(i)==key: + return i + + # Attitudes = hyps.keys() + #def search(Attitudes, a): + # for i in range(len(Attitudes)): + # if Attitudes[i] == a: + # return True + # return False + + #setconsistent + + def contexttoString(): + + return str(self.id) + str(self.hyps) + str(self.name) + + key_list = list(hyps.keys()) + val_list = list(hyps.values()) + presentin = [] + def checkContradiction(node): + + #for i in self.setofconsistentatts {B,I},{O,D} + # badal ! check andor with 0.0: + + for i in Context.val_list: + if val_list(i)== node: + att = val_list.index(node) + Context.presentin.append(att) + + + for j in Context.setofconistentatts: + key = Context.getIndex(Context.setofconistentatts(j)) + keystring = Context.setofconistentatts(j) + + v_list = list(hyps[key]) + # if node and !node in v_list: + #val_to_resolve = (node,!node,keystring) + #Context.resolveContradiction(val_to_resolve) + # return valtoresolve + # else: + # return "" + + + + #node.supportset in an attitude in resolve + #ret a tuple that says the nodes that contradict each other and the attitude they are in + #law mafeesh contradictionn ret empty string + + + # def resolveContradiction(val_to_resolve): + + # val = list(val_to_resolve) + # del hyps[val(2)[val(1)]] + #hayerga3li not p w edisres, haseel not p men desires + + + +#hakhod node +#1. check law node.downcable.rel (negation) is in the same context +#2. if false, break, return no contradiction +#3. if true: +#4. check the consistent attitudes, if negation of the node and the node are both present in +# attitudes that have to be consistent. +#5. if false; break. +#6. if true; check if the node and its negation are supported. + + +#def checkContradiction(node): + + # if node.ant(e).downcable.channels(i).report.sign == + + #check if n and not n are supported in the context for that set + + #hansheel n or not n? ask the user + #if they want to remove n + #hanrooh lel values that are in att 1 that pass the test and display them to the user + #remove one from each row so it is no longer supported + #update hyps + #give the supports n and ask to remove one node from each cell + + + \ No newline at end of file diff --git a/code/core/modules/Revision/ContextController.py b/code/core/modules/Revision/ContextController.py index 3521908..8a8ec15 100644 --- a/code/core/modules/Revision/ContextController.py +++ b/code/core/modules/Revision/ContextController.py @@ -5,33 +5,34 @@ def __init__(self, contextSet, attitudeSet, id): - setOfAttitudes = ["Beliefs", "Desires", "Intentions", ] + + # setOfAttitudes = ["Beliefs", "Desires", "Intentions", ] + # #setter dynamic + + # def setAttitudes(attitude): + # setofattitudes = [ ] + # input_string = input("Enter all attitudes separated by space ") + # # Split string into words + # family_list = input_string.split(" ") + # for attitude in family_list: + # setofattitudes.append(attitude) + + def getkey(val): + for key, value in Context.hyps.items(): + if val == value: + return key + + return "key doesn't exist" + setOfContexts = [] + #append self fel constructor + + #method to translate set pf attitudes to indices and then haave them be the key to both dictionaries. -def removeContext(Context c): - setOfContexts.remove(c.id) - - -#helper method to get key - -def get_key(val): - for key, value in hyps.items(): - if val == value: - return key - - return "key doesn't exist" - + def removeContext(context): + setOfContexts.remove((Context(context.id)) + -def checkContext(Proposition p): - - keys = hyps.keys() - values = hyps.values() - if p in values: - get_key(p) - - - - - \ No newline at end of file + diff --git a/code/core/modules/Revision/PropositionSet.py b/code/core/modules/Revision/PropositionSet.py index dfd55df..5ed5f0c 100644 --- a/code/core/modules/Revision/PropositionSet.py +++ b/code/core/modules/Revision/PropositionSet.py @@ -1,7 +1,9 @@ #from path to proposition class PropositionSet(Proposition): - def __init__(self, id): + def __init__(self, id, name, propset): + self.name = name self.id = id + self.propSet = propSet #creating list @@ -10,14 +12,16 @@ def __init__(self, id): #appending instances of class proposition to this proposition set - def addToPropSet(Proposition p): - propSet.append(p.id) + def addToPropSet(node): + propSet.append(node.id) def isEmpty(): if len(propSet)==0: - print('the proposition set is empty') + return True + else: + return False - def remove(prop): - propSet.remove(p) + def remove(node): + self.propSet.remove(node.id) \ No newline at end of file diff --git a/code/core/modules/Revision/Support.py b/code/core/modules/Revision/Support.py index 43b91a2..d156804 100644 --- a/code/core/modules/Revision/Support.py +++ b/code/core/modules/Revision/Support.py @@ -1,38 +1,119 @@ +from PropositionSet.py import PropositionSet +from Context.py import Context class Support: - def __init__(self, id, node): + def __init__(self, name, id, node, attitudes): + self.name = name self.id = id self.node = node + self.attitudes = attitudes #not yet in thesis 27/5 - supportStruct: ({'Beliefs': 'Geeks', - 'Desires': 'For', - 'Intentions':'Geeks'}) - #props used to derive a propo for which this is a support - #attitude:support - - def createSupport(Proposition p, Attitude a): + attitudes = Context.setofattitudes() - supportStruct = add_values_in_dict(supportStruct, 'a', p) + supportStruct: {} + + + + + def generate_sets(sets_input): + + sets_input = re.sub(" ", "", sets_input) + sets_input = sets_input[1:-1] + + index1 = 0 + + for current_index, character in enumerate(sets_input): + if character == '[': + index1 = current_index + 1 + continue + + if character == ']': + result.append(get_set_from_comma_separated(sets_input[index1:current_index])) + + return result + + + def get_set_from_comma_separated(text): + generated_set = set() + + split_text = text.split(',') + for item in split_text: + generated_set.add(item) + + return frozenset(generated_set) + + # def insert_into_nested_dictionary(key, innerkey, sets_array, dictionary): + # if Context.getIndex(key) not in dictionary: + # supportStruct[Context.getIndex(key)][Context.getIndex(innerkey)] = set() + + # for item in sets_array: + # supportStruct[Context.getIndex(key)][Context.getIndex(innerkey)].add(item) + + + + + + def insert_into_two_dimensional_dict(key1, key2, new_set_of_values, dictionary): + + attitude_mainkey = (Context.getIndex(key1)) + attitude_innerkey = (Context.getIndex(key2)) + + if attitude_mainkey not in supportStruct: + supportStruct[attitude_mainkey] = {} + + if attitude_innerkey not in supportStruct[attitude_mainkey]: + supportStruct[attitude_mainkey][attitude_innerkey] = set() + + supportStruct[attitude_mainkey][attitude_innerkey].add(new_set_of_values) + + return supportStruct + + #insert_into_two_dimensional_dict(1, 2, frozenset(["test1", "tes2"]), x) + + + # def create_support(node, attitude): - if a not in supportStruct: - supportStruct[a] = p + # self.supportStruct = add_values_in_dict(self.supportStruct, Context.getIndex(attitude), node) - #3ayza ashoof law feeh key bel attitude da w law feeh azawed value, - #law mafeesh n update el dict + # if Context.getIndex(attitude) not in supportStruct: + # supportStruct[Context.getIndex(attitude)] = node - #helper method to append multiple values to the same key - def add_values_in_dict(supportStruct, key , list_of_values): - if key in supportStruct: - supportStruct[key] = list() - supportStruct[key].extend(list_of_values) - return supportStruct + # #3ayza ashoof law feeh key bel attitude da w law feeh azawed value, + # #law mafeesh n update el dict + # #helper method to append multiple values to the same key + # def add_values_in_dict(supportStruct, key , list_of_values): + # if key in self.supportStruct: + # supportStruct[key] = list() + # supportStruct[key].extend(list_of_values) + # return supportStruct + + # def get_values(supportStruct): + + # for v in supportStruct.values(): + # if isinstance(v, dict): + # yield from supportStruct(v) + # else: + # yield v + + + # allProps = (list(get_values(supportStruct))) + + + # def removePropFromSupports(node): + + # for i in allProps: + # if allProps(i) == node: + # allProps.remove(node) + + + def removePropFromSupports(supportStruct,node): - def removePropFromSupports(Proposition p): - - allProps = supportStruct.values() - for i in allProps: - if allProps[i] == p: - allProps.remove(p) - - \ No newline at end of file + for v in supportStruct.values(): + if isinstance(v, dict): + allprops = supportStruct[v] + for i in allprops: + if allprops(i) == node: + supportStruct[v].remove(node) + return supportStruct + \ No newline at end of file diff --git a/code/core/modules/Revision/SupportController.py b/code/core/modules/Revision/SupportController.py index e0c262c..b33c79f 100644 --- a/code/core/modules/Revision/SupportController.py +++ b/code/core/modules/Revision/SupportController.py @@ -1,16 +1,88 @@ import itertools +from PropositionSet.py import PropositionSet +from Support.py import Support class SupportController(Support,PropositionSet): def __init__(self, id, node): - super().__init__(self, id, node) + Support.__init__(self, name, id, node, attitudes) + PropositionSet.__init__(id, name, propset) + #self.propositionset = [] - - def combineSupports(PropositionSet): - for i in propSet: - xty + vals = [] + #helper method, cross product between two dictionaries + # def cartesian_product(dict1, dict2): + # cartesian_dict = {} + # dict1_length = len(list(dict1.values())[0]) + # dict2_length = len(list(dict2.values())[0]) + # h = [] + # for key in dict1: + # for value in dict1[key]: + # if not key in cartesian_dict: + # cartesian_dict[key] = [] + # cartesian_dict[key].extend([value]*dict2_length) + # else: + # cartesian_dict[key].extend([value]*dict2_length) + # for key in dict2: + # cartesian_dict[key] = dict2[key]*dict1_length + # return cartesian_dict + setofspropsets =[[]] #########menennnnnnnnnnn##### + temp = [] + def combineSupports(setofspropsets): + + for index in setofspropsetst: + var = index.supportset() + support_sets.append(var) + x = crossproduct(index, index+1) + temp.append(x) + + for j in temp: + self.union(j,j+1) + + + def crossproduct(list1, list2): + for combination in itertools.product(list1, list2): + return combination + + def union(list1, list2): + final_list = lst1 + lst2 + return final_list + + + + def removeFromSupports(propset, attitude): + + for v in Support.supportStruct.values(): + if isinstance(v, dict): + allprops = supportStruct[v] + for i in allprops: + if allprops(i) <= propset: + supportStruct[v].remove(propset) + return supportStruct + # vals.append(supportStruct.get(attitude)) + # for index in vals: + # for j in propset: + # if vals(index) == PropositionSet(propset[j]): + # Support.supportStruct.pop(vals[index]) + # return supportStruct + + + # def removePropFromSupports(supportStruct,node): + + # for v in supportStruct.values(): + # if isinstance(v, dict): + # allprops = supportStruct[v] + # for i in allprops: + # if allprops(i) == node: + # supportStruct[v].remove(node) + # return supportStruct + + + - #def removeFromSupports(PropositionSet): \ No newline at end of file + + + \ No newline at end of file