コード例 #1
0
ファイル: glue.py プロジェクト: steven-cutting/icsisumm
 def lambda_abstract(self, other):
     assert isinstance(other, GlueFormula)
     assert isinstance(other.meaning, logic.VariableExpression)
     return self.__class__(logic.LambdaExpression(other.meaning.variable, self.meaning), \
                           linearlogic.ApplicationExpression(
                               linearlogic.ApplicationExpression(
                                   linearlogic.Operator(linearlogic.Parser.IMPLIES),
                                   other.glue),
                               self.glue
                               )
                           )
コード例 #2
0
ファイル: glue.py プロジェクト: steven-cutting/icsisumm
    def applyto(self, arg):
        """ self = (\\x.(walk x), (subj -o f))
            arg  = (john        ,  subj)
            returns ((walk john),          f)
        """

        if self.indices.intersection(
                arg.indices):  # if the sets are NOT disjoint
            raise linearlogic.LinearLogicApplicationError, '%s applied to %s.  Indices are not disjoint.' % (
                self, arg)
        else:  # if the sets ARE disjoint
            return_indices = self.indices.union(arg.indices)

        try:
            return_glue = linearlogic.ApplicationExpression(
                self.glue, arg.glue, arg.indices)
        except linearlogic.LinearLogicApplicationError:
            raise linearlogic.LinearLogicApplicationError, '%s applied to %s' % (
                self, arg)

        arg_meaning_abstracted = arg.meaning
        if return_indices:
            for dep in self.glue.simplify(
            ).first.second.dependencies[::
                                        -1]:  # if self.glue is (A -o B), dep is in A.dependencies
                arg_meaning_abstracted = logic.LambdaExpression(
                    logic.Variable('v%s' % dep), arg_meaning_abstracted)
        return_meaning = logic.ApplicationExpression(self.meaning,
                                                     arg_meaning_abstracted)

        return self.__class__(return_meaning, return_glue, return_indices)
コード例 #3
0
    def applyto(self, arg):
        """ self = (\\x.(walk x), (subj -o f))
            arg  = (john        ,  subj)
            returns ((walk john),          f)
        """
        if self.indices & arg.indices:  # if the sets are NOT disjoint
            raise linearlogic.LinearLogicApplicationException(
                "'%s' applied to '%s'.  Indices are not disjoint." %
                (self, arg))
        else:  # if the sets ARE disjoint
            return_indices = (self.indices | arg.indices)

        try:
            return_glue = linearlogic.ApplicationExpression(
                self.glue, arg.glue, arg.indices)
        except linearlogic.LinearLogicApplicationException:
            raise linearlogic.LinearLogicApplicationException(
                "'%s' applied to '%s'" % (self.simplify(), arg.simplify()))

        arg_meaning_abstracted = arg.meaning
        if return_indices:
            for dep in self.glue.simplify(
            ).antecedent.dependencies[::
                                      -1]:  # if self.glue is (A -o B), dep is in A.dependencies
                arg_meaning_abstracted = self.make_LambdaExpression(
                    Variable('v%s' % dep), arg_meaning_abstracted)
        return_meaning = self.meaning.applyto(arg_meaning_abstracted)

        return self.__class__(return_meaning, return_glue, return_indices)