当前位置: 首页>>代码示例>>Python>>正文


Python SubtitleSet.from_list方法代码示例

本文整理汇总了Python中babelsubs.storage.SubtitleSet.from_list方法的典型用法代码示例。如果您正苦于以下问题:Python SubtitleSet.from_list方法的具体用法?Python SubtitleSet.from_list怎么用?Python SubtitleSet.from_list使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在babelsubs.storage.SubtitleSet的用法示例。


在下文中一共展示了SubtitleSet.from_list方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_replace_multiple_lines_with_single

# 需要导入模块: from babelsubs.storage import SubtitleSet [as 别名]
# 或者: from babelsubs.storage.SubtitleSet import from_list [as 别名]
    def test_replace_multiple_lines_with_single(self):
        set_1 = SubtitleSet.from_list('en', [
         (0, 1000, "Hey 1"),
         (1000, 2000, "Hey 2"),
         (2000, 3000, "Hey 3"),
         (3000, 4000, "Hey 4"),
        ])
        set_2 = SubtitleSet.from_list('en', [
         (0, 1000, "Hey 1"),
         (1000, 3000, "Hey 2 and 3"),
         (3000, 4000, "Hey 4"),
        ])
        result = diff(set_1, set_2)
        self.assertEqual(result['changed'], True)
        # for both time_change and text_changed, we calculate them as follows:
        # there are 7 total subs.  4 of those are matches and 2 in set_1 were
        # replaced with 1 in set_2.  So the change amount is 3/7.
        self.assertAlmostEqual(result['time_changed'], 3/7.0)
        self.assertAlmostEqual(result['text_changed'], 3/7.0)
        self.assertEqual(len(result['subtitle_data']), 4)

        # check the lines that haven't changed
        self.check_unchanged_subtitle_data(result, set_1, set_2, 0, 3)
        # check the line that was inserted
        line1 = result['subtitle_data'][1]
        self.assertEquals(line1['time_changed'], True)
        self.assertEquals(line1['text_changed'], True)
        self.assertEquals(line1['subtitles'][0], set_1[1])
        self.assertEquals(line1['subtitles'][1], set_2[1])
        line2 = result['subtitle_data'][2]
        self.assertEquals(line2['time_changed'], True)
        self.assertEquals(line2['text_changed'], True)
        self.assertEquals(line2['subtitles'][0], set_1[2])
        self.assertEquals(line2['subtitles'][1], self.empty_line())
开发者ID:pculture,项目名称:babelsubs,代码行数:36,代码来源:test_diffing.py

示例2: test_insert

# 需要导入模块: from babelsubs.storage import SubtitleSet [as 别名]
# 或者: from babelsubs.storage.SubtitleSet import from_list [as 别名]
    def test_insert(self):
        set_1 = SubtitleSet.from_list('en', [
         (0, 1000, "Hey 1"),
         (1000, 2000, "Hey 2"),
         (2000, 3000, "Hey 3"),
         (3000, 4000, "Hey 4"),
        ])
        set_2 = SubtitleSet.from_list('en', [
         (0, 1000, "Hey 1"),
         (500, 800, "Hey 1.5"),
         (1000, 2000, "Hey 2"),
         (2000, 3000, "Hey 3"),
         (3000, 4000, "Hey 4"),
        ])
        result = diff(set_1, set_2)
        self.assertEqual(result['changed'], True)
        # for both time_change and text_changed, we calculate them as follows:
        # there are 9 total subs.  8 of those are matches and 1 is new in
        # set_2.  So the change amount is 1/9
        self.assertAlmostEqual(result['time_changed'], 1/9.0)
        self.assertAlmostEqual(result['text_changed'], 1/9.0)
        self.assertEqual(len(result['subtitle_data']), 5)

        # check the lines that haven't changed
        self.check_unchanged_subtitle_data(result, set_1, set_2, 0, 2, 3, 4)
        # check the line that was inserted
        insert_sub_data = result['subtitle_data'][1]
        self.assertEquals(insert_sub_data['time_changed'], True)
        self.assertEquals(insert_sub_data['text_changed'], True)
        self.assertEquals(insert_sub_data['subtitles'][0], self.empty_line())
        self.assertEquals(insert_sub_data['subtitles'][1], set_2[1])
