Revised logic of checking for creature types

This commit is contained in:
mwisnowski 2024-12-11 11:36:29 -08:00
parent 6596a59c9e
commit 6c88c7cf38
3 changed files with 77 additions and 52 deletions

View file

@ -58,39 +58,7 @@ creature_types = ['Advisor', 'Aetherborn', 'Alien', 'Ally', 'Angel', 'Antelope',
'Thopter', 'Thrull', 'Tiefling', 'Time Lord', 'Toy', 'Treefolk', 'Trilobite', 'Triskelavite', 'Troll',
'Turtle', 'Tyranid', 'Unicorn', 'Urzan', 'Vampire', 'Varmint', 'Vedalken', 'Volver', 'Wall', 'Walrus',
'Warlock', 'Warrior', 'Wasp', 'Weasel', 'Weird', 'Werewolf', 'Whale', 'Wizard', 'Wolf', 'Wolverine', 'Wombat',
'Worm', 'Wraith', 'Wurm', 'Yeti', 'Zombie', 'Zubera', 'Advisors', 'Aetherborns', 'Aliens', 'Allys', 'Angels',
'Antelopes', 'Apes', 'Archers', 'Archons', 'Armadillos', 'Armys', 'Artificers', 'Assassins', 'Assembly-Workers',
'Astarteses', 'Atogs', 'Aurochss', 'Automatons', 'Avatars', 'Azras', 'Badgers', 'Balloons', 'Barbarians',
'Bards', 'Basilisks', 'Bats', 'Bears', 'Beasts', 'Beavers', 'Beebles', 'Beholders', 'Berserkers', 'Birds',
'Blinkmoths', 'Boars', 'Brainiacs', 'Bringers', 'Brushwaggs', "C'tans", 'Camarids', 'Camels', 'Capybaras',
'Caribous', 'Carriers', 'Cats', 'Centaurs', 'Chickens', 'Children', 'Chimeras', 'Citizens', 'Clerics', 'Clowns',
'Cockatrices', 'Constructs', 'Cowards', 'Coyotes', 'Crabs', 'Crocodiles', 'Custodeses', 'Cybermen', 'Cyclopss',
'Daleks', 'Dauthis', 'Demigods', 'Demons', 'Deserters', 'Detectives', 'Devils', 'Dinosaurs', 'Djinn', 'Doctors',
'Dogs', 'Dragons', 'Drakes', 'Dreadnoughts', 'Drones', 'Druids', 'Dryads', 'Dwarves', 'Efreets', 'Eggs',
'Elders', 'Eldrazis', 'Elementals', 'Elephants', 'Elves', 'Elks', 'Employees', 'Eyes', 'Faeries', 'Ferrets',
'Fish', 'Flagbearers', 'Foxes', 'Fractals', 'Frogs', 'Funguses', 'Gamers', 'Gargoyles', 'Germs', 'Giants',
'Giths', 'Glimmers', 'Gnolls', 'Gnomes', 'Goats', 'Goblins', 'Gods', 'Golems', 'Gorgons', 'Graveborns',
'Gremlins', 'Griffins', 'Guests', 'Hags', 'Halflings', 'Hamsters', 'Harpys', 'Heads', 'Hellions', 'Heroes',
'Hippos', 'Hippogriffs', 'Homarids', 'Homunculuses', 'Hornets', 'Horrors', 'Horses', 'Humans', 'Hydras',
'Hyenas', 'Illusions', 'Imps', 'Incarnations', 'Inklings', 'Inquisitors', 'Insects', 'Jackals', 'Jellyfish',
'Juggernauts', 'Kavus', 'Kirins', 'Kithkins', 'Knights', 'Kobolds', 'Kors', 'Krakens', 'Lamias', 'Lammasus',
'Leeches', 'Leviathans', 'Lhurgoyfs', 'Licids', 'Lizards', 'Manticores', 'Masticores', 'Mercenarys', 'Merfolks',
'Metathrans', 'Minions', 'Minotaurs', 'Mites', 'Moles', 'Mongers', 'Mongooses', 'Monks', 'Monkeys', 'Moonfolks',
'Mounts', 'Mice', 'Mutants', 'Myrs', 'Mystics', 'Nagas', 'Nautiluses', 'Necrons', 'Nephilims', 'Nightmares',
'Nightstalkers', 'Ninjas', 'Nobles', 'Noggles', 'Nomads', 'Nymphs', 'Octopuses', 'Ogres', 'Oozes', 'Orbs', 'Orcs',
'Orggs', 'Otters', 'Ouphes', 'Oxen', 'Oysters', 'Pangolins', 'Peasants', 'Pegasuses', 'Pentavites', 'Performers',
'Pests', 'Phelddagrifs', 'Phoenixes', 'Phyrexians', 'Pilots', 'Pinchers', 'Pirates', 'Plants', 'Porcupines',
'Possums', 'Praetors', 'Primarches', 'Prisms', 'Processors', 'Rabbits', 'Raccoons', 'Rangers', 'Rats', 'Rebels',
'Reflections', 'Revelers', 'Rhinos', 'Riggers', 'Robots', 'Rogues', 'Rukhs', 'Sables', 'Salamanders', 'Samurais',
'Sands', 'Saprolings', 'Satyrs', 'Scarecrows', 'Scientists', 'Scions', 'Scorpions', 'Scouts', 'Sculptures',
'Serfs', 'Serpents', 'Servoes', 'Shades', 'Shamans', 'Shapeshifters', 'Sharks', 'Sheep', 'Sirens', 'Skeletons',
'Skunks', 'Sliths', 'Slivers', 'Sloths', 'Slugs', 'Snails', 'Snakes', 'Soldiers', 'Soltaris', 'Spawns', 'Specters',
'Spellshapers', 'Sphinxes', 'Spiders', 'Spikes', 'Spirits', 'Splinters', 'Sponges', 'Spys', 'Squids', 'Squirrels',
'Starfish', 'Surrakars', 'Survivors', 'Synths', 'Teddys', 'Tentacles', 'Tetravites', 'Thalakoss', 'Thopters',
'Thrulls', 'Tieflings', 'Time Lords', 'Toys', 'Treefolks', 'Trilobites', 'Triskelavites', 'Trolls', 'Turtles',
'Tyranids', 'Unicorns', 'Urzans', 'Vampires', 'Varmints', 'Vedalkens', 'Volvers', 'Walls', 'Walruses', 'Warlocks',
'Warriors', 'Wasps', 'Weasels', 'Weirds', 'Werewolves', 'Whales', 'Wizards', 'Wolves', 'Wolverines', 'Wombats',
'Worms', 'Wraiths', 'Wurms', 'Yetis', 'Zombies', 'Zuberas' ]
'Worm', 'Wraith', 'Wurm', 'Yeti', 'Zombie', 'Zubera']
theme_tags = ['+1/+1 counter', 'one or more counters', 'token', 'gain life', 'one or more creature tokens',
'creature token', 'treasure', 'create token', 'draw a card', 'flash', 'choose a creature type',

View file

@ -218,4 +218,4 @@ def setup():
break
break
setup()
#setup()

View file

@ -1,14 +1,15 @@
from __future__ import annotations
import inquirer.prompt # type: ignore
#import inquirer.prompt # type: ignore
import keyboard # type: ignore
import pandas as pd # type: ignore
import pprint # type: ignore
import random
#import pprint # type: ignore
#import random
from fuzzywuzzy import fuzz, process # type: ignore
#from fuzzywuzzy import fuzz, process # type: ignore
import settings
import setup
colors = ['colorless', 'white', 'blue', 'black', 'green', 'red',
'azorius', 'orzhov', 'selesnya', 'boros', 'dimir',
@ -30,34 +31,89 @@ csv_directory = 'csv_files'
karnstruct = '0/0 colorless Construct'
def pluralize(word):
if word.endswith('y'):
return word[:-1] + 'ies'
elif word.endswith(('s', 'sh', 'ch', 'x', 'z')):
return word + 'es'
elif word.endswith(('f')):
return word[:-1] + 'ves'
else:
return word + 's'
# Determine any non-creature cards that have creature types mentioned
def kindred_tagging():
for color in colors:
print(f'Settings creature type tags on {color}_cards.csv.')
print(f'Settings creature type tags on {color}_cards.csv.\n')
# Setup dataframe
try:
df = pd.read_csv(f'csv_files/{color}_cards.csv')
df['creatureType'] = ''
except FileNotFoundError:
setup.regenerate_csvs()
df['creatureTypes'] = [[] for _ in range(len(df))]
# Set creature types
print(f'Checking for and setting creature types in {color}_cards.csv')
for index, row in df.iterrows():
kindred_tags = []
if 'Creature' in row['type']:
kindred_tags = []
creature_types = row['type']
split_types = creature_types.split()
for creature_type in split_types:
if creature_type not in settings.non_creature_types:
if creature_type not in kindred_tags:
kindred_tags.append(creature_type)
df.at[index, 'creatureType'] = kindred_tags
df.at[index, 'creatureTypes'] = kindred_tags
print(f'Creature types set in {color}_cards.csv.\n')
# Set outlaws
print(f'Checking for and setting Outlaw types in {color}_cards.csv')
outlaws = ['Assassin', 'Mercenary', 'Pirate', 'Rogue', 'Warlock']
for index, row in df.iterrows():
kindred_tags = row['creatureType']
if 'Creature' in row['type']:
kindred_tags = row['creatureTypes']
creature_types = kindred_tags
for creature_type in creature_types:
if creature_type in outlaws:
if 'Outlaw' not in kindred_tags:
kindred_tags.append('Outlaw')
df.at[index, 'creatureType'] = kindred_tags
df.at[index, 'creatureTypes'] = kindred_tags
print(f'Outlaw types set in {color}_cards.csv.\n')
# Check for creature types in text (i.e. how 'Voja, Jaws of the Conclave' cares about Elves)
print(f'Checking for and setting creature types found in the text of cards in {color}_cards.csv')
for index, row in df.iterrows():
"""if pd.isna(row['creatureTypes']):
row['creatureTypes'] = []"""
kindred_tags = row['creatureTypes']
if pd.isna(row['text']):
continue
for creature_type in settings.creature_types:
if ('Elite Inquisitor' in row['name']
or 'Breaker of Armies' in row['name']
or 'Cleopatra, Exiled Pharaoh' in row['name']
or 'Nath\'s Buffoon' in row['name']):
continue
if creature_type in row['name']:
continue
if pluralize(f'{creature_type}') in row['name']:
continue
if creature_type in row['text']:
if creature_type not in row['name']:
if creature_type not in kindred_tags:
kindred_tags.append(creature_type)
if creature_type in outlaws:
kindred_tags.append(creature_type)
df.at[index, 'creatureTypes'] = kindred_tags
if pluralize(f'{creature_type}') in row['text']:
if pluralize(f'{creature_type}') not in row['name']:
if creature_type not in kindred_tags:
kindred_tags.append(creature_type)
if creature_type in outlaws:
kindred_tags.append(creature_type)
df.at[index, 'creatureTypes'] = kindred_tags
print(f'Creature types from text set in {color}_cards.csv.\n')
# Overwrite file with creature type tags
df.to_csv(f'csv_files/{color}_cards.csv', index=False)
@ -837,6 +893,7 @@ tag_for_artifact()
tag_for_artifact_tokens()
tag_for_enchantment()
tag_for_enchantment_tokens()
tag_for_tokens()"""
tag_for_tokens()
setup_tags()
tag_for_life_matters()
tag_for_life_matters()"""
kindred_tagging()