Exemple #1
0
 def make_roma_subname(name_ja):
     subname = re.sub(r'[=]', '', name_ja)
     subname = re.sub(r'[「」]', '・', subname)
     adjusted_subname = ''
     for part in subname.split('・'):
         roma_part = romkan.to_roma(part)
         if part != roma_part and not contains_ja(roma_part):
             adjusted_subname += ' ' + roma_part.strip('-')
     return adjusted_subname.strip()
Exemple #2
0
    def _get_important_tokens(cls, oname, treenames=None):
        if treenames is None:
            treenames = set()

        if contains_ja(oname):
            return list(treenames)

        name = oname.split(", ")
        if len(name) == 1:
            return cls._name_to_tokens(oname)
        *n1, n2 = name
        n1 = ", ".join(n1)
        if treenames.intersection((n1, n2)):
            return [
                t for n in treenames.intersection((n1, n2))
                for t in cls._name_to_tokens(n)
            ]
        elif token_count(n1) == token_count(n2) or max(token_count(n1),
                                                       token_count(n2)) < 3:
            return cls._name_to_tokens(oname)
        else:
            return cls._name_to_tokens(min(n1, n2, key=token_count))
        def process(existing, new_map, name):
            if not existing:
                logger.info('preloading %i', len(new_map))
                existing.extend(new_map.keys())
                self.settings.save_settings()
                return None

            existing_set = set(existing)
            new_set = set(new_map.keys())
            delta_set = new_set - existing_set

            if delta_set:
                existing.extend(delta_set)
                self.settings.save_settings()

                msg = 'New monsters added to {}:'.format(name)
                for m in [new_map[x] for x in delta_set]:
                    msg += '\n\t[{}] {}'.format(m.monster_id, m.unoverridden_name_en)
                    if contains_ja(m.name_en) and m.name_en_override is not None:
                        msg += ' ({})'.format(m.name_en_override)
                return msg
            else:
                return None
Exemple #4
0
        def process(
                existing: List[int],  # Will be mutated
                new_map: Dict[int, "MonsterModel"],
                region: str) -> Optional[str]:
            if not existing:
                # If everything is new, assume nothing is and log all current monsters as seen
                logger.info('preloading %i monsters', len(new_map))
                existing.extend(new_map.keys())
                return None

            delta_set = set(new_map.keys()).difference(existing)

            if not delta_set:
                # There are no new monsters
                return None

            existing.extend(delta_set)
            msg = f'New monsters added to {region}:'
            for mid in sorted(delta_set):
                m = new_map[mid]
                msg += f'\n\t[{m.monster_id}] {m.unoverridden_name_en}'
                if contains_ja(m.name_en) and m.name_en_override:
                    msg += f' ({m.name_en_override})'
            return msg
Exemple #5
0
    async def _build_monster_index(self, monsters):
        async for m in AsyncIter(monsters):
            self.modifiers[m] = await self.get_modifiers(m)

            # ID
            self.manual_cardnames[str(m.monster_no_na)].add(m)
            if m.monster_id > 10000:
                self.manual_cardnames[str(m.monster_id)].add(m)
            if m.monster_no_na != m.monster_no_jp:
                self.name_tokens['na' + str(m.monster_no_na)].add(m)
                self.name_tokens['jp' + str(m.monster_no_jp)].add(m)

            # Name Tokens
            nametokens = self._name_to_tokens(m.name_en)
            last_token = m.name_en.split(',')[-1].strip()
            alt_monsters = self.graph.get_alt_monsters(m)
            autotoken = len([me for me in alt_monsters if not me.is_equip]) > 1

            for jpt in m.name_ja.split(" "):
                self.name_tokens[jpt].add(m)

            # Propagate name tokens throughout all evos
            for me in alt_monsters:
                for t in self.monster_id_to_name[me.monster_id]:
                    if t in nametokens:
                        self.add_name_token(t, m)
                if me.is_equip or contains_ja(me.name_en):
                    continue
                if last_token != me.name_en.split(',')[-1].strip():
                    autotoken = False

            # Find likely treenames
            treenames = set()
            regexes = [
                r"(?:Awoken|Reincarnated) (.*)",
                r".*, (.*'s Gem)",
            ]
            for me in alt_monsters:
                for r in regexes:
                    match = re.match(r, me.name_en)
                    if match:
                        treenames.add(match.group(1))

            # Add important tokens
            for token in self.monster_id_to_name[m.monster_id]:
                self.add_name_token(token, m)
            if m.monster_id in self.treename_overrides:
                pass
            elif autotoken:
                # Add a consistant last token as important token
                for token in self._name_to_tokens(
                        m.name_en.split(',')[-1].strip()):
                    self.add_name_token(token, m)
            else:
                # Add name tokens by guessing which ones are important
                for token in self._get_important_tokens(
                        m.name_en, treenames) + self._name_to_tokens(
                            m.roma_subname):
                    self.add_name_token(token, m)
                    if m.is_equip:
                        possessives = re.findall(r"(\w+)'s", m.name_en.lower())
                        for mevo in alt_monsters:
                            for token2 in possessives:
                                if token2 in self._name_to_tokens(mevo.name_en.lower()) \
                                        and token2 + "'s" not in self._name_to_tokens(mevo.name_en.lower()):
                                    self.add_name_token(token2, mevo)
                    else:
                        for mevo in alt_monsters:
                            if token in self._name_to_tokens(mevo.name_en):
                                self.add_name_token(token, mevo)

                # For equips only, add every name token from every other non-equip monster in the tree.
                # This has the effect of making automated name tokens behave slightly more like treenames
                # as opposed to nicknames, but only when dealing with equips, and is valuable so that we get
                # the moving-through-tree effect with higher priority, but without having to add
                # significantly more complicated logic in the lookup later on.
                # Test case: Mizutsune is a nickname for Dark Aurora, ID 4148. Issue: #614
                if m.is_equip:
                    for mevo in alt_monsters:
                        if not mevo.is_equip:
                            for token2 in self._get_important_tokens(
                                    mevo.name_en, treenames):
                                if token2 not in HAZARDOUS_IN_NAME_MODS:
                                    self.add_name_token(token2, m)

            # Fluff tokens
            for token in nametokens + list(
                    self.monster_id_to_forcedfluff[m.monster_id]):
                if m in self.name_tokens[token.lower()]:
                    continue
                self.add_fluff_token(token, m)

            # Monster Nickname
            for nick in self.monster_id_to_cardname[m.monster_id]:
                self.add_manual_nick_token(nick, m)

            # Tree Nickname
            base_id = self.graph.get_base_id(m)
            for nick in self.monster_id_to_treename[base_id]:
                self.add_manual_tree_token(nick, m)