<commit_before>; Copyright © 2011 Sattvik Software & Technology Resources, Ltd. Co.
; All rights reserved.
;
; This program and the accompanying materials are made available under the
; terms of the Eclipse Public License v1.0 which accompanies this distribution,
; and is available at <http://www.eclipse.org/legal/epl-v10.html>.
;
; By using this software in any fashion, you are agreeing to be bound by the
; terms of this license.  You must not remove this notice, or any other, from
; this software.

(ns neko.compilation
  "Utility functions for managing the compilation environment when using
  version of Clojure that supports dynamic compilation on the Dalvik virtual
  machine.

  To use this namespace, you need to call init with a context, such as an
  activity object.  This will create a cache directory where temporary files
  will be placed and will set the 'clojure.compile.path' system property and
  the '*compile-path*' var.  If the cache directory already exists, it will be
  cleaned out.

  Note that additional invocations to init within the same process will not have
  any effect."
  {:author "<NAME>"}
  (:use [neko.resource :only [get-resource]])
  (:import android.content.Context
           java.io.File))

(def #^{:doc "Whether or not compilation has been initialized."
        :private true}
  cache-dir (atom nil))

(def #^{:doc "The default name of the cache directory."}
  default-cache-dir "clojure_cache")

(defn- cache-file?
  "Predicate for determining if a given file name is a cache file."
  [^String name]
  (and (.startsWith name "repl-")
       (or (.endsWith name ".dex")
           (.endsWith name ".jar"))))

(defn clear-cache
  "Clears all DEX and JAR files from the cache directory."
  []
  (locking cache-dir
    (let [^File dir @cache-dir
          delete-file (fn [^String name] (.delete (File. dir name)))]
      (when dir
        (->>
          (.list dir)
          (filter cache-file?)
          (map delete-file)
          (dorun))))))

(defn get-data-readers [^Context context]
  (->> (.. context (getResources)
           (openRawResource (get-resource :raw :data-readers)))
       slurp
       read-string
       (map (fn [[k v]] [k (resolve v)]))
       (into {})))
<commit_msg>Read data readers file from assets (see lein-droid 37da7bf)<commit_after>; Copyright © 2011 Sattvik Software & Technology Resources, Ltd. Co.
; All rights reserved.
;
; This program and the accompanying materials are made available under the
; terms of the Eclipse Public License v1.0 which accompanies this distribution,
; and is available at <http://www.eclipse.org/legal/epl-v10.html>.
;
; By using this software in any fashion, you are agreeing to be bound by the
; terms of this license.  You must not remove this notice, or any other, from
; this software.

(ns neko.compilation
  "Utility functions for managing the compilation environment when using
  version of Clojure that supports dynamic compilation on the Dalvik virtual
  machine.

  To use this namespace, you need to call init with a context, such as an
  activity object.  This will create a cache directory where temporary files
  will be placed and will set the 'clojure.compile.path' system property and
  the '*compile-path*' var.  If the cache directory already exists, it will be
  cleaned out.

  Note that additional invocations to init within the same process will not have
  any effect."
  {:author "<NAME>"}
  (:use [neko.resource :only [get-resource]])
  (:import android.content.Context
           [java.io File FileNotFoundException]))

(def #^{:doc "Whether or not compilation has been initialized."
        :private true}
  cache-dir (atom nil))

(def #^{:doc "The default name of the cache directory."}
  default-cache-dir "clojure_cache")

(defn- cache-file?
  "Predicate for determining if a given file name is a cache file."
  [^String name]
  (and (.startsWith name "repl-")
       (or (.endsWith name ".dex")
           (.endsWith name ".jar"))))

(defn clear-cache
  "Clears all DEX and JAR files from the cache directory."
  []
  (locking cache-dir
    (let [^File dir @cache-dir
          delete-file (fn [^String name] (.delete (File. dir name)))]
      (when dir
        (->>
          (.list dir)
          (filter cache-file?)
          (map delete-file)
          (dorun))))))

(defn get-data-readers [^Context context]
  (when-let [readers-file (try (.open (.getAssets context) "data_readers.clj")
                               (catch FileNotFoundException e nil))]
    (->> readers-file
         slurp
         read-string
         (map (fn [[k v]] [k (resolve v)]))
         (into {}))))

{'fraction_non_alphanumeric': 0.10455821991790884, 'fraction_numerical': 0.004104558219917909, 'mean_word_length': 3.0051903114186853, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '7036951', 'n_tokens_mistral': 1365, 'n_tokens_neox': 1311, 'n_words': 568}