Exemplo n.º 1
0
def reify_program(prg: str,
                  calculate_sccs: bool = False,
                  reify_steps: bool = False) -> List[Symbol]:
    '''
    Reify the given program and return the reified symbols.

    Parameters
    ----------
    prg
        The program to reify in form of a string.
    calculate_sccs
        Whether to calculate SCCs of the reified program.
    reify_steps
        Whether to add a step number to the reified facts.

    Returns
    -------
    A list of symbols containing the reified facts.
    '''
    ret: List[Symbol] = []
    ctl = Control()
    reifier = Reifier(ret.append, calculate_sccs, reify_steps)
    ctl.register_observer(reifier)
    ctl.add("base", [], prg)
    ctl.ground([('base', [])])
    if calculate_sccs and not reify_steps:
        reifier.calculate_sccs()

    return ret
Exemplo n.º 2
0
def _reify(prg, calculate_sccs: bool = False, reify_steps: bool = False):
    if isinstance(prg, str):
        symbols = reify_program(prg, calculate_sccs, reify_steps)
    else:
        ctl = Control()
        symbols = []
        reifier = Reifier(symbols.append, calculate_sccs, reify_steps)
        ctl.register_observer(reifier)
        prg(ctl)

    return [str(sym) for sym in symbols]
Exemplo n.º 3
0
    def main(self, ctl: Control, files):
        prg = Program()
        ctl.register_observer(ProgramObserver(prg))

        for f in files:
            ctl.load(f)
        if not files:
            ctl.load('-')

        ctl.ground([("base", [])])

        fct, ukn = well_founded(prg)
        print('Facts:')
        print(f'{" ".join(map(str, fct))}')
        print('Unknown:')
        print(f'{" ".join(map(str, ukn))}')

        ctl.solve()