yonkasoft commited on
Commit
cba6b49
1 Parent(s): fa8e9f4

Upload 2 files

Browse files
Files changed (3) hide show
  1. .gitattributes +1 -0
  2. cleaned_processed_data.csv +3 -0
  3. combined.ipynb +378 -140
.gitattributes CHANGED
@@ -36,3 +36,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
36
  combined_output.csv filter=lfs diff=lfs merge=lfs -text
37
  combined_texts.csv filter=lfs diff=lfs merge=lfs -text
38
  processed_data.csv filter=lfs diff=lfs merge=lfs -text
 
 
36
  combined_output.csv filter=lfs diff=lfs merge=lfs -text
37
  combined_texts.csv filter=lfs diff=lfs merge=lfs -text
38
  processed_data.csv filter=lfs diff=lfs merge=lfs -text
39
+ cleaned_processed_data.csv filter=lfs diff=lfs merge=lfs -text
cleaned_processed_data.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0827f1e2337aaf3e75ccbed508fd13dcb2d26612a1a55a8922d25e77fc54dd85
3
+ size 391939173
combined.ipynb CHANGED
@@ -9,7 +9,7 @@
9
  },
10
  {
11
  "cell_type": "code",
12
- "execution_count": 3,
13
  "metadata": {},
14
  "outputs": [],
15
  "source": [
@@ -40,7 +40,7 @@
40
  },
41
  {
42
  "cell_type": "code",
43
- "execution_count": 4,
44
  "metadata": {},
45
  "outputs": [],
46
  "source": [
@@ -138,15 +138,15 @@
138
  ]
139
  },
140
  {
141
- "cell_type": "code",
142
- "execution_count": null,
143
  "metadata": {},
144
- "outputs": [],
145
- "source": []
 
146
  },
147
  {
148
  "cell_type": "code",
149
- "execution_count": 11,
150
  "metadata": {},
151
  "outputs": [],
152
  "source": [
@@ -204,13 +204,6 @@
204
  "save_to_csv(truncated_texts, output_file)\n"
205
  ]
206
  },
207
- {
208
- "cell_type": "code",
209
- "execution_count": null,
210
- "metadata": {},
211
- "outputs": [],
212
- "source": []
213
- },
214
  {
215
  "cell_type": "markdown",
216
  "metadata": {},
@@ -220,79 +213,37 @@
220
  },
221
  {
222
  "cell_type": "code",
223
- "execution_count": 11,
224
  "metadata": {},
225
  "outputs": [
226
  {
227
- "name": "stderr",
228
  "output_type": "stream",
229
  "text": [
230
- "c:\\gitProjects\\yeni\\.venv\\lib\\site-packages\\sklearn\\feature_extraction\\text.py:406: UserWarning: Your stop_words may be inconsistent with your preprocessing. Tokenizing the stop words generated tokens ['leh'] not in stop_words.\n",
231
- " warnings.warn(\n"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
232
  ]
233
  },
234
- {
235
- "ename": "KeyboardInterrupt",
236
- "evalue": "",
237
- "output_type": "error",
238
- "traceback": [
239
- "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
240
- "\u001b[1;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)",
241
- "Cell \u001b[1;32mIn[11], line 33\u001b[0m\n\u001b[0;32m 30\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m top_keywords_per_document, top_tfidf_scores_per_document\n\u001b[0;32m 32\u001b[0m \u001b[38;5;66;03m# Anahtar kelimeleri çıkar ve sonuçları al\u001b[39;00m\n\u001b[1;32m---> 33\u001b[0m top_keywords_per_document, top_tfidf_scores_per_document \u001b[38;5;241m=\u001b[39m \u001b[43mextract_keywords_tfidf\u001b[49m\u001b[43m(\u001b[49m\u001b[43mcombined\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mstop_words_list\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtop_n\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;241;43m10\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[0;32m 36\u001b[0m \u001b[38;5;66;03m# Sonuçları görüntüleme\u001b[39;00m\n\u001b[0;32m 37\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m i, (keywords, scores) \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28menumerate\u001b[39m(\u001b[38;5;28mzip\u001b[39m(top_keywords_per_document, top_tfidf_scores_per_document)):\n",
242
- "Cell \u001b[1;32mIn[11], line 21\u001b[0m, in \u001b[0;36mextract_keywords_tfidf\u001b[1;34m(combined, stop_words_list, top_n)\u001b[0m\n\u001b[0;32m 19\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m row \u001b[38;5;129;01min\u001b[39;00m X:\n\u001b[0;32m 20\u001b[0m tfidf_scores \u001b[38;5;241m=\u001b[39m row\u001b[38;5;241m.\u001b[39mtoarray()\u001b[38;5;241m.\u001b[39mflatten() \u001b[38;5;66;03m#değişkenleri düz bir değişken haline getirme\u001b[39;00m\n\u001b[1;32m---> 21\u001b[0m top_indices \u001b[38;5;241m=\u001b[39m \u001b[43mtfidf_scores\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43margsort\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m[\u001b[38;5;241m-\u001b[39mtop_n:][::\u001b[38;5;241m-\u001b[39m\u001b[38;5;241m1\u001b[39m] \u001b[38;5;66;03m# En yüksek n skoru bul\u001b[39;00m\n\u001b[0;32m 23\u001b[0m \u001b[38;5;66;03m#en yüksek skorlu kelimleri ve skorları bul\u001b[39;00m\n\u001b[0;32m 24\u001b[0m top_keywords \u001b[38;5;241m=\u001b[39m [feature_names[i] \u001b[38;5;28;01mfor\u001b[39;00m i \u001b[38;5;129;01min\u001b[39;00m top_indices]\n",
243
- "\u001b[1;31mKeyboardInterrupt\u001b[0m: "
244
- ]
245
- }
246
- ],
247
- "source": [
248
- "import csv\n",
249
- "from sklearn.feature_extraction.text import TfidfVectorizer\n",
250
- "from joblib import Parallel, delayed\n",
251
- "import pandas as pd\n",
252
- "\n",
253
- "df=pd.read_csv('combined_texts.csv')\n",
254
- "combined= df['combined'].tolist()\n",
255
- "def extract_keywords_tfidf(combined, stop_words_list,top_n=10):\n",
256
- " \"\"\"TF-IDF ile anahtar kelimeleri çıkarır, stop words listesi ile birlikte kullanır.\"\"\"\n",
257
- " vectorizer = TfidfVectorizer(stop_words=stop_words_list)\n",
258
- " X = vectorizer.fit_transform(combined) #bunu csv den oku \n",
259
- " feature_names = vectorizer.get_feature_names_out() #her kelimenin tf-ıdf vektöründeki karşılığını tutar \n",
260
- " #sorted_keywords = [feature_names[i] for i in X.sum(axis=0).argsort()[0, ::-1]]\n",
261
- " \n",
262
- " top_keywords_per_document = [] #her döküman için en iyi keywordsleri alır\n",
263
- " top_tfidf_scores_per_document = [] #tf-ıdf değeri en yüksek olan dökümanlar\n",
264
- "\n",
265
- " # Her dökümanı işleme\n",
266
- " for row in X:\n",
267
- " tfidf_scores = row.toarray().flatten() #değişkenleri düz bir değişken haline getirme\n",
268
- " top_indices = tfidf_scores.argsort()[-top_n:][::-1] # En yüksek n skoru bul\n",
269
- " \n",
270
- " #en yüksek skorlu kelimleri ve skorları bul\n",
271
- " top_keywords = [feature_names[i] for i in top_indices]\n",
272
- " top_tfidf_scores = [tfidf_scores[i] for i in top_indices]\n",
273
- " \n",
274
- " top_keywords_per_document.append(top_keywords)\n",
275
- " top_tfidf_scores_per_document.append(top_tfidf_scores)\n",
276
- " \n",
277
- " return top_keywords_per_document, top_tfidf_scores_per_document\n",
278
- "\n",
279
- "# Anahtar kelimeleri çıkar ve sonuçları al\n",
280
- "top_keywords_per_document, top_tfidf_scores_per_document = extract_keywords_tfidf(combined, stop_words_list, top_n=10)\n",
281
- " \n",
282
- "\n",
283
- "# Sonuçları görüntüleme\n",
284
- "for i, (keywords, scores) in enumerate(zip(top_keywords_per_document, top_tfidf_scores_per_document)):\n",
285
- " print(f\"Döküman {i+1}:\")\n",
286
- " for keyword, score in zip(keywords, scores):\n",
287
- " print(f\"{keyword}: {score:.4f}\")\n",
288
- " print(\"\\n\")\n"
289
- ]
290
- },
291
- {
292
- "cell_type": "code",
293
- "execution_count": 5,
294
- "metadata": {},
295
- "outputs": [
296
  {
297
  "name": "stderr",
298
  "output_type": "stream",
@@ -300,21 +251,6 @@
300
  "c:\\gitProjects\\yeni\\.venv\\lib\\site-packages\\sklearn\\feature_extraction\\text.py:406: UserWarning: Your stop_words may be inconsistent with your preprocessing. Tokenizing the stop words generated tokens ['leh'] not in stop_words.\n",
301
  " warnings.warn(\n"
302
  ]
303
- },
304
- {
305
- "ename": "KeyboardInterrupt",
306
- "evalue": "",
307
- "output_type": "error",
308
- "traceback": [
309
- "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
310
- "\u001b[1;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)",
311
- "Cell \u001b[1;32mIn[5], line 53\u001b[0m\n\u001b[0;32m 50\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m top_keywords_per_document, top_tfidf_scores_per_document\n\u001b[0;32m 52\u001b[0m \u001b[38;5;66;03m# Anahtar kelimeleri çıkar ve sonuçları al\u001b[39;00m\n\u001b[1;32m---> 53\u001b[0m top_keywords_per_document, top_tfidf_scores_per_document \u001b[38;5;241m=\u001b[39m \u001b[43mextract_keywords_tfidf\u001b[49m\u001b[43m(\u001b[49m\u001b[43mcombined\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mstop_words_list\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtop_n\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;241;43m10\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mn_jobs\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;241;43m-\u001b[39;49m\u001b[38;5;241;43m1\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[0;32m 55\u001b[0m \u001b[38;5;66;03m# Sonuçları görüntüleme\u001b[39;00m\n\u001b[0;32m 56\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m i, (keywords, scores) \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28menumerate\u001b[39m(\u001b[38;5;28mzip\u001b[39m(top_keywords_per_document, top_tfidf_scores_per_document)):\n",
312
- "Cell \u001b[1;32mIn[5], line 45\u001b[0m, in \u001b[0;36mextract_keywords_tfidf\u001b[1;34m(combined, stop_words_list, top_n, n_jobs)\u001b[0m\n\u001b[0;32m 42\u001b[0m top_tfidf_scores \u001b[38;5;241m=\u001b[39m [tfidf_scores[i] \u001b[38;5;28;01mfor\u001b[39;00m i \u001b[38;5;129;01min\u001b[39;00m top_indices]\n\u001b[0;32m 43\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m top_keywords, top_tfidf_scores\n\u001b[1;32m---> 45\u001b[0m results \u001b[38;5;241m=\u001b[39m \u001b[43mParallel\u001b[49m\u001b[43m(\u001b[49m\u001b[43mn_jobs\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mn_jobs\u001b[49m\u001b[43m)\u001b[49m\u001b[43m(\u001b[49m\u001b[43mdelayed\u001b[49m\u001b[43m(\u001b[49m\u001b[43mprocess_row\u001b[49m\u001b[43m)\u001b[49m\u001b[43m(\u001b[49m\u001b[43mrow\u001b[49m\u001b[43m)\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mfor\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mrow\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;129;43;01min\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mX\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 47\u001b[0m \u001b[38;5;66;03m# Sonuçları listelere ayırma\u001b[39;00m\n\u001b[0;32m 48\u001b[0m top_keywords_per_document, top_tfidf_scores_per_document \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mzip\u001b[39m(\u001b[38;5;241m*\u001b[39mresults)\n",
313
- "File \u001b[1;32mc:\\gitProjects\\yeni\\.venv\\lib\\site-packages\\joblib\\parallel.py:2007\u001b[0m, in \u001b[0;36mParallel.__call__\u001b[1;34m(self, iterable)\u001b[0m\n\u001b[0;32m 2001\u001b[0m \u001b[38;5;66;03m# The first item from the output is blank, but it makes the interpreter\u001b[39;00m\n\u001b[0;32m 2002\u001b[0m \u001b[38;5;66;03m# progress until it enters the Try/Except block of the generator and\u001b[39;00m\n\u001b[0;32m 2003\u001b[0m \u001b[38;5;66;03m# reaches the first `yield` statement. This starts the asynchronous\u001b[39;00m\n\u001b[0;32m 2004\u001b[0m \u001b[38;5;66;03m# dispatch of the tasks to the workers.\u001b[39;00m\n\u001b[0;32m 2005\u001b[0m \u001b[38;5;28mnext\u001b[39m(output)\n\u001b[1;32m-> 2007\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m output \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mreturn_generator \u001b[38;5;28;01melse\u001b[39;00m \u001b[38;5;28;43mlist\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43moutput\u001b[49m\u001b[43m)\u001b[49m\n",
314
- "File \u001b[1;32mc:\\gitProjects\\yeni\\.venv\\lib\\site-packages\\joblib\\parallel.py:1650\u001b[0m, in \u001b[0;36mParallel._get_outputs\u001b[1;34m(self, iterator, pre_dispatch)\u001b[0m\n\u001b[0;32m 1647\u001b[0m \u001b[38;5;28;01myield\u001b[39;00m\n\u001b[0;32m 1649\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_backend\u001b[38;5;241m.\u001b[39mretrieval_context():\n\u001b[1;32m-> 1650\u001b[0m \u001b[38;5;28;01myield from\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_retrieve()\n\u001b[0;32m 1652\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mGeneratorExit\u001b[39;00m:\n\u001b[0;32m 1653\u001b[0m \u001b[38;5;66;03m# The generator has been garbage collected before being fully\u001b[39;00m\n\u001b[0;32m 1654\u001b[0m \u001b[38;5;66;03m# consumed. This aborts the remaining tasks if possible and warn\u001b[39;00m\n\u001b[0;32m 1655\u001b[0m \u001b[38;5;66;03m# the user if necessary.\u001b[39;00m\n\u001b[0;32m 1656\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_exception \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mTrue\u001b[39;00m\n",
315
- "File \u001b[1;32mc:\\gitProjects\\yeni\\.venv\\lib\\site-packages\\joblib\\parallel.py:1762\u001b[0m, in \u001b[0;36mParallel._retrieve\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 1757\u001b[0m \u001b[38;5;66;03m# If the next job is not ready for retrieval yet, we just wait for\u001b[39;00m\n\u001b[0;32m 1758\u001b[0m \u001b[38;5;66;03m# async callbacks to progress.\u001b[39;00m\n\u001b[0;32m 1759\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m ((\u001b[38;5;28mlen\u001b[39m(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_jobs) \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m0\u001b[39m) \u001b[38;5;129;01mor\u001b[39;00m\n\u001b[0;32m 1760\u001b[0m (\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_jobs[\u001b[38;5;241m0\u001b[39m]\u001b[38;5;241m.\u001b[39mget_status(\n\u001b[0;32m 1761\u001b[0m timeout\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mtimeout) \u001b[38;5;241m==\u001b[39m TASK_PENDING)):\n\u001b[1;32m-> 1762\u001b[0m \u001b[43mtime\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43msleep\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m0.01\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[0;32m 1763\u001b[0m \u001b[38;5;28;01mcontinue\u001b[39;00m\n\u001b[0;32m 1765\u001b[0m \u001b[38;5;66;03m# We need to be careful: the job list can be filling up as\u001b[39;00m\n\u001b[0;32m 1766\u001b[0m \u001b[38;5;66;03m# we empty it and Python list are not thread-safe by\u001b[39;00m\n\u001b[0;32m 1767\u001b[0m \u001b[38;5;66;03m# default hence the use of the lock\u001b[39;00m\n",
316
- "\u001b[1;31mKeyboardInterrupt\u001b[0m: "
317
- ]
318
  }
319
  ],
320
  "source": [
@@ -322,10 +258,13 @@
322
  "import pandas as pd\n",
323
  "from sklearn.feature_extraction.text import TfidfVectorizer\n",
324
  "from joblib import Parallel, delayed\n",
 
 
 
325
  "\n",
326
  "\n",
327
  "# CSV dosyasını okuma\n",
328
- "df = pd.read_csv('combined_texts.csv')\n",
329
  "combined = df['combined'].tolist()\n",
330
  "\n",
331
  "\n",
@@ -371,18 +310,18 @@
371
  "\n",
372
  "def clean_data(file_path):\n",
373
  " \"\"\"CSV dosyasını okur ve veriyi düzenler.\"\"\"\n",
374
- " with open(file_path, 'r') as file:\n",
375
  " raw_text = file.read()\n",
376
  " \n",
377
  " data = parse_text(raw_text)\n",
378
  " \n",
379
  " # Veri çerçevesi oluştur\n",
380
- " df = pd.DataFrame(data, columns=['kaynakça'])\n",
381
  " \n",
382
  " return df\n",
383
  "\n",
384
  "# CSV dosyasını temizleyip düzenli bir DataFrame oluştur\n",
385
- "cleaned_df = clean_data('combined_texts.csv')\n",
386
  "\n",
387
  "# Düzenlenmiş veriyi kontrol et\n",
388
  "print(cleaned_df.head())\n",
@@ -405,7 +344,7 @@
405
  " top_tfidf_scores = [tfidf_scores[i] for i in top_indices]\n",
406
  " return top_keywords, top_tfidf_scores\n",
407
  "\n",
408
- " results = Parallel(n_jobs=n_jobs)(delayed(process_row)(row) for row in X)\n",
409
  "\n",
410
  " # Sonuçları listelere ayırma\n",
411
  " top_keywords_per_document, top_tfidf_scores_per_document = zip(*results)\n",
@@ -413,14 +352,81 @@
413
  " return top_keywords_per_document, top_tfidf_scores_per_document\n",
414
  "\n",
415
  "# Anahtar kelimeleri çıkar ve sonuçları al\n",
416
- "top_keywords_per_document, top_tfidf_scores_per_document = extract_keywords_tfidf(combined, stop_words_list, top_n=10, n_jobs=-1)\n",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
417
  "\n",
 
 
418
  "# Sonuçları görüntüleme\n",
419
  "for i, (keywords, scores) in enumerate(zip(top_keywords_per_document, top_tfidf_scores_per_document)):\n",
420
  " print(f\"Döküman {i+1}:\")\n",
421
  " for keyword, score in zip(keywords, scores):\n",
422
  " print(f\"{keyword}: {score:.4f}\")\n",
423
- " print(\"\\n\")\n"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
424
  ]
425
  },
