<commit_before>(ns traveler.datomic.utils
  (:require [cheshire.core :refer [generate-string]]
            [clojure.string :refer [split]]
            [datomic.api :as d]
            [hatch]
            [inflections.core :refer [plural]]
            [traveler.conf :as t-conf]
            [traveler.schema :as t-schema]
            [traveler.datomic.output-models :refer :all]))

(defn conf []
  (t-conf/load-config))

(defn db []
  (d/connect (get-in (conf) [:db :uri])))

(def tx-entity! (partial hatch/tx-clean-entity! t-schema/partitions t-schema/valid-attrs))

(defn strip-namespace
  "Strip the datomic namespace from keys in a map"
  [in]
  (reduce conj {}
          (map #(vector (keyword (name (first %))) (second %)) in)))

(defn get-namespace
  "Get the namespace of an attribute"
  [in]
  (first (split (apply str (rest (str in))) #"/")))

(defn ent
  "Get an entity by attribute value"
  [attr value]<commit_msg>convert - to _ so javascript understands json output<commit_after>(ns traveler.datomic.utils
  (:require [cheshire.core :refer [generate-string]]
            [clojure.string :refer [split replace]]
            [datomic.api :as d]
            [hatch]
            [inflections.core :refer [plural]]
            [traveler.conf :as t-conf]
            [traveler.schema :as t-schema]
            [traveler.datomic.output-models :refer :all]))

(defn conf []
  (t-conf/load-config))

(defn db []
  (d/connect (get-in (conf) [:db :uri])))

(def tx-entity! (partial hatch/tx-clean-entity! t-schema/partitions t-schema/valid-attrs))

(defn strip-namespace
  "Strip the datomic namespace from keys in a map"
  [in]
  (reduce conj {}
          (map #(vector (keyword (replace (name (first %)) #"-" "_"))
                        (second %)) in)))

(defn get-namespace
  "Get the namespace of an attribute"
  [in]
  (first (split (apply str (rest (str in))) #"/")))

(defn ent
  "Get an entity by attribute value"
  [attr value]
{'fraction_non_alphanumeric': 0.15309278350515465, 'fraction_numerical': 0.0, 'mean_word_length': 2.6553672316384183, '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': '5089376', 'n_tokens_mistral': 660, 'n_tokens_neox': 650, 'n_words': 183}