A community-supported supercharged document management system: scan, index and archive all your documents
Python aiangulararchivingdjangodmsdocument-managementdocument-management-systemllmmachine-learningocroptical-character-recognitionpdf
Add tests and improve whitespace handling
ishirav83746a9aeb52
diff --git a/src/documents/models.py b/src/documents/models.pyindex a9f17c2a2..ee6ee8d31 100644--- a/src/documents/models.py+++ b/src/documents/models.py@@ -128,11 +128,11 @@ class MatchingModel(models.Model):Example:' some random words "with quotes " and spaces'==>- ['some', 'random', 'words', 'with quotes', 'and', 'spaces']+ ['some', 'random', 'words', 'with\s+quotes', 'and', 'spaces']'''findterms = re.compile(r'"([^"]+)"|(\S+)').findall- normspace = re.compile(r'\s{2,}').sub- return [normspace(' ', (t[0] or t[1]).strip()) for t in findterms(self.match)]+ normspace = re.compile(r'\s+').sub+ return [normspace(r'\s+', (t[0] or t[1]).strip()) for t in findterms(self.match)]def save(self, *args, **kwargs):diff --git a/src/documents/tests/test_matchables.py b/src/documents/tests/test_matchables.pyindex 80b5bdb54..6e64fc5bf 100644--- a/src/documents/tests/test_matchables.py+++ b/src/documents/tests/test_matchables.py@@ -16,9 +16,9 @@ class TestMatching(TestCase):matching_algorithm=getattr(klass, algorithm))for string in true:- self.assertTrue(instance.matches(string))+ self.assertTrue(instance.matches(string), '"%s" should match "%s" but it does not' % (text, string))for string in false:- self.assertFalse(instance.matches(string))+ self.assertFalse(instance.matches(string), '"%s" should not match "%s" but it does' % (text, string))def test_match_all(self):@@ -54,6 +54,21 @@ class TestMatching(TestCase):))+ self._test_matching(+ 'brown fox "lazy dogs"',+ "MATCH_ALL",+ (+ "the quick brown fox jumped over the lazy dogs",+ "the quick brown fox jumped over the lazy dogs",+ ),+ (+ "the quick fox jumped over the lazy dogs",+ "the quick brown wolf jumped over the lazy dogs",+ "the quick brown fox jumped over the fat dogs",+ "the quick brown fox jumped over the lazy... dogs",+ )+ )+def test_match_any(self):self._test_matching(@@ -89,6 +104,18 @@ class TestMatching(TestCase):))+ self._test_matching(+ '"brown fox" " lazy dogs "',+ "MATCH_ANY",+ (+ "the quick brown fox",+ "jumped over the lazy dogs.",+ ),+ (+ "the lazy fox jumped over the brown dogs",+ )+ )+def test_match_literal(self):self._test_matching(