Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autopep8 Python code for style fixes #1668

Merged
merged 2 commits into from
Jun 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Python/.flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[flake8]
ignore=E501,F403,W504,F405,F401,E711,W503,E265,F811,E714,F841,E226,E713,F632,E722,F821
max-line-length=140
10 changes: 5 additions & 5 deletions Python/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ repos:
rev: v1.2.3
hooks:
- id: flake8

- repo: https://github.com/pre-commit/mirrors-autopep8
rev: master
hooks:
- id: autopep8
#
#- repo: https://github.com/pre-commit/mirrors-autopep8
# rev: master
# hooks:
# - id: autopep8
3 changes: 3 additions & 0 deletions Python/build.ci.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ pip install -e .\libraries\recognizers-sequence\

pip install -e .\libraries\recognizers-suite\

ECHO # Validating PEP8 style
call flake8 . --config=.\.flake8

pip install -r .\tests\requirements.txt

pytest --tb=line
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ class EnglishBooleanExtractorConfiguration(BooleanExtractorConfiguration):
only_top_match: bool

def __init__(self, only_top_match: bool = True):
self.regex_true = RegExpUtility.get_safe_reg_exp(EnglishChoice.TrueRegex)
self.regex_false = RegExpUtility.get_safe_reg_exp(EnglishChoice.FalseRegex)
self.token_regex = RegExpUtility.get_safe_reg_exp(EnglishChoice.TokenizerRegex, regex.S)
self.regex_true = RegExpUtility.get_safe_reg_exp(
EnglishChoice.TrueRegex)
self.regex_false = RegExpUtility.get_safe_reg_exp(
EnglishChoice.FalseRegex)
self.token_regex = RegExpUtility.get_safe_reg_exp(
EnglishChoice.TokenizerRegex, regex.S)
self.only_top_match = only_top_match
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ def extract(self, source: str):
top_score = 0.0
top_result_index = 0
for i in range(len(partial_results)):
data = ChoiceExtractDataResult(source, partial_results[i].data.score)
data = ChoiceExtractDataResult(
source, partial_results[i].data.score)
if data.score > top_score:
top_score = data.score
top_result_index = i
Expand All @@ -93,7 +94,7 @@ def match_value(self, source: List[str], match: List[str], start_pos: int) -> fl
total_deviation = 0
for match_token in match:
pos = StringUtility.index_of(source, match_token, start_pos)

if pos >= 0:
distance = pos - start_pos if matched > 0 else 0

Expand Down Expand Up @@ -134,8 +135,8 @@ def __tokenize(self, source: str) -> List[str]:
token = ''

return tokens


class BooleanExtractorConfiguration(ABC):
regex_true: Pattern
regex_false: Pattern
Expand All @@ -148,6 +149,7 @@ def __init__(self, regex_true, regex_false, token_regex, only_top_match):
self.token_regex = RegExpUtility.get_safe_reg_exp(token_regex)
self.only_top_match = only_top_match


class BooleanExtractor(ChoiceExtractor):
booleanTrue = Constants.SYS_BOOLEAN_TRUE
booleanFalse = Constants.SYS_BOOLEAN_FALSE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,3 @@ def get_resolution(self, sources: ParseResult):
'score': o.data.score}
for o in sources.data.other_matches]
return results

Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ def parse(self, ext_result):
result = ParseResult(ext_result)
data = ChoiceExtractDataResult(ext_result.data)
result.value = self.config.resolutions.get(result.type)
result.data = ChoiceParseDataResult(data.score, [self.__to_other_match_result(m) for m in data.other_matches])
result.data = ChoiceParseDataResult(
data.score, [self.__to_other_match_result(m) for m in data.other_matches])
return result

def __to_other_match_result(self, ext_result):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def __init__(self, target_culture: str = None, options: ChoiceOptions = ChoiceOp

def initialize_configuration(self):
self.register_model('BooleanModel', Culture.English, lambda options: BooleanModel(
BooleanParser(),BooleanExtractor(EnglishBooleanExtractorConfiguration())))
BooleanParser(), BooleanExtractor(EnglishBooleanExtractorConfiguration())))

@staticmethod
def is_valid_option(options: int) -> bool:
Expand Down
4 changes: 3 additions & 1 deletion Python/libraries/recognizers-choice/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
def read(fname):
return open(os.path.join(os.path.dirname(__file__), fname)).read()


NAME = 'recognizers-text-choice'
VERSION = '1.0.0.a0'
REQUIRES = ['recognizers-text', 'regex']
Expand All @@ -19,7 +20,8 @@ def read(fname):
url='https://github.com/Microsoft/Recognizers-Text',
author='Microsoft',
description='recognizers-text-choice README',
keywords=['nlp', 'nlp-entity-extraction', 'entity-extraction', 'parser-library'],
keywords=['nlp', 'nlp-entity-extraction',
'entity-extraction', 'parser-library'],
long_description=read('README.rst'),
license='MIT',
packages=find_packages(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from .parsers import DateTimeParser
from .utilities import DateTimeUtilityConfiguration


class BaseDateParserConfiguration(ABC):
@property
@abstractmethod
Expand Down
Loading