426
  {
@@ -437,23 +443,18 @@
437
  "keyword_embeddings = model.encode(top_keywords_per_document)\n"
438
  ]
439
  },
 
 
 
 
 
 
 
440
  {
441
  "cell_type": "code",
442
- "execution_count": 3,
443
  "metadata": {},
444
- "outputs": [
445
- {
446
- "name": "stdout",
447
- "output_type": "stream",
448
- "text": [
449
- "Keyword: bir, Similarity: 0.26726124191242445\n",
450
- "Keyword: anahtar, Similarity: 0.26726124191242445\n",
451
- "Keyword: kelimeleri, Similarity: 0.26726124191242445\n",
452
- "Keyword: test, Similarity: 0.26726124191242445\n",
453
- "Keyword: başka, Similarity: 0.0\n"
454
- ]
455
- }
456
- ],
457
  "source": [
458
  "from sklearn.feature_extraction.text import TfidfVectorizer\n",
459
  "from sklearn.metrics.pairwise import cosine_similarity\n",
@@ -481,6 +482,8 @@
481
  "\n",
482
  "# Örnek metin ve anahtar kelimeler\n",
483
  "#combined verileri \n",
 
 
484
  "text = \"Bu bir örnek metindir ve bu metin üzerinde anahtar kelimeleri test ediyoruz.\"\n",
485
  "keywords = [\"başka\", \"bir\", \"anahtar\", \"kelimeleri\", \"test\"] #bu keywordsler tf-değerinden alınarak arraylere çevrilmeli \n",
486
  " \n",
@@ -497,20 +500,79 @@
497
  },
498
  {
499
  "cell_type": "code",
500
- "execution_count": 10,
501
  "metadata": {},
502
- "outputs": [
503
- {
504
- "data": {
505
- "text/plain": [
506
- "<function __main__.process_texts(combined_texts, stop_words_list, top_n)>"
507
- ]
508
- },
509
- "execution_count": 10,
510
- "metadata": {},
511
- "output_type": "execute_result"
512
- }
513
- ],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
514
  "source": [
515
  "\n",
516
  "# BERT Tokenizer ve Model'i yükleyin\n",
@@ -575,17 +637,9 @@
575
  },
576
  {
577
  "cell_type": "code",
578
- "execution_count": 5,
579
  "metadata": {},
580
- "outputs": [
581
- {
582
- "name": "stdout",
583
- "output_type": "stream",
584
- "text": [
585
- "combined metinler 'combined_texts.csv' dosyasına başarıyla yazıld��.\n"
586
- ]
587
- }
588
- ],
589
  "source": [
590
  "#mongodb üzerinden combined_textleri çek\n",
591
  "import csv\n",
@@ -824,13 +878,197 @@
824
  " print(f\"Keyword: {keyword}, Similarity: {similarity}\")"
825
  ]
826
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
827
  {
828
  "cell_type": "code",
829
  "execution_count": null,
830
  "metadata": {},
831
  "outputs": [],
832
  "source": [
833
- " "
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
834
  ]
835
  }
836
  ],
 
9
  },
10
  {
11
  "cell_type": "code",
12
+ "execution_count": 1,
13
  "metadata": {},
14
  "outputs": [],
15
  "source": [
 
40
  },
41
  {
42
  "cell_type": "code",
43
+ "execution_count": 2,
44
  "metadata": {},
45
  "outputs": [],
46
  "source": [
 
138
  ]
139
  },
140
  {
141
+ "cell_type": "markdown",
 
142
  "metadata": {},
143
+ "source": [
144
+ "Metinleri Kısaltma Fonksiyonu (processed_data kaydetme)"
145
+ ]
146
  },
147
  {
148
  "cell_type": "code",
149
+ "execution_count": null,
150
  "metadata": {},
151
  "outputs": [],
152
  "source": [
 
204
  "save_to_csv(truncated_texts, output_file)\n"
205
  ]
206
  },
 
 
 
 
 
 
 
207
  {
208
  "cell_type": "markdown",
209
  "metadata": {},
 
213
  },
214
  {
215
  "cell_type": "code",
216
+ "execution_count": 9,
217
  "metadata": {},
218
  "outputs": [
219
  {
220
+ "name": "stdout",
221
  "output_type": "stream",
222
  "text": [
223
+ " 0 1 2 3 4 5 \\\n",
224
+ "0 1992 Hitachi Football League 6 0 \n",
225
+ "1 6 0 None None \n",
226
+ "2 1993 rowspan=\"\"3\"\" Kashiwa Reysol rowspan=\"\"2\"\" Football League \n",
227
+ "3 1994 0 0 0 0 \n",
228
+ "4 1995 J1 League 17 1 2 \n",
229
+ "\n",
230
+ " 6 7 8 9 ... 204 205 206 207 \\\n",
231
+ "0 colspan=\"\"2\"\" None None None ... None None None None \n",
232
+ "1 None None None None ... None None None None \n",
233
+ "2 12 5 1 0 ... None None None None \n",
234
+ "3 0 0 0 0 ... None None None None \n",
235
+ "4 0 colspan=\"\"2\"\" None None ... None None None None \n",
236
+ "\n",
237
+ " 208 209 210 211 212 213 \n",
238
+ "0 None None None None None None \n",
239
+ "1 None None None None None None \n",
240
+ "2 None None None None None None \n",
241
+ "3 None None None None None None \n",
242
+ "4 None None None None None None \n",
243
+ "\n",
244
+ "[5 rows x 214 columns]\n"
245
  ]
246
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
247
  {
248
  "name": "stderr",
249
  "output_type": "stream",
 
251
  "c:\\gitProjects\\yeni\\.venv\\lib\\site-packages\\sklearn\\feature_extraction\\text.py:406: UserWarning: Your stop_words may be inconsistent with your preprocessing. Tokenizing the stop words generated tokens ['leh'] not in stop_words.\n",
252
  " warnings.warn(\n"
253
  ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
254
  }
255
  ],
256
  "source": [
 
258
  "import pandas as pd\n",
259
  "from sklearn.feature_extraction.text import TfidfVectorizer\n",
260
  "from joblib import Parallel, delayed\n",
261
+ "from tqdm import tqdm\n",
262
+ "import csv\n",
263
+ "\n",
264
  "\n",
265
  "\n",
266
  "# CSV dosyasını okuma\n",
267
+ "df = pd.read_csv('processed_data.csv')\n",
268
  "combined = df['combined'].tolist()\n",
269
  "\n",
270
  "\n",
 
310
  "\n",
311
  "def clean_data(file_path):\n",
312
  " \"\"\"CSV dosyasını okur ve veriyi düzenler.\"\"\"\n",
313
+ " with open(file_path, 'r',encoding='utf-8') as file:\n",
314
  " raw_text = file.read()\n",
315
  " \n",
316
  " data = parse_text(raw_text)\n",
317
  " \n",
318
  " # Veri çerçevesi oluştur\n",
319
+ " df = pd.DataFrame(data)\n",
320
  " \n",
321
  " return df\n",
322
  "\n",
323
  "# CSV dosyasını temizleyip düzenli bir DataFrame oluştur\n",
324
+ "cleaned_df = clean_data('processed_data.csv')\n",
325
  "\n",
326
  "# Düzenlenmiş veriyi kontrol et\n",
327
  "print(cleaned_df.head())\n",
 
344
  " top_tfidf_scores = [tfidf_scores[i] for i in top_indices]\n",
345
  " return top_keywords, top_tfidf_scores\n",
346
  "\n",
347
+ " results = Parallel(n_jobs=n_jobs)(delayed(process_row)(row) for row in tqdm(X))\n",
348
  "\n",
349
  " # Sonuçları listelere ayırma\n",
350
  " top_keywords_per_document, top_tfidf_scores_per_document = zip(*results)\n",
 
352
  " return top_keywords_per_document, top_tfidf_scores_per_document\n",
353
  "\n",
354
  "# Anahtar kelimeleri çıkar ve sonuçları al\n",
355
+ "# İlk 100 dökümanı işleyin\n",
356
+ "combined_sample = combined[:400000]\n",
357
+ "top_keywords_per_document, top_tfidf_scores_per_document = extract_keywords_tfidf(combined_sample, stop_words_list, top_n=10, n_jobs=-1)\n",
358
+ "#n__jobs ın 2 olması aynı anda iki iş parçacığı yani iki işlem yanı anda yürütülür \n",
359
+ "#n__jobs ın -1 olması maksimum işlemci sayısının kullanılmasıdır.\n",
360
+ "\n",
361
+ "#Sonuçları CSV dosyasına kaydetme\n",
362
+ "with open('keywords_with_scores.csv', mode='w', newline='', encoding='utf-8') as file:\n",
363
+ " writer = csv.writer(file)\n",
364
+ " # Başlık satırını yazma\n",
365
+ " writer.writerow(['Document_Index'] + [f'Keyword_{i+1}' for i in range(10)] + [f'Score_{i+1}' for i in range(10)])\n",
366
+ " \n",
367
+ " # Her döküman için anahtar kelimeler ve skorları yazma\n",
368
+ " for i, (keywords, scores) in enumerate(zip(top_keywords_per_document, top_tfidf_scores_per_document)):\n",
369
+ " row = [i+1] + keywords + [f\"{score:.4f}\" for score in scores]\n",
370
+ " writer.writerow(row)\n",
371
  "\n",
372
+ "print(\"Sonuçlar 'keywords_with_scores.csv' dosyasına kaydedildi.\")\n",
373
+ "\"\"\"\n",
374
  "# Sonuçları görüntüleme\n",
375
  "for i, (keywords, scores) in enumerate(zip(top_keywords_per_document, top_tfidf_scores_per_document)):\n",
376
  " print(f\"Döküman {i+1}:\")\n",
377
  " for keyword, score in zip(keywords, scores):\n",
378
  " print(f\"{keyword}: {score:.4f}\")\n",
379
+ " print(\"\\n\")\n",
380
+ "\"\"\""
381
+ ]
382
+ },
383
+ {
384
+ "cell_type": "markdown",
385
+ "metadata": {},
386
+ "source": [
387
+ "Buradaki keywords ve skorlar yukarıda çekildi."
388
+ ]
389
+ },
390
+ {
391
+ "cell_type": "code",
392
+ "execution_count": null,
393
+ "metadata": {},
394
+ "outputs": [],
395
+ "source": [
396
+ "import pandas as pd\n",
397
+ "import csv\n",
398
+ "\n",
399
+ "# Anahtar kelimeleri ve TF-IDF skorlarını çekme\n",
400
+ "top_keywords_per_document, top_tfidf_scores_per_document = extract_keywords_tfidf(combined, stop_words_list, top_n=10, n_jobs=-1)\n",
401
+ "\n",
402
+ "# Sonuçları tablo şeklinde hazırlama\n",
403
+ "results_top = []\n",
404
+ "for keywords, scores in zip(top_keywords_per_document, top_tfidf_scores_per_document):\n",
405
+ " row = {}\n",
406
+ " for i, (keyword, score) in enumerate(zip(keywords, scores)):\n",
407
+ " row[f'Keyword_{i+1}'] = keyword\n",
408
+ " row[f'Score_{i+1}'] = score\n",
409
+ " results_top.append(row)\n",
410
+ "\n",
411
+ "# Sonuçları DataFrame'e dönüştürme\n",
412
+ "df = pd.DataFrame(results_top)\n",
413
+ "\n",
414
+ "# Sonuçları CSV'ye kaydetme\n",
415
+ "df.to_csv('keywords_with_scores.csv', index=False, encoding='utf-8')\n",
416
+ "\n",
417
+ "chunksize = 1000 # Küçük bir parça boyutu belirleyin\n",
418
+ "for i in range(0, len(df), chunksize):\n",
419
+ " df.iloc[i:i+chunksize].to_csv('keywords_with_scores.csv', mode='a', header=(i==0), index=False, encoding='utf-8')\n",
420
+ "\n",
421
+ "# Sonuçları terminalde görüntüleme\n",
422
+ "print(df.head())\n"
423
+ ]
424
+ },
425
+ {
426
+ "cell_type": "markdown",
427
+ "metadata": {},
428
+ "source": [
429
+ "Encoding yapmak için"
430
  ]
431
  },
432
  {
 
443
  "keyword_embeddings = model.encode(top_keywords_per_document)\n"
444
  ]
445
  },
446
+ {
447
+ "cell_type": "markdown",
448
+ "metadata": {},
449
+ "source": [
450
+ "Text ve keywords similarity denemesi"
451
+ ]
452
+ },
453
  {
454
  "cell_type": "code",
455
+ "execution_count": null,
456
  "metadata": {},
457
+ "outputs": [],
 
 
 
 
 
 
 
 
 
 
 
 
458
  "source": [
459
  "from sklearn.feature_extraction.text import TfidfVectorizer\n",
460
  "from sklearn.metrics.pairwise import cosine_similarity\n",
 
482
  "\n",
483
  "# Örnek metin ve anahtar kelimeler\n",
484
  "#combined verileri \n",
485
+ "\n",
486
+ "\n",
487
  "text = \"Bu bir örnek metindir ve bu metin üzerinde anahtar kelimeleri test ediyoruz.\"\n",
488
  "keywords = [\"başka\", \"bir\", \"anahtar\", \"kelimeleri\", \"test\"] #bu keywordsler tf-değerinden alınarak arraylere çevrilmeli \n",
489
  " \n",
 
500
  },
501
  {
502
  "cell_type": "code",
503
+ "execution_count": null,
504
  "metadata": {},
505
+ "outputs": [],
506
+ "source": [
507
+ "from sklearn.feature_extraction.text import TfidfVectorizer\n",
508
+ "from sklearn.metrics.pairwise import cosine_similarity\n",
509
+ "# Örnek metin ve anahtar kelimeler\n",
510
+ "#combined verileri \n",
511
+ "def get_text(file_path='processed_data.csv'):\n",
512
+ " \"\"\"CSV dosyasını okur ve veriyi düzenler.\"\"\"\n",
513
+ " with open(file_path, 'r',encoding='utf-8') as file:\n",
514
+ " raw_text = file.read()\n",
515
+ " \n",
516
+ " text = parse_text(raw_text)\n",
517
+ " \n",
518
+ " # Veri çerçevesi oluştur\n",
519
+ " df_text = pd.DataFrame(text)\n",
520
+ " \n",
521
+ " return df_text\n",
522
+ "\n",
523
+ "def get_keywords(file_path='keywords_with_scores.csv'):\n",
524
+ " \"\"\"CSV dosyasını okur ve veriyi düzenler.\"\"\"\n",
525
+ " with open(file_path, 'r',encoding='utf-8') as file:\n",
526
+ " raw_text = file.read()\n",
527
+ " \n",
528
+ " keywords = parse_text(raw_text)\n",
529
+ " \n",
530
+ " # Veri çerçevesi oluştur\n",
531
+ " df_keyword = pd.DataFrame(keywords)\n",
532
+ " \n",
533
+ " return df_keyword\n",
534
+ "\n",
535
+ "\n",
536
+ "def calculate_keyword_similarity(text, keywords):\n",
537
+ " # TF-IDF matrisini oluştur\n",
538
+ " tfidf_vectorizer = TfidfVectorizer()\n",
539
+ "\n",
540
+ " #texti ve anahtar kelimeleri tf-ıdf vektörlerine dönüştür\n",
541
+ " text_tfidf = tfidf_vectorizer.fit_transform(text) #burayı combined sütunundan almalıyım\n",
542
+ " #benzerlik hesaplama \n",
543
+ " similarity_array = []\n",
544
+ " for keyword in keywords:\n",
545
+ " # Her bir anahtar kelimeyi TF-IDF vektörüne dönüştür\n",
546
+ " keyword_tfidf = tfidf_vectorizer.transform([keyword]) #keywordleri teker teker alma fonksiyonu\n",
547
+ " \n",
548
+ " # Cosine similarity ile benzerlik hesapla\n",
549
+ " similarity = cosine_similarity(text_tfidf, keyword_tfidf)[0][0]\n",
550
+ " \n",
551
+ " # Anahtar kelime ve benzerlik skorunu kaydet\n",
552
+ " similarity_array.append((keyword, similarity))\n",
553
+ " \n",
554
+ " return similarity_array\n",
555
+ " \n",
556
+ "\n",
557
+ "\n",
558
+ "\n",
559
+ " \n",
560
+ "# Uygunluk skorunu hesapla\n",
561
+ "similarity_results = calculate_keyword_similarity(text, keywords)\n",
562
+ "top_5_keywords = sorted(similarity_results, key=lambda x: x[1], reverse=True)[:5]\n",
563
+ "# Her bir anahtar kelimenin uyumluluk skorunu yazdır\n",
564
+ "\n",
565
+ "for keyword, similarity in top_5_keywords:\n",
566
+ " print(f\"Keyword: {keyword}, Similarity: {similarity}\")\n",
567
+ " #print(f\"Keyword: '{keyword}' - Relevance score: {score:.4f}\")\n",
568
+ "\n"
569
+ ]
570
+ },
571
+ {
572
+ "cell_type": "code",
573
+ "execution_count": null,
574
+ "metadata": {},
575
+ "outputs": [],
576
  "source": [
577
  "\n",
578
  "# BERT Tokenizer ve Model'i yükleyin\n",
 
637
  },
638
  {
639
  "cell_type": "code",
640
+ "execution_count": null,
641
  "metadata": {},
642
+ "outputs": [],
 
 
 
 
 
 
 
 
643
  "source": [
644
  "#mongodb üzerinden combined_textleri çek\n",
645
  "import csv\n",
 
878
  " print(f\"Keyword: {keyword}, Similarity: {similarity}\")"
879
  ]
880
  },
881
+ {
882
+ "cell_type": "markdown",
883
+ "metadata": {},
884
+ "source": [
885
+ "Title değerini bir dataframe' e dönüştürür."
886
+ ]
887
+ },
888
+ {
889
+ "cell_type": "code",
890
+ "execution_count": 4,
891
+ "metadata": {},
892
+ "outputs": [
893
+ {
894
+ "name": "stdout",
895
+ "output_type": "stream",
896
+ "text": [
897
+ "metin başlıkları 'titles_texts.csv' dosyasına başarıyla yazıldı.\n",
898
+ " title\n",
899
+ "0 Pşıqo Ahecaqo\n",
900
+ "1 Craterolophinae\n",
901
+ "2 Notocrabro\n",
902
+ "3 Ibrahim Sissoko\n",
903
+ "4 Salah Cedid\n"
904
+ ]
905
+ }
906
+ ],
907
+ "source": [
908
+ "from pymongo import MongoClient\n",
909
+ "import pandas as pd\n",
910
+ "import csv\n",
911
+ "\n",
912
+ "# MongoDB'ye bağlanma\n",
913
+ "\n",
914
+ "def get_titles(database_name='combined_text', collection_name='text', host='localhost', port=27017,batch_size=1000,output_file='titles_texts.csv'):\n",
915
+ " client = MongoClient(f'mongodb://{host}:{port}/')\n",
916
+ " db = client[database_name]\n",
917
+ " collection = db[collection_name]\n",
918
+ " \n",
919
+ " #toplam döküman sayısını al\n",
920
+ " total_documents = collection.count_documents({})\n",
921
+ " #batch_documents = []\n",
922
+ "\n",
923
+ "\n",
924
+ " # MongoDB'den sadece title alanlarını çekme\n",
925
+ " titles = collection.find({}, {\"_id\": 0, \"title\": 1})\n",
926
+ "\n",
927
+ " # Verileri liste haline getirme ve DataFrame'e dönüştürme\n",
928
+ " df = pd.DataFrame(list(titles))\n",
929
+ "\n",
930
+ " \n",
931
+ " # CSV dosyasını aç ve yazmaya hazırla\n",
932
+ " with open(output_file, mode='w', newline='', encoding='utf-8') as file:\n",
933
+ " writer = csv.writer(file)\n",
934
+ " writer.writerow([\"titles\"]) # CSV başlığı\n",
935
+ "\n",
936
+ " # Belirtilen batch_size kadar dökümanları almak için döngü\n",
937
+ " for i in range(0, total_documents, batch_size):\n",
938
+ " cursor = collection.find({}, {\"title\":1, \"_id\": 0}).skip(i).limit(batch_size)\n",
939
+ " combined_texts = [doc['title'] for doc in cursor if 'title' in doc] #combined sütununa ilişkin verileri çeker \n",
940
+ "\n",
941
+ " # Batch verilerini CSV'ye yaz\n",
942
+ " with open(output_file, mode='a', newline='', encoding='utf-8') as file:\n",
943
+ " writer = csv.writer(file)\n",
944
+ " \n",
945
+ " for text in combined_texts:\n",
946
+ " writer.writerow([text])\n",
947
+ " \n",
948
+ " \n",
949
+ "\n",
950
+ " print(f\"metin başlıkları '{output_file}' dosyasına başarıyla yazıldı.\")\n",
951
+ "\n",
952
+ " # DataFrame'i görüntüleme\n",
953
+ " print(df.head())\n",
954
+ "\n",
955
+ "# Dökümanları CSV dosyasına yazdır\n",
956
+ "text=get_titles(batch_size=5000)\n",
957
+ " #batch_documents.extend((combined_texts, len(combined_texts)))\n",
958
+ " #append fonksiyonu listenin içerisine tek bir eleman gibi ekler yani list1 = [1, 2, 3, [4, 5]]\n",
959
+ " #fakat extend fonksiyonu list1 = [1, 2, 3, 4, 5] bir listeye yeni bir liste eklemeyi teker teker gerçekleştirir.\n",
960
+ " #return batch_documents\n",
961
+ "\n",
962
+ "# Dökümanları ve döküman sayısını batch olarak çekin\n",
963
+ "#combined_texts = mongo_db_combined_texts(batch_size=1000)\n",
964
+ "\n",
965
+ "# Her batch'i ayrı ayrı işleyebilirsiniz\n",
966
+ "#print(f\"Toplam döküman sayısı:{len(combined_texts)}\")\n",
967
+ "\n",
968
+ "#for index, text in enumerate (combined_texts[:10]):\n",
969
+ " #print(f\"Döküman {index + 1}: {text}\")\n",
970
+ "\n",
971
+ "#print(combined_texts)\n",
972
+ "\n",
973
+ " \n",
974
+ "\n",
975
+ "\n",
976
+ "\n"
977
+ ]
978
+ },
979
+ {
980
+ "cell_type": "markdown",
981
+ "metadata": {},
982
+ "source": [
983
+ "Veri güncelleme "
984
+ ]
985
+ },
986
+ {
987
+ "cell_type": "code",
988
+ "execution_count": 6,
989
+ "metadata": {},
990
+ "outputs": [
991
+ {
992
+ "name": "stdout",
993
+ "output_type": "stream",
994
+ "text": [
995
+ " Document_Index Keyword_1 Keyword_2 Keyword_3 \\\n",
996
+ "0 1 ahecaqo pşıqo çerkes \n",
997
+ "1 2 craterolophinae depastridae craterolophus \n",
998
+ "2 3 notocrabro crabronina oymağına \n",
999
+ "3 4 sissoko wolfsburg panathinaikos \n",
1000
+ "4 5 baas cedid salah \n",
1001
+ "\n",
1002
+ " Keyword_4 Keyword_5 Keyword_6 Keyword_7 Keyword_8 Keyword_9 \\\n",
1003
+ "0 çerkesya 1777 savaşına lakapları qo bjeduğ \n",
1004
+ "1 altfamilyasıdır clark 1863 cinsler taksonomi 2023 \n",
1005
+ "2 cinstir bağlantılar kaynakça ghost ghetto ghez \n",
1006
+ "3 konyaspor deportivo étienne coruña kiralandı imzaladı \n",
1007
+ "4 1970 1993 1926 siyasetçiler fraksiyon bitar \n",
1008
+ "\n",
1009
+ " ... Score_1 Score_2 Score_3 Score_4 Score_5 Score_6 Score_7 Score_8 \\\n",
1010
+ "0 ... 0.5162 0.4130 0.3481 0.1903 0.1850 0.1740 0.1032 0.1032 \n",
1011
+ "1 ... 0.7030 0.4687 0.2343 0.2052 0.2011 0.1808 0.1745 0.1583 \n",
1012
+ "2 ... 0.6762 0.6762 0.2125 0.1782 0.0714 0.0588 0.0000 0.0000 \n",
1013
+ "3 ... 0.8107 0.2490 0.1245 0.1159 0.1159 0.1139 0.1121 0.1065 \n",
1014
+ "4 ... 0.5065 0.4892 0.2026 0.1679 0.1610 0.1403 0.1205 0.1062 \n",
1015
+ "\n",
1016
+ " Score_9 Score_10 \n",
1017
+ "0 0.1032 0.1032 \n",
1018
+ "1 0.1555 0.1458 \n",
1019
+ "2 0.0000 0.0000 \n",
1020
+ "3 0.0913 0.0896 \n",
1021
+ "4 0.1062 0.1062 \n",
1022
+ "\n",
1023
+ "[5 rows x 21 columns]\n"
1024
+ ]
1025
+ }
1026
+ ],
1027
+ "source": [
1028
+ "import pandas as pd\n",
1029
+ "\n",
1030
+ "# Örnek TF-IDF skoru ve anahtar kelimeler\n",
1031
+ "keyword_data = pd.read_csv('keywords_with_scores.csv')\n",
1032
+ "\n",
1033
+ "df = pd.DataFrame(keyword_data)\n",
1034
+ "print(df.head())\n"
1035
+ ]
1036
+ },
1037
  {
1038
  "cell_type": "code",
1039
  "execution_count": null,
1040
  "metadata": {},
1041
  "outputs": [],
1042
  "source": [
1043
+ "import pandas as pd\n",
1044
+ "from langdetect import detect, DetectorFactory\n",
1045
+ "\n",
1046
+ "DetectorFactory.seed = 0 # Her zaman aynı sonuçları almak için\n",
1047
+ "\n",
1048
+ "def is_turkish(text):\n",
1049
+ " try:\n",
1050
+ " return detect(text) == 'tr'\n",
1051
+ " except:\n",
1052
+ " return False\n",
1053
+ "\n",
1054
+ "def filter_turkish_keywords(text):\n",
1055
+ " if pd.isna(text):\n",
1056
+ " return [] # NaN değerleri boş liste olarak döndür\n",
1057
+ " keywords = text.split(',') # Anahtar kelimeleri virgülle ayır\n",
1058
+ " return [kw.strip() for kw in keywords if is_turkish(kw.strip())]\n",
1059
+ "\n",
1060
+ "# CSV dosyasını oku\n",
1061
+ "df = pd.read_csv('path_to_your_file.csv')\n",
1062
+ "\n",
1063
+ "# Anahtar kelime sütunlarını belirle\n",
1064
+ "keyword_columns = ['Keyword_1', 'Keyword_2', 'Keyword_3', 'Keyword_4', 'Keyword_5', \n",
1065
+ " 'Keyword_6', 'Keyword_7', 'Keyword_8', 'Keyword_9', 'Keyword_10']\n",
1066
+ "\n",
1067
+ "# Her anahtar kelime sütunu için Türkçe olanları filtrele\n",
1068
+ "for col in keyword_columns:\n",
1069
+ " df[f'{col}_Turkish'] = df[col].apply(filter_turkish_keywords)\n",
1070
+ "\n",
1071
+ "print(df.head())\n"
1072
  ]
1073
  }
1074
  ],