From 249088aac2ca3481ab8768aedd7bbb400eb45a63 Mon Sep 17 00:00:00 2001 From: duysqubix Date: Fri, 4 Dec 2020 23:28:15 -0600 Subject: [PATCH] updated veriage on orcish to fine-tune language. Created function that capitalizes first word of each sentence. --- commands/informative.py | 3 ++- world/languages.py | 6 +++--- world/utils/utils.py | 16 +++++++++++++--- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/commands/informative.py b/commands/informative.py index 30ee39e..f03ee90 100644 --- a/commands/informative.py +++ b/commands/informative.py @@ -9,7 +9,7 @@ from evennia.utils import evmore from evennia.utils.utils import inherits_from from commands.command import Command -from world.utils.utils import can_see_obj, is_book, is_container, is_equipped, is_invis, is_obj, is_pc_npc, is_wielded, is_worn, match_name, parse_dot_notation, rplanguage_parse_string +from world.utils.utils import can_see_obj, capitalize_sentence, is_book, is_container, is_equipped, is_invis, is_obj, is_pc_npc, is_wielded, is_worn, match_name, parse_dot_notation, rplanguage_parse_string from evennia.utils.ansi import raw as raw_ansi @@ -154,6 +154,7 @@ def show_book(book): level=1.0 - lang_skill.level, language=book_lang) + contents_translated = capitalize_sentence(contents_translated) BookEvMore(ch, book_contents + contents_translated) if not self.args: diff --git a/world/languages.py b/world/languages.py index 89cc661..beb7827 100644 --- a/world/languages.py +++ b/world/languages.py @@ -125,10 +125,10 @@ class Orcish(_Language): __lang_name__ = "orcish" def define_language(self): - self.phonemes = "a u o g kh rz k r z th t m y ush am oo d ug zz gg eg ag oz uu us uth zu rul ol ru hz ri au ai kr" + self.phonemes = "a g kh rz k r z th t m ush am oo d ug zz gg eg ag oz uu us uth zu rul ol ru hz ri au ai kr gog rzn lag" self.vowels = "auo" - self.grammar = "ccvcc vccv cvccv cvccvcc" - self.word_length_variance = 1 + self.grammar = "ccvvcc ccvcc vccv vccvccvcc ccvvcvcc cvcccvcc cvcc vccccvc vcvcc cvccccv ccvcvccc cvccvcc cvcvcvcc cvcccvc ccccvc vcvvc vccvcvc ccvcv cvccvc cvccccvc cvccc cvccvcvc cvvcvc ccvccvccvc vcccvc vcvcvc ccvccvc cvccv cvcvccvcc cvcvcvc cvcvcv cvcccv cvcvcc cvcvcccc vcvccvc vccvc ccvcvc cvccccc cvcccccc" + self.word_length_variance = 2 VALID_LANGUAGES = { diff --git a/world/utils/utils.py b/world/utils/utils.py index 35a13a0..f42423a 100644 --- a/world/utils/utils.py +++ b/world/utils/utils.py @@ -10,6 +10,9 @@ from evennia.utils.utils import inherits_from, string_partial_matching from world.conditions import DetectHidden, DetectInvis, Hidden, HolyLight, Invisible, Sleeping, get_condition +_CAP_PATTERN = re.compile(r'((?<=[\.\?!\n]\s)(\w+)|(^\w+))') +_LANG_TAGS = re.compile('\>(.*?)\<', re.I) + def highlight_words(block, key_targets, color_codes): key_targets = make_iter(key_targets) @@ -23,6 +26,11 @@ def highlight_words(block, key_targets, color_codes): return block +def capitalize_sentence(string): + global _CAP_PATTERN + return _CAP_PATTERN.sub(lambda x: x.group().capitalize(), string) + + def rplanguage_parse_string(ch, string): """ Obfuscates string based on keys that set the type of language @@ -41,8 +49,9 @@ def rplanguage_parse_string(ch, string): If you plan on using this function, it is import that string supplied must have >[language]< first then contents in order for this function to parse correctly. """ - pattern = re.compile('\>(.*?)\<', re.I) - chunks = re.split(pattern, string)[1:] + global _LANG_TAGS + + chunks = re.split(_LANG_TAGS, string)[1:] if not chunks: # no tags found for a language return string @@ -70,7 +79,8 @@ def rplanguage_parse_string(ch, string): language=lang) new_string.append(obfuscated_string) - return "".join(new_string) + translated_string = "".join(new_string) + return capitalize_sentence(translated_string) def apply_obj_effects(ch, obj):