Esempio n. 1
0
 def value(context, idx, ptype):
     if ptype == AtomicPredicate.T_TAG:
         return context[idx][1]
     elif ptype == AtomicPredicate.T_CHAR:
         return context[idx][0]
     else:
         return char_class(context[idx][0])
Esempio n. 2
0
 def value(context, idx, ptype):
     if ptype == AtomicPredicate.T_TAG:
         return context[idx][1]
     elif ptype == AtomicPredicate.T_CHAR:
         return context[idx][0]
     else:
         return char_class(context[idx][0])
Esempio n. 3
0
    def test(self, context, idx):
        """Test the predicate under context.

        @type context: a list of (character, tag) tuples.
        @param context: the context

        @type idx: integer
        @param idx: the index to the context

        @return: the value of the predicate
        """
        o, t, v, n = self._test
        res = True
        if idx + o >= 0 and idx + o < len(context):
            char, tag = context[idx + o]
            if t == self.T_TAG:
                res = tag == v
            elif t == self.T_CHAR:
                res = char == v
            else:
                res = char_class(char) == v
        if n:
            res = not res
        return res
Esempio n. 4
0
    def test(self, context, idx):
        """Test the predicate under context.

        @type context: a list of (character, tag) tuples.
        @param context: the context

        @type idx: integer
        @param idx: the index to the context

        @return: the value of the predicate
        """
        o, t, v, n = self._test
        res = True
        if idx + o >= 0 and idx + o < len(context):
            char, tag = context[idx + o]
            if t == self.T_TAG:
                res = tag == v
            elif t == self.T_CHAR:
                res = char == v
            else:
                res = char_class(char) == v
        if n:
            res = not res
        return res