<commit_before>import logging
log = logging.getLogger(__name__)

from pathlib import Path

def filelist(folderpath, ext=None, flat=True):
    '''
    Returns a list of all the files contained in the folder specified by `folderpath`.
    To filter the files by extension simply add a list containing all the extension with `.` as the second argument.
    If `flat` is False, then the Path objects are returned.
    '''
    path = Path(folderpath)
    if not ext:
        ext = []
    if path.exists() and path.is_dir():
        if flat:
            return [ str(f) for f in path.iterdir() if f.is_file() and f.suffix in ext ]
        else:
            return [ f for f in path.iterdir() if f.is_file() and f.suffix in ext ]
    else:
        log.warn('Nothing found in "{}"'.format(str(folderpath)))<commit_msg>added method to get a dictionary containing ancient greek particles<commit_after>import json
import os

import logging
log = logging.getLogger(__name__)

from pathlib import Path

def filelist(folderpath, ext=None, flat=True):
    '''
    Returns a list of all the files contained in the folder specified by `folderpath`.
    To filter the files by extension simply add a list containing all the extension with `.` as the second argument.
    If `flat` is False, then the Path objects are returned.
    '''
    path = Path(folderpath)
    if not ext:
        ext = []
    if path.exists() and path.is_dir():
        if flat:
            return [ str(f) for f in path.iterdir() if f.is_file() and f.suffix in ext ]
        else:
            return [ f for f in path.iterdir() if f.is_file() and f.suffix in ext ]
    else:
        log.warn('Nothing found in "{}"'.format(str(folderpath)))

def particles(category=None):
    '''
    Returns a dict containing old greek particles grouped by category.
    '''
    filepath = os.path.join(os.path.dirname(__file__), './particles.json')
    with open(filepath) as f:
        try:
            particles = json.load(f)
        except ValueError as e:
            log.error('Bad json format in "{}"'.format(filepath))
        else:
            if category:
                if category in particles:
                    return particles[category]
                else:
                    log.warn('Category "{}" not contained in particle dictionary!'.format(category))
            return particles
{'fraction_non_alphanumeric': 0.09795570698466781, 'fraction_numerical': 0.0, 'mean_word_length': 2.459499263622975, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4587198', 'n_tokens_mistral': 653, 'n_tokens_neox': 641, 'n_words': 255}