Skip to content

Commit

Permalink
resolving lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
harjinder7 committed Nov 8, 2022
1 parent 297eb9b commit 81a0592
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 19 deletions.
4 changes: 2 additions & 2 deletions ner_v2/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -636,10 +636,10 @@ def phone_number(request):

if language == CHINESE_TRADITIONAL_LANG:
phone_number_detection = ChinesePhoneDetector(entity_name=entity_name, language=language,
locale=parameters_dict[PARAMETER_LOCALE])
locale=parameters_dict[PARAMETER_LOCALE])
else:
phone_number_detection = PhoneDetector(entity_name=entity_name, language=language,
locale=parameters_dict[PARAMETER_LOCALE])
locale=parameters_dict[PARAMETER_LOCALE])
message = parameters_dict[PARAMETER_MESSAGE]

ner_logger.debug(parameters_dict)
Expand Down
26 changes: 11 additions & 15 deletions ner_v2/detectors/numeral/number/zh-TW/number_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ def __init__(self, entity_name='number', unit_type=None):
]

self.special_chars_mapping = {
',': '、', # comma character
'.': '點' #dian ( period )
',': '、',
'.': '點'
}

def _get_base_map_choices(self, base_map):
Expand All @@ -63,7 +63,7 @@ def _filter_base_numbers_map(self):
if 0 <= v <= 9:
new_base_numbers_map[k] = v
self.base_numbers_map = new_base_numbers_map

def _have_digits_only(self, text=None, scale_map=None):
text = text or ''
scale_map = scale_map or {}
Expand All @@ -75,13 +75,13 @@ def _have_digits_only(self, text=None, scale_map=None):
only_digits = False
break
return only_digits

def replace_special_chars(self, text=None):
text = text or ''
for _char, _native_char in self.special_chars_mapping.items():
text = text.replace(_native_char, _char)
return text

def _detect_number_from_text(self, number_list=None, original_list=None):
"""
extract out the numbers from chinese text ( roman as well as chinese )
Expand All @@ -98,16 +98,15 @@ def _detect_number_from_text(self, number_list=None, original_list=None):
processed_text = self.processed_text

# need to handle decimal points as well

rgx_pattern = r'([{}]+)({}?([{}]*))'.format(
self.base_numbers_map_full,
self.special_chars_mapping.get('.', '\.'),
self.special_chars_mapping.get('.', '.'),
self.base_numbers_map_full
)
regex_digit_patterns = re.compile(rgx_pattern)
patterns = regex_digit_patterns.findall(self.processed_text)
for pattern in patterns:
full_number, number, original_text = None, None, None
full_number, number, original_text = None, None, None
if pattern[0].strip():
original_text = pattern[0].strip()
span = re.search(original_text, spanned_text).span()
Expand All @@ -118,10 +117,8 @@ def _detect_number_from_text(self, number_list=None, original_list=None):
number = self.get_number_digit_by_digit(original_text)
else:
number = self.get_number_with_digit_scaling(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 @@ -133,7 +130,7 @@ def _detect_number_from_text(self, number_list=None, original_list=None):
})
original_list.append(original_text)
return number_list, original_list

def extract_digits_only(self, text, with_scale=False):
text = text or ''
rgx_pattern = r'[-,.+\s{}]+'
Expand All @@ -142,11 +139,10 @@ def extract_digits_only(self, text, with_scale=False):
else:
rgx_pattern = re.compile(rgx_pattern.format(self.base_numbers_map_choices_full))
return rgx_pattern.findall(text)

def get_number_digit_by_digit(self, text=''):
return ''.join([str(self.base_numbers_map.get(_t, _t)) for _t in text])

def get_number_with_digit_scaling(self, text=''):
# change the below logic to work with scaling
return text

return text
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ def check_for_country_code(self, phone_num):

return phone_dict


class ChinesePhoneDetector(PhoneDetector):
"""
This method is used to detect phone numbers present in chinese text.
Expand All @@ -168,7 +169,7 @@ def __init__(self, entity_name, language=CHINESE_TRADITIONAL_LANG, locale=None):
"""
self._supported_languages = NumberDetector.get_supported_languages()
super(ChinesePhoneDetector, self).__init__(entity_name, language, locale)

# Using Chinese number detector here
self.number_detector = NumberDetector(self.entity_name, language=self.language)
self.language_number_detector = self.number_detector.get_language_number_detector()
Expand Down Expand Up @@ -201,6 +202,6 @@ def detect_entity(self, text, **kwargs):
else:
# This means our detector has detected some other country code.
self.phone.append({"country_calling_code": str(match.number.country_code),
"value": str(match.number.national_number)})
"value": str(match.number.national_number)})
self.original_phone_text.append(original_text[match.start:match.end])
return self.phone, self.original_phone_text

0 comments on commit 81a0592

Please sign in to comment.