diff --git a/src/nal/deriver.clj b/src/nal/deriver.clj index 2a94c23..5c493d3 100644 --- a/src/nal/deriver.clj +++ b/src/nal/deriver.clj @@ -1,7 +1,8 @@ (ns nal.deriver (:require [nal.deriver.utils :refer [walk]] - [nal.deriver.key-path :refer [mall-paths all-paths path mpath-invariants]] + [nal.deriver.key-path :refer [mall-paths all-paths mpath-invariants + path-with-max-level]] [nal.deriver.rules :refer [rule]])) (defn get-matcher [rules p1 p2] @@ -15,7 +16,7 @@ (fn [t1 t2] (mapcat #(% t1 t2) matchers))))) (def mget-matcher (memoize get-matcher)) -(def mpath (memoize path)) +(def mpath (memoize path-with-max-level)) (defn generate-conclusions [rules {p1 :statement :as t1} {p2 :statement :as t2}] (let [matcher (mget-matcher rules (mpath p1) (mpath p2))] diff --git a/src/nal/deriver/key_path.clj b/src/nal/deriver/key_path.clj index 6da6f02..f0d8d91 100644 --- a/src/nal/deriver/key_path.clj +++ b/src/nal/deriver/key_path.clj @@ -8,6 +8,18 @@ (conj (map path tail) fst)) :any)) +(defn path-with-max-level + ([statement] (path-with-max-level 0 statement)) + ([level statement] + (if (coll? statement) + (let [[fst & tail] statement] + (cons fst + (if (> 1 level) + (let [next-level (if (= 'conj fst) level (inc level))] + (map #(path-with-max-level next-level %) tail)) + (repeat (count tail) :any)))) + :any))) + (defn rule-path "Generates detailed pattern for the rule." [p1 p2]