def processMedlineFolder(medlineFolder, outFolder):
    'Basic function that iterates through abstracts in a medline file, do a basic word count and save to a file\n\n\tArgs:\n\t\tmedlineFolder (folder): Medline XML folder containing abstracts\n\t\toutFolder (folder): Folder to save output data to\n\tReturns:\n\t\tNothing\n\n\t'
    abstractCount = 0
    files = [f for f in listdir(medlineFolder) if isfile(join(medlineFolder, f))]
    files = sorted([f for f in files if f.endswith('xml')])
    outfile = join(outFolder, 'countWordsError.txt')
    with open(outfile, 'a') as result:
        for f in files:
            print(('Processing %s' % f))
            fullpath = join(medlineFolder, f)
            for (event, elem) in etree.iterparse(fullpath, events=('start', 'end', 'start-ns', 'end-ns')):
                if ((event == 'end') and (elem.tag == 'MedlineCitation')):
                    pmidElements = elem.findall('./PMID')
                    abstractElements = elem.findall('./Article/Abstract/AbstractText')
                    if ((len(pmidElements) != 1) or (len(abstractElements) != 1)):
                        continue
                    pmid = pmidElements[0].text
                    abstract = abstractElements[0].text
                    if (not (abstract is None)):
                        wordCount = len(abstract.split())
                        line = ('%s\t%d\n' % (pmid, wordCount))
                        result.write(line)
                        abstractCount += 1
    print(('%d abstracts processed' % abstractCount))
Basic function that iterates through abstracts in a medline file, do a basic word count and save to a file

Args:
        medlineFolder (folder): Medline XML folder containing abstracts
        outFolder (folder): Folder to save output data to
Returns:
        Nothing
def processMedlineFolder(medlineFolder, outFolder):
    'Basic function that iterates through abstracts in a medline file, do a basic word count and save to a file\n\n\tArgs:\n\t\tmedlineFolder (folder): Medline XML folder containing abstracts\n\t\toutFolder (folder): Folder to save output data to\n\tReturns:\n\t\tNothing\n\n\t'
    abstractCount = 0
    files = [f for f in listdir(medlineFolder) if isfile(join(medlineFolder, f))]
    files = sorted([f for f in files if f.endswith('xml')])
    outfile = join(outFolder, 'countWordsError.txt')
    with open(outfile, 'a') as result:
        for f in files:
            print(('Processing %s' % f))
            fullpath = join(medlineFolder, f)
            for (event, elem) in etree.iterparse(fullpath, events=('start', 'end', 'start-ns', 'end-ns')):
                if ((event == 'end') and (elem.tag == 'MedlineCitation')):
                    pmidElements = elem.findall('./PMID')
                    abstractElements = elem.findall('./Article/Abstract/AbstractText')
                    if ((len(pmidElements) != 1) or (len(abstractElements) != 1)):
                        continue
                    pmid = pmidElements[0].text
                    abstract = abstractElements[0].text
                    if (not (abstract is None)):
                        wordCount = len(abstract.split())
                        line = ('%s\t%d\n' % (pmid, wordCount))
                        result.write(line)
                        abstractCount += 1
    print(('%d abstracts processed' % abstractCount))