Diviser la pièce en actes
La conversion d'un texte non structuré en graphes lexicaux hiérarchiques est un processus itératif : on crée des scindeurs pour chaque entité lexicale, puis on scinde successivement selon chacune d'elles.
Dans cet exercice, vous allez concevoir un scindeur pour découper la pièce Roméo et Juliette en actes. Voici un aperçu de la structure de la pièce :
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...
...
Cette activité fait partie du cours
Graph RAG avec LangChain et Neo4j
Instructions de l’exercice
- Modifiez l'argument
splitterspour scinder aussi le texte selon le motif\n\nACT. - Configurez
act_splitterpour traiter la listeseparatorscomme des expressions régulières. - Scindez
romeo_and_julietà l'aide deact_splitter.
Exercice interactif pratique
Essayez cet exercice en complétant ce code d’exemple.
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])