コード例 #1
0
 def interpret(self, ex):
     """
     :param ex: ``AbstractBoxerDrs``
     :return: ``AbstractDrs``
     """
     if isinstance(ex, BoxerDrs):
         drs = DRS([Variable('x%d' % r) for r in ex.refs],
                   map(self.interpret, ex.conds))
         if ex.label is not None:
             drs.label = Variable('x%d' % ex.label)
         if ex.consequent is not None:
             drs.consequent = self.interpret(ex.consequent)
         return drs
     elif isinstance(ex, BoxerNot):
         return DrtNegatedExpression(self.interpret(ex.drs))
     elif isinstance(ex, BoxerPred):
         pred = self._add_occur_indexing('%s_%s' % (ex.pos, ex.name), ex)
         return self._make_atom(pred, 'x%d' % ex.var)
     elif isinstance(ex, BoxerNamed):
         pred = self._add_occur_indexing('ne_%s_%s' % (ex.type, ex.name),
                                         ex)
         return self._make_atom(pred, 'x%d' % ex.var)
     elif isinstance(ex, BoxerRel):
         pred = self._add_occur_indexing('%s' % (ex.rel), ex)
         return self._make_atom(pred, 'x%d' % ex.var1, 'x%d' % ex.var2)
     elif isinstance(ex, BoxerProp):
         return DrtProposition(Variable('x%d' % ex.var),
                               self.interpret(ex.drs))
     elif isinstance(ex, BoxerEq):
         return DrtEqualityExpression(
             DrtVariableExpression(Variable('x%d' % ex.var1)),
             DrtVariableExpression(Variable('x%d' % ex.var2)))
     elif isinstance(ex, BoxerCard):
         pred = self._add_occur_indexing('card_%s_%s' % (ex.type, ex.value),
                                         ex)
         return self._make_atom(pred, 'x%d' % ex.var)
     elif isinstance(ex, BoxerOr):
         return DrtOrExpression(self.interpret(ex.drs1),
                                self.interpret(ex.drs2))
     elif isinstance(ex, BoxerWhq):
         drs1 = self.interpret(ex.drs1)
         drs2 = self.interpret(ex.drs2)
         return DRS(drs1.refs + drs2.refs, drs1.conds + drs2.conds)
     assert False, '%s: %s' % (ex.__class__.__name__, ex)
コード例 #2
0
ファイル: boxer.py プロジェクト: navikohli/nltk
 def interpret(self, ex):
     """
     :param ex: ``AbstractBoxerDrs``
     :return: ``AbstractDrs``
     """
     if isinstance(ex, BoxerDrs):
         drs = DRS([Variable("x%d" % r) for r in ex.refs], map(self.interpret, ex.conds))
         if ex.label is not None:
             drs.label = Variable("x%d" % ex.label)
         if ex.consequent is not None:
             drs.consequent = self.interpret(ex.consequent)
         return drs
     elif isinstance(ex, BoxerNot):
         return DrtNegatedExpression(self.interpret(ex.drs))
     elif isinstance(ex, BoxerPred):
         pred = self._add_occur_indexing("%s_%s" % (ex.pos, ex.name), ex)
         return self._make_atom(pred, "x%d" % ex.var)
     elif isinstance(ex, BoxerNamed):
         pred = self._add_occur_indexing("ne_%s_%s" % (ex.type, ex.name), ex)
         return self._make_atom(pred, "x%d" % ex.var)
     elif isinstance(ex, BoxerRel):
         pred = self._add_occur_indexing("%s" % (ex.rel), ex)
         return self._make_atom(pred, "x%d" % ex.var1, "x%d" % ex.var2)
     elif isinstance(ex, BoxerProp):
         return DrtProposition(Variable("x%d" % ex.var), self.interpret(ex.drs))
     elif isinstance(ex, BoxerEq):
         return DrtEqualityExpression(
             DrtVariableExpression(Variable("x%d" % ex.var1)), DrtVariableExpression(Variable("x%d" % ex.var2))
         )
     elif isinstance(ex, BoxerCard):
         pred = self._add_occur_indexing("card_%s_%s" % (ex.type, ex.value), ex)
         return self._make_atom(pred, "x%d" % ex.var)
     elif isinstance(ex, BoxerOr):
         return DrtOrExpression(self.interpret(ex.drs1), self.interpret(ex.drs2))
     elif isinstance(ex, BoxerWhq):
         drs1 = self.interpret(ex.drs1)
         drs2 = self.interpret(ex.drs2)
         return DRS(drs1.refs + drs2.refs, drs1.conds + drs2.conds)
     assert False, "%s: %s" % (ex.__class__.__name__, ex)