def evaluate(self, programData, origProgData, argDict): results_array = c4_evaluator.runC4_wrapper(programData[0], argDict) orig_results_array = c4_evaluator.runC4_wrapper( origProgData[0], argDict) # ----------------------------------------------------------------- # # convert results array into dictionary eval_results_dict = tools.getEvalResults_dict_c4(results_array) orig_eval_results_dict = tools.getEvalResults_dict_c4( orig_results_array) # ----------------------------------------------------------------- # # collect all pos/not_ rule pairs rule_pairs = self.getRulePairs(eval_results_dict) logging.debug(" EVALUATE : rule_pairs = " + str(rule_pairs)) # ----------------------------------------------------------------- # # make sure tables do not overlap self.assertFalse(self.hasOverlap(rule_pairs, eval_results_dict)) # ----------------------------------------------------------------- # # make sure comb positive relation results are identical to molly # relation results self.check_results_alignment(orig_eval_results_dict, eval_results_dict)
def run_program_c4(program_data, argDict): # run c4 evaluation results_array = c4_evaluator.runC4_wrapper(program_data, argDict) parsedResults = tools.getEvalResults_dict_c4(results_array) return parsedResults
def evaluate(self, programData, expected_eval_path, argDict): noOverlap = False results_array = c4_evaluator.runC4_wrapper(programData[0], argDict) # ----------------------------------------------------------------- # # convert results array into dictionary eval_results_dict = tools.getEvalResults_dict_c4(results_array) # ----------------------------------------------------------------- # # collect all pos/not_ rule pairs rule_pairs = self.getRulePairs(eval_results_dict) logging.debug(" EVALUATE : rule_pairs = " + str(rule_pairs)) # ----------------------------------------------------------------- # # make sure tables do not overlap self.assertFalse(self.hasOverlap(rule_pairs, eval_results_dict)) # ----------------------------------------------------------------- # # make sure iedb_rewrites positive relation results are identical to molly # relation results if expected_eval_path: self.compare_evals(eval_results_dict, expected_eval_path)
def evaluate(self, allProgramData): # inject custom faults here. allProgramData = injectCustomFaults(allProgramData) results_array = c4_evaluator.runC4_wrapper(allProgramData) # ----------------------------------------------------------------- # # dump evaluation results locally eval_results_dump_dir = os.path.abspath(os.getcwd()) + "/data/" # make sure data dump directory exists if not os.path.isdir(eval_results_dump_dir): print "WARNING : evalulation results file dump destination does not exist at " + eval_results_dump_dir print "> creating data directory at : " + eval_results_dump_dir os.system("mkdir " + eval_results_dump_dir) if not os.path.isdir(eval_results_dump_dir): tools.bp( __name__, inspect.stack()[0][3], "FATAL ERROR : unable to create evaluation results dump directory at " + eval_results_dump_dir) print "...done." # data dump directory exists self.eval_results_dump_to_file(results_array, eval_results_dump_dir) # ----------------------------------------------------------------- # # parse results into a dictionary parsedResults = tools.getEvalResults_dict_c4(results_array) # ----------------------------------------------------------------- # return parsedResults
def get_program_results(self, argDict, cursor): # convert dedalus into c4 datalog allProgramData = dedt.translateDedalus(argDict, cursor) # run c4 evaluation results_array = c4_evaluator.runC4_wrapper(allProgramData[0], argDict) parsedResults = tools.getEvalResults_dict_c4(results_array) return parsedResults
def compare_evals(self, eval_results_dict, expected_eval_path): # ----------------------------------------------------------------- # # get a dictionary of the expected results expected_results_array = [] fo = open(expected_eval_path) for line in fo: line = line.rstrip() expected_results_array.append(line) fo.close() expected_eval_results_dict = tools.getEvalResults_dict_c4( expected_results_array) #self.check_results_alignment( expected_eval_results_dict, eval_results_dict ) #sys.exit( "blah" ) # ----------------------------------------------------------------- # # compare all positive tables (not prov) for rel_key in eval_results_dict: # ----------------------------------------------------------------- # # skip not_ rules, _prov rules, adom_ rules if rel_key.startswith( "not_" ) or \ rel_key.startswith( "domcomp_" ) or \ rel_key.startswith( "dom_" ) or \ rel_key.endswith( "_edb" ) or \ rel_key == "adom_string" or \ rel_key == "adom_int" or \ "_prov" in rel_key or \ "_agg" in rel_key : pass # ----------------------------------------------------------------- # else: actual_eval = eval_results_dict[rel_key] expected_eval = expected_eval_results_dict[rel_key] flag = True for expected_row in expected_eval: if not expected_row in actual_eval: logging.debug( " COMPARE_EVALS : missing row : relation = " + rel_key + "\nexpected_row = " + str(expected_row) + "\nactual_eval = " + str(actual_eval)) flag = False break self.assertTrue(flag)
def rewrite_to_datalog( argDict, factMeta, ruleMeta, cursor ) : logging.debug( " REWRITE : running process..." ) settings_path = argDict[ "settings" ] EOT = argDict[ "EOT" ] for rule in ruleMeta : rid = rule.rid cursor.execute( "SELECT attID,attName FROM GoalAtt WHERE rid=='" + str( rid ) + "'" ) goal_atts = cursor.fetchall() logging.debug( " DEDT : len( goal_atts ) = " + str( len( goal_atts )) ) goal_atts = tools.toAscii_multiList( goal_atts ) logging.debug( " DEDT : len( goal_atts ) = " + str( len( goal_atts )) ) logging.debug( " DEDT : goal_atts (0) = " + str( goal_atts ) ) logging.debug( " DEDT : r = " + dumpers.reconstructRule( rid, cursor ) ) # ----------------------------------------------------------------------------- # # dedalus rewrite logging.debug( " REWRITE : calling dedalus rewrites..." ) allMeta = dedalusRewriter.rewriteDedalus( argDict, factMeta, ruleMeta, cursor ) factMeta = allMeta[0] ruleMeta = allMeta[1] # be sure to fill in all the type info for the new rule definitions #setTypes.setTypes( cursor, argDict, ruleMeta ) for rule in ruleMeta : rid = rule.rid cursor.execute( "SELECT attID,attName FROM GoalAtt WHERE rid=='" + str( rid ) + "'" ) goal_atts = cursor.fetchall() goal_atts = tools.toAscii_multiList( goal_atts ) #logging.debug( " DEDT : goal_atts (1) = " + str( goal_atts ) ) logging.debug( " DEDT : rule.ruleData = " + str( rule.ruleData ) ) # ----------------------------------------------------------------------------- # # other rewrites # first get parameters for which rewrites to run. # ========== WILDCARD ========== # try : rewriteWildcards = tools.getConfig( settings_path, "DEFAULT", "WILDCARD_REWRITES", bool ) except ConfigParser.NoOptionError : logging.warning( "WARNING : no 'WILDCARD_REWRITES' defined in 'DEFAULT' section of " + settings_path + \ "...running without wildcard rewrites." ) rewriteWildcards = False pass # ========== DM ========== # try : RUN_DM = tools.getConfig( settings_path, "DEFAULT", "DM", bool ) except ConfigParser.NoOptionError : logging.warning( "WARNING : no 'DM' defined in 'DEFAULT' section of " + settings_path + \ "...running without dm rewrites" ) RUN_DM = False pass # ========== NW_DOM_DEF ========== # try : NW_DOM_DEF = tools.getConfig( settings_path, "DEFAULT", "NW_DOM_DEF", str ) except ConfigParser.NoOptionError : raise Exception( "no 'NW_DOM_DEF' defined in 'DEFAULT' section of " + settings_path + \ ". aborting..." ) # ========== COMBO ========== # try: RUN_COMB = tools.getConfig( settings_path, "DEFAULT", "COMB", bool ) except ConfigParser.NoOptionError : logging.info( "WARNING : no 'COMB' defined in 'DEFAULT' section of " + settings_path + \ "...running without combo rewrites" ) RUN_COMB = False pass # ========== IEDB ========== # try : RUN_IEDB_REWRITES = tools.getConfig( settings_path, "DEFAULT", "IEDB_REWRITES", bool ) except ConfigParser.NoOptionError : logging.info( "WARNING : no 'IEDB_REWRITES' defined in 'DEFAULT' section of " + settings_path + \ "...running without iedb rewrites" ) RUN_IEDB_REWRITES = False pass # ----------------------------------------------------------------------------- # # do wildcard rewrites # always do wildcard rewrites in prep for negative writes. if rewriteWildcards or \ ( NW_DOM_DEF == "sip" and \ ( argDict[ "neg_writes" ] == "dm" or \ argDict[ "neg_writes" ] == "combo" ) ) : logging.debug( " REWRITE : calling wildcard rewrites..." ) ruleMeta = rewrite_wildcards.rewrite_wildcards( ruleMeta, cursor ) # for rule in ruleMeta : # #logging.debug( "rule.ruleData = " + str( rule.ruleData ) ) # logging.debug( " REWRITE : (1) r = " + dumpers.reconstructRule( rule.rid, rule.cursor ) ) # #sys.exit( "blah2" ) # for rule in ruleMeta : # logging.debug( " DEDT : rule.ruleData (2) = " + str( rule.ruleData ) ) # be sure to fill in all the type info for the new rule definitions logging.debug( " REWRITE : running setTypes after wildcard rewrites." ) setTypes.setTypes( cursor, argDict, ruleMeta ) update_goal_types( ruleMeta ) else : setTypes.setTypes( cursor, argDict, ruleMeta ) # ----------------------------------------------------------------------------- # # iedb rewrites if RUN_IEDB_REWRITES or \ ( NW_DOM_DEF == "sip" and \ ( argDict[ "neg_writes" ] == "dm" or \ argDict[ "neg_writes" ] == "combo" ) ) : logging.debug( " REWRITE : calling iedb rewrites..." ) factMeta, ruleMeta = iedb_rewrites.iedb_rewrites( factMeta, \ ruleMeta, \ cursor, \ settings_path ) # for rule in ruleMeta : # rid = rule.rid # cursor.execute( "SELECT attID,attName FROM GoalAtt WHERE rid=='" + str( rid ) + "'" ) # goal_atts = cursor.fetchall() # goal_atts = tools.toAscii_multiList( goal_atts ) # logging.debug( " DEDT : goal_atts (3) = " + str( goal_atts ) ) #for rule in ruleMeta : # print c4_translator.get_c4_line( rule.ruleData, "rule" ) #for fact in factMeta : # print c4_translator.get_c4_line( fact.factData, "fact" ) #sys.exit( "asdf" ) # be sure to fill in all the type info for the new rule definitions logging.debug( " REWRITE : running setTypes after iedb rewrites." ) setTypes.setTypes( cursor, argDict, ruleMeta ) # ----------------------------------------------------------------------------- # # do dm rewrites if argDict[ "neg_writes" ] == "dm" : logging.debug( " REWRITE : calling dm rewrites..." ) factMeta, ruleMeta = dm.dm( factMeta, ruleMeta, cursor, argDict ) # returns new ruleMeta logging.debug( " REWRITE : final dm program lines:" ) for rule in ruleMeta : logging.debug( dumpers.reconstructRule( rule.rid, rule.cursor ) ) #sys.exit( "blah" ) # be sure to fill in all the type info for the new rule definitions logging.debug( " REWRITE : running setTypes after dm rewrites." ) setTypes.setTypes( cursor, argDict, ruleMeta ) # ----------------------------------------------------------------------------- # # do combo rewrites if argDict[ "neg_writes" ] == "comb" : # collect the results from the original program original_prog = c4_translator.c4datalog( argDict, cursor ) results_array = c4_evaluator.runC4_wrapper( original_prog, argDict ) parsedResults = tools.getEvalResults_dict_c4( results_array ) # run the neg rewrite for combinatorial approach # returns a new ruleMeta logging.debug( " REWRITE : calling combo rewrites..." ) ruleMeta, factMeta = combitorialNegRewriter.neg_rewrite( cursor, \ argDict, \ settings_path, ruleMeta, \ factMeta, \ parsedResults ) if argDict[ "neg_writes" ] == "combo" : logging.debug( " REWRITE : calling combo rewrites..." ) factMeta, ruleMeta = combo.combo( factMeta, ruleMeta, cursor, argDict ) #for r in ruleMeta : # print dumpers.reconstructRule( r.rid, r.cursor ) #sys.exit( "f**k" ) # for rule in ruleMeta : # rid = rule.rid # cursor.execute( "SELECT attID,attName FROM GoalAtt WHERE rid=='" + str( rid ) + "'" ) # goal_atts = cursor.fetchall() # goal_atts = tools.toAscii_multiList( goal_atts ) # logging.debug( " DEDT : goal_atts (2) = " + str( goal_atts ) ) # ----------------------------------------------------------------------------- # # provenance rewrites #logging.debug( " REWRITE : before prov dump :" ) #for rule in ruleMeta : # print rule # logging.debug( " REWRITE : (0) r = " + printRuleWithTypes( rule.rid, cursor ) ) #sys.exit( "blah2" ) # add the provenance rules to the existing rule set logging.debug( " REWRITE : calling provenance rewrites..." ) ruleMeta.extend( provenanceRewriter.rewriteProvenance( ruleMeta, cursor, argDict ) ) #for rule in ruleMeta : # #logging.debug( "rule.ruleData = " + str( rule.ruleData ) ) # logging.debug( " REWRITE : (1) rid = " + str( rule.rid ) + " : " + dumpers.reconstructRule( rule.rid, rule.cursor ) ) #sys.exit( "blah2" ) # be sure to fill in all the type info for the new rule definitions logging.debug( " REWRITE : running setTypes after provenance rewrites." ) setTypes.setTypes( cursor, argDict, ruleMeta ) # ----------------------------------------------------------------------------- # # for rule in ruleMeta : # logging.debug( "rule.ruleData = " + str( rule.ruleData ) ) # logging.debug( " REWRITE : (2) r = " + dumpers.reconstructRule( rule.rid, rule.cursor ) ) # sys.exit( "blah2" ) logging.debug( " REWRITE : ...done." ) return [ factMeta, ruleMeta ]
def get_current_results(argDict, cursor): original_prog = c4_translator.c4datalog(argDict, cursor) results_array = c4_evaluator.runC4_wrapper(original_prog, argDict) parsedResults = tools.getEvalResults_dict_c4(results_array) return parsedResults
def __init__( self, argDict = None, \ label = "", \ custom_fault = None ) : self.conclusion = "No conclusion." self.NUM_RUN_ITERATIONS = 0 self.graph_stats = None self.argDict = None self.label = label self.custom_fault = custom_fault self.tried_solns = [] # --------------------------------------------------------------- # # get configuration params # --------------------------------------------------------------- # # get dictionary of command line arguments if argDict: self.argDict = argDict else: self.argDict = parseCommandLineInput.parseCommandLineInput() # --------------------------------------------------------------- # # make sure the data directory exists if not os.path.isdir( os.path.abspath(self.argDict["data_save_path"] + "/../")): os.system("mkdir " + os.path.abspath(self.argDict["data_save_path"] + "/../")) if not os.path.isdir(os.path.abspath(self.argDict["data_save_path"])): os.system("mkdir " + os.path.abspath(self.argDict["data_save_path"])) # --------------------------------------------------------------- # # initialize a database for the IR saveDB = self.argDict["data_save_path"] + "/IR_" + label + ".db" if os.path.isfile(saveDB): os.remove(saveDB) # database for storing IR, stored in running script dir IRDB = sqlite3.connect(saveDB) self.cursor = IRDB.cursor() # --------------------------------------------------------------- # # generate the initial program self.datalog_with_clocks = None self.datalog_with_clocks = dedt.translateDedalus( self.argDict, self.cursor) # --------------------------------------------------------------- # # maintain a current solution index and formula id self.CURR_FMLA_ID = 0 self.CURR_SOLN_INDEX = 0 # --------------------------------------------------------------- # self.datalog_program_only = None self.clocks_only = None self.table_list_only = None self.datalog_program_only = self.get_program_only( self.datalog_with_clocks[0][0]) self.clocks_only = self.get_clocks_only(self.datalog_with_clocks[0][0]) self.table_list_only = self.datalog_with_clocks[0][1] logging.debug( " __INIT__ : self.datalog_program_only = " + \ str( self.datalog_program_only ) ) logging.debug( " __INIT__ : self.clocks_only = " + \ str( self.clocks_only ) ) logging.debug( " __INIT__ : self.table_list_only = " + \ str( self.table_list_only ) ) # --------------------------------------------------------------- # # perform evaluaton on the current version of datalog_with_clocks logging.debug(" __INIT__ : performing initial run...") # run c4 evaluation results_array = None results_dict = None results_array = c4_evaluator.runC4_wrapper( self.datalog_with_clocks[0], \ self.argDict ) results_dict = tools.getEvalResults_dict_c4(results_array) logging.debug(" __INIT__ : performing initial run...done.") # --------------------------------------------------------------- # # check for vacuous correctness if self.is_vacuously_correct(results_dict["pre"]): self.conclusion = "conclusion : spec is vacuously correct." elif self.is_vacuously_incorrect(results_dict["pre"], results_dict["post"]): self.conclusion = "conclusion : spec is vacuously incorrect." else: # --------------------------------------------------------------- # # generate orik rgg logging.debug(" __INIT__ : building initial provenance tree...") orik_rgg = copy.deepcopy(None) orik_rgg = ProvTree.ProvTree( rootname = "FinalState", \ parsedResults = results_dict, \ cursor = self.cursor, \ treeType = "goal", \ isNeg = False, \ eot = self.argDict[ "EOT" ], \ prev_prov_recs = {}, \ argDict = self.argDict ) self.graph_stats = None self.graph_stats = orik_rgg.create_pydot_graph( self.CURR_FMLA_ID, \ self.NUM_RUN_ITERATIONS, \ self.label ) logging.debug( " __INIT__ : building initial provenance tree...done.") # --------------------------------------------------------------- # # build a solution generator logging.debug(" __INIT__ : performing initial solve...") SOLVER_TYPE = argDict["solver"].lower() logging.debug(" __INIT__ : using solver type '" + SOLVER_TYPE + "'") if SOLVER_TYPE == "z3": self.solver = Z3_Solver.Z3_Solver(self.argDict, orik_rgg) elif SOLVER_TYPE == "pycosat": self.solver = PYCOSAT_Solver.PYCOSAT_Solver( self.argDict, orik_rgg) else: raise ValueError(" solver type '" + SOLVER_TYPE + "' not recognized.") logging.debug(" __INIT__ : performing initial solve...done.")
def run_on_custom_fault(self): logging.debug( " RUN ON CUSTOM FAULT : self.NUM_RUN_ITERATIONS = " + \ str( self.NUM_RUN_ITERATIONS ) ) # --------------------------------------------------------------- # # edit the clock table a_new_soln_clean = self.custom_fault logging.debug( " RUN ON CUSTOM FAULT : a_new_soln_clean : " + \ str( a_new_soln_clean ) ) new_clock_table = self.perform_clock_table_edits(a_new_soln_clean) logging.debug(" RUN ON CUSTOM FAULT : new_clock_table " + str(new_clock_table)) # --------------------------------------------------------------- # # perform another evaluation self.datalog_program_only.extend(new_clock_table) final_prog_info = [self.datalog_program_only, self.table_list_only] logging.debug(" RUN ON CUSTOM FAULT : final_prog_info = " + str(final_prog_info)) results_array = c4_evaluator.runC4_wrapper(final_prog_info, self.argDict) results_dict = tools.getEvalResults_dict_c4(results_array) # --------------------------------------------------------------- # # evaluate results to draw a conclusion if self.pre_does_not_imply_post(results_dict["pre"], results_dict["post"]): self.conclusion = "conclusion : found counterexample : " + str( a_new_soln_clean) return else: self.conclusion = "conclusion : spec is chaoxis-certified for " + \ "correctness on the given fault." print "+++++++++++++++++++++++++++++++" print " RUN ON CUSTOM FAULT : " print "results:" for key in results_dict: print ">>>>>>>>>>>>>>>>>>>>>>>>>" print key for tup in results_dict[key]: print tup # --------------------------------------------------------------- # # generate orik rgg logging.debug(" RUN ON CUSTOM FAULT : building provenance tree...") orik_rgg = copy.deepcopy(None) orik_rgg = ProvTree.ProvTree( rootname = "FinalState", \ parsedResults = results_dict, \ cursor = self.cursor, \ treeType = "goal", \ isNeg = False, \ eot = self.argDict[ "EOT" ], \ prev_prov_recs = {}, \ argDict = self.argDict ) self.graph_stats = None self.graph_stats = orik_rgg.create_pydot_graph( self.CURR_FMLA_ID, \ self.NUM_RUN_ITERATIONS, \ self.label ) logging.debug( " RUN ON CUSTOM FAULT : building provenance tree...done.")
def run(self): logging.debug( " CHAOXIS RUN : -----------------------------------------") logging.debug( " CHAOXIS RUN : self.NUM_RUN_ITERATIONS = " + \ str( self.NUM_RUN_ITERATIONS ) ) logging.debug( " CHAOXIS RUN : self.CURR_SOLN_INDEX = " + \ str( self.CURR_SOLN_INDEX ) ) logging.debug( " CHAOXIS RUN : self.CURR_FMLA_ID = " + \ str( self.CURR_FMLA_ID ) ) # --------------------------------------------------------------- # # break on vacuouc correctness if not self.conclusion == "No conclusion.": return # --------------------------------------------------------------- # # run on the custom fault only, if applicable if self.custom_fault: self.run_on_custom_fault() else: # --------------------------------------------------------------- # # get a new soln if self.solver.solver_type == "z3": a_new_soln = self.solver.get_next_soln() elif self.solver.solver_type == "pycosat": a_new_soln = self.get_soln_at_index(self.solver) else: raise ValueError( "alright. how did you get this far w/o specifying a " + \ "known solver? aborting..." ) logging.debug(" CHAOXIS RUN : a_new_soln = " + str(a_new_soln)) assert (a_new_soln != None) # --------------------------------------------------------------- # # edit the clock table a_new_soln_clean = self.get_clean_soln(a_new_soln) logging.debug(" CHAOXIS RUN : a_new_soln_clean : " + str(a_new_soln_clean)) # only try new solns if not self.already_tried(a_new_soln_clean): new_clock_table = self.perform_clock_table_edits( a_new_soln_clean) logging.debug( " CHAOXIS RUN : adding to tried_solns '" + \ str( a_new_soln_clean ) + "'" ) self.tried_solns.append(a_new_soln_clean) logging.debug(" CHAOXIS RUN : new_clock_table " + str(new_clock_table)) # --------------------------------------------------------------- # # perform another evaluation prog_cp = copy.deepcopy(self.datalog_program_only) prog_cp.extend(new_clock_table) final_prog_info = [prog_cp, self.table_list_only] logging.debug(" CHAOXIS RUN : final_prog_info = " + str(final_prog_info)) results_array = c4_evaluator.runC4_wrapper( final_prog_info, self.argDict) results_dict = tools.getEvalResults_dict_c4(results_array) # -------------------------------------------------------------- # # evaluate results to draw a conclusion if self.pre_does_not_imply_post(results_dict["pre"], results_dict["post"]): self.conclusion = "conclusion : found counterexample : " + \ str( a_new_soln_clean ) elif self.no_more_fmlas_or_solns(): self.conclusion = "conclusion : spec is chaoxis-certified for correctness." else: # --------------------------------------------------------------- # # repeat until a corrupting fault appears or until # no more formulas and solns exist if self.another_soln_exists() or \ self.another_fmla_exists() : self.NUM_RUN_ITERATIONS += 1 self.run() else: self.conclusion = "conclusion : alright, something's weird." else: if self.another_soln_exists() or \ self.another_fmla_exists() : self.NUM_RUN_ITERATIONS += 1 self.run() elif self.no_more_fmlas_or_solns(): self.conclusion = "conclusion : spec is chaoxis-certified for correctness." else: logging.debug(" CHAOXIS RUN : alright. this is weird.") logging.debug( " CHAOXIS RUN : NUM_RUN_ITERATIONS == " + \ str( self.NUM_RUN_ITERATIONS ) + ", tried_solns = " ) for d in self.tried_solns: logging.debug(" " + str(d))
def addDomainEDBs(original_prog, cursor): # --------------------------------------------------- # # run original program and grab results dictionary # # --------------------------------------------------- # results_array = c4_evaluator.runC4_wrapper(original_prog) parsedResults = tools.getEvalResults_dict_c4(results_array) # --------------------------------------------------- # # save results as edb facts in IR db # # --------------------------------------------------- # for relationName in parsedResults: print ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;" print "relationName : " + relationName # build fact name newEDBName = "dom_" + relationName + "_evalres" print "newEDBName : " + newEDBName # ---------------------------------------------------------- # # no evaluation data exists for this relation if parsedResults[relationName] == []: # set fact info fid = tools.getID() timeArg += 1 print ">>> INSERT INTO Fact VALUES ('" + fid + "','" + newEDBName + "','" + str( timeArg) + "')" cursor.execute("INSERT INTO Fact VALUES ('" + fid + "','" + newEDBName + "','" + str(timeArg) + "')") # get fact schema # observe a relation defined in a dedalust program can only be empty in this context if it is an IDB # because c4 define statements are derived from relations defined in the dedalus program only. cursor.execute("SELECT rid FROM Rule WHERE goalName=='" + relationName + "'") ridList = cursor.fetchall() ridList = tools.toAscii_list(ridList) pickedRID = ridList[0] cursor.execute( "SELECT attID,attName,attType FROM GoalAtt WHERE rid=='" + pickedRID + "'") attData = cursor.fetchall() attData = tools.toAscii_multiList(attData) # set fact data fattID = 0 for att in attData: attID = att[0] attName = att[1] attType = att[2] if attType == "string": d = '"___DEFAULTSTR___"' else: d = 9999999999 print ">>> INSERT INTO FactAtt (" + fid + "," + str( fattID) + "," + str(d) + "," + attType + ")" cursor.execute("INSERT INTO FactAtt VALUES ('" + fid + "','" + str(fattID) + "','" + str(d) + "','" + str(attType) + "')") fattID += 1 #tools.bp( __name__, inspect.stack()[0][3], "blah" ) # ---------------------------------------------------------- # # evaluation data exists for this relation else: for dataTup in parsedResults[relationName]: # build fact id fid = tools.getID() # default time arg to 1. domain edb facts are true starting at time 1. timeArg = 1 # set fact info print ">>> INSERT INTO Fact VALUES ('" + fid + "','" + newEDBName + "','" + str( timeArg) + "')" cursor.execute("INSERT INTO Fact VALUES ('" + fid + "','" + newEDBName + "','" + str(timeArg) + "')") fattID = 0 for d in dataTup: # get data type for d if d.isdigit(): attType = "int" else: attType = "string" # modify string data with quotes if attType == "string": d = '"' + d + '"' # set fact data print ">>> INSERT INTO FactAtt (" + fid + "," + str( fattID) + "," + str(d) + "," + attType + ")" cursor.execute("INSERT INTO FactAtt VALUES ('" + fid + "','" + str(fattID) + "','" + str(d) + "','" + str(attType) + "')") fattID += 1