File size: 634 Bytes
aebf6a6
 
 
 
 
9d49094
 
aebf6a6
 
9d49094
aebf6a6
 
 
 
9d49094
aebf6a6
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
def textsegmentation():
    # Read the contract text from the file
    with open(contract_file_path, 'r') as file:
        contract_text = file.read()

    # Tokenize the contract text into sentences
    sentences = nltk.sent_tokenize(contract_text)

    # Prepare data for CSV
    data = [(i+1, sentence) for i, sentence in enumerate(sentences)]

    # Write the data to CSV file
    with open(output_csv_file, 'w', newline='', encoding='utf-8') as file:
        writer = csv.writer(file)
        writer.writerow(['Sentence ID', 'Sentence Text'])  # Write header
        writer.writerows(data)

    print("Output saved to CSV file.")