From 77b46392054b34a1558fa8d49f999c4e079e7042 Mon Sep 17 00:00:00 2001 From: Sabe Jones Date: Thu, 19 Jan 2017 17:22:41 +0000 Subject: [PATCH 1/5] fix(decode): better title casing Fixes #18. --- lib/cardlib.py | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/lib/cardlib.py b/lib/cardlib.py index fdf04ed..1a7332c 100644 --- a/lib/cardlib.py +++ b/lib/cardlib.py @@ -11,7 +11,19 @@ from titlecase import titlecase except ImportError: def titlecase(s): - return s.title() + s = s.title() + smallwords = [ + "'S", + ' A ', + ' For ', + ' In ', + ' Of ', + ' The ', + ' To ', + ] + for word in smallwords: + s = s.replace(word, word.lower()) + return s try: import textwrap @@ -678,8 +690,9 @@ def format(self, gatherer = False, for_forum = False, vdump = False, for_html = outstr += ' '.join(map(str.capitalize, self.__dict__[field_supertypes]) + basetypes) if self.__dict__[field_subtypes]: - outstr += (' ' + utils.dash_marker + ' ' + - ' '.join(self.__dict__[field_subtypes]).title()) + outstr += (' ' + utils.dash_marker) + for subtype in self.__dict__[field_subtypes]: + outstr += ' ' + titlecase(subtype) if self.__dict__[field_pt]: outstr += ' (' + utils.from_unary(self.__dict__[field_pt]) + ')' @@ -864,7 +877,10 @@ def to_mse(self, print_raw = False, vdump = False): outstr += '\tsuper type: ' + ' '.join(self.__dict__[field_supertypes] + self.__dict__[field_types]).title() + '\n' if self.__dict__[field_subtypes]: - outstr += '\tsub type: ' + ' '.join(self.__dict__[field_subtypes]).title() + '\n' + outstr += ('\tsub type:') + for subtype in self.__dict__[field_subtypes]: + outstr += ' ' + titlecase(subtype) + outstr += '\n' if self.__dict__[field_pt]: ptstring = utils.from_unary(self.__dict__[field_pt]).split('/') From 5ba220a9d2a0ef1a0896117f58c0853377f212a2 Mon Sep 17 00:00:00 2001 From: Sabe Jones Date: Thu, 19 Jan 2017 17:30:44 +0000 Subject: [PATCH 2/5] refactor(whitespace): nix vim tabs --- lib/cardlib.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/cardlib.py b/lib/cardlib.py index 1a7332c..e7711ca 100644 --- a/lib/cardlib.py +++ b/lib/cardlib.py @@ -12,7 +12,7 @@ except ImportError: def titlecase(s): s = s.title() - smallwords = [ + smallwords = [ "'S", ' A ', ' For ', @@ -22,7 +22,7 @@ def titlecase(s): ' To ', ] for word in smallwords: - s = s.replace(word, word.lower()) + s = s.replace(word, word.lower()) return s try: @@ -692,7 +692,7 @@ def format(self, gatherer = False, for_forum = False, vdump = False, for_html = if self.__dict__[field_subtypes]: outstr += (' ' + utils.dash_marker) for subtype in self.__dict__[field_subtypes]: - outstr += ' ' + titlecase(subtype) + outstr += ' ' + titlecase(subtype) if self.__dict__[field_pt]: outstr += ' (' + utils.from_unary(self.__dict__[field_pt]) + ')' From f69245bc2d9943ad0cc058377aaecbc239d704f1 Mon Sep 17 00:00:00 2001 From: Sabe Jones Date: Thu, 19 Jan 2017 17:32:50 +0000 Subject: [PATCH 3/5] fix(decode): one more smallword --- lib/cardlib.py | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/cardlib.py b/lib/cardlib.py index e7711ca..6891964 100644 --- a/lib/cardlib.py +++ b/lib/cardlib.py @@ -16,6 +16,7 @@ def titlecase(s): "'S", ' A ', ' For ', + ' From ', ' In ', ' Of ', ' The ', From 54bfe2c1b53f9713d72fab11024847a319baa2dd Mon Sep 17 00:00:00 2001 From: Sabe Jones Date: Sat, 21 Jan 2017 03:38:41 +0000 Subject: [PATCH 4/5] feat(decode): more sentence and title casing Fixes #25. --- lib/cardlib.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/lib/cardlib.py b/lib/cardlib.py index 6891964..6f7e9b6 100644 --- a/lib/cardlib.py +++ b/lib/cardlib.py @@ -751,6 +751,10 @@ def format(self, gatherer = False, for_forum = False, vdump = False, for_html = #cardname = transforms.name_unpass_1_dashes(self.__dict__[field_name]) if vdump and not cardname: cardname = '_NONAME_' + else: + cardname = titlecase(cardname) + if for_forum: + cardname = '[b]' + cardname + '[/b]' outstr += cardname coststr = self.__dict__[field_cost].format(for_forum=for_forum, for_html=for_html) @@ -771,9 +775,17 @@ def format(self, gatherer = False, for_forum = False, vdump = False, for_html = outstr += linebreak - outstr += ' '.join(self.__dict__[field_supertypes] + self.__dict__[field_types]) + if self.__dict__[field_supertypes]: + for supertype in self.__dict__[field_supertypes]: + outstr += titlecase(supertype) + ' ' + for maintype in self.__dict__[field_types]: + outstr += titlecase(maintype) + ' ' if self.__dict__[field_subtypes]: - outstr += ' ' + utils.dash_marker + ' ' + ' '.join(self.__dict__[field_subtypes]) + outstr += utils.dash_marker + for subtype in self.__dict__[field_subtypes]: + outstr += ' ' + titlecase(subtype) + else: + outstr = outstr.strip() if self.__dict__[field_rarity]: if self.__dict__[field_rarity] in utils.json_rarity_unmap: @@ -791,6 +803,7 @@ def format(self, gatherer = False, for_forum = False, vdump = False, for_html = #mtext = transforms.text_unpass_3_uncast(mtext) mtext = transforms.text_unpass_4_unary(mtext) mtext = transforms.text_unpass_5_symbols(mtext, for_forum, for_html) + mtext = sentencecase(mtext) #mtext = transforms.text_unpass_6_cardname(mtext, cardname) mtext = transforms.text_unpass_7_newlines(mtext) #mtext = transforms.text_unpass_8_unicode(mtext) @@ -1057,5 +1070,3 @@ def get_types(self): def get_cmc(self): return self.__dict__[field_cost].cmc - - From 48644e75c72c41e8f89dee7b50067e28ca179eb4 Mon Sep 17 00:00:00 2001 From: Sabe Jones Date: Sun, 22 Jan 2017 04:05:19 +0000 Subject: [PATCH 5/5] fix(titlecase): still more words --- lib/cardlib.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/cardlib.py b/lib/cardlib.py index 6f7e9b6..391162c 100644 --- a/lib/cardlib.py +++ b/lib/cardlib.py @@ -15,12 +15,16 @@ def titlecase(s): smallwords = [ "'S", ' A ', + ' And ', + ' As ', + ' At ', ' For ', ' From ', ' In ', ' Of ', ' The ', ' To ', + ' With ', ] for word in smallwords: s = s.replace(word, word.lower())