m3hrdadfi commited on
Commit
8918872
2 Parent(s): 4350a5a a749413

Merge remote-tracking branch 'origin/saied' into develop

Browse files
Files changed (2) hide show
  1. src/data_utils.py +8 -0
  2. src/normalizer.py +8 -0
src/data_utils.py CHANGED
@@ -22,6 +22,14 @@ def filter_by_num_tokens(text, gt=64):
22
  def filter_by_num_sents(text, gt=2):
23
  return len(sent_tokenize(text)) > gt
24
 
 
 
 
 
 
 
 
 
25
 
26
  def normalizer(text, do_lowercase=False):
27
  text = normalize(text)
 
22
  def filter_by_num_sents(text, gt=2):
23
  return len(sent_tokenize(text)) > gt
24
 
25
+ def remove_adds(text,ratio=50):
26
+ comma = text.split(",")
27
+ colon = re.findall(r'(?:([^\W]+):([^\W]+))',text)
28
+ virgool = text.split("،")
29
+ length_add = len(comma)+len(colon)+len(virgool)
30
+
31
+ return True if length_add < ratio else False
32
+
33
 
34
  def normalizer(text, do_lowercase=False):
35
  text = normalize(text)
src/normalizer.py CHANGED
@@ -25,6 +25,13 @@ def multiple_replace(text, chars_to_mapping):
25
  pattern = "|".join(map(re.escape, chars_to_mapping.keys()))
26
  return re.sub(pattern, lambda m: chars_to_mapping[m.group()], str(text))
27
 
 
 
 
 
 
 
 
28
 
29
  def clean_url(text):
30
  # removing html tags
@@ -79,6 +86,7 @@ def normalize(text, zwnj="\u200c", tokenized=False):
79
  text = DOUBLE_QUOTE_REGEX.sub('"', text)
80
  text = CURRENCY_REGEX.sub(r" \1 ", text)
81
  text = clean_url(text)
 
82
  text = URL_REGEX.sub(" ", text)
83
  text = EMAIL_REGEX.sub(" ", text)
84
  text = PHONE_REGEX.sub(r" \1 ", text)
 
25
  pattern = "|".join(map(re.escape, chars_to_mapping.keys()))
26
  return re.sub(pattern, lambda m: chars_to_mapping[m.group()], str(text))
27
 
28
+ def remove_tags(text):
29
+ tag = "برچسب ها :"
30
+ try:
31
+ text = text[:text.index(tag)]
32
+ return text
33
+ except:
34
+ return text
35
 
36
  def clean_url(text):
37
  # removing html tags
 
86
  text = DOUBLE_QUOTE_REGEX.sub('"', text)
87
  text = CURRENCY_REGEX.sub(r" \1 ", text)
88
  text = clean_url(text)
89
+ text = remove_tags(text)
90
  text = URL_REGEX.sub(" ", text)
91
  text = EMAIL_REGEX.sub(" ", text)
92
  text = PHONE_REGEX.sub(r" \1 ", text)