-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdescription.py
40 lines (26 loc) · 1.14 KB
/
description.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from re import search, findall
"""
As seen in https://hades.fandom.com/wiki/Zeus/Quotes, there are human readable titles. ZeusWithDemeter -> Duo - Zeus and Demeter
The functions in here will try to create them automatically from the provided ID's
"""
# Don't use \d: NameCloseWithName
duo = (r"((?!Close)[A-Z][a-z]*)With(\D*)(\d*)", "Duo - {0} and {1} ({2})")
tests = [
duo
]
array_parse_ints = lambda x: int(x) if x.isnumeric() else x
def id_to_description(id):
result = None
for (regex, format_string) in tests:
result = search(regex, id)
if result is not None:
# Parse out any camelcase remaining
results = [split_camelcase(value) for value in result.groups()]
results = [array_parse_ints(value) for value in results]
description = format_string.format(*results)
return description
# If no matching description can be found, split the ID according to Camelcase
return split_camelcase(id)
def split_camelcase(string):
regex_search = findall(r"[A-Z][a-z]*|[0-9]*", string)
return " ".join([result for result in regex_search if result != ""])