mginoben commited on
Commit
40a4fcd
1 Parent(s): 6e30a48

Added english words lookup

Browse files
Files changed (2) hide show
  1. app.py +6 -3
  2. requirements.txt +1 -0
app.py CHANGED
@@ -7,7 +7,9 @@ from thefuzz import process, fuzz
7
  import numpy as np
8
  import re
9
  from string import punctuation
10
- import time
 
 
11
 
12
 
13
  API_URL = "https://api-inference.huggingface.co/models/Dabid/abusive-tagalog-profanity-detection"
@@ -36,8 +38,8 @@ contractions = read_text('contractions', 'json')
36
  lookup_words = read_text('lookup_words')
37
  obj_pronouns = read_text('obj_pronouns')
38
  profanities = read_text('profanities', 'json')
 
39
 
40
- loading_countdown = 0
41
 
42
  def fuzzy_lookup(tweet):
43
 
@@ -45,6 +47,8 @@ def fuzzy_lookup(tweet):
45
  lookup_profanity = np.concatenate([np.hstack(list(profanities.values())), list(profanities.keys())])
46
 
47
  for word in tweet.split():
 
 
48
  scores = []
49
  matched_words = []
50
  word = word.strip(punctuation)
@@ -121,7 +125,6 @@ def preprocess(tweet):
121
 
122
 
123
  def predict(tweet):
124
- global loading_countdown
125
 
126
  preprocessed_tweet, matched_profanity = preprocess(tweet)
127
 
 
7
  import numpy as np
8
  import re
9
  from string import punctuation
10
+ import nltk
11
+ nltk.download('words')
12
+ from nltk.corpus import words
13
 
14
 
15
  API_URL = "https://api-inference.huggingface.co/models/Dabid/abusive-tagalog-profanity-detection"
 
38
  lookup_words = read_text('lookup_words')
39
  obj_pronouns = read_text('obj_pronouns')
40
  profanities = read_text('profanities', 'json')
41
+ eng_words = set(words.words())
42
 
 
43
 
44
  def fuzzy_lookup(tweet):
45
 
 
47
  lookup_profanity = np.concatenate([np.hstack(list(profanities.values())), list(profanities.keys())])
48
 
49
  for word in tweet.split():
50
+ if word in eng_words:
51
+ break
52
  scores = []
53
  matched_words = []
54
  word = word.strip(punctuation)
 
125
 
126
 
127
  def predict(tweet):
 
128
 
129
  preprocessed_tweet, matched_profanity = preprocess(tweet)
130
 
requirements.txt CHANGED
@@ -1,3 +1,4 @@
1
  emoji
2
  thefuzz[speedup]
3
  numpy
 
 
1
  emoji
2
  thefuzz[speedup]
3
  numpy
4
+ nltk