Пример #1
0
    def test_furigana_positions_with_kanji_and_ascii_spaces(self):
        _, furigana_positions = inject_furigana(u"foobar   学び")

        self.assertEqual(furigana_positions[0][FURIGANA_POSITION_START], 9)
        self.assertEqual(furigana_positions[0][FURIGANA_POSITION_END], 10)
        self.assertEqual(furigana_positions[0][FURIGANA_POSITION_FURIGANA],
                         u"まな")
Пример #2
0
    def test_furigana_positions_with_kanji_and_hiragana_prefix_and_ascii_spaces(
            self):
        _, furigana_positions = inject_furigana(u"foo   で背を寄せる")

        self.assertEqual(furigana_positions[0][FURIGANA_POSITION_START], 7)
        self.assertEqual(furigana_positions[0][FURIGANA_POSITION_END], 8)
        self.assertEqual(furigana_positions[0][FURIGANA_POSITION_FURIGANA],
                         u"せ")
Пример #3
0
    def test_furigana_positions_with_kanji_and_ascii(self):
        _, furigana_positions = inject_furigana("学びfoobar学び")

        self.assertEqual(furigana_positions[0][FURIGANA_POSITION_START], 0)
        self.assertEqual(furigana_positions[0][FURIGANA_POSITION_END], 1)
        self.assertEqual(furigana_positions[0][FURIGANA_POSITION_FURIGANA], "まな")

        self.assertEqual(furigana_positions[1][FURIGANA_POSITION_START], 8)
        self.assertEqual(furigana_positions[1][FURIGANA_POSITION_END], 9)
        self.assertEqual(furigana_positions[1][FURIGANA_POSITION_FURIGANA], "まな")
Пример #4
0
def inject_furigana(request):
    try:
        text = request.data['text']
    except KeyError:
        raise ValidationError("Must supply text parameter.")

    text_with_furigana, furigana_positions = inject.inject_furigana(text)

    return Response({
        'text_with_furigana': text_with_furigana,
        'furigana_positions': furigana_positions,
    })
Пример #5
0
    def test_furigana_positions_with_kanji(self):
        _, furigana_positions = inject_furigana("背を寄せる")

        se_kanji = furigana_positions[0]
        self.assertEqual(se_kanji[FURIGANA_POSITION_START], 0)
        self.assertEqual(se_kanji[FURIGANA_POSITION_END], 1)
        self.assertEqual(se_kanji[FURIGANA_POSITION_FURIGANA], "せ")

        yoseru_kanji = furigana_positions[1]
        self.assertEqual(yoseru_kanji[FURIGANA_POSITION_START], 2)
        self.assertEqual(yoseru_kanji[FURIGANA_POSITION_END], 3)
        self.assertEqual(yoseru_kanji[FURIGANA_POSITION_FURIGANA], "よ")
Пример #6
0
    def test_furigana_positions_with_kanji(self):
        _, furigana_positions = inject_furigana(u"背を寄せる")

        se_kanji = furigana_positions[0]
        self.assertEqual(se_kanji[FURIGANA_POSITION_START], 0)
        self.assertEqual(se_kanji[FURIGANA_POSITION_END], 1)
        self.assertEqual(se_kanji[FURIGANA_POSITION_FURIGANA], u"せ")

        yoseru_kanji = furigana_positions[1]
        self.assertEqual(yoseru_kanji[FURIGANA_POSITION_START], 2)
        self.assertEqual(yoseru_kanji[FURIGANA_POSITION_END], 3)
        self.assertEqual(yoseru_kanji[FURIGANA_POSITION_FURIGANA], u"よ")
Пример #7
0
    def test_furigana_positions_with_kanji_and_hiragana_prefix_and_ascii_spaces(self):
        _, furigana_positions = inject_furigana("foo   で背を寄せる")

        self.assertEqual(furigana_positions[0][FURIGANA_POSITION_START], 7)
        self.assertEqual(furigana_positions[0][FURIGANA_POSITION_END], 8)
        self.assertEqual(furigana_positions[0][FURIGANA_POSITION_FURIGANA], "せ")
Пример #8
0
 def test_kanji_and_ascii_spaces(self):
     text_with_furigana, _ = inject_furigana("foobar   学び")
     self.assertEqual("foobar   |学《まな》び", text_with_furigana)
Пример #9
0
 def test_expression_with_kanji(self):
     text_with_furigana, _ = inject_furigana("背を寄せる")
     self.assertEqual("|背《せ》を|寄《よ》せる", text_with_furigana)
Пример #10
0
 def test_plain_ascii_text(self):
     ascii_text = 'foo bar'
     text_with_furigana, _ = inject_furigana(ascii_text)
     self.assertEqual(ascii_text, text_with_furigana)
Пример #11
0
 def test_kanji_and_ascii_spaces(self):
     text_with_furigana, _ = inject_furigana(u"foobar   学び")
     self.assertEqual(u"foobar   |学《まな》び", text_with_furigana)
Пример #12
0
 def test_expression_with_kanji(self):
     text_with_furigana, _ = inject_furigana(u"背を寄せる")
     self.assertEqual(u"|背《せ》を|寄《よ》せる", text_with_furigana)
Пример #13
0
 def test_plain_ascii_text(self):
     ascii_text = u'foo bar'
     text_with_furigana, _ = inject_furigana(ascii_text)
     self.assertEqual(ascii_text, text_with_furigana)