Skip to content

Commit

Permalink
Minor fixes based on flake8 - closes issue #103
Browse files Browse the repository at this point in the history
  • Loading branch information
phirework committed Jun 15, 2020
1 parent 64d63b6 commit f0d41e3
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/corporacreator/corpora.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

def common_wrapper(sentence, up_votes, down_votes):
is_valid, sentence = common(sentence)
if False == is_valid:
if is_valid is False:
up_votes = 0
down_votes = 2
return pd.Series([sentence, up_votes, down_votes])
Expand Down Expand Up @@ -52,7 +52,7 @@ def create(self):
raise argparse.ArgumentTypeError("ERROR: You have requested languages which do not exist in clips.tsv")
else:
locales = corpora_data.locale.unique()

for locale in locales:
_logger.info("Selecting %s corpus data..." % locale)
corpus_data = corpora_data.loc[
Expand Down
4 changes: 2 additions & 2 deletions src/corporacreator/corpus.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Corpus:
Attributes:
args ([str]): Command line parameters as list of strings
locale (str): Locale of this :class:`corporacreator.Corpus`
locale (str): Locale of this :class:`corporacreator.Corpus`
corpus_data (:class:`pandas.DataFrame`): `pandas.DataFrame` Containing the corpus data
"""

Expand Down Expand Up @@ -49,7 +49,7 @@ def _preprocessor_wrapper(self, client_id, sentence, up_votes, down_votes):
preprocessors, self.locale.replace("-", "")
) # Get locale specific preprocessor
sentence = preprocessor(client_id, sentence)
if None == sentence or not sentence.strip():
if sentence is None or not sentence.strip():
up_votes = 0
down_votes = 2
return pd.Series([sentence, up_votes, down_votes])
Expand Down
6 changes: 3 additions & 3 deletions src/corporacreator/preprocessors/cy.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ def cy(client_id, sentence):
# TODO: geiriau Saesneg / English inspired/pronunced words:
# wallace, celsius, ddiesel, wicipedia, william, chiswell, f., h.

sentence = sentence.replace("’", "'") # fix apostrophes
sentence = sentence.replace("’", "'") # fix apostrophes
sentence = sentence.replace("wwna", "wna")
sentence = sentence.replace(" siwr ", " siŵr ")
sentence = sentence.replace("\\tungellog"," ungellog")
sentence = sentence.replace("\\tungellog", " ungellog")

return sentence
25 changes: 13 additions & 12 deletions src/corporacreator/preprocessors/de.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,32 @@
QUOTE_PATTERN = re.compile(r'^\"{3}(.*)\"{2}(.*)\"{1}$')
QUOTE_PATTERN_2 = re.compile(r'^\"{1}(.*)\"{2}(.*)\"{2}(.*)\"{1}$')
QUOTE_PATTERN_3 = re.compile(r'^\"{1}(.*)\"{1}$')



def _change_multi_quotes(sentence):
"""Changes all quotes from patterns like
"""Changes all quotes from patterns like
[\"""content""content"] to ["content"content] or
["content""content""content"] to [content"content"content] or
["content" to content]
Args:
sentence (str): Sentence to be cleaned up.
Returns:
(str): Cleaned up sentence. Returns the sentence 'as-is', if matching
did not work as expected
"""
matches = QUOTE_PATTERN.match(sentence) # pattern: \"\"\"content\"\"content\"
matches2 = QUOTE_PATTERN_2.match(sentence) # pattern: \"content\"\"content\"\"content\"
matches3 = QUOTE_PATTERN_3.match(sentence) # patter: \"content\"
if matches != None and matches.lastindex == 2:
matches = QUOTE_PATTERN.match(sentence) # pattern: \"\"\"content\"\"content\"
matches2 = QUOTE_PATTERN_2.match(sentence) # pattern: \"content\"\"content\"\"content\"
matches3 = QUOTE_PATTERN_3.match(sentence) # patter: \"content\"

if matches is not None and matches.lastindex == 2:
return "\"{}\"{}".format(matches.group(1), matches.group(2))
elif matches2 != None and matches2.lastindex == 3:
elif matches2 is not None and matches2.lastindex == 3:
return "{}\"{}\"{}".format(matches2.group(1), matches2.group(2), matches2.group(3))
elif matches3 != None and matches3.lastindex == 1:
elif matches3 is not None and matches3.lastindex == 1:
return "{}".format(matches3.group(1))

return sentence


Expand Down
1 change: 1 addition & 0 deletions src/corporacreator/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

_logger = logging.getLogger(__name__)


def main(args):
"""Main entry point allowing external calls
Expand Down

0 comments on commit f0d41e3

Please sign in to comment.