def print_var(event=None): """print_var Reads the functions and the query and says if there exists a smart plan or not. :param event: The event which called the function """ functions = get_functions() q = [x.strip() for x in query.get().split(",")] i_grammar = FunctionIndexedGrammar(functions, [q]) if i_grammar.is_empty(): showinfo("Emptyness", "There exists no smart plan") else: showinfo("Emptyness", "There exists a smart plan")
def find_prolog(event=None): functions = get_functions() q = query.get() q_g = [x.strip() for x in query.get().split(",")] i_grammar = FunctionIndexedGrammar(functions, [q_g]) if i_grammar.is_empty(): showinfo("Prolog", "There exists no smart plan") return write_prolog(functions, q, 10, "tmp/tmp_prolog.pl") p = subprocess.Popen(["swipl", "-f", "tmp/tmp_prolog.pl", "-q", "main"], stdout=subprocess.PIPE) output, err = p.communicate() if (len(output) == 0): showinfo("Prolog", "No plan found by Prolog") else: showinfo("Prolog", "The found plan:\n" + read_output(output))
functions[x + " + IE"] = functions[x][:] + functions["IE"][:] functions["ALL"] = functions["IE"][:] for x in webservices: functions["ALL"] += functions[x][:] def remove_minus(rel): if rel.endswith("m"): return rel[:-1] else: return rel terminals = dict() for key in functions: i_grammar = FunctionIndexedGrammar(functions[key], [[""]], palindrome=False) terminals[key] = i_grammar.get_terminals() terminals[key].remove("epsilon") terminals[key].remove("end") terminals[key].remove("query") terminals[key] = list(filter(lambda x: "_IN" not in x, terminals[key])) terminals[key] = list(set(map(lambda x: remove_minus(x), terminals[key]))) terminals[key] = terminals[key] + \ list(map(lambda x: x + "m", terminals[key])) results = [] for key in functions:
pfsm = fsm.get_palindrome_fsm(query, weak=False) fsm_not_weak_res = pfsm.is_empty() fsm_not_weak_time = time.time() - current_time # === WEAK === pfsm = fsm.get_palindrome_fsm(query, weak=True) fsm_weak_res = pfsm.is_empty() fsm_weak_time = time.time() - current_time # ==== SUSIE ==== current_time = time.time() i_grammar = FunctionIndexedGrammar(functions, [[query]], palindrome=True, susie=True) susie_res = i_grammar.is_empty() susie_time = time.time() - current_time with open("pali_vs_susie_weak.csv", "a") as f: f.write(str(fsm_not_weak_res) + "," + str(fsm_weak_res) + "," + str(susie_res) + "," + str(fsm_not_weak_time) + "," + str(fsm_weak_time) + "," + str(susie_time) + "," + str(n_relations) + "," + str(size_max) + "," + str(n_functions) + "\n")
# number relations n_relations = 10 size_max = 10 generator = FunctionGenerator(n_relations) functions = [] optims = [2, 3, 6, 7, 8] deltas = dict() for optim in optims: deltas[optim] = [] for i in range(0, 1000): # 1 function, size_max is 10 functions = [] temp = generator.generate(25, size_max) functions += temp query = generator.get_random_query(functions) for optim in optims: current_time = time.time() grammar = FunctionIndexedGrammar(functions, [[query]], optim=optim) grammar.is_empty() delta_t = time.time() - current_time with open("rule_ordering2.csv", "a") as f: f.write( str(optim) + "," + str(i) + "," + str(delta_t) + "," + str(n_relations) + "," + str(size_max) + "\n") deltas[optim].append(delta_t)
Tests the time it takes to get the emptyness """ import time from function_generator import FunctionGenerator from function_indexed_grammar import FunctionIndexedGrammar import cProfile def get_millis(): return int(round(time.time() * 1000)) current_time = get_millis() total = 0 n_loop = 10 for _ in range(n_loop): generator = FunctionGenerator(5) functions = generator.generate(25, 10) query = generator.get_random_query(functions) # print(functions) # print(query) grammar = FunctionIndexedGrammar(functions, query) # cProfile.run("grammar.is_empty()") print(get_millis() - current_time) total += get_millis() - current_time current_time = get_millis() print("Mean :" + str(total / n_loop))
n_relations = 6 size_max = 6 generator = FunctionGenerator(n_relations) functions = [] for i in range(0, 1000): # 10 functions, size_max is 10 functions = [] n_functions = 9 temp = generator.generate(n_functions, size_max) functions += temp query = generator.get_random_query(functions) current_time = time.time() grammar = FunctionIndexedGrammar(functions, [[query]], 7, False) res0 = grammar.is_empty() delta_t0 = time.time() - current_time n_rules0 = grammar.get_n_rules() n_rules0 = n_rules0[0] + n_rules0[1] current_time = time.time() grammar = FunctionIndexedGrammar(functions, [[query]], 7, True) res1 = grammar.is_empty() delta_t1 = time.time() - current_time n_rules1 = grammar.get_n_rules() n_rules1 = n_rules1[0] + n_rules1[1] functions.append(Function(functions[-1].get_inverse_function(), "f")) current_time = time.time()
functions.append(["describes-"]) # Make each function unique print("Number functions:", len(functions)) f_temp = [] for f in functions: if f not in f_temp: f_temp.append(f) functions = f_temp print("Number functions:", len(functions)) for i in range(len(functions)): functions[i] = Function(functions[i], "f" + str(i)) print(functions[i]) i_grammar = FunctionIndexedGrammar(functions, [[""]]) terminals = i_grammar.get_terminals() terminals.remove("epsilon") terminals.remove("end") terminals.remove("query") def remove_minus(rel): if rel.endswith("m"): return rel[:-1] else: return rel terminals = set(map(lambda x: remove_minus(x), terminals))