本文整理匯總了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()