import collections


def get_patent_descriptions(soup):
    """ Get description from USPTO patft HTML.

    Parameters
    ----------
    soup : bs4.BeautifulSoup
        Patent HTML.

    Returns
    -------
    dict[str, str]
        Description header - text mapping.
    """
    try:
        descr_header = next(t for t in soup.find_all('center')
                            if t.text.lower() == 'description')
    except StopIteration:
        return None

    descr_contents = descr_header.find_next('hr')
    descr_lines = str(descr_contents).split('<br><br>')[1:-1]

    descriptions_as_lines = collections.defaultdict(list)
    current_header = None
    for line in (l.strip() for l in descr_lines):
        if line.isupper():  # I.e. header row.
            current_header = line
        else:
            descriptions_as_lines[current_header].append(line)

    descriptions = {key: ' '.join(value) for key, value
                    in descriptions_as_lines.items()}
    return descriptions