<commit_before><commit_msg>Added a files namespace to handle file input<commit_after>(ns extracter.files
  (:require [clojure.java.io :as io]))

(defn contains?
  [^java.util.regex.Pattern re ^String s]
  (boolean (re-find re s)))

(defn fact?
  "Returns true if the given file appears to contain at least one fact docstring."
  [^java.io.File f]
  (with-open [fin (io/reader f)]
    (->> fin
         line-seq
         (some (partial contains? #"# Fact: ")))))

(defn file?
  [^java.io.File f]
  (.isFile f))

(defn facts-in-dir
  "Returns a lazy sequence of java.io.File instances for every fact source file in a directory path.
  Scans recursively."
  [^String path]
  (->> path
       io/file
       file-seq
       (filter file?)
       (filter fact?)))
{'fraction_non_alphanumeric': 0.13720316622691292, 'fraction_numerical': 0.0, 'mean_word_length': 2.9123711340206184, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '2064259', 'n_tokens_mistral': 261, 'n_tokens_neox': 252, 'n_words': 86}