Exemplo n.º 1
0
 def _kanji_to_kana(self, char):
     glyph = self.c.lookup_char(char).first()
     if glyph is None:
         return None
     romaji_on = glyph.kJapaneseKun.lower()
     romaji_kun = glyph.kJapaneseOn.lower()
     jp_on = jaconv.alphabet2kana(romaji_on).split(' ')
     jp_kun = jaconv.hira2kata(jaconv.alphabet2kana(romaji_kun)).split(' ')
     return jp_on, jp_kun, glyph.kDefinition
def tester(
):  # only complete function once user correctly identifies all Kanji in learned_list
    mastered = {}
    while mastered != learned_list:
        for i in range(0, len(learned_list)):
            current_card = random.choice(list(learned_list.items()))
            if current_card[0] in mastered.keys(
            ):  # choosing only non-mastered Kanji
                continue
            user_answer = input(
                'What does {} read as? Type in Romaji: '.format(
                    current_card[0]))
            # using jaconv module. converting Romaji to Hiragana and Katakana
            hiragana_answer = jaconv.alphabet2kana(
                u'{}'.format(user_answer))  # takes Romaji --> Hiragana
            katakana_answer = jaconv.hira2kata(
                u'{}'.format(hiragana_answer))  # takes Hiragana --> Katakana
            if hiragana_answer in current_card[
                    1] or katakana_answer in current_card[
                        1]:  # checking for on/kun readings
                print('Correct!')
                mastered[current_card[0]] = current_card[1]
            else:
                print('Incorrect. This reads as {}'.format(current_card[1]))
    print('Congratulations! You have mastered the learned_list')
Exemplo n.º 3
0
def test_alphabet2kana():
    assert_equal(jaconv.alphabet2kana('mamisan'), 'まみさん')
    assert_equal(jaconv.alphabet2kana('doggu doguu'), 'どっぐ どぐう')
    assert_equal(jaconv.alphabet2kana('botchi'), 'ぼっち')
    assert_equal(jaconv.alphabet2kana('fainarufantaji-'), 'ふぁいなるふぁんたじー')
    assert_equal(jaconv.alphabet2kana('atsui'), 'あつい')
    assert_equal(jaconv.alphabet2kana('itoh'), 'いとう')
    assert_equal(jaconv.alphabet2kana('ohtaku'), 'おおたく')
    assert_equal(jaconv.alphabet2kana('namba'), 'なんば')
Exemplo n.º 4
0
def get_names(filename: str, gender: str):
    with open(filename, newline='') as csvfile:
        reader = csv.DictReader(csvfile)
        for row in reader:
            name = row['name']
            name_simplified = simplify_swedish_name(row['name'])
            count = normalize_int(row['count'])
            katakana = jaconv.hira2kata(jaconv.alphabet2kana(name_simplified))
            if is_simple_katakana(katakana):
                yield { 'name': name, 'katakana': katakana, 'count': count, 'gender': gender }
Exemplo n.º 5
0
def alpha_to_full(text):
    return jaconv.alphabet2kana(text)
Exemplo n.º 6
0
def test_alphabet2kana():
    assert_equal(jaconv.alphabet2kana('mamisan'), 'まみさん')
    assert_equal(jaconv.alphabet2kana('doggu doguu'), 'どっぐ どぐう')
    assert_equal(jaconv.alphabet2kana('botchi'), 'ぼっち')
    assert_equal(jaconv.alphabet2kana('fainarufantaji-'), 'ふぁいなるふぁんたじー')
Exemplo n.º 7
0
def test_alphabet2kana():
    assert_equal(jaconv.alphabet2kana('mamisan'), 'まみさん')
    assert_equal(jaconv.alphabet2kana('doggu doguu'), 'どっぐ どぐう')
    assert_equal(jaconv.alphabet2kana('botchi'), 'ぼっち')
    assert_equal(jaconv.alphabet2kana('fainarufantaji-'), 'ふぁいなるふぁんたじー')
Exemplo n.º 8
0
    def update(self, events):
        for event in events:
            if event.type == pygame.KEYDOWN:
                self.cursor_visible = True  # So the user sees where he writes

                # If none exist, create counter for that key:
                if event.key not in self.keyrepeat_counters:
                    self.keyrepeat_counters[event.key] = [0, event.unicode]

                if event.key == pl.K_BACKSPACE:
                    self.input_string = (
                        self.input_string[:max(self.cursor_position - 1, 0)] +
                        self.input_string[self.cursor_position:])

                    # Subtract one from cursor_pos, but do not go below zero:
                    self.cursor_position = max(self.cursor_position - 1, 0)
                elif event.key == pl.K_DELETE:
                    self.input_string = (
                        self.input_string[:self.cursor_position] +
                        self.input_string[self.cursor_position + 1:])

                elif event.key == pl.K_RETURN:
                    return True

                elif event.key == pl.K_RIGHT:
                    # Add one to cursor_pos, but do not exceed len(input_string)
                    self.cursor_position = min(self.cursor_position + 1,
                                               len(self.input_string))

                elif event.key == pl.K_LEFT:
                    # Subtract one from cursor_pos, but do not go below zero:
                    self.cursor_position = max(self.cursor_position - 1, 0)

                elif event.key == pl.K_END:
                    self.cursor_position = len(self.input_string)

                elif event.key == pl.K_HOME:
                    self.cursor_position = 0

                elif event.key == pl.K_TAB:
                    self.input_string = jaconv.alphabet2kana(self.input_string)

                elif len(
                        self.input_string
                ) < self.max_string_length or self.max_string_length == -1:
                    # If no special key is pressed, add unicode of key to input_string

                    self.input_string = (
                        self.input_string[:self.cursor_position] +
                        event.unicode +
                        self.input_string[self.cursor_position:])
                    self.cursor_position += len(
                        event.unicode)  # Some are empty, e.g. K_UP

            elif event.type == pl.KEYUP:
                # *** Because KEYUP doesn't include event.unicode, this dict is stored in such a weird way
                if event.key in self.keyrepeat_counters:
                    del self.keyrepeat_counters[event.key]

        # Update key counters:
        for key in self.keyrepeat_counters:
            self.keyrepeat_counters[key][0] += self.clock.get_time(
            )  # Update clock

            # Generate new key events if enough time has passed:
            if self.keyrepeat_counters[key][
                    0] >= self.keyrepeat_intial_interval_ms:
                self.keyrepeat_counters[key][0] = (
                    self.keyrepeat_intial_interval_ms -
                    self.keyrepeat_interval_ms)

                event_key, event_unicode = key, self.keyrepeat_counters[key][1]
                pygame.event.post(
                    pygame.event.Event(pl.KEYDOWN,
                                       key=event_key,
                                       unicode=event_unicode))

        # Re-render text surface:
        self.surface = self.font_object.render(self.input_string,
                                               self.antialias, self.text_color)

        # Update self.cursor_visible
        self.cursor_ms_counter += self.clock.get_time()
        if self.cursor_ms_counter >= self.cursor_switch_ms:
            self.cursor_ms_counter %= self.cursor_switch_ms
            self.cursor_visible = not self.cursor_visible

        if self.cursor_visible:
            cursor_y_pos = self.font_object.size(
                self.input_string[:self.cursor_position])[0]
            # Without this, the cursor is invisible when self.cursor_position > 0:
            if self.cursor_position > 0:
                cursor_y_pos -= self.cursor_surface.get_width()
            self.surface.blit(self.cursor_surface, (cursor_y_pos, 0))

        self.clock.tick()
        return False