def test_missing_modifiers(self): ''' fetch every ideaset in common, Try to convert it into a modifier. If any does not exist in modifier, add it to missing modifiers list. ''' missingModifierList = [] ideaDict = gen_country_ideas_library() nonNatIdeaDict = gen_non_national_ideas_library() for ideaName, ideaSet in ideaDict.items() : try: idea = ideaGroup(ideaName, ideaSet) except KeyError as e: if str(e) not in missingModifierList: missingModifierList.append(str(e)) for ideaName, ideaSet in nonNatIdeaDict.items(): try: idea = ideaGroup(ideaName, ideaSet) except KeyError as e: if str(e) not in missingModifierList: missingModifierList.append(str(e)) if len(missingModifierList) > 0: print(missingModifierList) self.assertTrue(False) else: self.assertTrue(True)
def trigger_search(tag): ''' mimic the way EU4 handles idea set triggers. first check if the tag satisfies any national idea triggers, then group idea triggers, finally default ideas if no triggers hit. Then beautify the idea name and return an IdeaGroup. ''' country = tagLib[tag] nat_triggers = load_triggers(nationalTriggerPath) group_triggers = load_triggers(groupTriggerPath) # hit national ideas first to find a match for ideaName, trigger in nat_triggers.items(): if trigger.evaluate(country): return ideaGroup(re.sub('_ideas', '', ideaName), IdeaLib[ideaName]) # hit group idea sets next for a match for groupIdeaName, groupTrigger in group_triggers.items(): if groupTrigger.evaluate(country): return ideaGroup(re.sub('_ideas', '', groupIdeaName), IdeaLib[groupIdeaName]) # if nothing else hits, return generic ideas return ideaGroup('generic', nonNatIdeasLib['generic'])
def countrySearch(name): ''' find the closest match to the name is looking for. ''' max = 0 most_likely = "" # if the name is already a country tag, go directly to trigger based searching if is_tag(name): return trigger_search(name) # first, use fuzzy search to match the name with any country tag for country in countryTagLib: f = fuzz.ratio(country, name.lower()) if f > max: max = f most_likely = country # then, use fuzzy search to match the name with any group national idea, generic or basic idea groups. for ideaset in nonNatIdeasLib: f = fuzz.ratio(ideaset, name.lower()) if f > max: max = f most_likely = ideaset print('SEARCH: Most likely: "' + most_likely + '", fuzz value = ' + str(max)) # if it's closest to a country name, start trigger Search to best match the idea set for that country if most_likely in countryTagLib: return trigger_search(countryTagLib[most_likely]) # otherwise, it's not a country, and we can return an ideaGroup to reply. try: group = ideaGroup(most_likely, nonNatIdeasLib[most_likely]) # IdeaGroupLib[most_likely] = group return group except KeyError as e: # key error will usually only happen if a modifier is missing from the modifier list, which means # I need to patch it in, as Custom ideas doesn't catch all of them. reddit.redditor('professormadlib').message('EU4IdeaBot Error', str(e)) raise