コード例 #1
0
    def test_cusip_annotation(self):
        ant = CusipAnnotation(coords=(2, 20),
                              code='SBN11',
                              tba='tba1',
                              ppn='ppn1',
                              internal=True,
                              checksum='0x0A')
        self.assertEqual('en', ant.locale)
        cite = ant.get_cite()
        self.assertEqual('/en/cusip/SBN11/ppn1', cite)

        ldic = ant.to_dictionary_legacy()
        self.assertEqual(True, ldic['internal'])
        self.assertEqual('SBN11', ldic['text'])
コード例 #2
0
ファイル: cusip.py プロジェクト: suryak-cs/lexpredict-lexnlp
def get_cusip_annotations(text: str) -> Generator[CusipAnnotation, None, None]:
    """
    INFO: https://www.cusip.com/pdf/CUSIP_Intro_03.14.11.pdf
    """
    for match in CUSIP_PTN_RE.finditer(text):
        capture = match.capturesdict()
        code = ''.join(capture['code'])
        issuer_id = ''.join(capture['issuer_id'])
        issue_id = ''.join(capture['issue_id'])
        checksum = int(capture['checksum'][0])
        ppn = False

        # validate CUSIP
        if not is_cusip_valid(code):
            continue

        tba = TBA_PTN_RE.fullmatch(code)
        if tba:
            tba = tba.groupdict()
            settlement_month_name = TBA_MONTHS.get(tba['settlement_month'])
            # if not settlement_month_name:
            #     continue
            tba['settlement_month_name'] = settlement_month_name
        elif PPN_PTN_RE.search(code):
            ppn = True

        internal = bool(INTERNAL_ISSUER_ID_PTN_RE.match(issuer_id))
        ant = CusipAnnotation(coords=(match.start(1), match.end(1)),
                              code=code,
                              issuer_id=issuer_id,
                              issue_id=issue_id,
                              checksum=checksum,
                              internal=internal,
                              tba=tba,
                              ppn=ppn)
        yield ant