Découper la pièce en actes
La conversion d’un texte non structuré en graphes lexicaux hiérarchiques est un processus itératif : vous créez des séparateurs pour chaque entité lexicale, puis vous découpez successivement selon chacun d’eux.
Dans cet exercice, vous allez concevoir un séparateur pour scinder 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...
...
Cet exercice fait partie du cours
<cours>Graph RAG avec LangChain et Neo4j</cours>Instructions de l’exercice
- Mettez à jour l’argument
splitterspour découper également le texte selon le motif\n\nACT. - Configurez
act_splitterpour traiter la listeseparatorscomme des expressions régulières. - Découpez
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])