Skip to content

Commit

Permalink
Renamed namespace.
Browse files Browse the repository at this point in the history
  • Loading branch information
oubiwann committed Oct 15, 2018
1 parent 811ad5f commit 67a4834
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 41 deletions.
14 changes: 8 additions & 6 deletions src/clj_wordnet/coerce.clj → src/wordnet/coerce.clj
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
(ns clj-wordnet.coerce
(:require [clojure.string :as str]
[clojure.set :refer [map-invert]])
(:import [edu.mit.jwi.item POS Pointer]
[java.lang.reflect Field]))
(ns wordnet.coerce
(:require
[clojure.set :refer [map-invert]]
[clojure.string :as str])
(:import
(edu.mit.jwi.item POS Pointer)
(java.lang.reflect Field)))

(defn to-keyword [k]
(-> k
name
(str/replace #"[_ ]" "-")
str/lower-case
str/lower-case
keyword))

(def keyword->pointer
Expand Down
24 changes: 14 additions & 10 deletions src/clj_wordnet/core.clj → src/wordnet/core.clj
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
(ns clj-wordnet.core
(:require [clojure.java.io :refer [file]]
[clojure.string :refer [upper-case lower-case]]
[clj-wordnet.coerce :as coerce]
[clojure.string :as s]
[clojure.set :refer :all])
(:import [edu.mit.jwi IDictionary Dictionary RAMDictionary]
[edu.mit.jwi.item IIndexWord ISynset ISynsetID SynsetID IWordID WordID IWord POS IPointer]
[edu.mit.jwi.data ILoadPolicy]
[edu.mit.jwi.morph WordnetStemmer]))
(ns wordnet.core
(:require
[clojure.java.io :refer [file]]
[clojure.set :refer :all]
[clojure.string :as s]
[clojure.string :refer [upper-case lower-case]]
[wordnet.coerce :as coerce])
(:import
(edu.mit.jwi IDictionary Dictionary RAMDictionary)
(edu.mit.jwi.data ILoadPolicy)
(edu.mit.jwi.item IIndexWord ISynset ISynsetID SynsetID
IWordID WordID IWord POS IPointer)
(edu.mit.jwi.morph WordnetStemmer)))


; JWI ICacheDictionary is not threadsafe
(def coarse-lock (Object.))
Expand Down
42 changes: 21 additions & 21 deletions test/clj_wordnet/core_test.clj → test/wordnet/core_test.clj
Original file line number Diff line number Diff line change
@@ -1,60 +1,60 @@
(ns clj-wordnet.core-test
(ns wordnet.core-test
(:require
[clojure.test :refer :all]
[clj-wordnet.test-client :refer [wordnet]]
[clj-wordnet.core :refer :all]))
[wordnet.core :refer :all]
[wordnet.test-client :as test-client]))

(deftest fetch-with-noun
(is (= "dog" (:lemma (first (wordnet "dog" :noun))))))
(is (= "dog" (:lemma (first (test-client/dict "dog" :noun))))))

(deftest fetch-exact
(is (= "metal supports for logs in a fireplace; \"the andirons were too hot to touch\""
(-> "dog#n#7" wordnet synset :gloss))))
(-> "dog#n#7" test-client/dict synset :gloss))))

(deftest fetch-without-pos
(is (= "dog" (:lemma (first (wordnet "dog "))))))
(is (= "dog" (:lemma (first (test-client/dict "dog "))))))

(deftest fetch-by-stemming
(is (= nil (:lemma (first (wordnet "dogs")))))
(is (= "dog" (:lemma (first (wordnet "dogs" :stem)))))
(is (= "buy" (:lemma (first (wordnet "bought" :stem))))))
(is (= nil (:lemma (first (test-client/dict "dogs")))))
(is (= "dog" (:lemma (first (test-client/dict "dogs" :stem)))))
(is (= "buy" (:lemma (first (test-client/dict "bought" :stem))))))

(deftest fetch-unknown-word
(is (empty? (wordnet "fdssfsfs"))))
(is (empty? (test-client/dict "fdssfsfs"))))

(deftest fetch-empty-word
(is (empty? (wordnet ""))))
(is (empty? (test-client/dict ""))))

(deftest fetch-nil-word
(is (empty? (wordnet nil))))
(is (empty? (test-client/dict nil))))

(deftest word-id-lookup
(let [dog (first (wordnet "dog" :noun))]
(is (= dog (wordnet "WID-02086723-N-01-dog")))))
(let [dog (first (test-client/dict "dog" :noun))]
(is (= dog (test-client/dict "WID-02086723-N-01-dog")))))

(deftest synset-id-lookup
(is (= "a member of the genus Canis (probably descended from the common wolf) that has been domesticated by man since prehistoric times; occurs in many breeds; \"the dog barked all night\""
(:gloss (wordnet "SID-02086723-N")))))
(:gloss (test-client/dict "SID-02086723-N")))))

(deftest synset-words
(is (= '("dog" "domestic_dog" "Canis_familiaris")
(map :lemma (words (wordnet "SID-02086723-N"))))))
(map :lemma (words (test-client/dict "SID-02086723-N"))))))

(deftest related-synset-test
(is (= '("SID-02085998-N" "SID-01320032-N")
(map (comp str :id) (related-synsets (wordnet "SID-02086723-N") :hypernym)))))
(map (comp str :id) (related-synsets (test-client/dict "SID-02086723-N") :hypernym)))))

(deftest semantic-relations-test
(is (= '(:holonym-member :hypernym :hyponym :meronym-part)
(sort (keys (semantic-relations (wordnet "SID-02086723-N")))))))
(sort (keys (semantic-relations (test-client/dict "SID-02086723-N")))))))

(deftest lexical-relations-test
(is (:derivationally-related (lexical-relations (wordnet "WID-00982557-A-01-quick")))))
(is (:derivationally-related (lexical-relations (test-client/dict "WID-00982557-A-01-quick")))))

(deftest hypernym-test
(is (= '("SID-02085998-N" "SID-01320032-N" "SID-02077948-N" "SID-01889397-N" "SID-01864419-N" "SID-01474323-N" "SID-01468898-N" "SID-00015568-N" "SID-00004475-N" "SID-00004258-N" "SID-00003553-N" "SID-00002684-N" "SID-00001930-N" "SID-00001740-N" "SID-00015568-N" "SID-00004475-N" "SID-00004258-N" "SID-00003553-N" "SID-00002684-N" "SID-00001930-N" "SID-00001740-N")
(map :id (hypernyms (synset (wordnet "dog#n#1")))))))
(map :id (hypernyms (synset (test-client/dict "dog#n#1")))))))

(deftest hypernym-instance-test
(is (= '("SID-08714745-N" "SID-08562388-N" "SID-08508836-N" "SID-08569713-N" "SID-08648560-N" "SID-00027365-N" "SID-00002684-N" "SID-00001930-N" "SID-00001740-N")
(map :id (hypernym-instances (synset (wordnet "england#n#1")))))))
(map :id (hypernym-instances (synset (test-client/dict "england#n#1")))))))
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns clj-wordnet.test-client
(:use [clojure.test]
[clj-wordnet.core]))
(ns wordnet.test-client
(:require
[wordnet.core :as wordnet]))

;; =========================================================================
;; Don't change the path - it is used for running local and Travis CI builds
Expand All @@ -11,4 +11,4 @@
;;
;; $ git submodule update --init data
;;
(def wordnet (make-dictionary "./data/dict"))
(def dict (wordnet/make-dictionary "./data/dict"))

0 comments on commit 67a4834

Please sign in to comment.