<commit_before>;; This is usefull to display the functions, ask the user for the
;; input parameters, and then execute them, presenting the result to
;; the user.
;; Intended to expose the functions in a Browser, but it could be
;; anything else: command line, rich client, ...
;;
(ns fnx.meta.expose
  "Expose the public functions of a namespace"
  (:use [clojure.string :only [split join escape]]
        [midje.sweet]))

;; * First we load the ns with `require`
;; * Then we get the public functions (read from bottom to top):
;; * We want only functions, not the other vars: We can spot them because they have an `:arglists` in their meta.
;; * Get the public vars with `ns-publics`
;;
(defn ns-public-fn
  "Given a ns symbol, returns all the public fns of this ns."
  [ns] (do (require ns)
           (filter #(:arglists (meta %))
                   (vals (ns-publics (find-ns ns))))))

(defn fun-str "Transform a function name without the #' in front of its name."
  [s]
  (join "" (drop 2 s)))

(defn resolve-str "Wrapper around 'resolve' to deal with string representing #'namespace/function"
  [s]
  (resolve (symbol (fun-str s))))

(defn list-ns "List the fnx namespaces to expose."
  [prefix-ns]
  (filter #(.contains (str (ns-name %)) prefix-ns) (all-ns)))

(defn fn-name "Transform a list of parameters into a function name"
  [& s]
  (str "#'" (join "/" [(join "." (butlast s)) (last s)])))

(defn apply-fn "Apply the function fun to the map args"
  [f args]
  (apply f (vals args)))

(defn load-ns! "Get the namespaces from the file namespaces-to-load"
  []
  (clojure.string/split (slurp "namespaces-to-load") #"\n"))

(fact
  (load-ns!) => ["fnx.meta.expose" "fnx.meta.example"])

(defn- parent "Given a namespace, return the namespace's 'parent'"
  [n]
  (when n
      (let [r (split n #"\.")]
        (if (<= 2 (count r)) (join "." (butlast r)) nil))))

(fact "parent"
  (parent nil) => nil
  (parent "foo.aws.extra") => "foo.aws"
  (parent "foo.aws") => "foo"
  (parent "foo") => nil)
<commit_msg>Cleanup - Limit the visibility of functions at the moment.<commit_after>;; This is usefull to display the functions, ask the user for the
;; input parameters, and then execute them, presenting the result to
;; the user.
;; Intended to expose the functions in a Browser, but it could be
;; anything else: command line, rich client, ...
;;
(ns fnx.meta.expose
  "Expose the public functions of a namespace"
  (:use [clojure.string :only [split join escape]]
        [midje.sweet]))

;; * First we load the ns with `require`
;; * Then we get the public functions (read from bottom to top):
;; * We want only functions, not the other vars: We can spot them because they have an `:arglists` in their meta.
;; * Get the public vars with `ns-publics`
;;
(defn- ns-public-fn
  "Given a ns symbol, returns all the public fns of this ns."
  [ns] (do (require ns)
           (filter #(:arglists (meta %))
                   (vals (ns-publics (find-ns ns))))))

(defn- fun-str "Transform a function name without the #' in front of its name."
  [s]
  (join "" (drop 2 s)))

(defn- resolve-str "Wrapper around 'resolve' to deal with string representing #'namespace/function"
  [s]
  (resolve (symbol (fun-str s))))

(defn- list-ns "List the fnx namespaces to expose."
  [prefix-ns]
  (filter #(.contains (str (ns-name %)) prefix-ns) (all-ns)))

(defn- fn-name "Transform a list of parameters into a function name"
  [& s]
  (str "#'" (join "/" [(join "." (butlast s)) (last s)])))

(defn- apply-fn "Apply the function fun to the map args"
  [f args]
  (apply f (vals args)))

(defn- load-ns! "Get the namespaces from the file namespaces-to-load"
  []
  (clojure.string/split (slurp "namespaces-to-load") #"\n"))

(fact
  (load-ns!) => ["fnx.meta.expose" "fnx.meta.example"])

(defn- parent "Given a namespace, return the namespace's 'parent'"
  [n]
  (when n
      (let [r (split n #"\.")]
        (if (<= 2 (count r)) (join "." (butlast r)) nil))))

(fact "parent"
  (parent nil) => nil
  (parent "foo.aws.extra") => "foo.aws"
  (parent "foo.aws") => "foo"
  (parent "foo") => nil)

{'fraction_non_alphanumeric': 0.15834557023984336, 'fraction_numerical': 0.0009789525208027412, 'mean_word_length': 3.3617929562433297, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, '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': '2623836', 'n_tokens_mistral': 1387, 'n_tokens_neox': 1361, 'n_words': 542}