awoo
Browse filesSigned-off-by: Balazs Horvath <[email protected]>
dataset_tools/Escape Parentheses.ipynb
CHANGED
@@ -130,7 +130,7 @@
|
|
130 |
},
|
131 |
{
|
132 |
"cell_type": "code",
|
133 |
-
"execution_count":
|
134 |
"metadata": {},
|
135 |
"outputs": [],
|
136 |
"source": [
|
@@ -144,18 +144,19 @@
|
|
144 |
" content = file.read()\n",
|
145 |
" original_content = content\n",
|
146 |
"\n",
|
147 |
-
" #
|
148 |
-
" content = re.sub(r\"(?<!\\\\)(
|
149 |
-
" # Escape unescaped closing parentheses\n",
|
150 |
-
" content = re.sub(r\"(?<!\\\\)(\\\\*)(\\))\", r\"\\1\\\\\\2\", content)\n",
|
151 |
"\n",
|
152 |
-
"
|
153 |
-
"
|
154 |
-
" print(f\"Original: {original_content}\")\n",
|
155 |
-
" print(f\"Modified: {content}\")\n",
|
156 |
"\n",
|
157 |
-
"
|
158 |
-
"
|
|
|
|
|
|
|
|
|
|
|
159 |
"\n",
|
160 |
"\n",
|
161 |
"def process_directory(directory):\n",
|
@@ -163,8 +164,8 @@
|
|
163 |
" escape_parentheses(file_path)\n",
|
164 |
"\n",
|
165 |
"\n",
|
166 |
-
"directory_path = r\"E:\\training_dir\"\n",
|
167 |
-
"
|
168 |
"process_directory(directory_path)"
|
169 |
]
|
170 |
}
|
|
|
130 |
},
|
131 |
{
|
132 |
"cell_type": "code",
|
133 |
+
"execution_count": 4,
|
134 |
"metadata": {},
|
135 |
"outputs": [],
|
136 |
"source": [
|
|
|
144 |
" content = file.read()\n",
|
145 |
" original_content = content\n",
|
146 |
"\n",
|
147 |
+
" # Replace any (not preceded by \\) with \\(\n",
|
148 |
+
" content = re.sub(r\"(?<!\\\\)(\\()\", r\"\\\\\\1\", content)\n",
|
|
|
|
|
149 |
"\n",
|
150 |
+
" # Replace any )not preceded by \\) with \\)\n",
|
151 |
+
" content = re.sub(r\"(?<!\\\\)(\\))\", r\"\\\\\\1\", content)\n",
|
|
|
|
|
152 |
"\n",
|
153 |
+
" if content != original_content:\n",
|
154 |
+
" print(f\"Warning: File '{file_path}' was modified.\")\n",
|
155 |
+
" print(f\"Original: {original_content}\")\n",
|
156 |
+
" print(f\"Modified: {content}\")\n",
|
157 |
+
"\n",
|
158 |
+
" with open(file_path, \"w\") as file:\n",
|
159 |
+
" file.write(content)\n",
|
160 |
"\n",
|
161 |
"\n",
|
162 |
"def process_directory(directory):\n",
|
|
|
164 |
" escape_parentheses(file_path)\n",
|
165 |
"\n",
|
166 |
"\n",
|
167 |
+
"# directory_path = r\"E:\\training_dir\"\n",
|
168 |
+
"directory_path = r\"C:\\Users\\kade\\Desktop\\training_dir_staging\"\n",
|
169 |
"process_directory(directory_path)"
|
170 |
]
|
171 |
}
|
dataset_tools/e621 JSON to txt.ipynb
CHANGED
The diff for this file is too large to render.
See raw diff
|
|