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
4

1 に答える 1

5

1N は、リーダーと REPL が BigInt に使用する構文です。

これらの呼び出しの 1 つは bigint を返しています。


re: 「もっといい書き方があると思います」

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))
于 2012-07-22T21:01:29.050 に答える