Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_partition_word(self):
p = inflect.engine()
for txt, part in (
(' cow ', (' ', 'cow', ' ')),
('cow', ('', 'cow', '')),
(' cow', (' ', 'cow', '')),
('cow ', ('', 'cow', ' ')),
(' cow ', (' ', 'cow', ' ')),
('', ('', '', '')),
('bottle of beer', ('', 'bottle of beer', '')),
# spaces give weird results
# (' '),('', ' ', '')),
# (' '),(' ', ' ', '')),
# (' '),(' ', ' ', '')),
):
self.assertEqual(p.partition_word(txt), part)
import inflect
p = inflect.engine()
def test_compound_1():
assert p.singular_noun("hello-out-there") == "hello-out-there"
def test_compound_2():
assert p.singular_noun("hello out there") == "hello out there"
def test_compound_3():
assert p.singular_noun("continue-to-operate") == "continue-to-operate"
def test_compound_4():
assert p.singular_noun("case of diapers") == "case of diapers"
def test_ancient_1():
p = inflect.engine()
# DEFAULT...
assert p.plural_noun("person") == "people"
# "person" PLURALS ACTIVATED...
p.classical(persons=True)
assert p.plural_noun("person") == "persons"
# OTHER CLASSICALS NOT ACTIVATED...
assert p.plural_noun("wildebeest") == "wildebeests"
assert p.plural_noun("formula") == "formulas"
assert p.plural_noun("error", 0) == "errors"
assert p.plural_noun("brother") == "brothers"
def scan(line):
' scan a line and split into words '
words = line.split(' ')
# analyse words
result = []
# for each word, send it to the analyzer to analyse
for word in words:
# singular noun
p = inflect.engine()
# the inflect will singular 'princess' into 'princes' that I don't want
if word != 'princess' and p.singular_noun(word):
word = p.singular_noun(word)
# Make sure the scanner handles user input in any capitalization and case.
type = analyse(word.lower())
result.append((type, word))
return result
def prep_mlf(trsfile, mlffile, word_dictionary, surround, between,
dialog_file=False):
dict_tmp = {}
infl = inflect.engine()
# Read in the dictionary to ensure all of the words
# we put in the MLF file are in the dictionary. Words
# that are not are skipped with a warning.
f = open(word_dictionary, 'r')
dictionary = { } # build hash table
for line in f.readlines():
if line != "\n" and line != "" :
dictionary[line.split()[0]] = True
f.close()
speakers = None
emotions = None
if dialog_file:
dialog = json.load(open(trsfile, 'r'))
def pday(dayfmt):
"""
P the day
>>> print(pday('2012-08-24'))
Friday the 24th
"""
year, month, day = map(int, dayfmt.split('-'))
return '{day} the {number}'.format(
day=calendar.day_name[calendar.weekday(year, month, day)],
number=inflect.engine().ordinal(day),
)
def create_inflect_engine(self):
if self.noinflect:
return _DummyInflectEngine()
else:
import inflect
return inflect.engine()
from sa_tools_core.libs.permission import require_user
from sa_tools_core.libs.sentry import report, send_sentry
from sa_tools_core.libs.template import render_notification
from sa_tools_core.libs.icinga import get_icinga_api
from sa_tools_core.libs.notification_gateway import add_notification
from sa_tools_core.notify import NOTIFY_TYPES, Notifier
from sa_tools_core.utils import get_os_username, AttrDict, import_string
from sa_tools_core.consts import ICINGA_EMAIL, ICINGA_CLUSTER_CONFIG_CLASS, ALERT_WIKI_BASE_URL
requests_logger = logging.getLogger('requests')
logger = logging.getLogger(__name__)
icinga_cluster_config = import_string(ICINGA_CLUSTER_CONFIG_CLASS)
inflect_engine = inflect.engine()
@require_user
def show(args):
icinga_api = get_icinga_api(icinga_cluster_config)
params = {}
if args.attrs:
params['attrs'] = args.attrs
if args.filter:
params['filter'] = args.filter
res = (icinga_api.api.objects.url(inflect_engine.plural(args.type)).get(**params))
if args.raw:
print(res)
else:
pprint(res)
def singularize(noun):
"""
args
- noun : a noun e.g "man"
returns the singular form of the word if it finds one. Otherwise,
returns the word itself.
"""
singular = inflect.engine().singular_noun(noun)
if singular in ALL_WORDNET_WORDS:
return singular
return noun
def get_related_wikihow_actions_advanced_search(seed_word):
page = _advanced_search_wikihow(seed_word)
# Try again but with plural if nothing is found
if not page:
page = _advanced_search_wikihow(inflect.engine().plural(seed_word))
if page:
soup = BeautifulSoup(page.content, "html.parser")
actions_elements = soup.find_all("div", class_="mw-search-result-heading")
actions = [clean_wikihow_action(x.find("a")["title"]) for x in actions_elements]
return actions
return []