def parse_ids(graph, label):
    """
    Extract up to three valid element IDs (indentaion markers)
    from a paragraph, and return a paragraph for each ID found.
    """
    raw_ids = re.findall(paren_id_patterns['initial'], graph_top(graph))
    clean_ids = [bit.strip('*') for bit in raw_ids if bit][:3]
    for clean_id in clean_ids:
        #  clean up edge-case bolding caused by italicized IDs, such as
        #  '(F)(<I>1</I>)' from reg 1026.7
        graph = graph.replace("**{}**".format(clean_id), clean_id)
    valid_ids = LEVEL_STATE.multiple_id_test(clean_ids)
    if not valid_ids or LEVEL_STATE.level() == 6:
        return parse_singleton_graph(graph, label)
    else:
        return parse_multi_id_graph(graph, valid_ids, label)
示例#2
0
def parse_ids(graph, label):
    """
    Extract up to three valid element IDs (indentaion markers)
    from a paragraph, and return a paragraph for each ID found.
    """
    raw_ids = re.findall(
        paren_id_patterns['initial'], graph_top(graph))
    clean_ids = [bit.strip('*') for bit in raw_ids if bit][:3]
    for clean_id in clean_ids:
        #  clean up edge-case bolding caused by italicized IDs, such as
        #  '(F)(<I>1</I>)' from reg 1026.7
        graph = graph.replace("**{}**".format(clean_id), clean_id)
    valid_ids = LEVEL_STATE.multiple_id_test(clean_ids)
    if not valid_ids or LEVEL_STATE.level() == 6:
        return parse_singleton_graph(graph, label)
    else:
        return parse_multi_id_graph(graph, valid_ids, label)
示例#3
0
def parse_singleton_graph(graph_text, label):
    """Take a paragraph with a single ID and return styled with a braced ID"""
    new_graph = ''
    id_refs = PAYLOAD.interp_refs.get(label)
    id_match = re.search(paren_id_patterns['initial'], graph_top(graph_text))
    linted = lint_paragraph(combine_bolds(graph_text))
    if not id_match:
        return '\n' + linted + '\n'
    id_token = id_match.group(1).strip('*')
    if not LEVEL_STATE.token_validity_test(id_token):
        return '\n' + linted + '\n'
    LEVEL_STATE.next_token = id_token
    pid = LEVEL_STATE.next_id()
    if pid:
        new_graph += "\n{" + pid + "}\n"
    new_graph += linted + '\n'
    if id_refs and pid in id_refs:
        new_graph += '\n' + id_refs[pid] + '\n'
    return new_graph
def parse_singleton_graph(graph_text, label):
    """Take a paragraph with a single ID and return styled with a braced ID"""
    new_graph = ''
    id_refs = PAYLOAD.interp_refs.get(label)
    id_match = re.search(paren_id_patterns['initial'], graph_top(graph_text))
    linted = lint_paragraph(combine_bolds(graph_text))
    if not id_match:
        return '\n' + linted + '\n'
    id_token = id_match.group(1).strip('*')
    if not LEVEL_STATE.token_validity_test(id_token):
        return '\n' + linted + '\n'
    LEVEL_STATE.next_token = id_token
    pid = LEVEL_STATE.next_id()
    if pid:
        new_graph += "\n{" + pid + "}\n"
    new_graph += linted + '\n'
    if id_refs and pid in id_refs:
        new_graph += '\n' + id_refs[pid] + '\n'
    return new_graph