Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split keywords #47

Merged
merged 1 commit into from
Jun 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions app/parsing/cr/extract_cr.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,16 @@ async def extract(comp_rules):
rules_flattened = {}
glossary_json = {}

def split_ability_words(rules_text):
def split_ability_words(rules_text: str):
splitter = re.compile(r", (?:and )?")
list_str = re.findall(r"The ability words are (.*)", rules_text)[0]
trimmed = rules_text.rstrip(". ")
list_str = re.findall(r"The ability words are (.*)", trimmed)[0]
return splitter.split(list_str)

def split_keywords(title: str):
"""Sometimes one title contains multiple keywords ("Daybound and Nightbound"). We want to separate those."""
return title.split(" and ")

start_index = comp_rules.find("Glossary")
comp_rules = comp_rules[start_index:]

Expand Down Expand Up @@ -84,9 +89,9 @@ def split_ability_words(rules_text):
rules_flattened[new_rule["ruleNumber"]] = new_rule
rule_object_ref = new_rule
if re.fullmatch(keyword_regex, new_rule["ruleNumber"]):
keywords["keywordAbilities"].append(new_rule["ruleText"])
keywords["keywordAbilities"].extend(split_keywords(new_rule["ruleText"]))
elif re.fullmatch(keyword_action_regex, new_rule["ruleNumber"]):
keywords["keywordActions"].append(new_rule["ruleText"])
keywords["keywordActions"].extend(split_keywords(new_rule["ruleText"]))
elif new_rule["ruleNumber"] == ability_words_rule:
keywords["abilityWords"] = split_ability_words(new_rule["ruleText"])

Expand Down