def assertz(self, clause: Union[Atom, Clause]): if isinstance(clause, Atom): query = f"assertz({clause})." return pyxsb.pyxsb_command_string(query) else: query = f"assertz(({clause}))." return pyxsb.pyxsb_command_string(query)
def retract(self, clause: Union[Atom, Clause]): if isinstance(clause, Atom): return pyxsb.pyxsb_command_string(f"retract({clause}).") else: return pyxsb.pyxsb_command_string(f"retract(({clause})).")
def use_module(self, module: str, **kwargs): assert 'predicates' in kwargs, "XSB Prolog: need to specify which predicates to import from module" predicates = kwargs['predicates'] command = f"use_module({module},[{','.join([x.get_name() + '/' + str(x.get_arity()) for x in predicates])}])." return pyxsb.pyxsb_command_string(command)
def consult(self, filename: str): return pyxsb.pyxsb_command_string(f"consult('{filename}').")