feat: wiki 讀取與對白抽取腳本 (#4)
fetch_wiki.py 用 tea 讀取 wiki;extract_dialogues.py 抽出「」對白與前後文, 並用規則判定明確的說話者。原文與輸出放在 repo 之外。 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
b0ed5efedf
commit
9cf8196a3e
@@ -0,0 +1,64 @@
|
||||
import unittest
|
||||
|
||||
from extract_dialogues import attribute, cn_number, pick_subject
|
||||
|
||||
|
||||
class PickSubject(unittest.TestCase):
|
||||
def test_single_candidate_with_cue_is_high(self):
|
||||
self.assertEqual(pick_subject("亞絲娜一邊流淚一邊對我叫道"), ("亞絲娜", ["亞絲娜"], True))
|
||||
|
||||
def test_object_wo_is_not_speaker(self):
|
||||
self.assertEqual(pick_subject("在我背後的亞絲娜同樣相當氣憤地反問")[0], "亞絲娜")
|
||||
|
||||
def test_narrator_is_wo(self):
|
||||
self.assertEqual(pick_subject("我低聲說道")[0], "我")
|
||||
|
||||
def test_first_subject_wins_and_is_not_high(self):
|
||||
who, cands, high = pick_subject("我關掉地圖,瞄了亞絲娜一眼,說道")
|
||||
self.assertEqual((who, cands, high), ("我", ["我", "亞絲娜"], False))
|
||||
|
||||
def test_frame_clause_is_skipped(self):
|
||||
self.assertEqual(pick_subject("面對桐人這種問題,莉法先是瞪了他一下後才繼續說道")[0], "莉法")
|
||||
|
||||
def test_wo_men_is_not_speaker(self):
|
||||
self.assertIsNone(pick_subject("我們一起說道")[0])
|
||||
|
||||
def test_no_candidate(self):
|
||||
self.assertEqual(pick_subject("她聳了聳肩後繼續說道"), (None, [], False))
|
||||
|
||||
|
||||
class Attribute(unittest.TestCase):
|
||||
def test_lead_in_same_paragraph(self):
|
||||
r = attribute("亞絲娜小聲說:", "", "")
|
||||
self.assertEqual((r[0], r[2], r[3]), ("asuna", "high", "lead_in"))
|
||||
|
||||
def test_lead_in_previous_paragraph_even_with_inner_quote(self):
|
||||
r = attribute("", "", "他喊著「回復!」。亞絲娜小聲對我說:")
|
||||
self.assertEqual((r[0], r[3]), ("asuna", "lead_in_prev"))
|
||||
|
||||
def test_narrator_maps_to_kirito(self):
|
||||
self.assertEqual(attribute("我低聲說道:", "", "")[0], "kirito")
|
||||
|
||||
def test_trail(self):
|
||||
r = attribute("", ",亞絲娜低聲說。", "")
|
||||
self.assertEqual((r[0], r[3]), ("asuna", "trail"))
|
||||
|
||||
def test_trail_without_cue_is_not_attributed(self):
|
||||
self.assertIsNone(attribute("", "亞絲娜點了點頭。", "")[0])
|
||||
|
||||
def test_leafa_mode_from_alias(self):
|
||||
from extract_dialogues import resolve
|
||||
self.assertEqual(resolve("莉法"), ("suguha", "leafa"))
|
||||
self.assertEqual(resolve("直葉"), ("suguha", "real"))
|
||||
|
||||
def test_unknown_when_nothing_matches(self):
|
||||
self.assertEqual(attribute("", "", "")[0], None)
|
||||
|
||||
|
||||
class Numerals(unittest.TestCase):
|
||||
def test_chapters(self):
|
||||
self.assertEqual([cn_number(x) for x in ("一", "十", "十一", "二十", "二十五")], [1, 10, 11, 20, 25])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user