<commit_before>(ns plastic.main.validator
  (:require-macros [plastic.logging :refer [log info warn error group group-end measure-time]])
  (:require [schema.core :as s :include-macros true]
            [plastic.validator :refer [cached factory]]
            [plastic.main.editor.model :as editor]
            [plastic.main.editor.toolkit.id :as id]))

; -------------------------------------------------------------------------------------------------------------------

(def TODO s/Any)

(def editor-id s/Int)

(def node-id (s/either s/Int s/Str))

(def maybe-node-id (s/maybe node-id))

(def node-id-list [node-id])

(def node-id-set #{node-id})

(def line-number s/Int)

(def form-id s/Int)

(def scope-id s/Int)

(def children-table-row
  [(s/one {s/Keyword TODO} "row options")
   node-id])

(def children-table
  [(s/one {s/Keyword TODO} "table options")
   children-table-row])

(def layout-info
  {:id                        node-id
   :tag                       s/Keyword
   (s/optional-key :line)     line-number
   (s/optional-key :text)     s/Str
   (s/optional-key :type)     s/Keyword
   (s/optional-key :children) (s/either children-table node-id-list)
   s/Keyword                  TODO})

(def editor-layout
  (cached {form-id {node-id layout-info}}))

(def selectable-info
  {:id                        node-id
   :tag                       s/Keyword
   (s/optional-key :line)     line-number
   (s/optional-key :text)     s/Str
   (s/optional-key :type)     s/Keyword
   (s/optional-key :children) (s/either children-table node-id-list)
   s/Keyword                  TODO})

(def editor-selectables
  (cached {form-id {node-id selectable-info}}))

(def spatial-item
  {:id                    node-id
   :tag                   s/Keyword
   (s/optional-key :line) line-number
   (s/optional-key :text) s/Str
   (s/optional-key :type) s/Keyword
   s/Keyword              TODO})

(def spatial-info
  {line-number [spatial-item]})

(def editor-spatial-web
  (cached {form-id spatial-info}))

(def structural-item
  {:left  maybe-node-id
   :right maybe-node-id
   :up    maybe-node-id
   :down  maybe-node-id})

(def structural-info
  {node-id structural-item})

(def editor-structural-web
  (cached {form-id structural-info}))

(def analysis-scope
  {:id       scope-id
   :depth    s/Int
   s/Keyword TODO})

(def analysis-item
  {(s/optional-key :scope)        analysis-scope
   (s/optional-key :parent-scope) TODO
   (s/optional-key :decl-scope)   analysis-scope
   (s/optional-key :related)      node-id-set
   s/Keyword                      TODO})

(def analysis-info
  {node-id analysis-item})

(def editor-analysis
  (cached {form-id analysis-info}))

(def editor-render-state
  (cached {:order [form-id]}))

(def editor-members
  {:id                               editor-id
   :uri                              s/Str
   (s/optional-key :render-state)    editor-render-state
   (s/optional-key :layout)          editor-layout
   (s/optional-key :selectables)     editor-selectables
   (s/optional-key :spatial-web)     editor-spatial-web
   (s/optional-key :structural-web)  editor-structural-web
   (s/optional-key :analysis)        editor-analysis
   (s/optional-key :highlight)       node-id-set
   (s/optional-key :cursor)          node-id-set
   (s/optional-key :selection)       node-id-set
   (s/optional-key :puppets)         node-id-set
   (s/optional-key :focused-form-id) node-id-set
   (s/optional-key :editing)         node-id-set
   (s/optional-key :inline-editor)   TODO
   (s/optional-key :xform-report)    TODO})

(defn editor-nodes-present-in-layout? [editor node-or-nodes]<commit_msg>more aggressive caching to speed validation up<commit_after>(ns plastic.main.validator
  (:require-macros [plastic.logging :refer [log info warn error group group-end measure-time]])
  (:require [schema.core :as s :include-macros true]
            [plastic.validator :refer [cached factory]]
            [plastic.main.editor.model :as editor]
            [plastic.main.editor.toolkit.id :as id]))

; -------------------------------------------------------------------------------------------------------------------

(def TODO s/Any)

(def editor-id s/Int)

(def node-id (s/either s/Int s/Str))

(def maybe-node-id (s/maybe node-id))

(def node-id-list [node-id])

(def node-id-set #{node-id})

(def line-number s/Int)

(def form-id s/Int)

(def scope-id s/Int)

(def children-table-row
  [(s/one {s/Keyword TODO} "row options")
   node-id])

(def children-table
  [(s/one {s/Keyword TODO} "table options")
   children-table-row])

(def layout-info
  (cached
    {:id                        node-id
     :tag                       s/Keyword
     (s/optional-key :line)     line-number
     (s/optional-key :text)     s/Str
     (s/optional-key :type)     s/Keyword
     (s/optional-key :children) (s/either children-table node-id-list)
     s/Keyword                  TODO}))

(def editor-layout
  (cached {form-id {node-id layout-info}}))

(def selectable-info
  (cached
    {:id                        node-id
     :tag                       s/Keyword
     (s/optional-key :line)     line-number
     (s/optional-key :text)     s/Str
     (s/optional-key :type)     s/Keyword
     (s/optional-key :children) (s/either children-table node-id-list)
     s/Keyword                  TODO}))

(def editor-selectables
  (cached {form-id {node-id selectable-info}}))

(def spatial-item
  (cached
    {:id                    node-id
     :tag                   s/Keyword
     (s/optional-key :line) line-number
     (s/optional-key :text) s/Str
     (s/optional-key :type) s/Keyword
     s/Keyword              TODO}))

(def spatial-info
  (cached {line-number [spatial-item]}))

(def editor-spatial-web
  (cached {form-id spatial-info}))

(def structural-item
  (cached
    {:left  maybe-node-id
     :right maybe-node-id
     :up    maybe-node-id
     :down  maybe-node-id}))

(def structural-info
  {node-id structural-item})

(def editor-structural-web
  (cached {form-id structural-info}))

(def analysis-scope
  {:id       scope-id
   :depth    s/Int
   s/Keyword TODO})

(def analysis-item
  (cached
    {(s/optional-key :scope)        analysis-scope
     (s/optional-key :parent-scope) TODO
     (s/optional-key :decl-scope)   analysis-scope
     (s/optional-key :related)      node-id-set
     s/Keyword                      TODO}))

(def analysis-info
  {node-id analysis-item})

(def editor-analysis
  (cached {form-id analysis-info}))

(def editor-render-state
  (cached {:order [form-id]}))

(def editor-members
  {:id                               editor-id
   :uri                              s/Str
   (s/optional-key :render-state)    editor-render-state
   (s/optional-key :layout)          editor-layout
   (s/optional-key :selectables)     editor-selectables
   (s/optional-key :spatial-web)     editor-spatial-web
   (s/optional-key :structural-web)  editor-structural-web
   (s/optional-key :analysis)        editor-analysis
   (s/optional-key :highlight)       node-id-set
   (s/optional-key :cursor)          node-id-set
   (s/optional-key :selection)       node-id-set
   (s/optional-key :puppets)         node-id-set
   (s/optional-key :focused-form-id) node-id-set
   (s/optional-key :editing)         node-id-set
   (s/optional-key :inline-editor)   TODO
   (s/optional-key :xform-report)    TODO})

(defn editor-nodes-present-in-layout? [editor node-or-nodes]
{'fraction_non_alphanumeric': 0.1670940747739236, 'fraction_numerical': 0.0, 'mean_word_length': 1.94866693195384, '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': '811250', 'n_tokens_mistral': 2489, 'n_tokens_neox': 2473, 'n_words': 541}