<commit_before>(ns pc.models.layer
  (:require [pc.datomic :as pcd]
            [datomic.api :refer [db q] :as d]))


;; We'll pretend we have a type here
#_(t/def-alias Layer (HMap :mandatory {:document/id Long
                                       :db/id Long
                                       :layer/name String}
                           :optional {:layer/type Keyword
                                      :layer/child Long}))

;; This will work as long as other things don't get a document id
(defn all [db]
  (pcd/touch-all '{:find [?t]
                   :where [[?t :layer/name]]}
                 db))

(defn find-by-document [db document]
  (map (partial d/entity db)
       (d/q '{:find [[?t ...]]
              :in [$ ?document-id]
              :where [[?t :document/id ?document-id]
                      [?t :layer/name]]}
            db (:db/id document))))

(defn read-api [layer]
  (select-keys layer [:layer/name
                      :layer/uuid
                      :layer/type
                      :layer/start-x
                      :layer/start-y
                      :layer/end-x
                      :layer/end-y
                      :layer/rx<commit_msg>note about pull api<commit_after>(ns pc.models.layer
  (:require [pc.datomic :as pcd]
            [datomic.api :refer [db q] :as d]))


;; We'll pretend we have a type here
#_(t/def-alias Layer (HMap :mandatory {:document/id Long
                                       :db/id Long
                                       :layer/name String}
                           :optional {:layer/type Keyword
                                      :layer/child Long}))

;; This will work as long as other things don't get a document id
(defn all [db]
  (pcd/touch-all '{:find [?t]
                   :where [[?t :layer/name]]}
                 db))

(defn find-by-document [db document]
  (map (partial d/entity db)
       (d/q '{:find [[?t ...]]
              :in [$ ?document-id]
              :where [[?t :document/id ?document-id]
                      [?t :layer/name]]}
            db (:db/id document))))

;; TODO: can use pull API here
(defn read-api [layer]
  (select-keys layer [:layer/name
                      :layer/uuid
                      :layer/type
                      :layer/start-x
                      :layer/start-y
                      :layer/end-x
                      :layer/end-y
                      :layer/rx
{'fraction_non_alphanumeric': 0.12566955088586731, 'fraction_numerical': 0.0, 'mean_word_length': 1.1392070484581498, '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': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4404992', 'n_tokens_mistral': 713, 'n_tokens_neox': 672, 'n_words': 192}