Skip to content

Commit

Permalink
[Python][Recognizers-Text] NumberWithUnit class Refactor (#1815)
Browse files Browse the repository at this point in the history
* Add fixes to matcher and add sequence

* Signature Migrations

* Add abstract_matcher signatures

* Change type of value to [srt]

* Add the matcher class into a new file

* Delete extra decorators & insert class

* Fix matcher implementation

* Add AANode methods implementation

* Add get_tokenized_text implementation

* Apply PR's feedback

* Fix autopep

* Add missing methods to AaNode class

* Add tests to string_matcher

* Add missing Init implementations using multipledispatch

* Finishing touches and implementation with passing tests

* Add Spanish-Portuguese-French

* Json spec fixes

* Feedback Applied

* Minor fixes of interfaces
  • Loading branch information
Maihav authored and tellarin committed Aug 23, 2019
1 parent 65d8f9c commit f3c0291
Show file tree
Hide file tree
Showing 23 changed files with 431 additions and 181 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ def handle_less(self, extra: DateTimeExtra) -> TimeResult:
return TimeResult(_all / 60, _all % 60, second)

def handle_digit(self, extra: DateTimeExtra) -> TimeResult:
print(extra.named_entity)
hour = self.match_to_value(next(iter(extra.named_entity['hour']), ''))
minute = self.match_to_value(next(iter(extra.named_entity['min']), ''))
second = self.match_to_value(next(iter(extra.named_entity['sec']), ''))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,30 @@ def non_unit_regex(self) -> Pattern:
def ambiguous_unit_number_multiplier_regex(self) -> Pattern:
return None

@property
def ambiguity_filters_dict(self) -> Dict[Pattern, Pattern]:
return None

@property
def extract_type(self) -> str:
raise NotImplementedError

@property
def suffix_list(self) -> Dict[str, str]:
raise NotImplementedError

@property
def prefix_list(self) -> Dict[str, str]:
raise NotImplementedError

@property
def ambiguous_unit_list(self) -> List[str]:
raise NotImplementedError

@property
def culture_info(self) -> CultureInfo:
return self._culture_info

def __init__(self, culture_info: CultureInfo):
if culture_info is None:
culture_info = CultureInfo(Culture.Chinese)
Expand Down Expand Up @@ -98,7 +122,7 @@ def prefix_list(self) -> Dict[str, str]:
def ambiguous_unit_list(self) -> List[str]:
return self._ambiguous_unit_list

def __init__(self, culture_info: CultureInfo = None):
def __init__(self, culture_info: CultureInfo = Culture.Chinese):
super().__init__(culture_info)
self._suffix_list = ChineseNumericWithUnit.CurrencySuffixList
self._prefix_list = ChineseNumericWithUnit.CurrencyPrefixList
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@

# pylint: disable=abstract-method
class EnglishNumberWithUnitExtractorConfiguration(NumberWithUnitExtractorConfiguration):
@property
def ambiguity_filters_dict(self) -> Dict[Pattern, Pattern]:
return EnglishNumericWithUnit.AmbiguityFiltersDict

@property
def unit_num_extractor(self) -> Extractor:
return self._unit_num_extractor
Expand Down Expand Up @@ -58,6 +62,10 @@ def __init__(self, culture_info: CultureInfo):
# pylint: enable=abstract-method

class EnglishAgeExtractorConfiguration(EnglishNumberWithUnitExtractorConfiguration):
@property
def ambiguity_filters_dict(self) -> Dict[Pattern, Pattern]:
return EnglishNumericWithUnit.AmbiguityFiltersDict

@property
def extract_type(self) -> str:
return Constants.SYS_UNIT_AGE
Expand All @@ -82,6 +90,11 @@ def __init__(self, culture_info: CultureInfo = None):


class EnglishCurrencyExtractorConfiguration(EnglishNumberWithUnitExtractorConfiguration):

@property
def ambiguity_filters_dict(self) -> Dict[Pattern, Pattern]:
return EnglishNumericWithUnit.AmbiguityFiltersDict

@property
def extract_type(self) -> str:
return Constants.SYS_UNIT_CURRENCY
Expand All @@ -106,6 +119,11 @@ def __init__(self, culture_info: CultureInfo = None):


class EnglishDimensionExtractorConfiguration(EnglishNumberWithUnitExtractorConfiguration):

@property
def ambiguity_filters_dict(self) -> Dict[Pattern, Pattern]:
return EnglishNumericWithUnit.AmbiguityFiltersDict

@property
def extract_type(self) -> str:
return Constants.SYS_UNIT_DIMENSION
Expand Down Expand Up @@ -137,6 +155,11 @@ def __init__(self, culture_info: CultureInfo = None):


class EnglishTemperatureExtractorConfiguration(EnglishNumberWithUnitExtractorConfiguration):

@property
def ambiguity_filters_dict(self) -> Dict[Pattern, Pattern]:
return EnglishNumericWithUnit.AmbiguityFiltersDict

@property
def extract_type(self) -> str:
return Constants.SYS_UNIT_TEMPERATURE
Expand Down
Loading

0 comments on commit f3c0291

Please sign in to comment.