本文整理汇总了Python中inflect.engine方法的典型用法代码示例。如果您正苦于以下问题:Python inflect.engine方法的具体用法?Python inflect.engine怎么用?Python inflect.engine使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类inflect
的用法示例。
在下文中一共展示了inflect.engine方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_resource_url
# 需要导入模块: import inflect [as 别名]
# 或者: from inflect import engine [as 别名]
def get_resource_url(cls, resource, base_url):
"""
Construct the URL for talking to this resource.
i.e.:
http://myapi.com/api/resource
Note that this is NOT the method for calling individual instances i.e.
http://myapi.com/api/resource/1
Args:
resource: The resource class instance
base_url: The Base URL of this API service.
returns:
resource_url: The URL for this resource
"""
if resource.Meta.resource_name:
url = '{}/{}'.format(base_url, resource.Meta.resource_name)
else:
p = inflect.engine()
plural_name = p.plural(resource.Meta.name.lower())
url = '{}/{}'.format(base_url, plural_name)
return cls._parse_url_and_validate(url)
示例2: get_related_wikihow_actions_basic_search
# 需要导入模块: import inflect [as 别名]
# 或者: from inflect import engine [as 别名]
def get_related_wikihow_actions_basic_search(seed_word):
page = basic_search_wikihow(seed_word)
# Try again but with plural if nothing is found
if not page:
page = basic_search_wikihow(inflect.engine().plural(seed_word))
soup = BeautifulSoup(page.content, "html.parser")
actions_elements = soup.find_all("a", class_="result_link")
action_titles = list(
chain.from_iterable(
[a.find_all("div", "result_title") for a in actions_elements]
)
)
actions = [
clean_wikihow_action(remove_how_to(x.get_text()))
for x in action_titles
if x is not None and not x.get_text().startswith("Category")
]
return actions
示例3: blacklisted_titles
# 需要导入模块: import inflect [as 别名]
# 或者: from inflect import engine [as 别名]
def blacklisted_titles(self):
"""
Pluralize the blacklisted titles.
Returns: list
"""
p = inflect.engine()
singulars = self.config.get('blacklisted_titles', [])
return map(
tokenize_field,
singulars + [p.plural(s) for s in singulars],
)
示例4: syntactic_analysis
# 需要导入模块: import inflect [as 别名]
# 或者: from inflect import engine [as 别名]
def syntactic_analysis(self, src):
i = inflect.engine()
relations = {}
foreign_keys = {}
for table in src:
for k, v in table.items():
if k == 'table_name':
foreign_keys[(i.singular_noun(v) if i.singular_noun(v) else v) + '_id'] = v
for table in src:
for k, v in table.items():
if k == 'table_name':
table_name = v
for e in table:
if 'column_name' in e:
if e['column_name'] in foreign_keys.keys():
relations[table_name + ':' + e['column_name']] = foreign_keys[e['column_name']] + ':id'
result = {}
result['src'] = src
result['relations'] = relations
return result
示例5: dump
# 需要导入模块: import inflect [as 别名]
# 或者: from inflect import engine [as 别名]
def dump(self):
"""
Dump Domino account hashes.
"""
# Check if the user can access names.nsf
if self.check_access(self.username, self.password)['names.nsf']:
if self.auth_type == 'basic':
self.session.auth = (self.username, self.password)
# Enumerate account URLs
account_urls = self.get_accounts()
if account_urls:
self.logger.info("Found {0} account {1}".format(len(account_urls), inflect.engine().plural('hash', len(account_urls))))
self.get_hashes(account_urls)
else:
self.logger.warn('No account hashes found')
else:
self.logger.error("Unable to access {0}/names.nsf, bad username or password".format(self.url))
示例6: bruteforce
# 需要导入模块: import inflect [as 别名]
# 或者: from inflect import engine [as 别名]
def bruteforce(self, userlist):
"""
Perform a reverse brute force attack with multiple usernames and one password.
"""
if self.auth_type == 'open':
self.logger.info("{0}/names.nsf does not require authentication".format(self.url))
else:
usernames = self.build_userlist(userlist)
valid_accounts = self.brute_accounts(usernames)
print('\n')
if valid_accounts:
self.logger.info("Found {0} valid {1}".format(len(valid_accounts), inflect.engine().plural('account', len(valid_accounts))))
print(tabulate.tabulate(valid_accounts, headers=['Username', 'Password', 'Account Type'], tablefmt='simple'))
else:
self.logger.warn('No valid accounts found')
示例7: main
# 需要导入模块: import inflect [as 别名]
# 或者: from inflect import engine [as 别名]
def main():
'''
main engine head
* called on program start
* calls config check
* proceeds to main menu
* handles ^c and ^d ejects
'''
redraw()
print("""
if you don't want to be here at any point, press <ctrl-d> and it'll all go away.
just keep in mind that you might lose anything you've started here.\
""")
try:
print(check_init())
except EOFError:
print(stop())
return
redraw()
while 1:
try:
print(main_menu())
except EOFError:
print(stop())
break
except KeyboardInterrupt:
redraw(EJECT)
else:
break
示例8: og_description
# 需要导入模块: import inflect [as 别名]
# 或者: from inflect import engine [as 别名]
def og_description(self) -> str:
p = inflect.engine()
fmt = titlecase.titlecase(p.a(self.format_name))
description = '{fmt} match.'.format(fmt=fmt)
return description
示例9: day2ordinal
# 需要导入模块: import inflect [as 别名]
# 或者: from inflect import engine [as 别名]
def day2ordinal(m: Match) -> str:
p = inflect.engine()
return p.ordinal(int(m.group(1)))
示例10: prizes_by_finish
# 需要导入模块: import inflect [as 别名]
# 或者: from inflect import engine [as 别名]
def prizes_by_finish(multiplier: int = 1) -> List[Dict[str, Any]]:
prizes, finish, p = [], 1, inflect.engine()
while True:
pz = prize_by_finish(finish)
if not pz:
break
prizes.append({'finish': p.ordinal(finish), 'prize': pz * multiplier})
finish += 1
return prizes
示例11: og_description
# 需要导入模块: import inflect [as 别名]
# 或者: from inflect import engine [as 别名]
def og_description(self) -> str:
if self.public() and self.archetype_name:
p = inflect.engine()
archetype_s = titlecase.titlecase(p.a(self.archetype_name))
else:
archetype_s = 'A'
description = '{archetype_s} deck by {author}'.format(archetype_s=archetype_s, author=self.person)
return description
示例12: num_tournaments
# 需要导入模块: import inflect [as 别名]
# 或者: from inflect import engine [as 别名]
def num_tournaments(self) -> str:
return inflect.engine().number_to_words(len(tournaments.all_series_info()))
示例13: inflect
# 需要导入模块: import inflect [as 别名]
# 或者: from inflect import engine [as 别名]
def inflect(self):
"""Return instance of inflect."""
if self._inflect is None:
import inflect
self._inflect = inflect.engine()
return self._inflect
示例14: contributions_ordinal
# 需要导入模块: import inflect [as 别名]
# 或者: from inflect import engine [as 别名]
def contributions_ordinal(self):
p = inflect.engine()
return p.ordinal(self.num_contributions)
示例15: create_inflect_engine
# 需要导入模块: import inflect [as 别名]
# 或者: from inflect import engine [as 别名]
def create_inflect_engine(self):
if self.noinflect:
return _DummyInflectEngine()
else:
import inflect
return inflect.engine()