시작하기무료로 시작하기

연극을 막(Act)으로 나누기

비정형 텍스트를 계층적 어휘 그래프로 변환하는 과정은 반복적이에요. 각 어휘 단위를 위한 스플리터를 만들고, 차례대로 해당 기준으로 분할해요.

이 연습에서는 연극 Romeo and Juliet막(Act) 단위로 나누는 스플리터를 설계해 볼 거예요. 연극의 구조 미리보기는 다음과 같아요:

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_splitterseparators 목록을 정규식으로 처리하도록 설정하세요.
  • 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])
코드 편집 및 실행