Spaces:
Sleeping
Sleeping
Anis Taluqdar commited on
Commit ·
792f49a
1
Parent(s): 57cf97a
updated
Browse files
app.py
CHANGED
|
@@ -83,6 +83,34 @@ def remove_no_not(sentence):
|
|
| 83 |
return cleaned_sentence
|
| 84 |
|
| 85 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
|
| 87 |
def clean_text(text):
|
| 88 |
text = re.sub(r'[^\w\s]', '', text)
|
|
@@ -91,31 +119,34 @@ def clean_text(text):
|
|
| 91 |
return text
|
| 92 |
|
| 93 |
def main_func(sentence):
|
| 94 |
-
sentence = clean_text(sentence)
|
| 95 |
|
| 96 |
-
|
| 97 |
-
# print(removed_no_sentence)
|
| 98 |
|
| 99 |
-
|
|
|
|
| 100 |
print("Original:", sentence)
|
| 101 |
-
print("Modified:",
|
| 102 |
-
|
| 103 |
else:
|
| 104 |
-
|
| 105 |
-
print(
|
| 106 |
-
print("Modified:", modified_sentence)
|
| 107 |
|
| 108 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
demo = gr.Interface(title="POS/NEG Sentence APP", fn=main_func, inputs="text", outputs="text", css="footer {visibility: hidden}", examples=[
|
| 114 |
-
|
| 115 |
-
["
|
|
|
|
|
|
|
| 116 |
["Onion price is increasing"]])
|
| 117 |
|
| 118 |
if __name__ == "__main__":
|
| 119 |
demo.launch(show_api=False)
|
| 120 |
-
|
| 121 |
-
#["I don't like that food?"],
|
|
|
|
| 83 |
return cleaned_sentence
|
| 84 |
|
| 85 |
|
| 86 |
+
def transform_contractions(sentence):
|
| 87 |
+
|
| 88 |
+
contractions_mapping = {
|
| 89 |
+
"don't": "do",
|
| 90 |
+
"doesn't": "does",
|
| 91 |
+
"won't": "will",
|
| 92 |
+
"isn't": "is",
|
| 93 |
+
"aren't": "are",
|
| 94 |
+
"wasn't": "was",
|
| 95 |
+
"weren't": "were",
|
| 96 |
+
"haven't": "have",
|
| 97 |
+
"hasn't": "has",
|
| 98 |
+
"hadn't": "had",
|
| 99 |
+
"can't": "can",
|
| 100 |
+
"couldn't": "could",
|
| 101 |
+
"shouldn't": "should",
|
| 102 |
+
"mightn't": "might",
|
| 103 |
+
"mustn't": "must"
|
| 104 |
+
# Add any other contractions you need to handle
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
for contraction, replacement in contractions_mapping.items():
|
| 109 |
+
pattern = r'\b' + contraction + r'\b'
|
| 110 |
+
sentence = re.sub(pattern, replacement, sentence)
|
| 111 |
+
|
| 112 |
+
return sentence
|
| 113 |
+
|
| 114 |
|
| 115 |
def clean_text(text):
|
| 116 |
text = re.sub(r'[^\w\s]', '', text)
|
|
|
|
| 119 |
return text
|
| 120 |
|
| 121 |
def main_func(sentence):
|
|
|
|
| 122 |
|
| 123 |
+
# sentence = clean_text(sentence)
|
|
|
|
| 124 |
|
| 125 |
+
removed_dont = transform_contractions(sentence)
|
| 126 |
+
if len(removed_dont) != len(sentence):
|
| 127 |
print("Original:", sentence)
|
| 128 |
+
print("Modified:", removed_dont)
|
| 129 |
+
|
| 130 |
else:
|
| 131 |
+
removed_no_sentence = remove_no_not(sentence)
|
| 132 |
+
# print(removed_no_sentence)
|
|
|
|
| 133 |
|
| 134 |
+
if len(removed_no_sentence) != len(sentence):
|
| 135 |
+
return removed_no_sentence
|
| 136 |
+
else:
|
| 137 |
+
modified_sentence = modify_sentence(sentence)
|
| 138 |
+
return modified_sentence
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
demo = gr.Interface(title="POS/NEG Sentence APP", fn=main_func, inputs="text", outputs="text", css="footer {visibility: hidden}", examples=[
|
| 144 |
+
["I hate football"],
|
| 145 |
+
["Don't I like that food?"],
|
| 146 |
+
["I can't Swim"],
|
| 147 |
+
["it looks delicious"],
|
| 148 |
["Onion price is increasing"]])
|
| 149 |
|
| 150 |
if __name__ == "__main__":
|
| 151 |
demo.launch(show_api=False)
|
| 152 |
+
|
|
|