เริ่มต้นใช้งานเริ่มต้นใช้งานได้ฟรี

การแบ่งบทละครออกเป็น Acts

การแปลงข้อความที่ไม่มีโครงสร้างให้เป็น lexical graph แบบลำดับชั้นนั้นเป็นกระบวนการที่ทำซ้ำหลายรอบ โดยต้องสร้าง splitter สำหรับแต่ละหน่วยคำศัพท์ แล้วค่อยแบ่งข้อความตามลำดับ

ในแบบฝึกหัดนี้ คุณจะออกแบบ splitter เพื่อแบ่งบทละคร Romeo and Juliet ออกเป็น acts ต่อไปนี้คือตัวอย่างโครงสร้างของบทละคร:

The Project Gutenberg eBook of Romeo and Juliet
This ebook is for the use of anyone anywhere in the United States...

**PROLOGUE:**

 Enter Chorus.

CHORUS.
Two households, both alike in dignity...

ACT I

SCENE I. A public place.
 Enter Sampson and Gregory armed with swords and bucklers.

SAMPSON.
Gregory, on my word, we'll not carry coals...
...

แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร

Graph RAG ด้วย LangChain และ Neo4j

ดูคอร์ส

คำแนะนำการฝึกหัด

  • อัปเดตอาร์กิวเมนต์ splitters เพื่อแบ่งข้อความตามรูปแบบ \n\nACT ด้วย
  • กำหนดค่า act_splitter ให้ถือว่ารายการ separators เป็น regular expressions
  • แบ่ง romeo_and_juliet โดยใช้ act_splitter

แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ

ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์

act_splitter = RecursiveCharacterTextSplitter(
  separators=[ 
    r"\n\nTHE PROLOGUE.",
    r"\n\n\*\*\* END",
    # Split by the word ACT
    r"____"
  ],
  # Configure the patterns as regular expressions
  ____=True
)

# Split the play using act_splitter
acts = act_splitter.____(____)

for act in acts:
  print(act.strip().split("\n")[0])
แก้ไขและรันโค้ด