开发者ID:pculture,项目名称:babelsubs,代码行数:33,代码来源:test_diffing.py

示例3: test_simple_replace

# 需要导入模块: from babelsubs.storage import SubtitleSet [as 别名]
# 或者: from babelsubs.storage.SubtitleSet import from_list [as 别名]
    def test_simple_replace(self):
        set_1 = SubtitleSet.from_list('en', [
         (0, 1000, "Hey 1"),
         (1000, 2000, "Hey 2"),
         (2000, 3000, "Hey 3"),
         (3000, 4000, "Hey 4"),
        ])
        set_2 = SubtitleSet.from_list('en', [
         (0, 1000, "Hey 1"),
         (1000, 2000, "Hey New 2"),
         (2000, 3000, "Hey 3"),
         (3000, 4000, "Hey 4"),
        ])
        result = diff(set_1, set_2)
        self.assertEqual(result['changed'], True)
        self.assertAlmostEqual(result['time_changed'], 0)
        # for text_changed, we calculate as follows: there are 8 total subs.
        # 6 of those are matches and 1 is different in both sets.  So 2/8.0
        # has been changed.
        self.assertAlmostEqual(result['text_changed'], 2/8.0)
        self.assertEqual(len(result['subtitle_data']), 4)

        # check the lines that haven't changed
        self.check_unchanged_subtitle_data(result, set_1, set_2, 0, 2, 3)
        # check the line that was inserted
        insert_sub_data = result['subtitle_data'][1]
        self.assertEquals(insert_sub_data['time_changed'], False)
        self.assertEquals(insert_sub_data['text_changed'], True)
        self.assertEquals(insert_sub_data['subtitles'][0], set_1[1])
        self.assertEquals(insert_sub_data['subtitles'][1], set_2[1])
开发者ID:pculture,项目名称:babelsubs,代码行数:32,代码来源:test_diffing.py

示例4: test_calc_changes

# 需要导入模块: from babelsubs.storage import SubtitleSet [as 别名]
# 或者: from babelsubs.storage.SubtitleSet import from_list [as 别名]
 def test_calc_changes(self):
     set_1 = SubtitleSet.from_list(
         "en", [(0, 1000, "Hey 1"), (1000, 2000, "Hey 2"), (2000, 3000, "Hey 3"), (3000, 4000, "Hey 4")]
     )
     set_2 = SubtitleSet.from_list(
         "en", [(0, 1000, "Hey 1"), (1000, 2000, "Hey New 2"), (2000, 3000, "Hey 3"), (3000, 4000, "Hey 4")]
     )
     text_changed, time_changed = calc_changes(set_1, set_2)
     self.assertAlmostEqual(time_changed, 0)
     self.assertAlmostEqual(text_changed, 2 / 8.0)
开发者ID:pculture,项目名称:babelsubs,代码行数:12,代码来源:test_diffing.py

示例5: test_data_ordering

# 需要导入模块: from babelsubs.storage import SubtitleSet [as 别名]
# 或者: from babelsubs.storage.SubtitleSet import from_list [as 别名]
    def test_data_ordering(self):
        set_1 = SubtitleSet.from_list("en", [(0, 1000, "Hey 1")])
        set_2 = SubtitleSet.from_list("en", [(0, 1000, "Hey 1"), (1200, 2000, "Hey 2"), (2000, 3000, "Hey 3")])
        result = diff(set_1, set_2)

        subs_result = result["subtitle_data"][2]["subtitles"]
        # make sure the 0 index subs is for set_1, test
        # we respect the ordering of arguments passed to diff
        self.assertEqual(subs_result[0].text, None)
        self.assertEqual(subs_result[1].text, "Hey 3")
开发者ID:pculture,项目名称:babelsubs,代码行数:12,代码来源:test_diffing.py

