本文整理汇总了Python中titlecase.titlecase函数的典型用法代码示例。如果您正苦于以下问题:Python titlecase函数的具体用法?Python titlecase怎么用?Python titlecase使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了titlecase函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
开发者ID:downingstreet,项目名称:dirt-jockey,代码行数:30,代码来源:standardize.py
示例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])
开发者ID:ingeropb,项目名称:python-titlecase,代码行数:7,代码来源:tests.py
示例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")
开发者ID:cmthompson,项目名称:weiss,代码行数:32,代码来源:isi_plugin.py
示例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()
开发者ID:activefrequency,项目名称:voterguide,代码行数:26,代码来源:utils.py
示例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')
开发者ID:shad7,项目名称:tvrenamer,代码行数:7,代码来源:test_titlecase.py
示例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()
开发者ID:combor,项目名称:postcodeinfo,代码行数:33,代码来源:utils.py
示例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()
开发者ID:brizandrew,项目名称:alachua-jail-lookup,代码行数:25,代码来源:db.py
示例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
开发者ID:SanthoshBala,项目名称:us-code,代码行数:26,代码来源:olrc_parser.py
示例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")
开发者ID:mcraveiro,项目名称:referencer,代码行数:32,代码来源:isi-plugin.py
示例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)
开发者ID:hgeg,项目名称:wiki,代码行数:7,代码来源:wiki.py
示例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
})
开发者ID:jclgoodwin,项目名称:bustimes.org.uk,代码行数:60,代码来源:import_maneo_stops.py
示例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)
开发者ID:ctbrennan,项目名称:cross-platform-message-analytics,代码行数:30,代码来源:parse_analyze.py
示例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)
开发者ID:ctbrennan,项目名称:cross-platform-message-analytics,代码行数:32,代码来源:parse_analyze.py
示例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
开发者ID:ixc,项目名称:titlecase.py,代码行数:7,代码来源:tests.py
示例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()
开发者ID:YangLiu928,项目名称:NDP_Projects,代码行数:59,代码来源:process_data.py
示例16: parseJournalListFile
def parseJournalListFile(filename):
fp = open(filename, "r")
doc = fp.read()
fp.close()
soup = BeautifulSoup(doc)
dts = soup.findAll("dt")
journalList = {}
for dt in dts:
# Get the name minus the number
fullName = getName.match(dt.text).groups()[1].strip()
fullName = fullName.lower()
fullName = titlecase(fullName)
journalList[fullName] = {}
# Get the following definition data elements, which include:
# . frequency of publication
# . ISSN
# . address + indicies
dds = dt.fetchNextSiblings("dd", limit=3)
# We need to check if the ISSN is in the second dd;
# if not, then we assume that there was no frequency given,
# and we need to take only two dds instead
if (dds[1].text.find("ISSN") == -1):
dds = dt.fetchNextSiblings("dd", limit=2)
journalList[fullName]["frequency"] = "none"
journalList[fullName]["ISSN"] = dds[0].text[6:]
address = dds[1].contents[0].lower()
journalList[fullName]["address"] = titlecase(address)
citationIndicies = dds[1].contents[1]
links = citationIndicies.findAll("a")
linkList = []
for link in links:
linkList.append((link["href"], link.text))
journalList[fullName]["citationIndicies"] = linkList
else:
journalList[fullName]["frequency"] = dds[0].text.strip()
journalList[fullName]["ISSN"] = dds[1].text[6:]
address = dds[2].contents[0].lower()
journalList[fullName]["address"] = titlecase(address)
citationIndicies = dds[2].contents[1]
links = citationIndicies.findAll("a")
linkList = []
for link in links:
linkList.append((link["href"], link.text))
journalList[fullName]["citationIndicies"] = linkList
return journalList
开发者ID:zeitkunst,项目名称:JJPS,代码行数:59,代码来源:parseJournalList.py
示例17: test_callback
def test_callback():
def abbreviation(word, **kwargs):
if word.upper() in ('TCP', 'UDP'):
return word.upper()
s = 'a simple tcp and udp wrapper'
assert titlecase(s) == 'A Simple Tcp and Udp Wrapper'
assert titlecase(s, callback=abbreviation) == 'A Simple TCP and UDP Wrapper'
assert titlecase(s.upper(), callback=abbreviation) == 'A Simple TCP and UDP Wrapper'
开发者ID:johnfraney,项目名称:python-titlecase,代码行数:8,代码来源:tests.py
示例18: race
def race(text):
race_map = {
"B": "Black"
}
if text in race_map:
return titlecase(race_map[text])
else:
return titlecase(text)
开发者ID:webmaven,项目名称:comport,代码行数:8,代码来源:cleaners.py
示例19: get_timings
def get_timings(input_filename):
# Avoid needing this during venusian scan
def errback(msg):
print (msg)
kardata = open(input_filename, 'rb').read()
midifile = midi.midiParseData(
kardata,
errback,
'utf-8'
)
if midifile is None:
print ('Not a valid midi file %s' % input_filename)
return
lyrics_list = midifile.lyrics.list
timings = []
lyrics_text = []
first_ms = lyrics_list[0].ms
current_line = []
title = ' '.join([x.capitalize() for x in input_filename.split('_')])
artist = ''
for i, lyric in enumerate(lyrics_list):
if i == 0:
title = titlecase.titlecase(lyric.text)
if i == 1:
artist = titlecase.titlecase(lyric.text)
current_line.append([float(lyric.ms-first_ms)/1000, lyric.text])
try:
next_lyric = lyrics_list[i+1]
except IndexError:
next_lyric = None
if lyric.line != getattr(next_lyric, 'line', None):
last_ms = lyric.ms
newline = (
float(first_ms)/1000,
float(last_ms)/1000,
current_line,
)
timings.append(newline)
if next_lyric:
first_ms = next_lyric.ms
else:
first_ms = last_ms
line_text = ''.join(
[syllable[1] for syllable in current_line]
)
lyrics_text.append(line_text.rstrip())
current_line = []
timings.append( # why do we append this
(
float(first_ms)/1000,
float(lyrics_list[-1].ms)/1000,
current_line,
)
)
lyrics = '\n'.join(lyrics_text)
return kardata, title, artist, lyrics, json.dumps(timings, indent=2)
开发者ID:notaliens,项目名称:youshouldsing,代码行数:57,代码来源:import_midi.py
示例20: test_callback
def test_callback():
def abbreviation(word, **kwargs):
if word.upper() in ('TCP', 'UDP'):
return word.upper()
s = 'a simple tcp and udp wrapper'
assert titlecase(s) == 'A Simple Tcp and Udp Wrapper'
assert titlecase(s, callback=abbreviation) == 'A Simple TCP and UDP Wrapper'
assert titlecase(s.upper(), callback=abbreviation) == 'A Simple TCP and UDP Wrapper'
assert titlecase(u'crème brûlée', callback=lambda x, **kw: x.upper()) == u'CRÈME BRÛLÉE'
开发者ID:ppannuto,项目名称:python-titlecase,代码行数:9,代码来源:tests.py
注:本文中的titlecase.titlecase函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论