Fix previous changes (didn't catch until post-push)
This commit is contained in:
parent
e95b2bf71a
commit
76116901c3
6 changed files with 31 additions and 31 deletions
|
@ -173,7 +173,7 @@ class Datamine:
|
|||
str(len(self.by_type)) + ' combinations')
|
||||
print('Breakdown by type:')
|
||||
d = sorted(self.by_type_inclusive,
|
||||
lambda x: len(self.by_type_inclusive[x]),
|
||||
key=lambda x: len(self.by_type_inclusive[x]),
|
||||
reverse=True)
|
||||
rows = [[k for k in d[:hsize]]]
|
||||
rows += [[len(self.by_type_inclusive[k]) for k in rows[0]]]
|
||||
|
@ -183,7 +183,7 @@ class Datamine:
|
|||
+ str(len(self.by_subtype)) + ' combinations'))
|
||||
print('-- Popular subtypes: --')
|
||||
d = sorted(self.by_subtype_inclusive,
|
||||
lambda x: len(self.by_subtype_inclusive[x]),
|
||||
key=lambda x: len(self.by_subtype_inclusive[x]),
|
||||
reverse=True)
|
||||
rows = []
|
||||
for k in d[0:vsize]:
|
||||
|
@ -191,7 +191,7 @@ class Datamine:
|
|||
printrows(padrows(rows))
|
||||
print('-- Top combinations: --')
|
||||
d = sorted(self.by_subtype,
|
||||
lambda x: len(self.by_subtype[x]),
|
||||
key=lambda x: len(self.by_subtype[x]),
|
||||
reverse = True)
|
||||
rows = []
|
||||
for k in d[0:vsize]:
|
||||
|
@ -202,7 +202,7 @@ class Datamine:
|
|||
+ str(len(self.by_supertype)) + ' combinations'))
|
||||
print('Breakdown by supertype:')
|
||||
d = sorted(self.by_supertype_inclusive,
|
||||
lambda x: len(self.by_supertype_inclusive[x]),
|
||||
key=lambda x: len(self.by_supertype_inclusive[x]),
|
||||
reverse=True)
|
||||
rows = [[k for k in d[:hsize]]]
|
||||
rows += [[len(self.by_supertype_inclusive[k]) for k in rows[0]]]
|
||||
|
@ -217,7 +217,7 @@ class Datamine:
|
|||
printrows(padrows(rows))
|
||||
print('-- Popular mana costs: --')
|
||||
d = sorted(self.by_cost,
|
||||
lambda x: len(self.by_cost[x]),
|
||||
key=lambda x: len(self.by_cost[x]),
|
||||
reverse = True)
|
||||
rows = []
|
||||
for k in d[0:vsize]:
|
||||
|
@ -230,7 +230,7 @@ class Datamine:
|
|||
', largest toughness: ' + str(max(list(map(len, self.by_toughness))) - 1)))
|
||||
print('-- Popular p/t values: --')
|
||||
d = sorted(self.by_pt,
|
||||
lambda x: len(self.by_pt[x]),
|
||||
key=lambda x: len(self.by_pt[x]),
|
||||
reverse = True)
|
||||
rows = []
|
||||
for k in d[0:vsize]:
|
||||
|
@ -239,7 +239,7 @@ class Datamine:
|
|||
print('--------------------')
|
||||
print('Loyalty values:')
|
||||
d = sorted(self.by_loyalty,
|
||||
lambda x: len(self.by_loyalty[x]),
|
||||
key=lambda x: len(self.by_loyalty[x]),
|
||||
reverse = True)
|
||||
rows = []
|
||||
for k in d[0:vsize]:
|
||||
|
@ -253,7 +253,7 @@ class Datamine:
|
|||
+ str(max(self.by_textlines)) + ' lines'))
|
||||
print('-- Line counts by frequency: --')
|
||||
d = sorted(self.by_textlines,
|
||||
lambda x: len(self.by_textlines[x]),
|
||||
key=lambda x: len(self.by_textlines[x]),
|
||||
reverse = True)
|
||||
rows = []
|
||||
for k in d[0:vsize]:
|
||||
|
@ -273,17 +273,17 @@ class Datamine:
|
|||
print('********************')
|
||||
if len(self.by_name) > 0:
|
||||
scardname = sorted(self.by_name,
|
||||
len,
|
||||
key=len,
|
||||
reverse=False)[0]
|
||||
print('Shortest Cardname: (' + str(len(scardname)) + ')')
|
||||
print(' ' + scardname)
|
||||
lcardname = sorted(self.by_name,
|
||||
len,
|
||||
key=len,
|
||||
reverse=True)[0]
|
||||
print('Longest Cardname: (' + str(len(lcardname)) + ')')
|
||||
print(' ' + lcardname)
|
||||
d = sorted(self.by_name,
|
||||
lambda x: len(self.by_name[x]),
|
||||
key=lambda x: len(self.by_name[x]),
|
||||
reverse = True)
|
||||
rows = []
|
||||
for k in d[0:vsize]:
|
||||
|
@ -299,7 +299,7 @@ class Datamine:
|
|||
print('--------------------')
|
||||
if len(self.by_type) > 0:
|
||||
ltypes = sorted(self.by_type,
|
||||
len,
|
||||
key=len,
|
||||
reverse=True)[0]
|
||||
print('Longest card type: (' + str(len(ltypes)) + ')')
|
||||
print(' ' + ltypes)
|
||||
|
@ -307,7 +307,7 @@ class Datamine:
|
|||
print('No cards indexed by type?')
|
||||
if len(self.by_subtype) > 0:
|
||||
lsubtypes = sorted(self.by_subtype,
|
||||
len,
|
||||
key=len,
|
||||
reverse=True)[0]
|
||||
print('Longest subtype: (' + str(len(lsubtypes)) + ')')
|
||||
print(' ' + lsubtypes)
|
||||
|
@ -315,7 +315,7 @@ class Datamine:
|
|||
print('No cards indexed by subtype?')
|
||||
if len(self.by_supertype) > 0:
|
||||
lsupertypes = sorted(self.by_supertype,
|
||||
len,
|
||||
key=len,
|
||||
reverse=True)[0]
|
||||
print('Longest supertype: (' + str(len(lsupertypes)) + ')')
|
||||
print(' ' + lsupertypes)
|
||||
|
@ -324,7 +324,7 @@ class Datamine:
|
|||
print('--------------------')
|
||||
if len(self.by_cost) > 0:
|
||||
lcost = sorted(self.by_cost,
|
||||
len,
|
||||
key=len,
|
||||
reverse=True)[0]
|
||||
print('Longest mana cost: (' + str(len(lcost)) + ')')
|
||||
print(' ' + utils.from_mana(lcost))
|
||||
|
@ -341,7 +341,7 @@ class Datamine:
|
|||
print('--------------------')
|
||||
if len(self.by_power) > 0:
|
||||
lpower = sorted(self.by_power,
|
||||
len,
|
||||
key=len,
|
||||
reverse=True)[0]
|
||||
print('Largest creature power: ' + utils.from_unary(lpower))
|
||||
print('\n' + plimit(self.by_power[lpower][0].encode()) + '\n')
|
||||
|
@ -349,7 +349,7 @@ class Datamine:
|
|||
print('No cards indexed by power?')
|
||||
if len(self.by_toughness) > 0:
|
||||
ltoughness = sorted(self.by_toughness,
|
||||
len,
|
||||
key=len,
|
||||
reverse=True)[0]
|
||||
print('Largest creature toughness: ' +
|
||||
utils.from_unary(ltoughness))
|
||||
|
|
|
@ -601,7 +601,7 @@ def text_unpass_1_choice(s, delimit = False):
|
|||
choice_regex = (re.escape(choice_open_delimiter) + re.escape(unary_marker)
|
||||
+ r'.*' + re.escape(bullet_marker) + r'.*' + re.escape(choice_close_delimiter))
|
||||
choices = re.findall(choice_regex, s)
|
||||
for choice in sorted(choices, len, reverse=True):
|
||||
for choice in sorted(choices, key=len, reverse=True):
|
||||
fragments = choice[1:-1].split(bullet_marker)
|
||||
countfrag = fragments[0]
|
||||
optfrags = fragments[1:]
|
||||
|
|
16
lib/utils.py
16
lib/utils.py
|
@ -130,7 +130,7 @@ def to_unary(s, warn = False):
|
|||
def from_unary(s):
|
||||
numbers = re.findall(re.escape(unary_marker + unary_counter) + '*', s)
|
||||
# again, largest first so we don't replace substrings and break everything
|
||||
for n in sorted(numbers, len, reverse=True):
|
||||
for n in sorted(numbers, key=len, reverse=True):
|
||||
i = (len(n) - len(unary_marker)) / len(unary_counter)
|
||||
s = s.replace(n, str(i))
|
||||
return s
|
||||
|
@ -381,18 +381,18 @@ mana_unary_regex = (re.escape(mana_json_open_delimiter) + number_unary_regex
|
|||
def mana_translate(jmanastr):
|
||||
manastr = jmanastr
|
||||
for n in sorted(re.findall(mana_unary_regex, manastr),
|
||||
len, reverse=True):
|
||||
key=len, reverse=True):
|
||||
ns = re.findall(number_unary_regex, n)
|
||||
i = (len(ns[0]) - len(unary_marker)) // len(unary_counter)
|
||||
manastr = manastr.replace(
|
||||
n, mana_unary_marker + mana_unary_counter * i)
|
||||
for n in sorted(re.findall(mana_decimal_regex, manastr),
|
||||
len, reverse=True):
|
||||
key=len, reverse=True):
|
||||
ns = re.findall(number_decimal_regex, n)
|
||||
i = int(ns[0])
|
||||
manastr = manastr.replace(
|
||||
n, mana_unary_marker + mana_unary_counter * i)
|
||||
for jsym in sorted(mana_symall_jdecode, len, reverse=True):
|
||||
for jsym in sorted(mana_symall_jdecode, key=len, reverse=True):
|
||||
if jsym in manastr:
|
||||
manastr = manastr.replace(jsym, mana_encode_direct(jsym))
|
||||
return mana_open_delimiter + manastr + mana_close_delimiter
|
||||
|
@ -460,14 +460,14 @@ def mana_untranslate(manastr, for_forum = False, for_html = False):
|
|||
# notice the calls to .upper(), this way we recognize lowercase symbols as well just in case
|
||||
def to_mana(s):
|
||||
jmanastrs = re.findall(mana_json_regex, s)
|
||||
for jmanastr in sorted(jmanastrs, len, reverse=True):
|
||||
for jmanastr in sorted(jmanastrs, key=len, reverse=True):
|
||||
s = s.replace(jmanastr, mana_translate(jmanastr.upper()))
|
||||
return s
|
||||
|
||||
|
||||
def from_mana(s, for_forum=False):
|
||||
manastrs = re.findall(mana_regex, s)
|
||||
for manastr in sorted(manastrs, len, reverse=True):
|
||||
for manastr in sorted(manastrs, key=len, reverse=True):
|
||||
s = s.replace(manastr, mana_untranslate(manastr.upper(), for_forum = for_forum))
|
||||
return s
|
||||
|
||||
|
@ -507,14 +507,14 @@ symbol_regex = '[' + tap_marker + untap_marker + ']'
|
|||
|
||||
def to_symbols(s):
|
||||
jsymstrs = re.findall(json_symbol_regex, s)
|
||||
for jsymstr in sorted(jsymstrs, len, reverse=True):
|
||||
for jsymstr in sorted(jsymstrs, key=len, reverse=True):
|
||||
s = s.replace(jsymstr, json_symbol_trans[jsymstr])
|
||||
return s
|
||||
|
||||
|
||||
def from_symbols(s, for_forum=False, for_html=False):
|
||||
symstrs = re.findall(symbol_regex, s)
|
||||
#for symstr in sorted(symstrs, len, reverse = True):
|
||||
#for symstr in sorted(symstrs, key=len, reverse = True):
|
||||
# We have to do the right thing here, because the thing we replace exists in the thing
|
||||
# we replace it with...
|
||||
for symstr in set(symstrs):
|
||||
|
|
|
@ -50,18 +50,18 @@ def main(fname1, fname2, verbose = True):
|
|||
ratios[k] = float(v2 * tot1) / float(v1 * tot2)
|
||||
|
||||
print('shared: ' + str(len(ratios)))
|
||||
for k in sorted(ratios, lambda x: d2[x], reverse=True):
|
||||
for k in sorted(ratios, key=lambda x: d2[x], reverse=True):
|
||||
print(' ' + k + ': ' + str(d2[k]) + '/' +
|
||||
str(d1[k]) + ' (' + str(ratios[k]) + ')')
|
||||
print('')
|
||||
|
||||
print('1 only: ' + str(len(only_1)))
|
||||
for k in sorted(only_1, lambda x: d1[x], reverse=True):
|
||||
for k in sorted(only_1, key=lambda x: d1[x], reverse=True):
|
||||
print(' ' + k + ': ' + str(d1[k]))
|
||||
print('')
|
||||
|
||||
print('2 only: ' + str(len(only_2)))
|
||||
for k in sorted(only_2, lambda x: d2[x], reverse=True):
|
||||
for k in sorted(only_2, key=lambda x: d2[x], reverse=True):
|
||||
print(' ' + k + ': ' + str(d2[k]))
|
||||
print('')
|
||||
|
||||
|
|
|
@ -95,7 +95,7 @@ def main(fname, oname, gmin = 2, gmax = 8, nltk = False, sep = False, verbose =
|
|||
|
||||
with open(oname_full, 'wt') as f:
|
||||
for ngram in sorted(gramdict,
|
||||
lambda x: gramdict[x],
|
||||
key=lambda x: gramdict[x],
|
||||
reverse = True):
|
||||
f.write((ngram + ': ' + str(gramdict[ngram]) + '\n').encode('utf-8'))
|
||||
|
||||
|
|
|
@ -108,7 +108,7 @@ def check_vocab(fname):
|
|||
else:
|
||||
vocab[word] += 1
|
||||
|
||||
for word in sorted(vocab, lambda x: vocab[x], reverse=True):
|
||||
for word in sorted(vocab, key=lambda x: vocab[x], reverse=True):
|
||||
print(('{:8d} : {:s}'.format(vocab[word], word)))
|
||||
|
||||
n = 3
|
||||
|
|
Loading…
Reference in a new issue