1
0
mirror of https://github.com/QData/TextAttack.git synced 2021-10-13 00:05:06 +03:00

update tests to include numbers in words

This commit is contained in:
Jack Morris
2020-07-01 15:18:04 -04:00
parent dafd251614
commit ebbb81ffb9
10 changed files with 36 additions and 42 deletions

View File

@@ -1,5 +1,7 @@
def has_letter(word):
""" Returns true if `word` contains at least one character in [A-Za-z]. """
""" Returns true if `word` contains at least one character in [A-Za-z].
"""
# TODO implement w regex
for c in word:
if c.isalpha():
return True
@@ -21,10 +23,11 @@ def add_indent(s_, numSpaces):
def words_from_text(s, words_to_ignore=[]):
""" Lowercases a string, removes all non-alphanumeric characters,
and splits into words. """
# TODO implement w regex
words = []
word = ""
for c in " ".join(s.split()):
if c.isalpha():
if c.isalnum():
word += c
elif c in "'-" and len(word) > 0:
# Allow apostrophes and hyphens as long as they don't begin the