Пример #1
0
    def extract(self):
        """ Yields Quotation instance extractable from text """
        closed = True
        for index, char in enumerate(self.text):
            if char in QUOTATION_MAP.get(self.lc, []):
                if char in LONE_RANGERS and index > 0:
                    prev_char = self.text[index-1]
                    if ALPHANUMERIC_PATTERN.match(prev_char):
                        # prev char is a alphabet; highly likely to be a lone ranger, not a true quotation
                        # ignore lone ranger
                        continue

                closed = not closed  # toggle to open from start
                prev = Quotation.create(self.lc, char, force_close=closed)
                yield prev
Пример #2
0
    def test_pairing(self):
        """ Test to check that there is a closing quotation for every opening quotation """
        from utils import QUOTATION_MAP

        for quotations in QUOTATION_MAP.values():
            self.assertTrue(len(quotations) and len(quotations) % 2 == 0)