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
def write_all_rel(pos, fp):
    for i, synset in enumerate(list(wn.all_synsets(pos))):
        if i%100 == 0:
            print("{} -> {}".format(synset.name(), str(synset.hyponyms())))

        for synset_sub in synset.hyponyms():
            for word_parent in synset.lemma_names(lang=LANG):
                for word_child in synset.lemma_names(lang=LANG):
                    fp.write("{},{}\n".format(word_parent, word_child))
Example #4
0
 def __init__(self):
     self.vocab = set()
     for synset in list(wn.all_synsets("n")):
         self._traverse(synset)
Example #5
0
# 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[ ]:


x[0].lemma_names(lang="tha")


# In[ ]:


wn.synsets("親", lang="jpn")


# In[ ]: