Dictionary generates word list and keyword list

Added code to generate a list of keywords and frequencies for all cards.
Added the CSV output files.
This commit is contained in:
Dan Niemitalo 2020-11-29 10:07:19 -06:00
parent 21a52cc5c2
commit 40f12289a2
3 changed files with 1299 additions and 0 deletions

View file

@ -31,7 +31,21 @@ def word_list(card):
return words return words
def keyword_list(card):
if 'booster' not in card or card['booster'] is False:
return []
if 'type_line' not in card:
return []
if card['set_type'] in ['funny', 'vanguard', 'memorabilia']:
return []
if 'oracle_text' not in card:
return []
if 'keywords' not in card:
return []
return card['keywords']
d = {} d = {}
k = {}
for card in data: for card in data:
if 'oracle_text' in card: if 'oracle_text' in card:
card_words = word_list(card) card_words = word_list(card)
@ -40,11 +54,26 @@ for card in data:
d[word] = 1 d[word] = 1
else: else:
d[word] += 1 d[word] += 1
card_keywords = keyword_list(card)
for keyword in card_keywords:
if keyword not in k:
k[keyword] = 1
else:
k[keyword] += 1
f_oracle_cards.close() f_oracle_cards.close()
output = open('mtgdict.csv', "w+", encoding='utf8') output = open('mtgdict.csv', "w+", encoding='utf8')
output.write('word,frequency\n')
for word in d: for word in d:
output.write(f"{word},{d[word]}\n") output.write(f"{word},{d[word]}\n")
output.close() output.close()
k_output = open('mtgkeywords.csv', 'w+', encoding='utf8')
k_output.write('keyword,frequency\n')
for keyword in k:
k_output.write(f"{keyword},{k[keyword]}\n")
k_output.close()

1059
mtgdict.csv Normal file

File diff suppressed because it is too large Load diff

211
mtgkeywords.csv Normal file
View file

