コード例 #1
0
ファイル: logicalform.py プロジェクト: r101280/srl-nlp
    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_skolemize(self):
        # TODO test with for alls
        in_list = [
            ['some', ['A'], ['and', ['b'], ['some', ['B'], ['a', ['c']]]]],
            ['fol', ['1'], ['some', ['A'], ['and', ['b'], ['some', ['B'], ['a', ['c']]]]]],
            # some(A,and(4,all(B,a(4)))) -> all(B,and(4,a(4)))
            ['some', ['A'], ['and', ['b'], ['all', ['B'], ['a', ['c']]]]],
            ['some', ['A'], ['and', ['b'], ['all', ['B'], ['a', ['B']]]]],
        ]
        out_list = [
            ['and', ['b'], ['a', ['c']]],
            ['and', ['b'], ['a', ['c']]],
            ['all', ['B'], ['and', ['b'], ['a', ['c']]]],
            ['all', ['B'], ['and', ['b'], ['a', ['B']]]],  # TODO this b should be changed
        ]

        for in_test, test in zip(in_list, out_list):
            f = FOL()
            f.info = in_test
            f.skolemize()
            output = f.info
            assert output == test, (output, test)