Skip to content

Commit

Permalink
Fixed extract-best-path()
Browse files Browse the repository at this point in the history
  • Loading branch information
julosaure committed Sep 16, 2012
1 parent 1c4626b commit 559fbc4
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions src/decloder/translator.clj
Expand Up @@ -9,7 +9,7 @@


;; GLOBALS ;; GLOBALS


(def MAX_HYPO_PER_STACK 1000) (def MAX_HYPO_PER_STACK 100)


;; UTILS ;; UTILS


Expand Down Expand Up @@ -94,9 +94,9 @@


(if (= pos 0) (if (= pos 0)
(let [hypos (filter #(= (first (key %)) src-token) (model :lex-prob)) (let [hypos (filter #(= (first (key %)) src-token) (model :lex-prob))
titi (println "(count hypos) " (count hypos)) ;titi (println "(count hypos) " (count hypos))
stack_ (reduce new-hypo (stacks 0) hypos) stack_ (reduce new-hypo (stacks 0) hypos)
tata (println "(count stack_) " (count stack_))] ];tata (println "(count stack_) " (count stack_))]
(recur (rest src-sentence_) (+ pos 1) (assoc stacks 0 stack_))) (recur (rest src-sentence_) (+ pos 1) (assoc stacks 0 stack_)))


(recur (rest src-sentence_) (+ pos 1) (recur (rest src-sentence_) (+ pos 1)
Expand Down Expand Up @@ -142,16 +142,26 @@


(defn extract-best-path [graph] (defn extract-best-path [graph]
(let [nb-stacks (count graph)] (let [nb-stacks (count graph)]
(loop [cpt (- nb-stacks 1) (loop [cpt (- nb-stacks 1)]
cur-stack (graph cpt) (let [cur-stack (graph cpt)]
best-path []] (if (= 0 (count cur-stack))
(if (< cpt 0) (recur (- cpt 1))
(map #(:token %) best-path) (loop [hypo (key (first cur-stack))
(recur (- cpt 1) (graph (- cpt 1)) (concat (first cur-stack) best-path)) best-path []]
(if (nil? hypo)
best-path
(do
;(println "c" best-path)
;(println "d" hypo)
(recur (:pred hypo) (concat [(:token hypo)] best-path))
)
)
)
)
) )
) )
) )
) )


(defn tokenize-sentence [s] (defn tokenize-sentence [s]
(map clojure.string/lower-case (map clojure.string/lower-case
Expand Down Expand Up @@ -191,7 +201,7 @@
sent-tok-id (tokens-to-ids model sent-tok)] sent-tok-id (tokens-to-ids model sent-tok)]
(println "Tokenized: " sent-tok) (println "Tokenized: " sent-tok)
(println "Ids: " sent-tok-id) (println "Ids: " sent-tok-id)
(let [;model (filter-src-lex-probs model sent-tok-id) (let [model (filter-src-lex-probs model sent-tok-id)
graph (search model sent-tok-id) graph (search model sent-tok-id)
best-path (extract-best-path graph) best-path (extract-best-path graph)
inv-voc-trg (reduce #(assoc %1 (val %2) (key %2)) {} (model :voc-trg)) inv-voc-trg (reduce #(assoc %1 (val %2) (key %2)) {} (model :voc-trg))
Expand Down

0 comments on commit 559fbc4

Please sign in to comment.