コード例 #1
0
  def combine(self, function, argument):
    if self.can_combine(function, argument):
      categ = FunctionalCategory(
        function.categ().res().res(), argument.categ().arg(), argument.categ().dir()
      )

      # TODO type-inference
      fsem, asem = function.semantics(), argument.semantics()
      new_arg = l.ApplicationExpression(asem, l.VariableExpression(fsem.variable)).simplify()
      new_term = l.ApplicationExpression(fsem.term, new_arg).simplify()
      semantics = l.LambdaExpression(fsem.variable, new_term)

      yield categ, semantics
コード例 #2
0
    def combine(self, function, argument):
        if not function.categ().is_function():
            return

        subs = function.categ().arg().can_unify(argument.categ())
        if subs is None:
            return

        if not self._typecheck(function, argument):
            return

        categ = function.categ().res().substitute(subs)
        fsem, asem = function.semantics(), argument.semantics()
        if fsem is not None and asem is not None:
            # if function's type is not set, do the best we can to infer.
            if fsem.type is None and self._ontology is not None \
                and isinstance(fsem, l.IndividualVariableExpression):
                fsem.variable.type = self._ontology.types[
                    asem.type.flat + fsem.variable.type.flat[1:]]

            semantics = l.ApplicationExpression(fsem, asem).simplify()
        else:
            semantics = None

        yield categ, semantics
コード例 #3
0
  def combine(self, function, argument):
    if not (function.categ().is_function() and argument.categ().is_function()):
      return
    if function.categ().dir().can_compose() and argument.categ().dir().can_compose():
      subs = function.categ().arg().can_unify(argument.categ().res())
      if subs is not None:
        categ = FunctionalCategory(
            function.categ().res().substitute(subs),
            argument.categ().arg().substitute(subs),
            argument.categ().dir())

        fsem, asem = function.semantics(), argument.semantics()
        if fsem is not None and asem is not None:
          semantics = l.LambdaExpression(asem.variable, l.ApplicationExpression(fsem, asem.term).simplify())
        else:
          semantics = None

        yield categ, semantics
コード例 #4
0
ファイル: combinator.py プロジェクト: cogsci2020verb/pyccg
    def combine(self, function, argument):
        if not function.categ().is_function():
            return

        subs = function.categ().arg().can_unify(argument.categ())
        if subs is None:
            return

        if not self._typecheck(function, argument):
            return

        categ = function.categ().res().substitute(subs)
        fsem, asem = function.semantics(), argument.semantics()
        if fsem is not None and asem is not None:
            semantics = l.ApplicationExpression(
                function.semantics(), argument.semantics()).simplify()
        else:
            semantics = None

        yield categ, semantics
コード例 #5
0
ファイル: combinator.py プロジェクト: cogsci2020verb/pyccg
    def combine(self, function, arg):
        if not (function.categ().is_primitive() and arg.categ().is_function()
                and arg.categ().res().is_function()):
            return

        # Type-raising matches only the innermost application.
        arg = innermostFunction(arg.categ())

        subs = function.categ().can_unify(arg.arg())
        if subs is not None:
            xcat = arg.res().substitute(subs)
            categ = FunctionalCategory(
                xcat, FunctionalCategory(xcat, function.categ(), arg.dir()),
                -(arg.dir()))

            # compute semantics
            semantics = None
            if function.semantics() is not None:
                core = deepcopy(function.semantics())
                parent = None
                while isinstance(core, l.LambdaExpression):
                    parent = core
                    core = core.term

                var = l.Variable("F")
                while var in core.free():
                    var = l.unique_variable(pattern=var)
                core = l.ApplicationExpression(
                    l.FunctionVariableExpression(var), core)

                if parent is not None:
                    parent.term = core
                else:
                    semantics = core

                semantics = l.LambdaExpression(var, semantics)

            yield categ, semantics