Пример #1
0
def prehandler(ws):
    logging.info('************ prehandler ************')
    _ws = Words(ws.source)
    while True:
        w = ws.getword()
        if not w: break

        if w.name() == '%':
            end = '\n'
            l = ws.find(end).getword_byindex(-1).pos[2] - w.pos[2] + len(end) 
            w = Word(Word.TYPE_COMMENT, l, 'comment',  w.pos)
            _ws.append(w)

        elif w.name() == '\starttyping':

            end = '\stoptyping'
            l = ws.find(end).getword_byindex(-1).pos[2] - w.pos[2] + len(end) 
            w = Word(Word.TYPE_TYPING,   l, 'typing',w.pos)
            _ws.append(w)

        else:
            _ws.append(w)
            ws.update()

    return _ws
Пример #2
0
 def involution_stable_grothendieck(self, n, degree_bound=None):
     assert self.is_involution() and self.is_unsigned()
     ans = Vector()
     ell = self.involution_length
     for w in self.get_involution_hecke_words(degree_bound, n):
         ans += BETA**(len(w) - ell) * Word.quasisymmetrize(w, Word.decreasing_zeta)
     return self._symmetrize(ans, n)
Пример #3
0
 def e_crystal_operator(self, i, multisetvalued=True):
     if multisetvalued:
         crystal_word = self.crystal_reading_word()
         operated = Word.e_crystal_operator(i, *crystal_word, unpack=False)
         return self.from_crystal_reading_word(operated)
     else:
         s = sorted([(x, y, v) for x, y, value in self
                     for v in value if v in [i, i + 1]],
                    key=lambda t: (t[1], -t[0], -t[2]))
         ell = len(s) + 1
         while len(s) < ell:
             ell = len(s)
             for x in range(len(s) - 1):
                 if s[x][-1] > s[x + 1][-1]:
                     s = s[:x] + s[x + 2:]
                     break
         s = [p for p in s if p[-1] == i + 1]
         if len(s) == 0:
             return None
         x, y, _ = s[0]
         if (x, y - 1) in self and i + 1 in self.get(x, y - 1,
                                                     unpack=False):
             return self.remove(x, y - 1, i + 1).add(x, y, i)
         else:
             return self.remove(x, y, i + 1).add(x, y, i)
Пример #4
0
 def extract_words(self):
     min_y2: int = 100000
     max_y1: int = 0
     for word_element in self.object_element.iter('WORD'):
         word = Word(word_element)
         min_y2 = word.y2 if word.y2 < min_y2 else min_y2
         max_y1 = word.y1 if word.y1 > max_y1 else max_y1
         self.word_list.append(word)
     self.min_word_y2 = min_y2 if min_y2 != 100000 else 0
     self.max_word_y1 = max_y1
Пример #5
0
            def post(self):
                '''Loads the words to database'''
                data = request.json
                new_word = Word(word=data["word"])

                if len(data['word']) != 5:
                    return "Word should be exactly 5 characters long", 400

                session.add(new_word)
                session.commit()
                return "Word Added successfully", 201
Пример #6
0
    def play_one_game(self):
        # asking the user if they want to play the game again
        if self.play_again():
            # if the user wants to play again, it will reset everything and start over
            self.random_word = Word().get_random_word()
            self.random_word = self.random_word[:-1]
            Hangman.game_run(self)

        # if the user doesn't want to play anymore the game will end
        else:
            print()
            print('Thank you for playing NFL Hangman!')
Пример #7
0
def dragon_algo(s):
    s = pretty_dot(s)
    s = remove_spaces(s)
    s = pretty_comma(s)
    s = pretty_slash(s)

    print(s)

    word_group = []
    for k, w in enumerate(s.split()):
        if w == '':
            continue
        word = Word(k, w)
        word_group.append(word)
Пример #8
0
 def generate():
     for level in HECKE_CACHE[key][:-1]:
         yield level
     if HECKE_CACHE[key]:
         level = HECKE_CACHE[key][-1]
     else:
         start = (cls.identity(), ())
         level = {start}
     while level:
         next_level = set()
         yield level
         for pi, w in level:
             for i in range(1, n):
                 s = Permutation.s_i(i)
                 sigma = pi % s
                 v = w + (i,)
                 if ascent_bound is None or Word.ascents(v) < ascent_bound:
                     next_level.add((sigma, v))
         level = next_level
