Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions code/core/modules/Revision/Context
Original file line number Diff line number Diff line change
@@ -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():






196 changes: 196 additions & 0 deletions code/core/modules/Revision/Context.py
Original file line number Diff line number Diff line change
@@ -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



38 changes: 38 additions & 0 deletions code/core/modules/Revision/ContextController.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
class ContextController(Context):

def __init__(self, contextSet, attitudeSet, id):
super().__init__(self, contextSet, attitudeSet)




# 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):
setOfContexts.remove((Context(context.id))



27 changes: 27 additions & 0 deletions code/core/modules/Revision/PropositionSet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#from path to proposition
class PropositionSet(Proposition):
def __init__(self, id, name, propset):
self.name = name
self.id = id
self.propSet = propSet


#creating list

propSet = []


#appending instances of class proposition to this proposition set
def addToPropSet(node):
propSet.append(node.id)

def isEmpty():
if len(propSet)==0:
return True
else:
return False

def remove(node):
self.propSet.remove(node.id)


Loading