File size: 2,514 Bytes
89b0168
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
{
 "cells": [
  {
   "cell_type": "code",
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2024-09-24T11:11:31.348040Z",
     "start_time": "2024-09-24T11:11:28.329888Z"
    }
   },
   "source": [
    "import os\n",
    "import re\n",
    "\n",
    "# Function to capitalize the first letter of each sentence\n",
    "def capitalize_sentences(text):\n",
    "    # Use regular expression to match sentence boundaries\n",
    "    return re.sub(r'(?<!\\w)([.!?]\\s+|^)(\\w)', lambda m: m.group(0).upper(), text)\n",
    "\n",
    "folder_path = \"/home/vahan/Downloads/data_news_preprocessed/data_news_preprocessed\"  # Change this to your folder path\n",
    "# Replace with the path to your folder\n",
    "\n",
    "# Loop through each file in the folder\n",
    "for filename in os.listdir(folder_path):\n",
    "    if filename.endswith('.txt'):\n",
    "        file_path = os.path.join(folder_path, filename)\n",
    "\n",
    "        # Open and read the content of the file\n",
    "        with open(file_path, 'r', encoding='utf-8') as file:\n",
    "            content = file.read()\n",
    "\n",
    "        # Capitalize the first letter of each sentence\n",
    "        updated_content = capitalize_sentences(content)\n",
    "\n",
    "        # Write the updated content back to the file\n",
    "        with open(file_path, 'w', encoding='utf-8') as file:\n",
    "            file.write(updated_content)\n",
    "\n",
    "print(\"All text files have been updated.\")\n",
    "\n",
    "\n",
    "# Specify the folder containing txt files\n",
    "folder_path = \"/home/vahan/Downloads/data_news_preprocessed/data_news_preprocessed\"  # Change this to your folder path\n",
    "\n"
   ],
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "All text files have been updated.\n"
     ]
    }
   ],
   "execution_count": 2
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": "",
   "id": "fe6f29ac4735fa3e"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}