Esempio n. 1
0
def str2clause(s):
    """
    :param s: 
    :return: 
    """
    s = s.replace(" ", "").replace(".", "")
    atoms = s.split(":-")
    head_str = atoms[0]
    head = str2atom(head_str)
    if len(atoms) == 2:
        body_strs = atoms[1].replace("),", ") ").split(" ")
        body = [str2atom(s) for s in body_strs]
        clause = Clause(head, body)
        var_strs = []
        for atom in body + [head]:
            print(atom)
        for strs in [var_string(atom) for atom in body + [head]]:
            var_strs.extend(strs)
        return clause.replace_by_dict(
            {s: i
             for i, s in enumerate(unique_list(var_strs))})
    else:
        return Clause(head, [])
Esempio n. 2
0
 def predicates(self):
     return unique_list([atom.predicate for atom in self.atoms])
Esempio n. 3
0
 def variables(self):
     return unique_list(sum([atom.variables for atom in self.atoms], []))
Esempio n. 4
0
 def constants(self):
     return unique_list(sum([atom.constants for atom in self.atoms], []))
Esempio n. 5
0
 def constants(self):
     const = [symbol for symbol in self.terms if isinstance(symbol, str)]
     return unique_list(const)