Example #1
0
    def test_wordnet(self):
        self.assertIsInstance(wordnet.langs(), list)
        self.assertIn("tha", wordnet.langs())

        self.assertEqual(
            wordnet.synset("spy.n.01").lemma_names("tha"), ["สปาย", "สายลับ"])
        self.assertIsNotNone(wordnet.synsets("นก"))
        self.assertIsNotNone(wordnet.all_synsets(pos=wn.ADJ))

        self.assertIsNotNone(wordnet.lemmas("นก"))
        self.assertIsNotNone(wordnet.all_lemma_names(pos=wn.ADV))
        self.assertIsNotNone(wordnet.lemma("cat.n.01.cat"))

        self.assertEqual(wordnet.morphy("dogs"), "dog")

        bird = wordnet.synset("bird.n.01")
        mouse = wordnet.synset("mouse.n.01")
        self.assertEqual(wordnet.path_similarity(bird, mouse),
                         bird.path_similarity(mouse))
        self.assertEqual(wordnet.wup_similarity(bird, mouse),
                         bird.wup_similarity(mouse))
        self.assertEqual(wordnet.lch_similarity(bird, mouse),
                         bird.lch_similarity(mouse))

        cat_key = wordnet.synsets("แมว")[0].lemmas()[0].key()
        self.assertIsNotNone(wordnet.lemma_from_key(cat_key))
Example #2
0
    def test_wordnet(self):
        self.assertIsNotNone(wordnet.langs())

        self.assertEqual(
            wordnet.synset("spy.n.01").lemma_names("tha"), ["สปาย", "สายลับ"]
        )
        self.assertIsNotNone(wordnet.synsets("นก"))
        self.assertIsNotNone(wordnet.all_synsets(pos=wn.ADJ))

        self.assertIsNotNone(wordnet.lemmas("นก"))
        self.assertIsNotNone(wordnet.all_lemma_names(pos=wn.ADV))
        self.assertIsNotNone(wordnet.lemma("cat.n.01.cat"))

        self.assertEqual(wordnet.morphy("dogs"), "dog")

        bird = wordnet.synset("bird.n.01")
        mouse = wordnet.synset("mouse.n.01")
        self.assertEqual(
            wordnet.path_similarity(bird, mouse), bird.path_similarity(mouse)
        )
        self.assertEqual(
            wordnet.wup_similarity(bird, mouse), bird.wup_similarity(mouse)
        )

        cat_key = wordnet.synsets("แมว")[0].lemmas()[0].key()
        self.assertIsNotNone(wordnet.lemma_from_key(cat_key))
Example #3
0
        self.vocab = set()
        for synset in list(wn.all_synsets("n")):
            self._traverse(synset)
    
    def _traverse(self, synset):
        for word in synset.lemma_names("tha"):
            self.vocab.add(word)
        for synset_sub in list(synset.hyponyms()):
            print(synset_sub)
            self._traverse(synset_sub)


# In[ ]:


len(wn.all_lemma_names(pos="n", lang="tha"))


# In[ ]:


wn.synset("object.n.01").lemma_names(lang="jpn")


# In[ ]:


x = list(wn.all_synsets("n"))


# In[ ]: