"""
*******************************************************
Owner: Ashutosh Jha
For: APPCAIR BITS Pilani Goa Campus, Reflexis Systems
Function Name: addCombinationRules
THis function takes a Tree() Node, current row and a
bool value representing string type condition. The
function adds the input condition and data to the node.
*******************************************************
"""
def addCombinationRules(node,rule_list,cur_row,isstr):
#converting the expression into input condition
node.inp_cond = "("
for i in range(0,len(rule_list)):
if((rule_list[i]!="(") and (rule_list[i]!=")") and (rule_list[i]!="/")
and (rule_list[i]!="*") and (rule_list[i]!="+") and (rule_list[i]!="-")):
node.inp_cond = node.inp_cond + "cur_row['" + rule_list[i] + "']"
else:
#print(rule_list[i])
node.inp_cond = node.inp_cond + rule_list[i]
node.inp_cond = node.inp_cond + ")"
print("Value of your expression for Current row is:",eval(node.inp_cond))
#adding comparators and values to which comparison has to be made
if((isstr == "y") or (isstr == "Y")):
val_cmp = input("Enter the string to compare the expression with, i.e. enter RHS value:")
node.inp_cond = node.inp_cond + "==" + "'" + val_cmp + "'"
else:
op_dict = {1:"==",2:"<=",3:">="}
print("Kindly choose the operator by indicating" +
" the serial number from the following:")
for key, value in op_dict.items():
print(key, ' : ', value)
op = int(input())
val_cmp = float(input("Enter the value to compare the expression with, i.e. enter RHS:"))
if op in [1,2,3]:
node.inp_cond = node.inp_cond + op_dict[op] + str(val_cmp)
else:
print("Fail: Wrong input for operator. Do what is told! Exiting for now!")
exit(0)
node.data ="""
if(eval(node.inp_cond) == True):
node.belongs = True
print("Row No.",z,"satisfies condition in node",node.name)
else:
print("Row No.",z,"Does not satisfy condition in node",node.name)
node.belongs = False"""