Пример #9
0
 def generate():
     for level in ORTHOGONAL_HECKE_CACHE[key][:-1]:
         yield level
     if ORTHOGONAL_HECKE_CACHE[key]:
         level = ORTHOGONAL_HECKE_CACHE[key][-1]
     else:
         start = (cls.identity(), ())
         level = {start}
     while level:
         next_level = set()
         yield level
         for pi, w in level:
             for i in range(n):
                 s = Permutation.s_i(i)
                 sigma = s % pi % s
                 v = w + (i,)
                 if peak_bound is None or Word.peaks(v) <= peak_bound:
                     if hecke or sigma != pi:
                         next_level.add((sigma, v))
         level = next_level
Пример #10
0
def words(infile):
    inMarkers = False
    frame_rate = None

    def frames_to_seconds(frames):
        return float(frames) / frame_rate

    for event, elem in iterparse(infile, ('start', 'end')):
        if event == 'start' and elem.tag == XMPDM_MARKERS:
            inMarkers = True
            if not frame_rate:
                raise Exception(
                    "No frame rate specifier found before beginning of markers."
                )
        elif event == 'end' and elem.tag == XMPDM_MARKERS:
            inMarkers = False
        elif event == 'end' and elem.tag == XMPDM_FRAMERATE:
            frame_rate = parse_frame_rate(elem.text)
        elif inMarkers and event == 'end' and elem.tag == RDF_LI:
            yield Word(
                token=elem.find(XMPDM_NAME).text,
                intime=frames_to_seconds(elem.find(XMPDM_STARTTIME).text),
                duration=frames_to_seconds(elem.find(XMPDM_DURATION).text))
Пример #11
0
 def generate():
     for level in SYMPLECTIC_HECKE_CACHE[key][:-1]:
         yield level
     if SYMPLECTIC_HECKE_CACHE[key]:
         level = SYMPLECTIC_HECKE_CACHE[key][-1]
     else:
         a = cls.identity()
         for i in range(1, n, 2):
             a *= cls.s_i(i)
         start = (a, ())
         level = {start}
     while level:
         next_level = set()
         yield level
         for pi, w in level:
             for i in range(1, n):
                 s = Permutation.s_i(i)
                 if pi(i) != i + 1:
                     sigma = s % pi % s
                     v = w + (i,)
                     if ascent_bound is None or Word.ascents(v) < ascent_bound:
                         if hecke or sigma != pi:
                             next_level.add((sigma, v))
         level = next_level
Пример #12
0
 def __init__(self):
     random_word = Word().get_random_word()
     self.random_word = random_word[:-1]
Пример #13
0
def test_crystal_operators():
    w = (2, 1, 1)
    assert Word.e_crystal_operator(1, w) is None
    assert Word.f_crystal_operator(1, w) == (2, 1, 2)
    assert Word.e_crystal_operator(2, w) is None
    assert Word.f_crystal_operator(2, w) == (3, 1, 1)

    w = (2, 1, 2)
    assert Word.e_crystal_operator(1, w) == (2, 1, 1)
    assert Word.f_crystal_operator(1, w) is None
    assert Word.e_crystal_operator(2, w) is None
    assert Word.f_crystal_operator(2, w) == (2, 1, 3)

    w = (2, 1, 3)
    assert Word.e_crystal_operator(1, w) is None
    assert Word.f_crystal_operator(1, w) is None
    assert Word.e_crystal_operator(2, w) == (2, 1, 2)
    assert Word.f_crystal_operator(2, w) == (3, 1, 3)

    w = (3, 1, 3)
    assert Word.e_crystal_operator(1, w) is None
    assert Word.f_crystal_operator(1, w) == (3, 2, 3)
    assert Word.e_crystal_operator(2, w) == (2, 1, 3)
    assert Word.f_crystal_operator(2, w) is None

    w = (3, 1, 1)
    assert Word.e_crystal_operator(1, w) is None
    assert Word.f_crystal_operator(1, w) == (3, 1, 2)
    assert Word.e_crystal_operator(2, w) == (2, 1, 1)
    assert Word.f_crystal_operator(2, w) is None