def test_cli_tree(self, output): words = ["test"] sys.argv = ["ety.py", "-t"] + words ety.cli() tree = ety.tree("test") expected_lines = len(tree) self.assertEqual(expected_lines, output.lines)
def test_cli_multiple_words_tree(self, output): words = ["test", "word"] sys.argv = ["ety.py", "-t"] + words ety.cli() trees = [ety.tree(word) for word in words] expected_length = sum(len(tree) for tree in trees) + len(words) - 1 self.assertEqual(expected_length, output.lines)
async def ety(self, ctx, word, *flags): """Look up the etymology of a word. Add -soft to the end to look up words that are parts of other words. -r does something too I don't remember though""" is_soft = '-soft' in flags resources_ = flags[flags.index('-r') + 1:] if '-r' in flags else RESOURCES resources = [res.replace(',', '').strip() for res in resources_] def format_embed(fields, resource): embed = discord.Embed.from_dict({ 'color': 0xDD0000, 'title': word, 'author': { 'name': props[resource]['name'], 'icon_url': str(ctx.author.avatar_url) }, 'url': props[resource]['list']['url'].format(word), 'fields': fields }) return embed async with ctx.typing(): embeds = [ format_embed([{ 'value': ety.tree(word).__str__(), 'name': word }], 'wiki') ] for resource in resources: for fields in await self.scrape_fields(word, resource, is_soft): embeds.append(format_embed(fields, resource)) # from pprint import pprint # pprint([embed.to_dict() for embed in embeds]) paginator = disputils.BotEmbedPaginator(ctx, embeds) ctx.bot.loop.create_task(paginator.run())
def cli(): """ Command line interface :return: Exit code """ parser = argparse.ArgumentParser(prog="ety") parser.add_argument("words", type=str, nargs='+', help="the search word(s)") parser.add_argument("-r", "--recursive", help="search origins recursively", action="store_true") parser.add_argument("-t", "--tree", help="display etymology tree", action="store_true") args = parser.parse_args() output = '' for word in args.words: source_word = ety.Word(word, color=True) roots = ety.origins(word, recursive=args.recursive) if not roots: print("No origins found for word: {}".format(word)) continue # Bullet point: '\u2022' if args.tree: output += '%s\n\n' % str(ety.tree(source_word)) else: output += '\n\n%s\n \u2022 ' % source_word output += '\n \u2022 '.join(root.pretty for root in roots) print(output.strip()) return 0
def test_tree(self): self.assertGreaterEqual( len(str(ety.tree('aerodynamically')).split('\n')), 10) self.assertGreaterEqual(len(str(ety.tree('fabric')).split('\n')), 4)
print(f"\nThe language of the entered word is: {langcodes[toTB_lang]}") if choice == 1: # Know the meaning if toTB_lang != 'en': syns = wordnet.synsets(toTB.translate(to='en')) else: syns = wordnet.synsets(word) print(f"The most common meaning of '{word}' in English is:") print(syns[0].definition()) elif choice == 2: # Translate it toLang = str( input("Which language do you want the word to be translated in? ") ).lower().capitalize() langCode = langCode_to_lang(langcodes, toLang) print(f"'{word}' translated into {toLang} is:") print(toTB.translate(to=langCode[0])) toTB2 = TextBlob(word) toTB2_lang = toTB.detect_language() print(f"\nThe etymological root of '{word}' is as below: \n") if toTB2_lang != 'en': print(ety.tree(str(toTB2.translate(to='en')))) else: print(ety.tree(word))
def test_tree(self): self.assertGreaterEqual( len(str(ety.tree("aerodynamically")).split("\n")), 10) self.assertGreaterEqual(len(str(ety.tree("fabric")).split("\n")), 4) self.assertGreaterEqual(len(str(ety.tree("potato")).split("\n")), 2)
def test_tree_dict(self): self.assertIsInstance(ety.tree("potato").__dict__, dict)
def test_wintu_code(self): tree = str(ety.tree("Wintun")) self.assertEqual(tree, "Wintun (English)\n└── wintʰu·n (Wintu)")
def test_nah_lang_code(self): tree = str(ety.tree("avocado")) self.assertTrue( tree.startswith("avocado (English)\n└── aguacate (Spanish)")) self.assertTrue("Nahuatl languages" in tree)