예제 #1
0
 def __init__(self,
              items,
              level1=DEFAULT_LEVEL1,
              level2=DEFAULT_LEVEL2,
              level3=DEFAULT_LEVEL3):
     from calibre_extensions.matcher import Matcher
     self.m = Matcher(items,
                      primary_collator().capsule, str(level1), str(level2),
                      str(level3))
예제 #2
0
        def test_mem_leaks(self):
            import gc
            from calibre.utils.mem import get_memory as memory
            m = Matcher(['a'], scorer=CScorer)
            m('a')

            def doit(c):
                m = Matcher([
                    c + 'im/one.gif',
                    c + 'im/two.gif',
                    c + 'text/one.html',
                ],
                            scorer=CScorer)
                m('one')

            start = memory()
            for i in range(10):
                doit(str(i))
            gc.collect()
            used10 = memory() - start
            start = memory()
            for i in range(100):
                doit(str(i))
            gc.collect()
            used100 = memory() - start
            if used100 > 0 and used10 > 0:
                self.assertLessEqual(used100, 2 * used10)
예제 #3
0
 def test_non_bmp(self):
     raw = '_\U0001f431-'
     m = Matcher([raw], scorer=CScorer)
     positions = next(itervalues(m(raw)))
     self.assertEqual(
         positions, (0, 1, 2)
     )
예제 #4
0
 def doit(c):
     m = Matcher([
         c + 'im/one.gif',
         c + 'im/two.gif',
         c + 'text/one.html',
     ],
                 scorer=CScorer)
     m('one')
예제 #5
0
class CScorer:
    def __init__(self,
                 items,
                 level1=DEFAULT_LEVEL1,
                 level2=DEFAULT_LEVEL2,
                 level3=DEFAULT_LEVEL3):
        from calibre_extensions.matcher import Matcher
        self.m = Matcher(items,
                         primary_collator().capsule, str(level1), str(level2),
                         str(level3))

    def __call__(self, query):
        scores, positions = self.m.calculate_scores(query)
        yield from zip(scores, positions)
예제 #6
0
class CScorer(object):
    def __init__(self,
                 items,
                 level1=DEFAULT_LEVEL1,
                 level2=DEFAULT_LEVEL2,
                 level3=DEFAULT_LEVEL3):
        from calibre_extensions.matcher import Matcher
        self.m = Matcher(items,
                         primary_collator().capsule, unicode_type(level1),
                         unicode_type(level2), unicode_type(level3))

    def __call__(self, query):
        scores, positions = self.m.calculate_scores(query)
        for score, pos in zip(scores, positions):
            yield score, pos