mirror of
https://github.com/alvierahman90/otfmacros.git
synced 2024-12-15 12:01:59 +00:00
Remove word_utils.py
This commit is contained in:
parent
efe903b8b1
commit
ad848e47ec
@ -2,7 +2,6 @@
|
||||
|
||||
import sys
|
||||
import re
|
||||
import word_utils as words
|
||||
|
||||
SEPARATORS = [' ', '\n', 's']
|
||||
|
||||
@ -12,13 +11,31 @@ def get_args():
|
||||
|
||||
import argparse
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("-m", "--macros", default=["macros"], action="append", help="Extra files where macros are stored")
|
||||
parser.add_argument("-s", "--silent", default=False, action="store_true", help="Do not print processed file")
|
||||
parser.add_argument("-m", "--macros", default=["macros"], action="append",
|
||||
help="Extra files where macros are stored")
|
||||
parser.add_argument("-s", "--silent", default=False, action="store_true",
|
||||
help="Do not print processed file")
|
||||
parser.add_argument("input", help="The file to be processed")
|
||||
parser.add_argument("output", help="The location of the output")
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
def is_consonant(letter):
|
||||
if not isinstance(letter, str):
|
||||
raise ValueError("Argument 'letter' must be type str")
|
||||
if len(letter) != 1:
|
||||
raise ValueError("Argument 'letter' must be 1 long")
|
||||
return not is_vowel(letter)
|
||||
|
||||
|
||||
def is_vowel(letter):
|
||||
if not isinstance(letter, str):
|
||||
raise ValueError("Argument 'letter' must be type str")
|
||||
if len(letter) != 1:
|
||||
raise ValueError("Argument 'letter' must be 1 long")
|
||||
return letter in 'aeiou'
|
||||
|
||||
|
||||
def pluralize(word, macro=None):
|
||||
"""
|
||||
Returns the plural form of a word.
|
||||
@ -32,15 +49,16 @@ def pluralize(word, macro=None):
|
||||
if word[-1] in 'sxz' or word[-2:] in ['ch', 'sh']:
|
||||
return word + 'es'
|
||||
if word[-1] == 'y':
|
||||
if words.is_consonant(word[-2]):
|
||||
if is_consonant(word[-2]):
|
||||
return word[:-1] + 'ies'
|
||||
if word[-1] == 'o':
|
||||
if words.is_consonant(word[-2]):
|
||||
if is_consonant(word[-2]):
|
||||
return word + 'es'
|
||||
if word[-1] == 'f':
|
||||
return word[:-1] + 'ves'
|
||||
return word + 's'
|
||||
|
||||
|
||||
def upper_check(token, word):
|
||||
lowercase = False
|
||||
all_caps = True
|
||||
@ -58,6 +76,7 @@ def upper_check(token, word):
|
||||
|
||||
return word
|
||||
|
||||
|
||||
def process(tokens, macros):
|
||||
output = tokens
|
||||
|
||||
@ -74,21 +93,15 @@ def process(tokens, macros):
|
||||
full_stopped = True
|
||||
token = token[:-1]
|
||||
|
||||
match = False
|
||||
plural = False
|
||||
|
||||
# if no macro is found (or if it is not a macro at all, the value
|
||||
# will not be changed
|
||||
value = token
|
||||
|
||||
for macro in macros:
|
||||
if macro[0].lower() == token.lower():
|
||||
match = True
|
||||
value = macro[1]
|
||||
break
|
||||
elif macro[0].lower() + 's' == token.lower():
|
||||
match = True
|
||||
plural = True
|
||||
value = pluralize(macro[1], macro=macro)
|
||||
break
|
||||
|
||||
@ -105,6 +118,7 @@ def process(tokens, macros):
|
||||
|
||||
return output
|
||||
|
||||
|
||||
def tokenize(input):
|
||||
"""
|
||||
Return of list of tokens from string (convert file contents to format to be
|
||||
@ -130,6 +144,7 @@ def get_macros(input):
|
||||
|
||||
return macros
|
||||
|
||||
|
||||
def main(args):
|
||||
""" Entry point for script """
|
||||
|
||||
|
@ -1,14 +0,0 @@
|
||||
def is_consonant(letter):
|
||||
if not isinstance(letter, str):
|
||||
raise ValueError("Argument 'letter' must be type str")
|
||||
if len(letter) != 1:
|
||||
raise ValueError("Argument 'letter' must be 1 long")
|
||||
return not is_vowel(letter)
|
||||
|
||||
def is_vowel(letter):
|
||||
if not isinstance(letter, str):
|
||||
raise ValueError("Argument 'letter' must be type str")
|
||||
if len(letter) != 1:
|
||||
raise ValueError("Argument 'letter' must be 1 long")
|
||||
return letter in 'aeiou'
|
||||
|
Loading…
Reference in New Issue
Block a user