Skip to content

Commit

Permalink
simplifying the code of detection based on digits
Browse files Browse the repository at this point in the history
  • Loading branch information
harjinder7 committed Nov 8, 2022
1 parent 81a0592 commit 414600d
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions ner_v2/detectors/numeral/number/zh-TW/number_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def _filter_base_numbers_map(self):
def _have_digits_only(self, text=None, scale_map=None):
text = text or ''
scale_map = scale_map or {}

scaling_digits = set(list(scale_map.keys()))
only_digits = True
for _digit in text:
Expand Down Expand Up @@ -113,12 +113,10 @@ def _detect_number_from_text(self, number_list=None, original_list=None):
start_span = end_span + span[0]
end_span += span[1]
spanned_text = spanned_text[span[1]:]
if self._have_digits_only(original_text, self.scale_map):
number = self.get_number_digit_by_digit(original_text)
else:
number = self.get_number_with_digit_scaling(original_text)
number = self.get_number(original_text)
if number.isnumeric():
full_number = number

if full_number:
_pattern = re.compile(re.escape(original_text), flags=_re_flags)
if _pattern.search(processed_text):
Expand All @@ -131,6 +129,11 @@ def _detect_number_from_text(self, number_list=None, original_list=None):
original_list.append(original_text)
return number_list, original_list

def get_number(self, original_text):
if self._have_digits_only(original_text, self.scale_map):
return self.get_number_digit_by_digit(original_text)
return self.get_number_with_digit_scaling(original_text)

def extract_digits_only(self, text, with_scale=False):
text = text or ''
rgx_pattern = r'[-,.+\s{}]+'
Expand Down

0 comments on commit 414600d

Please sign in to comment.