示例6: test_unsynced_reflect_time_changes

# 需要导入模块: from babelsubs.storage import SubtitleSet [as 别名]
# 或者: from babelsubs.storage.SubtitleSet import from_list [as 别名]
    def test_unsynced_reflect_time_changes(self):
        set_1 = SubtitleSet.from_list('en', [
            (0, 1000, "Hey 1"),
            ])
        set_2 = SubtitleSet.from_list('en', [
            (0, 1000, "Hey 1"),
            (None, None, "Hey 2"),
            ])
        result = diff(set_1, set_2)

        self.assertAlmostEqual(result['time_changed'], 1/3.0)
开发者ID:bendk,项目名称:babelsubs,代码行数:13,代码来源:test_diffing.py

示例7: test_text_changes

# 需要导入模块: from babelsubs.storage import SubtitleSet [as 别名]
# 或者: from babelsubs.storage.SubtitleSet import from_list [as 别名]
 def test_text_changes(self):
     set_1 = SubtitleSet.from_list(
         "en", [(0, 1000, "Hey 1"), (1000, 2000, "Hey 2"), (2000, 3000, "Hey 3"), (3000, 4000, "Hey 4")]
     )
     set_2 = SubtitleSet.from_list(
         "en", [(0, 1000, "Hey 1"), (1000, 2000, "Hey 22"), (2000, 3000, "Hey 3"), (3000, 4000, "Hey 4")]
     )
     result = diff(set_1, set_2)
     self.assertEqual(result["changed"], True)
     self.assertEqual(result["text_changed"], 1 / 4.0)
     self.assertEqual(result["time_changed"], 0)
     self.assertEqual(len(result["subtitle_data"]), 4)
     # only sub #2 should have text changed
     for i, sub_data in enumerate(result["subtitle_data"]):
         self.assertEqual(sub_data["text_changed"], i == 1)
开发者ID:pculture,项目名称:babelsubs,代码行数:17,代码来源:test_diffing.py

示例8: test_one_set_empty

# 需要导入模块: from babelsubs.storage import SubtitleSet [as 别名]
# 或者: from babelsubs.storage.SubtitleSet import from_list [as 别名]
 def test_one_set_empty(self):
     set_1 = SubtitleSet.from_list(
         "en", [(0, 1000, "Hey 1"), (1000, 2000, "Hey 2"), (2000, 3000, "Hey 3"), (3000, 4000, "Hey 4")]
     )
     result = diff(set_1, SubtitleSet("en"))
     self.assertEqual(result["changed"], True)
     self.assertEqual(result["text_changed"], 1.0)
     self.assertEqual(result["time_changed"], 1.0)
开发者ID:pculture,项目名称:babelsubs,代码行数:10,代码来源:test_diffing.py

示例9: test_time_changes

# 需要导入模块: from babelsubs.storage import SubtitleSet [as 别名]
# 或者: from babelsubs.storage.SubtitleSet import from_list [as 别名]
 def test_time_changes(self):
     set_1 = SubtitleSet.from_list('en', [
      (0, 1000, "Hey 1"),
      (1000, 2000, "Hey 2"),
      (2000, 3000, "Hey 3"),
      (3000, 4000, "Hey 4"),
     ])
     set_2 = SubtitleSet.from_list('en', [
      (0, 1000, "Hey 1"),
      (1200, 2000, "Hey 2"),
      (2000, 3000, "Hey 3"),
      (3000, 4000, "Hey 4"),
     ])
     result = diff(set_1, set_2)
     self.assertEqual(result['changed'], True)
     self.assertEqual(result['time_changed'], 1/4.0)
     self.assertEqual(result['text_changed'], 0)
     self.assertEqual(len(result['subtitle_data']), 4)
     # only sub #2 should have text changed
     for i,sub_data in enumerate(result['subtitle_data']):
         self.assertEqual(sub_data['time_changed'], i ==1)
         self.assertFalse(sub_data['text_changed'])
开发者ID:bendk,项目名称:babelsubs,代码行数:24,代码来源:test_diffing.py

