CommencezCommencez gratuitement

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

Voir le cours

Instructions de l’exercice

  • Modifiez l'argument splitters pour scinder aussi le texte selon le motif \n\nACT.
  • Configurez act_splitter pour traiter la liste separators comme des expressions régulières.
  • Scindez romeo_and_juliet à l'aide de act_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])
Modifier et exécuter le code