@ -0,0 +1,211 @@
keyword,frequency
Enchant,875
Flying,1565
Adapt,12
Horsemanship,26
Landwalk,114
Swampwalk,39
Kicker,132
Enrage,16
Domain,27
Cycling,199
Bloodthirst,14
Trample,403
Flash,227
Prowess,39
Revolt,16
First strike,211
Fight,62
Multikicker,9
Awaken,13
Hexproof,51
Heroic,41
Islandwalk,27
Scry,166
Exalted,29
Menace,77
Cohort,9
Mountainwalk,17
Flashback,84
Haste,285
Reach,128
Bestow,29
Renown,18
Forestwalk,24
Cascade,8
Equip,232
Devoid,98
Protection,165
Amass,22
Vigilance,215
Addendum,9
Morbid,17
Cumulative upkeep,79
Threshold,81
Indestructible,51
Graft,13
Assist,16
Manifest,15
Defender,220
Rebound,20
Madness,30
Infect,41
Evoke,13
Escape,22
Overload,14
Clash,25
Double strike,41
Channel,10
Bushido,34
Modular,12
Sunburst,14
Mill,231
Partner,26
Reinforce,2
Will of the council,9
Flanking,27
Chroma,9
Ripple,5
Ninjutsu,6
Undying,13
Surveil,17
Suspend,45
Exert,22
Conspire,9
Landcycling,11
Basic landcycling,4
Typecycling,13
Tribute,11
Landfall,73
Megamorph,25
Vanishing,13
Shroud,32
Retrace,10
Dash,17
Dethrone,7
Lifelink,119
Ascend,23
Affinity,18
Metalcraft,27
Unleash,13
Convoke,45
Entwine,24
Ingest,9
Deathtouch,107
Hidden agenda,15
Shadow,34
Monstrosity,23
Transmute,13
Mentor,13
Delve,23
Delirium,37
Mutate,30
Spell mastery,15
Fear,32
Kinship,12
Melee,6
Grandeur,5
Support,11
Adamant,17
Evolve,13
Radiance,8
Echo,44
Morph,126
Level Up,18
Fading,16
Proliferate,26
Explore,13
Changeling,31
Split second,10
Persist,19
Afterlife,10
Intimidate,17
Spectacle,10
Scavenge,11
Bolster,19
Meld,3
Amplify,9
Buyback,39
Epic,5
Improvise,13
Riot,11
Soulshift,26
Living weapon,8
Battalion,12
Cipher,11
Legendary landwalk,2
Raid,29
Unearth,17
Miracle,7
Phasing,12
Swampcycling,1
Constellation,25
Goad,5
Splice,29
Crew,29
Rampage,12
Soulbond,17
Companion,10
Champion,11
Surge,11
Fabricate,14
Bloodrush,12
Council's dilemma,6
Banding,23
Detain,11
Outlast,8
Annihilator,8
Afflict,9
Fateful hour,6
Exploit,11
Extort,8
Forestcycling,2
Dredge,11
Ferocious,19
Inspired,19
Forecast,8
Devour,10
Converge,11
Rally,14
Strive,17
Investigate,23
Hellbent,15
Populate,6
Storm,14
Fateseal,1
Imprint,19
Escalate,8
Recover,7
Wither,24
Eternalize,9
Wizardcycling,1
Hideaway,3
Emerge,10
Formidable,12
Totem armor,11
Haunt,10
Transform,4
Hexproof from,2
Skulk,8
Undergrowth,12
Desertwalk,1
Slivercycling,1
Battle Cry,6
Fortify,1
Provoke,8
Transfigure,1
Assemble,1
Embalm,13
Plainswalk,4
Jump-start,10
Islandcycling,2
Prowl,7
Lieutenant,1
Mountaincycling,1
Replicate,6
Nonbasic landwalk,1
Parley,4
Sweep,4
Aura Swap,1
Gravestorm,1
Plainscycling,2
1 keyword frequency
2 Enchant 875
3 Flying 1565
4 Adapt 12
5 Horsemanship 26
6 Landwalk 114
7 Swampwalk 39
8 Kicker 132
9 Enrage 16
10 Domain 27
11 Cycling 199
12 Bloodthirst 14
13 Trample 403
14 Flash 227
15 Prowess 39
16 Revolt 16
17 First strike 211
18 Fight 62
19 Multikicker 9
20 Awaken 13
21 Hexproof 51
22 Heroic 41
23 Islandwalk 27
24 Scry 166
25 Exalted 29
26 Menace 77
27 Cohort 9
28 Mountainwalk 17
29 Flashback 84
30 Haste 285
31 Reach 128
32 Bestow 29
33 Renown 18
34 Forestwalk 24
35 Cascade 8
36 Equip 232
37 Devoid 98
38 Protection 165
39 Amass 22
40 Vigilance 215
41 Addendum 9
42 Morbid 17
43 Cumulative upkeep 79
44 Threshold 81
45 Indestructible 51
46 Graft 13
47 Assist 16
48 Manifest 15
49 Defender 220
50 Rebound 20
51 Madness 30
52 Infect 41
53 Evoke 13
54 Escape 22
55 Overload 14
56 Clash 25
57 Double strike 41
58 Channel 10
59 Bushido 34
60 Modular 12
61 Sunburst 14
62 Mill 231
63 Partner 26
64 Reinforce 2
65 Will of the council 9
66 Flanking 27
67 Chroma 9
68 Ripple 5
69 Ninjutsu 6
70 Undying 13
71 Surveil 17
72 Suspend 45
73 Exert 22
74 Conspire 9
75 Landcycling 11
76 Basic landcycling 4
77 Typecycling 13
78 Tribute 11
79 Landfall 73
80 Megamorph 25
81 Vanishing 13
82 Shroud 32
83 Retrace 10
84 Dash 17
85 Dethrone 7
86 Lifelink 119
87 Ascend 23
88 Affinity 18
89 Metalcraft 27
90 Unleash 13
91 Convoke 45
92 Entwine 24
93 Ingest 9
94 Deathtouch 107
95 Hidden agenda 15
96 Shadow 34
97 Monstrosity 23
98 Transmute 13
99 Mentor 13
100 Delve 23
101 Delirium 37
102 Mutate 30
103 Spell mastery 15
104 Fear 32
105 Kinship 12
106 Melee 6
107 Grandeur 5
108 Support 11
109 Adamant 17
110 Evolve 13
111 Radiance 8
112 Echo 44
113 Morph 126
114 Level Up 18
115 Fading 16
116 Proliferate 26
117 Explore 13
118 Changeling 31
119 Split second 10
120 Persist 19
121 Afterlife 10
122 Intimidate 17
123 Spectacle 10
124 Scavenge 11
125 Bolster 19
126 Meld 3
127 Amplify 9
128 Buyback 39
129 Epic 5
130 Improvise 13
131 Riot 11
132 Soulshift 26
133 Living weapon 8
134 Battalion 12
135 Cipher 11
136 Legendary landwalk 2
137 Raid 29
138 Unearth 17
139 Miracle 7
140 Phasing 12
141 Swampcycling 1
142 Constellation 25
143 Goad 5
144 Splice 29
145 Crew 29
146 Rampage 12
147 Soulbond 17
148 Companion 10
149 Champion 11
150 Surge 11
151 Fabricate 14
152 Bloodrush 12
153 Council's dilemma 6
154 Banding 23
155 Detain 11
156 Outlast 8
157 Annihilator 8
158 Afflict 9
159 Fateful hour 6
160 Exploit 11
161 Extort 8
162 Forestcycling 2
163 Dredge 11
164 Ferocious 19
165 Inspired 19
166 Forecast 8
167 Devour 10
168 Converge 11
169 Rally 14
170 Strive 17
171 Investigate 23
172 Hellbent 15
173 Populate 6
174 Storm 14
175 Fateseal 1
176 Imprint 19
177 Escalate 8
178 Recover 7
179 Wither 24
180 Eternalize 9
181 Wizardcycling 1
182 Hideaway 3
183 Emerge 10
184 Formidable 12
185 Totem armor 11
186 Haunt 10
187 Transform 4
188 Hexproof from 2
189 Skulk 8
190 Undergrowth 12
191 Desertwalk 1
192 Slivercycling 1
193 Battle Cry 6
194 Fortify 1
195 Provoke 8
196 Transfigure 1
197 Assemble 1
198 Embalm 13
199 Plainswalk 4
200 Jump-start 10
201 Islandcycling 2
202 Prowl 7
203 Lieutenant 1
204 Mountaincycling 1
205 Replicate 6
206 Nonbasic landwalk 1
207 Parley 4
208 Sweep 4
209 Aura Swap 1
210 Gravestorm 1
211 Plainscycling 2