pubmed_parser/medline_parser.py
def parse_medline_xml(path, year_info_only=True, nlm_category=False,
                      author_list=False, reference_list=False):
    """Parse XML file from Medline XML format available at
    ftp://ftp.nlm.nih.gov/nlmdata/.medleasebaseline/gz/

    Parameters
    ----------
    path: str
        The path
    year_info_only: bool
        if True, this tool will only attempt to extract year information from PubDate.
        if False, an attempt will be made to harvest all available PubDate information.
        If only year and month information is available, this will yield a date of
        the form 'YYYY-MM'. If year, month and day information is available,
        a date of the form 'YYYY-MM-DD' will be returned.
        NOTE: the resolution of PubDate information in the Medline(R) database varies
        between articles.
        Defaults to True.
    nlm_category: bool, default False
        if True, this will parse structured abstract where each section if original Label
        if False, this will parse structured abstract where each section will be assigned to
        NLM category of each sections
    author_list: bool, default False,
        if True, return parsed author output as a list of authors
        if False, return parsed author output as a string of authors concatenated with ;
    reference_list: bool, default False
        if True, parse reference list as an output
        if False, return string of PMIDs concatenated with ;

    Returns
    -------
    article_list: list
        Dictionary containing information about articles in NLM format (see
        `parse_article_info`). Articles that have been deleted will be
        added with no information other than the field `delete` being `True`
    """
    tree = read_xml(path)
    medline_citations = tree.findall('//MedlineCitationSet/MedlineCitation')
    if len(medline_citations) == 0:
        medline_citations = tree.findall('//PubmedArticle')
    article_list = list(map(lambda m: parse_article_info(m, year_info_only, nlm_category, author_list, reference_list), medline_citations))
    delete_citations = tree.findall('//DeleteCitation/PMID')
    dict_delete = [{
        'title': np.nan,
        'abstract': np.nan,
        'journal': np.nan,
        'authors': np.nan,
        'affiliations': np.nan,
        'pubdate': np.nan,
        'pmid': p.text.strip(),
        'doi': np.nan,
        'other_id': np.nan,
        'pmc': np.nan,
        'mesh_terms': np.nan,
        'keywords': np.nan,
        'publication_types': np.nan,
        'chemical_list': np.nan,
        'delete': True,
        'medline_ta': np.nan,
        'nlm_unique_id': np.nan,
        'issn_linking': np.nan,
        'country': np.nan,
        'references': np.nan
    } for p in delete_citations]
    article_list.extend(dict_delete)
    return article_list
Parse XML file from Medline XML format available at
    ftp://ftp.nlm.nih.gov/nlmdata/.medleasebaseline/gz/

    Parameters
    ----------
    path: str
        The path
    year_info_only: bool
        if True, this tool will only attempt to extract year information from PubDate.
        if False, an attempt will be made to harvest all available PubDate information.
        If only year and month information is available, this will yield a date of
        the form 'YYYY-MM'. If year, month and day information is available,
        a date of the form 'YYYY-MM-DD' will be returned.
        NOTE: the resolution of PubDate information in the Medline(R) database varies
        between articles.
        Defaults to True.
    nlm_category: bool, default False
        if True, this will parse structured abstract where each section if original Label
        if False, this will parse structured abstract where each section will be assigned to
        NLM category of each sections
    author_list: bool, default False,
        if True, return parsed author output as a list of authors
        if False, return parsed author output as a string of authors concatenated with ;
    reference_list: bool, default False
        if True, parse reference list as an output
        if False, return string of PMIDs concatenated with ;

    Returns
    -------
    article_list: list
        Dictionary containing information about articles in NLM format (see
        `parse_article_info`). Articles that have been deleted will be
        added with no information other than the field `delete` being `True`
    


Parameters

str
The path
year_info_only: bool
if True, this tool will only attempt to extract year information from PubDate.
if False, an attempt will be made to harvest all available PubDate information.
If only year and month information is available, this will yield a date of
the form 'YYYY-MM'. If year, month and day information is available,
a date of the form 'YYYY-MM-DD' will be returned.
NOTE: the resolution of PubDate information in the Medline(R) database varies
between articles.
Defaults to True.
nlm_category: bool, default False
if True, this will parse structured abstract where each section if original Label
if False, this will parse structured abstract where each section will be assigned to
NLM category of each sections
author_list: bool, default False,
if True, return parsed author output as a list of authors
if False, return parsed author output as a string of authors concatenated with ;
reference_list: bool, default False
if True, parse reference list as an output
if False, return string of PMIDs concatenated with .

Returns

