for dataset in args.input_datasets: instances += utils.load_flattened_data(dataset) role_constraints = utils.get_role_constraints(roles, instances) formulas = get_formulas(args.formula_file) domains = get_domains(roles, instances) # generates the markov logic network mln = MLN(logic="FirstOrderLogic", grammar="PRACGrammar") for domain, values in domains.items(): # domains for value in values: if len(value) > 1: const = ''.join(value) elif len(value) > 0: const = value[0] else: const = "None" mln.update_domain({domain: [const]}) for role in roles.keys(): # predicates mln.predicate(Predicate( role, [role + "_d!"])) # hard-functional constraints only for formula in formulas: # formulas formula_str = "0.0 " for idx in range(len(formula)): role = formula[idx] if idx + 1 < len(formula): formula_str += role + "(+?" + role[:2] + ")" + " ^ " else: formula_str += role + "(+?" + role[:2] + ")" mln << formula_str mln.write() mln.tofile(args.output_mln) print("The initial MLN has been written to '" + args.output_mln + "'.")
# r_i2e[triple[0]] = i2e[triple[0]] # r_e2i[i2e[triple[0]]] = triple[0] # if triple[2] not in r_i2e: # r_i2e[triple[2]] = i2e[triple[2]] # r_e2i[i2e[triple[2]]] = triple[2] # if triple[1] not in r_i2r: # r_i2r[triple[1]] = i2r[triple[1]] # r_r2i[i2r[triple[1]]] = triple[1] # generates the markov logic network mln = MLN(logic="FirstOrderLogic", grammar="PRACGrammar") # declares the constants for ent in e2i.keys(): ent_type = ent.split("-")[-1] if ent_type == "r": mln.update_domain({"rooms": [ent]}) elif ent_type == "l": mln.update_domain({"locations": [ent]}) elif ent_type == "o": mln.update_domain({"objects": [ent]}) elif ent_type == "a": mln.update_domain({"actions": [ent]}) elif ent_type == "s": mln.update_domain({"states": [ent]}) else: print("Error: Unknown entity type for domains!") exit() # declares the predicates rel2mln = { "HasEffect": [["actions", "states"], ["IsAction(?x)", "IsState(?y)"]], "InverseActionOf": [["actions", "actions"],