 
 (defn save-iyye-type-to-db [type]
   (let [types-list-str (fn [types]
-          (reduce #(str %1 "_" %2) types))
+                         (reduce #(str %1 "_" %2) types))
         rel-key (fn [name ind]
-          (keyword (str name ind)))
+                  (keyword (str name ind)))
         get-rel
         (fn [ind rel]
-          {(rel-key "Relation-name" ind) (:Name (:atom rel))
-             (rel-key "Relation-uname" ind) (:Uname (:atom rel))
-            (rel-key "Relation-AccordingTo" ind) (:AccordingTo (:Predicate rel))
-            (rel-key "Relation-When" ind) (:When (:Predicate rel))
-            (rel-key "Relation-Time" ind) (:Time (:Predicate rel))
-             (rel-key "Relation-Prob" ind) (:Prob (:Predicate rel))
-             (rel-key "Relation-Types-List" ind) (types-list-str (:Types rel))
-           (rel-key "Relation-Data-List1" ind) (types-list-str (map name (keys (:Data rel))))
-               (rel-key "Relation-Data-List2" ind) (types-list-str (vals (:Data rel)))
+          {(rel-key "Relation-name" ind)        (:Name (:name rel))
+           (rel-key "Relation-uname" ind)       (:Uname (:name rel))
+           (rel-key "Relation-AccordingTo" ind) (:AccordingTo (:Predicate rel))
+           (rel-key "Relation-When" ind)        (:When (:Predicate rel))
+           (rel-key "Relation-Time" ind)        (:Time (:Predicate rel))
+           (rel-key "Relation-Prob" ind)        (:Prob (:Predicate rel))
+           (rel-key "Relation-Types-List" ind)  (types-list-str (:Types rel))
+           (rel-key "Relation-Data-List1" ind)  (types-list-str (map name (keys (:Data rel))))
+           (rel-key "Relation-Data-List2" ind)  (types-list-str (vals (:Data rel)))
            })]
-    (let [write-type (reduce conj {:Uname (:Uname (:atom type))
-                                   :Name  (:Name (:atom type))}
+    (let [write-type (reduce conj {:Uname (:Uname (:name type))
+                                   :Name  (:Name (:name type))}
                              (map-indexed get-rel (:Relations type)))
           ]
       ; (when @dbg-IO (print-io-str @dbg-IO (pr-str "add list: " type ":::"

            rel-vec
            (let [rel-uname (t (mykey "Relation-uname" num))]
              (recur (conj rel-vec
                         (->Iyye_Relation
                           (->Iyye_Atom (t (mykey "Relation-name" num))
                                        rel-uname
                                        false)
                           (->Iyye_ModalPredicate
                             (t (mykey "Relation-AccordingTo" num))
                             (t (mykey "Relation-When" num))
                             (t (mykey "Relation-Time" num))
                             (t (mykey "Relation-Prob" num)))
                           (create-types num)
                           (:Function (@action-words (t (mykey "Relation-uname" num))))
                           (:PredicateFunction (@action-words (t (mykey "Relation-uname" num))))
                           (create-data num)))
                   (inc num)))))]
    (->Iyye_Type (->Iyye_Atom (:Name t) (:Uname t) false) relations-list)))

(defn create-iyye-relation [Name Predicate Types Function PredicateFunction & builtin]
  (let [action-atom (create-iyye-atom Name builtin)
        relation (->Iyye_Relation action-atom Predicate Types Function PredicateFunction [])]
    relation))

(def time-start (persistence/local-time-to-string))
(defn get-supertypes [atype]
  "gets types: self, type, immidiate parents"               ; FIXME Yumzia:0 get all parents
  (if-not (:UNKNOWN atype)
    (let [rels (:Relations atype)]
      (conj (for [supertype rels :when (:super (:Data supertype))]
              {:Name (:super (:Data supertype)) :Predicate (:Predicate supertype)})
              {:Name "type" :Predicate (->Iyye_ModalPredicate :IYE :AXIOM time-start :ALWAYS)}
              {:Name (:Name (:atom atype)) :Predicate (->Iyye_ModalPredicate :IYE :AXIOM time-start :ALWAYS)}))
    {:UNKNOWN (:UNKNOWN atype)}))

(defn create-iyye-instance [values])

  (:require
    [clojure.tools.logging :as log]
    [iyye.bios.ioframes :as ioframes]
    [iyye.bios.persistence :as persistence]))
    ;[iyye.subcon.knowledge.relation :as relation]

(def dbg-IO (ref nil))

(def builtin-words (ref {}))

(defrecord Iyye_ModalPredicate [AccordingTo When Time Prob ])
(defrecord Iyye_Name [Name Uname Type Word2vec Tags])
(defrecord Iyye_Type [name Relations toString])
(defrecord Iyye_Verb [name Types Result Function Complexity])
;(defrecord Iyye_Query [verb PredicateFunction])
(defrecord Iyye_Relation [name Types Predicate Function PredicateFunction Data])
(defrecord Iyye_Instance [name type])
(defrecord Iyye_Error [bug toString])

(defn pred-toString [pred] (pr-str ))

(def names-number (ref 0))
(defn inc-names! []
  (dosync (ref-set names-number (inc @names-number)))
  @names-number)

(defn get-types [verb] (if (:Types verb)
                         (:Types verb)
                         (if (:verb verb)
                           ())))

(defn create-iyye-name [name type & builtin]
  (let [uname (str name (inc-names!))
        b (if (nil? builtin) false (first builtin))
        atom (->Iyye_Name name uname type nil {})]
    atom))

(defn create-iyye-type [Name & builtin]
  (let [type-atom (create-iyye-name Name "type" builtin)
        type (->Iyye_Type type-atom (list) pr-str)]
    type))

(defn create-iyye-type-from-db [t]
