コード例 #1
0
 def _needsCutout(self, itemType):
     if self.flagged == 0:
         return False
     elif itemType == self.itemType:
         return self.flagged != len(self)
     elif self.flagged == 1:
         return find(lambda item: item.flagged, self)._needsCutout(itemType)
     else:
         return True
コード例 #2
0
ファイル: document.py プロジェクト: CeON/SegmEdit
 def _needsCutout(self, itemType):
     if self.flagged == 0:
         return False
     elif itemType == self.itemType:
         return self.flagged != len(self)
     elif self.flagged == 1:
         return find(lambda item: item.flagged, self)._needsCutout(itemType)
     else:
         return True
コード例 #3
0
async def on_message(message):
    if message.author == client.user:
        return

    if message.embeds and str(message.author.id) == '365975655608745985':
        embed = message.embeds[0].to_dict()
        if 'A wild pokémon has аppeаred!' in embed['title']:
            name = utility.find(embed['image']['url'])
            msg = f'It\'s {name}!'
            if name is None:
                msg = 'I\'m not familiar with this pokemon. I\'ll try and revisit this soon.'
                print(embed['image']['url'])
            else:
                print(f'Identified {name}')
            e = discord.Embed(title=msg, color=discord.colour.Color.dark_red())
            await message.channel.send(embed=e)
コード例 #4
0
ファイル: identityaa.py プロジェクト: bzhan/bfh_python
def homotopyMap(sd_left, sd_right):
    """Implements the homotopy map. Input is a pair of strand diagrams from the
    same PMC. Outputs a list of (from zero to two) pairs that the homotopy maps
    the input pair to.

    """
    # Two helper functions
    def startType(sd, pair):
        """Returns -1 if sd has horizontal strands at pair, ``n`` if sd has
        strand starting at point ``n`` in the pair, -2 otherwise (left
        idempotent of sd is not occupied at pair).

        """
        for p, q in sd.strands:
            if sd.pmc.pairid[p] == pair:
                return p
        if pair in sd.left_idem:
            return -1
        return -2

    def getStrandsAtPoint(sd, point):
        """List of strands (recorded as pair (p,q)) covering the point
        key_pos+1, including any double horizontal at point key_pos+1
        (recorded as (key_pos+1, key_pos+1)).

        """
        result = [(p, q) for p, q in sd.strands if p <= point <= q]
        if sd.pmc.pairid[point] in sd.double_hor:
            result.append((point, point))
        return result

    # To start, we find key_pos and other important locations
    result = []
    pmc = sd_left.pmc
    assert pmc == sd_right.pmc
    total_mult = [a + b for a, b in zip(sd_left.multiplicity,
                                        sd_right.multiplicity)]
    ordering = _getIntervalOrdering(pmc)

    # Index of first interval with multiplicity >= 2 (note multiplicity
    # cannot jump by more than 1.
    lowest_two = find(total_mult, 2)
    # Compute key_pos for two cases
    if lowest_two == -1:
        # Total multiplicity one case
        unoccupied_id = [i for i in range(len(ordering))
                         if total_mult[ordering[i]] != 0]
        assert len(unoccupied_id) > 0
        key_pos = ordering[unoccupied_id[0]]
        # Always use the lowest / highest possible interval, does not appear
        # helpful.
        # key_pos = -1
        # for i in range(len(ordering)):
        #     if total_mult[ordering[i]] != 0 and \
        #             (i == 0 or total_mult[ordering[i-1]] == 0):
        #         if key_pos == -1 or ordering[i] > key_pos:
        #             key_pos = ordering[i]
        total_mult_one = True
    else:
        # Total multiplicity >1 case
        key_pos = lowest_two - 1
        total_mult_one = False
    # Compute key_pair and forbid_pos
    key_pair = pmc.pairid[key_pos+1]
    forbid_pos = pmc.otherp[key_pos+1]
    assert total_mult[key_pos] != 0
    if total_mult_one:
        assert forbid_pos == pmc.n-1 or total_mult[forbid_pos] == 0

    # Now, some more specific information about this generator
    type_left, type_right = \
        startType(sd_left, key_pair), startType(sd_right, key_pair)
    assert type_left != forbid_pos and type_right != forbid_pos

    left_avail = getStrandsAtPoint(sd_left, key_pos+1)
    right_avail = getStrandsAtPoint(sd_right, key_pos+1)
    total_avail = sorted([((p, q), _LEFT) for p, q in left_avail] +
                         [((p, q), _RIGHT) for p, q in right_avail])
    assert len(total_avail) >= 2
    (start1, end1), side1 = total_avail[0]
    (start2, end2), side2 = total_avail[1]

    # Homotopies for the three usual cases
    if side1 == _LEFT and side2 == _LEFT:
        # First case: both lowest available strands are on the left.
        # Un-cross two strands on the left.
        if end1 <= end2:
            return result
        result.append((_uncross(sd_left, start1, end1, start2, end2), sd_right))
    elif side1 == _RIGHT and side2 == _RIGHT:
        # Second case: both lowest available strands are on the right.
        # Cross two strands on the right.
        if end1 >= end2:
            return result
        result.append((sd_left, _cross(sd_right, start1, end1, start2, end2)))
    elif side1 == _RIGHT and side2 == _LEFT:
        # Third (and fourth case in paper). Lowest strand on the right
        # and the second lowest on the left. Move strand to the left.
        result.append(_moveLeft((sd_left, sd_right), start1, start2))
    else:
        return result

    if not total_mult_one:
        return result
    # Three special cases only for the multiplicity one case
    forbid_start = [a for a, b in sd_left.strands if b == forbid_pos]
    if not forbid_start:
        return result
    forbid_start = forbid_start[0]
    gen_start = (sd_left, sd_right)
    if side1 == _RIGHT and side2 == _RIGHT:
        gen_step1 = (sd_left, _cross(sd_right, start1, end1, start2, end2))
        gen_step2 = _moveRight(gen_step1, forbid_start, forbid_pos)
        gen_step3 = _moveLeft(gen_step2, start1, end1)
    elif side1 == _RIGHT and side2 == _LEFT and forbid_start != key_pos+1:
        gen_step1 = _moveLeft(gen_start, start1, key_pos+1)
        gen_step2 = _moveRight(gen_step1, forbid_start, forbid_pos)
        gen_step3 = (_uncross(gen_step2[0], start1, end2, key_pos+1, key_pos+1)
                     ,gen_step2[1])
    elif side1 == _RIGHT and side2 == _LEFT and forbid_start == key_pos+1:
        gen_step1 = _moveLeft(gen_start, start1, key_pos+1)
        gen_step2 = _moveRight(gen_step1, start1, forbid_pos)
        gen_step3 = _moveLeft(gen_step2, start1, key_pos+1)
    else:
        return result
    result.append(gen_step3)
    return result