本文整理汇总了Python中UtilFunc.matchName方法的典型用法代码示例。如果您正苦于以下问题:Python UtilFunc.matchName方法的具体用法?Python UtilFunc.matchName怎么用?Python UtilFunc.matchName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UtilFunc
的用法示例。
在下文中一共展示了UtilFunc.matchName方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getNumberFromNameInFile
# 需要导入模块: import UtilFunc [as 别名]
# 或者: from UtilFunc import matchName [as 别名]
def getNumberFromNameInFile(name, yearbookReferenceFilePath):
nameSep = re.findall('[A-Z][^A-Z]*',name)
# print '### name:{0} nameSep: {1}'.format(name, nameSep)
nameDict = {'WrittenLast':''.join(nameSep[0:-1]),'WrittenFirst':nameSep[-1]}
yearbookNames = UtilFunc.parseDataFromFile(yearbookReferenceFilePath)
jaroMatchIndex = UtilFunc.matchName(nameDict, yearbookNames)['AlphaIndex']
return jaroMatchIndex
示例2: test_matchName_07
# 需要导入模块: import UtilFunc [as 别名]
# 或者: from UtilFunc import matchName [as 别名]
def test_matchName_07(self):
name = [{'WrittenLast':'Min','WrittenFirst':'Twins'},['Min','Nicolas'],None]
returnValue = UtilFunc.matchName(name[0],self.refData,name[2])
self.assertEqual([returnValue['YearbookLast'],returnValue['YearbookFirst']],name[1])
示例3: test_matchName_06
# 需要导入模块: import UtilFunc [as 别名]
# 或者: from UtilFunc import matchName [as 别名]
def test_matchName_06(self):
name = [{'WrittenLast':'Lunsford','WrittenFirst':'Erik-Scott'},['Lunsford','Erik-Scott'],0]
returnValue = UtilFunc.matchName(name[0],self.refData,name[2])
self.assertEqual([returnValue['YearbookLast'],returnValue['YearbookFirst']],name[1])
示例4: test_matchName_04
# 需要导入模块: import UtilFunc [as 别名]
# 或者: from UtilFunc import matchName [as 别名]
def test_matchName_04(self):
name = [{'WrittenLast':'MercerRyan','WrittenFirst':''},['Mercer','Ryan'],0]
returnValue = UtilFunc.matchName(name[0],self.refData,name[2])
self.assertEqual([returnValue['YearbookLast'],returnValue['YearbookFirst']],name[1])
示例5: indexList
# 需要导入模块: import UtilFunc [as 别名]
# 或者: from UtilFunc import matchName [as 别名]
def indexList(inputFilePath, inputCompleteFilePath, errorFilePath, yearbookReferenceFilePath, outputFilePath):
names = []
#list of dictionaries
yearbookNames = UtilFunc.parseDataFromFile(yearbookReferenceFilePath)
#list of dicitonaries
namesOutput = []
with open(inputFilePath, 'r') as fWN:
for writtenIndex, line in enumerate(fWN):
#could have been simpler, but sometimes last names are not included
#may have to worry about only last name. Spell checker will reject that
# lineSplit = line.replace('\n','').split(None,1)[::-1]
lineSplit = line.replace('\n','').split(None,1)
l0 = lineSplit[0]
l1 = ''
if len(lineSplit) > 1:
l1 = lineSplit[1]
else:
l1 = '_'
names.append({ 'WrittenIndex':str(writtenIndex),
'WrittenFirst':l0,
'WrittenLast':l1})
# with open(yearbookNamesFile, 'r') as fYBN:
# for index, line in enumerate(fYBN):
# #Skip the heading
# if index > 0:
# (l0,l1,l2,l3) = line.replace('\r','').replace('\n','').split(',')
# yearbookNames.append({ 'AlphaIndex':l0,
# 'YearbookLast':l1,
# 'YearbookFirst':l2,
# 'GraduatedLLA09':l3})
namesOutput = []
for name in names:
jaroMatch = UtilFunc.matchName(name, yearbookNames)
namesOutput.append(jaroMatch)
# for n in namesOutput: #debugging
# print(str(n) + '\n')
#append missing names
for ybn in yearbookNames:
if ybn['AlphaIndex'] not in [no['AlphaIndex'] for no in namesOutput]:
temp = ybn.copy()
temp.update({ 'WrittenIndex':'-',
'WrittenLast':'',
'WrittenFirst':'',
'Spelling':str(0)})
namesOutput.append(temp)
with open(outputFilePath,'w') as fOut:
fOut.write('AlphaIndex,WrittenIndex,WrittenLast,WrittenFirst,YearbookLast,YearbookFirst,Spelling,GraduatedLLA09\n')
for no in namesOutput:
fOut.write('{},{},{},{},{},{},{},{}\n'.format( no['AlphaIndex'],
no['WrittenIndex'],
no['WrittenLast'],
no['WrittenFirst'],
no['YearbookLast'],
no['YearbookFirst'],
no['Spelling'],
no['GraduatedLLA09']))
shutil.copy(inputFilePath,inputCompleteFilePath)
os.remove(inputFilePath)
return