How to use the refextract.references.regexs.re_kb_line.search function in refextract

To help you get started, we’ve selected a few refextract examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github inspirehep / refextract / refextract / references / kbs.py View on Github external
def lazy_parser(fh):
        for rawline in fh:
            if rawline.startswith('#'):
                continue
            rawline = rawline.rstrip("\n")
            # Test line to ensure that it is a correctly formatted
            # knowledge base line:
            # Extract the seek->replace terms from this KB line
            m_kb_line = re_kb_line.search(rawline)
            if m_kb_line:  # good KB line
                yield m_kb_line.group('seek'), m_kb_line.group('repl')
            else:
                raise ValueError("Badly formatted kb '%s' at line %s" % (path, rawline))
github inspirehep / refextract / refextract / references / kbs.py View on Github external
    @see build_journals_kb
    """
    def make_tuple(match):
        regexp = match.group('seek')
        repl = match.group('repl')
        return regexp, repl

    kb = []

    with file_resolving(fpath) as fh:
        for rawline in fh:
            if rawline.startswith('#'):
                continue
            # Extract the seek->replace terms from this KB line:
            m_kb_line = re_kb_line.search(rawline)
            kb.append(make_tuple(m_kb_line))

    return kb
github inspirehep / refextract / refextract / references / kbs.py View on Github external
def build_authors_kb(fpath):
    replacements = []
    with file_resolving(fpath) as fh:
        for rawline in fh:
            if rawline.startswith('#'):
                continue

            # Extract the seek->replace terms from this KB line:
            m_kb_line = re_kb_line.search(rawline)
            if m_kb_line:
                seek = m_kb_line.group('seek')
                repl = m_kb_line.group('repl')
                replacements.append((seek, repl))

    return replacements