<commit_before>package genfs

import (
	"io"
	"io/ioutil"
	"os"
	"path/filepath"
	"regexp"
	"strings"
	"text/template"
	"time"
)

// Filter is a func that returns true for file names that should be excluded.
type Filter func(name string) bool

// FilterNone does not match any file names, i.e. it includes all files when
// used with the Files func.
var FilterNone = func(string) bool { return false }

// FilterRegexp returns a filter func for the given posix regexp expr, or an
// error.
func FilterRegexp(expr string) (Filter, error) {
	r, err := regexp.CompilePOSIX(expr)
	if err != nil {
		return nil, err
	}
	return func(name string) bool {
		return r.MatchString(name)
	}, nil
}

// Files recursively searches path and returns all files not matched by the
// ignore filter or an error.
func Files(path string, ignore Filter) ([]*File, error) {
	return files(path, path, ignore)
}

func files(path, root string, ignore Filter) ([]*File, error) {
	file, err := os.Open(path)
	if err != nil {
		return nil, err
	}
	defer file.Close()
	stat, err := file.Stat()
	if err != nil {
		return nil, err
	}
	relPath, err := filepath.Rel(root, path)
	if err != nil {
		return nil, err
	}
	if ignore(relPath) {
		return nil, nil
	}
	result := &File{
		path:    relPath,
		name:    stat.Name(),<commit_msg>docs: improve language<commit_after>package genfs

import (
	"io"
	"io/ioutil"
	"os"
	"path/filepath"
	"regexp"
	"strings"
	"text/template"
	"time"
)

// Filter is a func that returns true for file names that should be excluded.
type Filter func(name string) bool

// FilterNone does not match any file names, i.e. it includes all files when
// used with the Files func.
var FilterNone = func(string) bool { return false }

// FilterRegexp returns a filter func for the given posix regexp expr, or an
// error.
func FilterRegexp(expr string) (Filter, error) {
	r, err := regexp.CompilePOSIX(expr)
	if err != nil {
		return nil, err
	}
	return func(name string) bool {
		return r.MatchString(name)
	}, nil
}

// Files recursively searches path and returns all files not excluded by the
// ignore filter or an error.
func Files(path string, ignore Filter) ([]*File, error) {
	return files(path, path, ignore)
}

func files(path, root string, ignore Filter) ([]*File, error) {
	file, err := os.Open(path)
	if err != nil {
		return nil, err
	}
	defer file.Close()
	stat, err := file.Stat()
	if err != nil {
		return nil, err
	}
	relPath, err := filepath.Rel(root, path)
	if err != nil {
		return nil, err
	}
	if ignore(relPath) {
		return nil, nil
	}
	result := &File{
		path:    relPath,
		name:    stat.Name(),
{'fraction_non_alphanumeric': 0.12164236377590176, 'fraction_numerical': 0.0, 'mean_word_length': 3.5025906735751295, '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': '578189', 'n_tokens_mistral': 916, 'n_tokens_neox': 889, 'n_words': 333}