-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcleaning.py
More file actions
75 lines (65 loc) · 1.94 KB
/
cleaning.py
File metadata and controls
75 lines (65 loc) · 1.94 KB
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
# metinlerde bulunan fazla boşluğu kaldırma
# %%
text =" Bu metin örneği fazla boşluk içeriyor. "
def remove_extra_whitespace(text):
"""
Remove extra whitespace from the text.
"""
return ' '.join(text.split())
remove_extra_whitespace(text)
# %%
text = "Bu MEtin Büyük küçük KÜÇÜK"
# buyuk harfleri küçük harfe çevirme
def convert_to_lowercase(text):
"""
Convert all characters in the text to lowercase.
"""
return text.lower()
convert_to_lowercase(text)
# %%
# noktalama işaretlerini kaldırma
text = "Bu metin, noktalama işaretleri içeriyor! Evet, gerçekten de; içeriyor."
import string
def remove_punctuation(text):
"""
Remove punctuation from the text.
"""
return text.translate(str.maketrans('', '', string.punctuation))
remove_punctuation(text)
# %%
# özel karakterleri kaldırma
import re
text = "Bu metin, özel karakterler içeriyor! @#&*()du##%"
def remove_special_characters(text):
"""
Remove special characters from the text.
"""
return ''.join(e for e in text if e.isalnum() or e.isspace())
cleanText = re.sub(r'[^a-zA-Z0-9\s]', '', text) # Remove special characters
print(cleanText)
print("------------------------")
remove_special_characters(text)
# %%
# yazım hatalarını düzeltme
from textblob import TextBlob
text = "this is a smaple text with speling erors."
def correct_spelling(text):
"""
Correct spelling errors in the text.
"""
return str(TextBlob(text).correct())
print(TextBlob(text).correct())
print("------------------------")
print(correct_spelling(text))
# %%
# html etiketlerini kaldırma
from bs4 import BeautifulSoup
html_text = "<p>Bu metin <strong>HTML</strong> etiketleri içeriyordu.</p>"
def remove_html_tags(text):
"""
Remove HTML tags from the text.
"""
soup = BeautifulSoup(text, "html.parser")# with bs parse and get text
return soup.get_text()
print(remove_html_tags(html_text))
# %%