शुरू करेंमुफ़्त में शुरू करें

नाटक को Acts में बाँटना

असंरचित टेक्स्ट को हायरेरिकल लेक्सिकल ग्राफ़ में बदलना एक iterative प्रक्रिया है. इसमें हर lexical entity के लिए स्प्लिटर बनाना और फिर बारी-बारी से उसी के आधार पर टेक्स्ट को बाँटना शामिल होता है.

इस अभ्यास में, आप एक स्प्लिटर डिज़ाइन करेंगे जो नाटक 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...
...

यह अभ्यास पाठ्यक्रम का हिस्सा है

LangChain और Neo4j के साथ Graph RAG

पाठ्यक्रम देखें

अभ्यास निर्देश

  • splitters आर्ग्यूमेंट को अपडेट करें ताकि टेक्स्ट \n\nACT पैटर्न पर भी स्प्लिट हो.
  • act_splitter को इस तरह कॉन्फ़िगर करें कि separators सूची को रेगुलर एक्सप्रेशन की तरह ट्रीट किया जाए.
  • act_splitter का उपयोग करके romeo_and_juliet को स्प्लिट करें.

इंटरैक्टिव व्यावहारिक अभ्यास

इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।

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])
कोड संपादित करें और चलाएँ