示例10: test_delete

# 需要导入模块: from babelsubs.storage import SubtitleSet [as 别名]
# 或者: from babelsubs.storage.SubtitleSet import from_list [as 别名]
    def test_delete(self):
        set_1 = SubtitleSet.from_list(
            "en", [(0, 1000, "Hey 1"), (1000, 2000, "Hey 2"), (2000, 3000, "Hey 3"), (3000, 4000, "Hey 4")]
        )
        set_2 = SubtitleSet.from_list("en", [(0, 1000, "Hey 1"), (2000, 3000, "Hey 3"), (3000, 4000, "Hey 4")])
        result = diff(set_1, set_2)
        self.assertEqual(result["changed"], True)
        # for both time_change and text_changed, we calculate them as follows:
        # there are 7 total subs.  6 of those are matches and 1 is new in
        # set_2.  So the change amount is 1/9
        self.assertAlmostEqual(result["time_changed"], 1 / 7.0)
        self.assertAlmostEqual(result["text_changed"], 1 / 7.0)
        self.assertEqual(len(result["subtitle_data"]), 4)

        # check the lines that haven't changed
        self.check_unchanged_subtitle_data(result, set_1, set_2, 0, 2, 3)
        # check the line that was deleted
        delete_sub_data = result["subtitle_data"][1]
        self.assertEquals(delete_sub_data["time_changed"], True)
        self.assertEquals(delete_sub_data["text_changed"], True)
        self.assertEquals(delete_sub_data["subtitles"][1], self.empty_line())
        self.assertEquals(delete_sub_data["subtitles"][0], set_1[1])
开发者ID:pculture,项目名称:babelsubs,代码行数:24,代码来源:test_diffing.py

示例11: test_replace_single_line_with_multiple

# 需要导入模块: from babelsubs.storage import SubtitleSet [as 别名]
# 或者: from babelsubs.storage.SubtitleSet import from_list [as 别名]
    def test_replace_single_line_with_multiple(self):
        set_1 = SubtitleSet.from_list(
            "en", [(0, 1000, "Hey 1"), (1000, 2000, "Hey 2"), (2000, 3000, "Hey 3"), (3000, 4000, "Hey 4")]
        )
        set_2 = SubtitleSet.from_list(
            "en",
            [
                (0, 1000, "Hey 1"),
                (1000, 1500, "Hey 2.1"),
                (1500, 2000, "Hey 2.2"),
                (2000, 3000, "Hey 3"),
                (3000, 4000, "Hey 4"),
            ],
        )
        result = diff(set_1, set_2)
        self.assertEqual(result["changed"], True)
        # for both time_change and text_changed, we calculate them as follows:
        # there are 9 total subs.  6 of those are matches and 1 in set 1 was
        # changed to 2 in set 2.  So the change amount is 3/9.
        self.assertAlmostEqual(result["time_changed"], 3 / 9.0)
        self.assertAlmostEqual(result["text_changed"], 3 / 9.0)
        self.assertEqual(len(result["subtitle_data"]), 5)

        # check the lines that haven't changed
        self.check_unchanged_subtitle_data(result, set_1, set_2, 0, 3, 4)
        # line 1 in set_1 was replaced my lines 2 and 3 in set_2
        line1 = result["subtitle_data"][1]
        self.assertEquals(line1["time_changed"], True)
        self.assertEquals(line1["text_changed"], True)
        self.assertEquals(line1["subtitles"][0], set_1[1])
        self.assertEquals(line1["subtitles"][1], set_2[1])
        line2 = result["subtitle_data"][2]
        self.assertEquals(line2["time_changed"], True)
        self.assertEquals(line2["text_changed"], True)
        self.assertEquals(line2["subtitles"][0], self.empty_line())
        self.assertEquals(line2["subtitles"][1], set_2[2])
开发者ID:pculture,项目名称:babelsubs,代码行数:38,代码来源:test_diffing.py


注:本文中的babelsubs.storage.SubtitleSet.from_list方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。