nebius/SWE-bench-extra huggingface dataset:
Repository: unnonouno/mrep

Issue:
Support regexp contidion
Users cannot find partially matched features such as "人名". I need to support regexp condition for this problem.

Comments:

Patch:
diff --git a/.travis.yml b/.travis.yml
index 177de39..9c1021f 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -7,6 +7,7 @@ python:
   - "3.4"
 
 install:
+  - pip install coverage==3.7.1
   - pip install tornado
   - pip install coveralls
   - wget https://mecab.googlecode.com/files/mecab-0.996.tar.gz
diff --git a/README.rst b/README.rst
index 1715f6f..d3f9e93 100644
--- a/README.rst
+++ b/README.rst
@@ -68,6 +68,12 @@ Pattern
 `<pos=XXX>`
   matches morphemes whose POS are `XXX`
 
+`<feature=XXX>`
+  matches morphemes whose features are `XXX`
+
+`<feature=~XXX>`
+  matches morphemes whose features maches a RegExp pattern `XXX`
+
 `X*`
   matches repetiion of a pattern X
 
diff --git a/mrep/builder.py b/mrep/builder.py
index afc189d..627563f 100644
--- a/mrep/builder.py
+++ b/mrep/builder.py
@@ -96,13 +96,22 @@ def term(s, pos):
         p = consume(s, p, ')')
         return (p, t)
     elif c == '<':
+        m = re.match(r'<([^>]+)=~([^>]+)>', s[pos:])
+        if m:
+            p = pos + m.end()
+            key = m.group(1)
+            pat = m.group(2)
+            return p, pattern.Condition(
+                lambda x: key in x and re.search(pat, x[key]))
+
         m = re.match(r'<([^>]+)=([^>]+)>', s[pos:])
-        if not m:
-            raise InvalidPattern(pos)
-        p = pos + m.end()
-        key = m.group(1)
-        value = m.group(2)
-        return p, pattern.Condition(lambda x: key in x and x[key] == value)
+        if m:
+            p = pos + m.end()
+            key = m.group(1)
+            value = m.group(2)
+            return p, pattern.Condition(lambda x: key in x and x[key] == value)
+
+        raise InvalidPattern(pos)
 
     elif c == '.':
         return pos + 1, pattern.Condition(lambda x: True)


Test patch:
diff --git a/test/builder_test.py b/test/builder_test.py
index 71560b5..c9d4026 100644
--- a/test/builder_test.py
+++ b/test/builder_test.py
@@ -18,6 +18,15 @@ class TermTest(unittest.TestCase):
         t.match([{'x': 'y'}], 0, lambda s, p: ps.append(p))
         self.assertEqual([1], ps)
 
+    def testPatternCondition(self):
+        p, t = mrep.builder.term('<x=~y>', 0)
+        self.assertIsNotNone(t)
+        self.assertEqual(6, p)
+        self.assertEqual('.', repr(t))
+        ps = []
+        t.match([{'x': 'zyw'}], 0, lambda s, p: ps.append(p))
+        self.assertEqual([1], ps)
+
     def testParen(self):
         p, t = mrep.builder.term('(.)', 0)
         self.assertIsNotNone(t)