list
Dictionary containing information about articles in NLM format (see
`parse_article_info`). Articles that have been deleted will be
added with no information other than the field `delete` being `True`
Parameters str The path year_info_only : bool if True this tool will only attempt to extract year information from PubDate . if False an attempt will be made to harvest all available PubDate information . If only year and month information is available this will yield a date of the form ' YYYY - MM ' . If year month and day information is available a date of the form ' YYYY - MM - DD ' will be returned . NOTE : the resolution of PubDate information in the Medline ( R ) database varies between articles . Defaults to True . nlm_category : bool default False if True this will parse structured abstract where each section if original Label if False this will parse structured abstract where each section will be assigned to NLM category of each sections author_list : bool default False if True return parsed author output as a list of authors if False return parsed author output as a string of authors concatenated with ; reference_list : bool default False if True parse reference list as an output if False return string of PMIDs concatenated with . Returns list Dictionary containing information about articles in NLM format ( see ` parse_article_info ` ) . Articles that have been deleted will be added with no information other than the field ` delete ` being ` True `
def parse_medline_xml(path, year_info_only=True, nlm_category=False,
                      author_list=False, reference_list=False):
    tree = read_xml(path)
    medline_citations = tree.findall('//MedlineCitationSet/MedlineCitation')
    if len(medline_citations) == 0:
        medline_citations = tree.findall('//PubmedArticle')
    article_list = list(map(lambda m: parse_article_info(m, year_info_only, nlm_category, author_list, reference_list), medline_citations))
    delete_citations = tree.findall('//DeleteCitation/PMID')
    dict_delete = [{
        'title': np.nan,
        'abstract': np.nan,
        'journal': np.nan,
        'authors': np.nan,
        'affiliations': np.nan,
        'pubdate': np.nan,
        'pmid': p.text.strip(),
        'doi': np.nan,
        'other_id': np.nan,
        'pmc': np.nan,
        'mesh_terms': np.nan,
        'keywords': np.nan,
        'publication_types': np.nan,
        'chemical_list': np.nan,
        'delete': True,
        'medline_ta': np.nan,
        'nlm_unique_id': np.nan,
        'issn_linking': np.nan,
        'country': np.nan,
        'references': np.nan
    } for p in delete_citations]
    article_list.extend(dict_delete)
    return article_list
def parse_medline_xml ( path , year_info_only = True , nlm_category = False , author_list = False , reference_list = False ) : tree = read_xml ( path ) medline_citations = tree . findall ( '//MedlineCitationSet/MedlineCitation' ) if len ( medline_citations ) == 0 : medline_citations = tree . findall ( '//PubmedArticle' ) article_list = list ( map ( lambda m : parse_article_info ( m , year_info_only , nlm_category , author_list , reference_list ) , medline_citations ) ) delete_citations = tree . findall ( '//DeleteCitation/PMID' ) dict_delete = [ { 'title' : np . nan , 'abstract' : np . nan , 'journal' : np . nan , 'authors' : np . nan , 'affiliations' : np . nan , 'pubdate' : np . nan , 'pmid' : p . text . strip ( ) , 'doi' : np . nan , 'other_id' : np . nan , 'pmc' : np . nan , 'mesh_terms' : np . nan , 'keywords' : np . nan , 'publication_types' : np . nan , 'chemical_list' : np . nan , 'delete' : True , 'medline_ta' : np . nan , 'nlm_unique_id' : np . nan , 'issn_linking' : np . nan , 'country' : np . nan , 'references' : np . nan } for p in delete_citations ] article_list . extend ( dict_delete ) return article_list
Parse XML file from Medline XML format available at
ftp://ftp.nlm.nih.gov/nlmdata/.medleasebaseline/gz
Parse XML file from Medline XML format available at ftp : // ftp . nlm . nih . gov / nlmdata / . medleasebaseline / gz
"""Parse XML file from Medline XML format available at
    ftp://ftp.nlm.nih.gov/nlmdata/.medleasebaseline/gz/

    Parameters
    ----------
    path: str
        The path
    year_info_only: bool
        if True, this tool will only attempt to extract year information from PubDate.
        if False, an attempt will be made to harvest all available PubDate information.
        If only year and month information is available, this will yield a date of
        the form 'YYYY-MM'. If year, month and day information is available,
        a date of the form 'YYYY-MM-DD' will be returned.
        NOTE: the resolution of PubDate information in the Medline(R) database varies
        between articles.
        Defaults to True.
    nlm_category: bool, default False
        if True, this will parse structured abstract where each section if original Label
        if False, this will parse structured abstract where each section will be assigned to
        NLM category of each sections
    author_list: bool, default False,
        if True, return parsed author output as a list of authors
        if False, return parsed author output as a string of authors concatenated with ;
    reference_list: bool, default False
        if True, parse reference list as an output
        if False, return string of PMIDs concatenated with ;

    Returns
    -------
    article_list: list
        Dictionary containing information about articles in NLM format (see
        `parse_article_info`). Articles that have been deleted will be
        added with no information other than the field `delete` being `True`
    """
path
year_info_only
nlm_category
author_list
reference_list