Dividir la obra en actos
Convertir texto no estructurado en grafos léxicos jerárquicos es un proceso iterativo que implica crear divisores (splitters) para cada entidad léxica y luego dividir por cada una, en ese orden.
En este ejercicio, vas a diseñar un divisor para segmentar la obra Romeo and Juliet en actos. Aquí tienes un adelanto de la estructura de la obra:
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...
...
Este ejercicio forma parte del curso
Graph RAG con LangChain y Neo4j
Instrucciones del ejercicio
- Actualiza el argumento
splitterspara que también divida el texto con el patrón\n\nACT. - Configura
act_splitterpara tratar la listaseparatorscomo expresiones regulares. - Divide
romeo_and_julietusandoact_splitter.
ejercicio interactivo práctico
Prueba este ejercicio completando este código de ejemplo.
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])