<commit_before>#!/usr/bin/python
# -*- coding: UTF-8 -*-
import os
from niprov.filesystem import Filesystem


packageroot = os.path.split(os.path.split(__file__)[0])[0]
defaultfilterfile = os.path.join(packageroot,'discovery-filter.txt')

class FileFilter(object):

    def __init__(self, filesys=Filesystem()):
        self.filters = filesys.readlines(defaultfilterfile)

    def include(self, filepath):
        for filt in self.filters:
            if filt in filepath:
                return True
        return False
<commit_msg>Made sure that creating a Filefilter object does not raise an exception if filter file is not available. This happens e.g. on readthedocs.org<commit_after>#!/usr/bin/python
# -*- coding: UTF-8 -*-
import os
from niprov.filesystem import Filesystem


packageroot = os.path.split(os.path.split(__file__)[0])[0]
defaultfilterfile = os.path.join(packageroot,'discovery-filter.txt')

class FileFilter(object):

    def __init__(self, filesys=Filesystem()):
        try:
            self.filters = filesys.readlines(defaultfilterfile)
        except:
            self.filters = None

    def include(self, filepath):
        if not self.filters:
            raise ValueError('Was not able to load filter file.')
        for filt in self.filters:
            if filt in filepath:
                return True
        return False

{'fraction_non_alphanumeric': 0.10398230088495575, 'fraction_numerical': 0.004424778761061947, 'mean_word_length': 2.8771428571428572, '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': '4471455', 'n_tokens_mistral': 410, 'n_tokens_neox': 394, 'n_words': 107}