2012-07-22 94 views
2
;; ------------------------- DICE COEFFS ------------------------ 

(defn dice-set-coeff [a b] 
    (* (/ (count (clojure.set/intersection a b)) 
     (+ (count a) (count b))) 
    2)) 

(defn dice-lst-coeff [a b] 
    (dice-set-coeff (set a) (set b))) 

;; ------------------------- BIGRAMS ---------------------------- 

(defn now-nxt [xs] 
    "im sure there is a better way to write this" 
    (map #(list %1 %2) xs (rest xs))) 

(defn bigram [xs] 
    (list now-nxt xs)) 

(defn dice-string-bigram [a b] 
    (dice-lst-coeff (bigram a) (bigram b))) 

爲什麼我在結果中得到1N?

tst.core> (dice-string-bigram "hello" "hello") 
1N 
tst.core> (dice-string-bigram "hello" "helap") 
1/2 
tst.core> (dice-string-bigram "hello" "howdy") 
0 
tst.core> (== (dice-string-bigram "hello" "hello") 1) 
true 

回答

5

1N是reader和REPL用於BigInts的語法。

其中一個調用返回bigint。


重:「我確定有一個更好的方式來寫這個」

user> (now-nxt a) 
((\h \e) (\e \l) (\l \l) (\l \o)) 
user> (partition 2 1 a) 
((\h \e) (\e \l) (\l \l) (\l \o)) 
+0

布里爾,只需要知道我一直在尋找!謝謝 – beoliver 2012-07-22 21:06:22

+0

回覆:'now-nxt'謝謝。 – beoliver 2012-07-22 22:14:32

相關問題