Пример #1
0
    def __init__(self, *args, **kargs):
        """Creates a new Logical Formula
        LF(fol) -> lf

        The first parameter must be the source to be used to generate the LF.
        If it is a FOL, you can specify the argument 'header' to eliminate the header if it is there
        """
        if len(args) > 0:
            header = kargs.get('header', None)
            fol = copy(args[0])
            if isinstance(fol, str):
                fol = FOL(fol)
            if header and args[0].info[0] == header:
                fol.info = fol.info[-1]
            #    print "*"
            # print ">", header, fol
            try:
                # print '\n-', fol
                logger.debug('FOL: %s', fol)
                fol.convert2PrenexForm()
                logger.debug('PRENEX FOL: %s', fol)
                # print '*', fol
                fol.skolemize()
                logger.debug('SKOLEMIZED FOL: %s', fol)
                fol.push_operand(FOL.OR)
                self.info = fol.info
                logger.debug('LF: %s', self)
            except AttributeError as e:
                raise Exception('Not a valid FOL%s' % fol)
        else:
            self.info = []
Пример #2
0
 def test_convert2PrenexForm(self):
     in_list = [
         # some(A,and(b,some(B,a(c)))) -> some(A,some(B,and(b,a(c))))
         ['some', ['A'], ['and', ['b'], ['some', ['B'], ['a', ['c']]]]],
         # fol(1, some(A,and(b,some(B,a(c))))) -> some(A,some(B,and(b,a(c))))
         ['fol', ['1'], ['some', ['A'], ['and', ['b'], ['some', ['B'], ['a', ['c']]]]]],
         ['some', ['A'], ['and', ['b'], ['all', ['B'], ['a', ['c']]]]],
         # some(A, and (b, all(B, a(b)))) -> some(A, all(B, and (4, a(4))))
         ['some', ['A'], ['and', ['b'], ['all', ['B'], ['some', ['C'], ['a', ['C']]]]]],
     ]
     out_list = [
         ['some', ['A'], ['some', ['B'], ['and', ['b'], ['a', ['c']]]]],
         ['fol', ['1'], ['some', ['A'], ['some', ['B'], ['and', ['b'], ['a', ['c']]]]]],
         ['some', ['A'], ['all', ['B'], ['and', ['b'], ['a', ['c']]]]],
         ['some', ['A'], ['all', ['B'], ['some', ['C'], ['and', ['b'], ['a', ['C']]]]]],
     ]
     for in_test, test in zip(in_list, out_list):
         f = FOL()
         f.info = in_test
         f.convert2PrenexForm()
         output = f.info
         assert output == test, (output, test)