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))
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))
def find_synonyms(path_folder, namefile): word = rw.get_data(f'./{path_folder}/{namefile}.csv') max = len(word) bar = IncrementalBar(f'Progress', max=max, suffix='%(percent)d%% %(elapsed_td)s') for row in word: trans_word = transform(row["word"]) try: find_synonyms = lemmas(trans_word) row.update({"synonyms": find_synonyms}) except: pass bar.next() bar.finish() fieldnames = [ 'word', 'synonyms', 'tf-idf-pos', 'tf-idf-neg', 'tf-idf-val', 'node-label' ] rw.write_data_by_columns(f"./synonyms/pythai/{path_folder}/{namefile}.csv", fieldnames, word)