Skip to content

Commit

Permalink
starting to work on the recognizer
Browse files Browse the repository at this point in the history
  • Loading branch information
egri-nagy committed Sep 19, 2023
1 parent a0405cf commit 42cccac
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion experiments/TRANSDUCERS/automata.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
;;TODO write a function that checks the io-pairs for contradicting pairs
;; like the same word requiring two different outputs

(def stop \⏹)

(defn proper-prefixes
"All proper prefixes of the given word, starting from the empty word."
[coll]
Expand All @@ -19,4 +21,27 @@
inputs."
[io-pairs]
(update-vals (group-by second io-pairs)
(partial map first)))
(partial map first)))

(defn firsts-in-trie
"Returns a set of the elements that appear the first positions in the
branches."
[trie]
(cond
(empty? trie) #{}
(vector? (first trie)) (into #{} (map first (first trie)))
:else #{(first trie)}))

(defn recognizer
"Returns a recognizer FA for the trie."
([trie] (recognizer trie 0 {} #{:accept}))
([trie state delta acceptors]
(let [elts (take-while (fn [x] (not (vector? x))) trie)
(reduce (fn [])
delta)]
(if (= (count trie) (count elts))
(conj result new-so-far)
(reduce
(fn [r v] (retrieve v new-so-far r))
result
(last trie))))))

0 comments on commit 42cccac

Please sign in to comment.