Example #1
0
 def test_match_path(self):
     seq = [[1, 2],     # x and y
            [1],        # x
            [1, 2, 3],  # x, y and z
            [1, 2],     # x and y
            [2, 3],     # y and z
            [0, 4, 5],
            []]
     regexptn = refo.Star(self.y) + refo.Plus(self.x + self.z)
     m = refomatch(regexptn, seq, keep_path=True)
     self.assert_(isinstance(m, Match))
     path = m.get_path()
     self.assertEqual([4, 1, 9, 1, 9], path)
Example #2
0
import refo


def path_function(x):
    def f(xs):
        if x in xs:
            return x * x
        return None

    return f


x = refo.Predicate(path_function(1))
y = refo.Predicate(path_function(2))
z = refo.Predicate(path_function(3))

seq = [
    [1, 2],  # x and y
    [1],  # x
    [1, 2, 3],  # x, y and z
    [3],  # z
    [0, 4, 5],
    []
]

regex = refo.Star(y) + refo.Plus(x + z)
m = refo.match(regex, seq, keep_path=True)
print(m.get_path())
Example #3
0
 def custom_negative_rule_feature(*args, **kwargs):
     # always matchs
     return refo.Star(refo.Any())