本文整理汇总了Python中titlecase.titlecase函数的典型用法代码示例。如果您正苦于以下问题:Python titlecase函数的具体用法?Python titlecase怎么用?Python titlecase使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了titlecase函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: standardize_manufacturer
def standardize_manufacturer(data, d, abbr):
manufacturer = str(data["manufacturer"])
model = str(data["model"])
remove_hyphen = model.replace("-", "").lower()
# Split the string into individual words. split() returns a list.
split_model = remove_hyphen.split()
# Combine model number
if len(split_model[0]) < 4:
split_model[0] += split_model[1]
del split_model[1]
# Spell check the model name. If it is an abbreviation, replace it with its full form.
for i in range(1, len(split_model)):
if split_model[i] in abbr:
split_model[i] = titlecase(abbr[split_model[i]])
else:
split_model[i] = titlecase(spell_correct.correct(split_model[i]))
# Convert the model number to upper case.
split_model[0] = split_model[0].upper()
# Join the list with a single space to give the model string.
model = " ".join(split_model)
# Add the manufacturer and model to a dictionary of lists.
if manufacturer not in d:
d[manufacturer].append(model)
elif model not in d[manufacturer]:
d[manufacturer].append(model)
示例2: test_ordinals_list_item
def test_ordinals_list_item(self):
"""
Test - numbers ending in ordinals like 1st and 24th
"""
from titlecase import ORDINALS
assert '34Th' not in titlecase(TEST_DATA[2][0])
assert '1st' in titlecase(TEST_DATA[2][0])
示例3: set_fields_from_data
def set_fields_from_data(self,data):
xmldoc = minidom.parseString(data)
self.authors=get_field(xmldoc,"primaryauthor")
more_authors=get_fields(xmldoc,"author",' and ')
if(len(more_authors)>0):
self.authors+=' and '+more_authors
self.authors = capitalize_authors(self.authors)
self.abstract=get_field(xmldoc,"p")
self.keywords=get_fields(xmldoc,"keyword",', ')
self.journal=get_field(xmldoc,"source_title")
if self.journal.isupper():
if UseTitlecase:
self.journal = titlecase(self.journal.lower())
else:
self.journal = self.journal.title()
doi=get_last_field(xmldoc,"article_no")
if len(doi) > 0:
self.doi = doi[4:]
else:
self.doi = doi
self.pages=get_field(xmldoc,"bib_pages")
if self.pages == '-':
artn = get_field(xmldoc,"article_no")
self.pages = artn[4:]
self.title=get_field(xmldoc,"item_title")
if self.title.isupper():
if UseTitlecase:
self.title = titlecase(self.title.lower())
else:
self.title = self.title.title()
self.year=get_attribute_from_field(xmldoc,"bib_issue","year")
self.volume=get_attribute_from_field(xmldoc,"bib_issue","vol")
示例4: normalize_ordinals
def normalize_ordinals(name):
"""
Change 'Eighth Plymouth' to '8th Plymouth', and '8 Plymouth' to '8th Plymouth'
"""
# work around "SD 1"/"HD 1"
if name.startswith("SD "):
name = name.replace("SD ", "")
if name.startswith("HD "):
name = name.replace("HD ", "")
if name.isnumeric():
return name
for key, val in ORDINALS.items():
# split words, to make sure that 'fifth' doesn't match 'thirty-fifth'
if key in name.lower().split(' '):
name = titlecase(name.lower().replace(key, val[1]))
for key, val in NUMERALS.items():
# split words, to make sure that '5' doesn't match 'thirty-fifth'
if key in name.lower().split(' '):
name = titlecase(name.lower().replace(key, val[1]))
# fix capitalization of "1ST", "2ND", etc"
name = name.replace('1ST ', '1st ').replace('2ND ', '2nd ').replace('3RD ', '3rd ').replace('4TH ', '4th ').replace('5TH ', '5th ').replace('6TH ', '6th ').replace('7TH ', '7th ').replace('8TH ', '8th ').replace('9TH ', '9th ').replace('10TH ', '10th ')
# do our best to strip extraneous spaces, inside and outside
return name.replace(' ', ' ').replace(' ', ' ').strip()
示例5: test_from_all_lower
def test_from_all_lower(self):
self.assertEqual(tc.titlecase('a very simple title'),
'A Very Simple Title')
self.assertEqual(tc.titlecase('o\'shea is not a good band'),
'O\'Shea Is Not a Good Band')
self.assertEqual(tc.titlecase('o\'do not wanton with those eyes'),
'O\'Do Not Wanton With Those Eyes')
示例6: format_building
def format_building(cls, sub_name, name, number):
if not any([sub_name, name, number]):
return ''
# Define exception to the usual rule requiring a newline for the
# building name. See p. 27 of PAF Guide for further information.
building_str = ''
exception = re.compile(r"^\d.*\d$|^\d.*\d[A-Za-z]$|^\d[A-Za-z]$|^.$")
for component in [sub_name, name]:
if component and exception.match(component):
building_str += component
if re.match(r"^[A-Za-z]$", component):
building_str += u", "
else:
building_str += u" "
else:
# Check if final portion of string is numeric/alphanumeric. If
# so, split and apply exception to that section only.
parts = titlecase(component).split(' ')
final = parts.pop()
if (exception.match(component) and
not number and
not re.match(r'/^\d*$/', final)):
building_str += u"%s\n%s " % (' '.join(parts), final)
else:
building_str += u"%s\n" % titlecase(component)
if number:
building_str += u"%d " % number
return building_str.lstrip()
示例7: insertInmateData
def insertInmateData(inmateInfo):
fname = titlecase(inmateInfo['fname'])
lname = titlecase(inmateInfo['lname'])
bookingNumber = inmateInfo['bookingNumber']
pod = inmateInfo['pod']
bookingDate = inmateInfo['bookingDate']
mni = inmateInfo['mni']
mugshotURL = inmateInfo['mugshotURL']
totalBond = inmateInfo['totalBond']
status = titlecase(inmateInfo['status'])
federal = inmateInfo['federal']
otherCounty = inmateInfo['otherCounty']
hold = inmateInfo['hold']
url = inmateInfo['url']
removed = 0
try:
conn = pymysql.connect(host=dbInfo.host, unix_socket=dbInfo.unix_socket, user=dbInfo.user, passwd=dbInfo.passwd, db=dbInfo.db, charset=dbInfo.charset)
cur = conn.cursor()
cur.execute("USE %s" % (dbInfo.db))
cur.execute('INSERT INTO inmates(fname, lname, bookingNumber, pod, bookingDate, mni, mugshotURL, totalBond, status, federal, otherCounty, hold, url,removed) VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)',(fname,lname,bookingNumber,pod,bookingDate,mni,mugshotURL,totalBond,status,federal,otherCounty,hold,url,removed))
cur.connection.commit()
cur.close()
finally:
conn.close()
示例8: _titleCaseTitleAndChapter
def _titleCaseTitleAndChapter(self, xmlSoup):
titles = xmlSoup.findAll("h1", {"class": "usc-title-head"})
for title in titles:
# Clean em dash and title case
title.string = u" \u2014 ".join([titlecase(s.lower()) for s in title.text.split(u"\u2014")])
chapters = xmlSoup.findAll("h3", {"class": "chapter-head"})
for chapter in chapters:
# Clean em dash and title case
chapter.string = u". ".join([titlecase(s.lower()) for s in chapter.text.split(u"\u2014")])
subchapters = xmlSoup.findAll("h3", {"class": "subchapter-head"})
for subchapter in subchapters:
# Clean em dash and title case
if u"\u2014" in subchapter.text:
[prefix, suffix] = subchapter.text.split(u"\u2014")
[heading, number] = prefix.split(" ", 1)
heading = titlecase(heading.lower())
suffix = titlecase(suffix.lower())
subchapter.string = u"%s %s\u2014%s" % (heading, number, suffix)
else:
subchapter.string = titlecase(subchapter.text.lower())
return
示例9: set_fields_from_data
def set_fields_from_data(self,isi_rec):
"""
xmlrec is a <REC> xml node
"""
xmldoc = isi_rec
self.authors=get_fields(xmldoc,"AuCollectiveName",' and ')
#self.authors = capitalize_authors(self.authors)
self.abstract=get_field(xmldoc,"abstract")
self.keywords=get_fields(xmldoc,"keyword",', ')
self.journal=get_field(xmldoc,"source_title")
if self.journal.isupper():
if UseTitlecase:
self.journal = titlecase(self.journal.lower())
else:
self.journal = self.journal.title()
doi=get_last_field(xmldoc,"article_no")
if len(doi) > 0:
self.doi = doi[4:]
else:
self.doi = doi
self.pages=get_field(xmldoc,"bib_pages")
if self.pages == '-':
artn = get_field(xmldoc,"article_no")
self.pages = artn[4:]
self.title=get_field(xmldoc,"item_title")
if self.title.isupper():
if UseTitlecase:
self.title = titlecase(self.title.lower())
else:
self.title = self.title.title()
self.year=get_attribute_from_field(xmldoc,"bib_issue","year")
self.volume=get_attribute_from_field(xmldoc,"bib_issue","vol")
示例10: create
def create(key):
try:
title = "%s (%s)"%tuple(titlecase(key.replace('-',' ')).split('_'))
except:
title = titlecase(key.replace('-',' '))
data = {'content':"%s\n==========\n..."%title, 'key':key}
return render_template('edit.html',**data)
示例11: handle_row
def handle_row(self, row):
atco_code = 'maneo-' + row['CODE']
defaults = {
'locality_centre': False,
'active': True,
'latlong': row['geometry']
}
name = row.get('\ufeffAPPCOM', row.get('APPCOM'))
name_parts = name.split(' - ', 1)
if len(name_parts) == 2:
if name_parts[1].startswith('Desserte'):
name = name_parts[0]
defaults['indicator'] = name_parts[1]
else:
defaults['town'] = titlecase(name_parts[1])
defaults['common_name'] = titlecase(name)
stop = StopPoint.objects.update_or_create(atco_code=atco_code, defaults=defaults)[0]
url = 'http://www.commentjyvais.fr/en/schedule/result/?' + urlencode({
'schedule[stop_area][autocomplete-hidden]': 'stop_area:G50:SA:' + row['IDARRET']
})
res = session.get(url)
soup = BeautifulSoup(res.text, 'lxml')
line_elements = soup.find_all('div', {'class': 'line-info'})
lines = set()
for element in line_elements:
line = element.find('span', {'class': 'ctp-line-code'})
if line is None:
continue
line = line.text.strip()
if line in lines:
continue
lines.add(line)
if len(line) > 24:
print(line)
continue
operator_name = element.find('img')['alt'].split()[0]
operator = Operator.objects.update_or_create(
id=slugify(operator_name).upper(),
name=operator_name,
region_id='FR'
)[0]
service = Service.objects.update_or_create(
service_code='maneo-' + line,
line_name=line,
region_id='FR',
date='2017-01-01'
)[0]
service.operator.add(operator)
StopUsage.objects.update_or_create(service=service, stop=stop, defaults={
'order': 0
})
示例12: parseSuperBackup
def parseSuperBackup():
tree = ET.parse('allsms.xml') #fix this later
root = tree.getroot()
newPersonDict = {}
newFullTextDict = {}
newNames = []
notFound = []
for message in root:
phoneNumber = formatPhoneNumber(message.attrib['address'])
if message.attrib['type'] == '2':
sender = me
elif message.attrib['name']:
sender = titlecase(message.attrib['name'])
elif phoneNumber in vCardDict.keys():
sender = titlecase(vCardDict[phoneNumber])
if sender not in newNames:
newNames.append(sender)
else:
continue #don't add plain phone numbers
date = message.attrib['time']
text = message.attrib['body']
dateFormatted = datetime.strptime(date, '%b %d, %Y %I:%M:%S %p') #"Jul 10, 2016 8:28:10 PM"
addToNewDict(newPersonDict, dateFormatted, text, sender)
addToNewDict(newFullTextDict, dateFormatted, text)
if 'y' in input("Enter 'y' if you would like to match duplicate names from Android SMS"):
matchDuplicates(newPersonDict)
mergeAndSortPersonDict(newPersonDict, confident)
mergeAndSortFullTextDict(newFullTextDict)
示例13: matchAliases
def matchAliases(existingNames, otherNames, otherNamesDict, confident):
CUTOFFSCORE = 2 #play around with this
for otherName in otherNames:
candidates = possMatches(otherName, existingNames) #list of possible matches (determined by small edit distance)
topCandidate, bestScore = candidates[0]
correctMatch = False
if not confident and bestScore < CUTOFFSCORE:
if otherName.isdigit(): #phone number
aliasDict[otherName] = otherName
#if candidates[1][1] >= bestScore - 1: #multiple best matches within 1 of eachother
elif candidates[1][1] == bestScore: #multiple best matches equal to eachother
writingStyleSimilarityDict = {} #candidate existingName -> similarity to otherName
toCompare = [candidates[0][0]]
for candidate in candidates:
if candidate[1] == bestScore:
writingStyleSimilarityDict[candidate[0]] = writingStyleMatchScore(otherName, otherNamesDict, candidate[0])
topCandidates = sorted(writingStyleSimilarityDict.keys(), key = lambda x: -writingStyleSimilarityDict[x])
i = 0
while not correctMatch and i < len(topCandidates):
topCandidate = topCandidates[i]
correctMatch = True if 'y' in input("Enter 'y' if " + otherName + " should be matched with " + topCandidate + ": ") else False
i += 1
else:
correctMatch = True if 'y' in input("Enter 'y' if " + otherName + " should be matched with " + topCandidate + ": ") else False
if correctMatch:
aliasDict[otherName] = topCandidate
else:
aliasDict[otherName] = titlecase(otherName)
elif confident:
aliasDict[otherName] = topCandidate
else:
aliasDict[otherName] = titlecase(otherName)
示例14: check_input_matches_expected_output
def check_input_matches_expected_output(in_, out):
"""Function yielded by test generator"""
try :
assert titlecase(in_) == out
except AssertionError:
print "%s != %s" % (titlecase(in_), out)
raise
示例15: _read_and_write
def _read_and_write(raw_file_route, pipe_file_route, pairs):
map = {'COUNTRY':1013,'DISTRICT':1014,'HSDESC':1012,'NAICS':1008,'SITC':1015}
file_name = _extract_file_name(raw_file_route)
if file_name not in map:
print 'we have not yet defined a type_cd for data in file ' + file_name
print 'program has exicted'
return
# if len(pairs)!=3:
# print 'This program is intended to process input that has 3 columns (after adding pipes)'
# print 'however the input document \'{0}\' contains {1} columns'.format(file_name,len(pairs))
# print 'program has exicted'
# return
# some constants
client_id = 1
type_cd = map[file_name]
raw_file = open(raw_file_route, 'r')
sql_file_name = 'pht_code_table_{0}.SQL'.format(type_cd)
sql_file = open(pipe_file_route + sql_file_name, 'w')
# some sql overhead
sql_file.write('DELETE FROM pht_code\nWHERE client_id=1 AND type_cd = \'{0}\';\n\r'.format(type_cd))
list_order=10
# i, j, k represents the column for code, description, and description_long
# these values differ by file
if type_cd==1015 or type_cd==1012:
i = 0
j = 2
k = 1
else:
i = 0
j = 1
k = 2
for line in raw_file:
line = line.strip()
code = titlecase(line[pairs[i][0]-1:pairs[i][1]].strip())
description = titlecase(line[pairs[j][0]-1:pairs[j][1]].strip())
try:
description_long = titlecase(line[pairs[k][0]-1:pairs[k][1]].strip())
except:
description_long='NULL'
sql = 'INSERT INTO pht_code (client_id, type_cd, code, parent_cd, ext_code, description, description_long, list_order, created_by, insert_dt, expire_dt)\nVALUES (1, {0}, {1}, NULL, NULL, {2}, {3}, {4}, \'load_table_data\', NOW(), NULL);\n\r'.format(type_cd,
_process_string_for_sql(str(type_cd)+'-'+code),
_process_string_for_sql(description),
description_long if description_long == 'NULL' else _process_string_for_sql(description_long),
list_order)
list_order=list_order+10
sql_file.write(sql)
sql_file.write('COMMIT;')
raw_file.close()
sql_file.close()