Package: cdiffer
Python C Extention 2 Sequence CompareEdit distance, Similarity and 2 sequence differences printing.How to Install?pipinstallcdifferRequirementpython3.6 or latercdiffer.distCompute absolute Levenshtein distance of two strings.Usagedist(sequence, sequence)Examples (it's hard to spell Levenshtein correctly):Helponbuilt-infunctiondistinmodulecdiffer:dist(...)ComputeabsoluteLevenshteindistanceoftwostrings.dist(sequence,sequence)Examples(it's hard to spell Levenshtein correctly):>>>dist('coffee','cafe')4>>>dist(list('coffee'),list('cafe'))4>>>dist(tuple('coffee'),tuple('cafe'))4>>>dist(iter('coffee'),iter('cafe'))4>>>dist(range(4),range(5))1>>>dist('coffee','xxxxxx')12>>>dist('coffee','coffee')0cdiffer.similarCompute similarity of two strings.Usagesimilar(sequence, sequence)The similarity is a number between 0 and 1,
base on levenshtein edit distance.Examples>>>fromcdifferimportsimilar>>>>>>similar('coffee','cafe')0.6>>>similar('hoge','bar')0.0cdiffer.differFind sequence of edit operations transforming one string to another.Usagediffer(source_sequence, destination_sequence, diffonly=False, rep_rate=60)Examples>>>fromcdifferimportdiffer>>>>>>forxindiffer('coffee','cafe'):...print(x)...['equal',0,0,'c','c']['delete',1,None,'o',None]['insert',None,1,None,'a']['equal',2,2,'f','f']['delete',3,None,'f',None]['delete',4,None,'e',None]['equal',5,3,'e','e']>>>forxindiffer('coffee','cafe',diffonly=True):...print(x)...['delete',1,None,'o',None]['insert',None,1,None,'a']['delete',3,None,'f',None]['delete',4,None,'e',None]>>>forxindiffer('coffee','cafe',rep_rate=0):...print(x)...['equal',0,0,'c','c']['replace',1,1,'o','a']['equal',2,2,'f','f']['delete',3,None,'f',None]['delete',4,None,'e',None]['equal',5,3,'e','e']>>>forxindiffer('coffee','cafe',diffonly=True,rep_rate=0):...print(x)...['replace',1,1,'o','a']['delete',3,None,'f',None]['delete',4,None,'e',None]cdiffer.compareThis Function is compare and prety printing 2 sequence data.Usagecompare(source_sequence, destination_sequence, diffonly=False, rep_rate=60, condition_value=" ---> ")Parameters :arg1 -> iterable : left comare target data.
arg2 -> iterable : right comare target data.
keya -> callable one argument function : Using sort and compare with key about `a` object.
keyb -> callable one argument function : Using sort and compare with key about `a` object.
header -> bool : output data with header(True) or without header(False). <default True>
diffonly -> bool : output data with equal data(False) or without equal data(True). <default False>
rep_rate -> int: Threshold to be considered as replacement.(-1 ~ 100). -1: allways replacement.
startidx -> int: output record index starting number. <default `0`>
condition_value -> str : Conjunctions for comparison.
na_value -> str: if not found data when filled value.
delete_sign_value -> str: if deleted data when adding sign value.
insert_sign_value ->  str: if insert data when adding sign value.Return : Lists of List1st column -> matching rate (0 ~ 100).
2nd column -> matching tagname (unicode string).
3rd over   -> compare data.ExamplesIn[1]:fromcdifferimportcompare...compare('coffee','cafe')[['tag','index_a','index_b','data'],['equal',0,0,'c'],['insert','-',1,'ADD ---> a'],['delete',1,'-','o ---> DEL'],['equal',2,2,'f'],['delete',3,'-','f ---> DEL'],['equal',4,3,'e'],['delete',5,'-','e ---> DEL']]In[2]:compare([list("abc"),list("abc")],[list("abc"),list("acc"),list("xtz")],rep_rate=50)[['tag','index_a','index_b','COL_00','COL_01','COL_02','COL_03'],['equal',0,0,'a','b','c'],['replace',1,1,'a','b ---> DEL','ADD ---> c','c'],['insert','-',2,'ADD ---> x','ADD ---> t','ADD ---> z']]In[3]:compare(["abc","abc"],["abc","acc","xtz"],rep_rate=40)[['tag','index_a','index_b','data'],['equal',0,0,'abc'],['replace',1,1,'abc ---> acc'],['insert','-',2,'ADD ---> xtz']]In[4]:compare(["abc","abc"],["abc","acc","xtz"],rep_rate=50)[['tag','index_a','index_b','data'],['equal',0,0,'abc'],['replace',1,1,'abc ---> acc'],['insert','-',2,'ADD ---> xtz']]PerformanceC:\Windows\system>ipythonPython3.7.7(tags/v3.7.7:d7c567b08f,Mar102020,10:41:24)[MSCv.190064bit(AMD64)]Type'copyright','credits'or'license'formoreinformationIPython7.21.0--AnenhancedInteractivePython.Type'?'forhelp.In[1]:fromcdifferimport*In[2]:%timeitdist('coffee','cafe')...:%timeitdist(list('coffee'),list('cafe'))...:%timeitdist(tuple('coffee'),tuple('cafe'))...:%timeitdist(iter('coffee'),iter('cafe'))...:%timeitdist(range(4),range(5))...:%timeitdist('coffee','xxxxxx')...:%timeitdist('coffee','coffee')125ns±0.534nsperloop(mean±std.dev.of7runs,10000000loopseach)677ns±2.3nsperloop(mean±std.dev.of7runs,1000000loopseach)638ns±3.42nsperloop(mean±std.dev.of7runs,1000000loopseach)681ns±2.16nsperloop(mean±std.dev.of7runs,1000000loopseach)843ns±3.66nsperloop(mean±std.dev.of7runs,1000000loopseach)125ns±0.417nsperloop(mean±std.dev.of7runs,10000000loopseach)50.5ns±0.338nsperloop(mean±std.dev.of7runs,10000000loopseach)In[3]:%timeitsimilar('coffee','cafe')...:%timeitsimilar(list('coffee'),list('cafe'))...:%timeitsimilar(tuple('coffee'),tuple('cafe'))...:%timeitsimilar(iter('coffee'),iter('cafe'))...:%timeitsimilar(range(4),range(5))...:%timeitsimilar('coffee','xxxxxx')...:%timeitsimilar('coffee','coffee')123ns±0.301nsperloop(mean±std.dev.of7runs,10000000loopseach)680ns±2.64nsperloop(mean±std.dev.of7runs,1000000loopseach)647ns±1.78nsperloop(mean±std.dev.of7runs,1000000loopseach)680ns±7.57nsperloop(mean±std.dev.of7runs,1000000loopseach)848ns±4.19nsperloop(mean±std.dev.of7runs,1000000loopseach)130ns±0.595nsperloop(mean±std.dev.of7runs,10000000loopseach)54.8ns±0.691nsperloop(mean±std.dev.of7runs,10000000loopseach)In[4]:%timeitdiffer('coffee','cafe')...:%timeitdiffer(list('coffee'),list('cafe'))...:%timeitdiffer(tuple('coffee'),tuple('cafe'))...:%timeitdiffer(iter('coffee'),iter('cafe'))...:%timeitdiffer(range(4),range(5))...:%timeitdiffer('coffee','xxxxxx')...:%timeitdiffer('coffee','coffee')735ns±4.18nsperloop(mean±std.dev.of7runs,1000000loopseach)1.36µs±5.17nsperloop(mean±std.dev.of7runs,1000000loopseach)1.31µs±5.25nsperloop(mean±std.dev.of7runs,1000000loopseach)1.37µs±5.04nsperloop(mean±std.dev.of7runs,1000000loopseach)1.33µs±5.32nsperloop(mean±std.dev.of7runs,1000000loopseach)1.07µs±6.75nsperloop(mean±std.dev.of7runs,1000000loopseach)638ns±3.67nsperloop(mean±std.dev.of7runs,1000000loopseach)In[5]:a=dict(zip('012345','coffee'))...:b=dict(zip('0123','cafe'))...:%timeitdist(a,b)...:%timeitsimilar(a,b)...:%timeitdiffer(a,b)524ns±2.6nsperloop(mean±std.dev.of7runs,1000000loopseach)539ns±2.23nsperloop(mean±std.dev.of7runs,1000000loopseach)1.07µs±1.9nsperloop(mean±std.dev.of7runs,1000000loopseach)In[6]:%timeitcompare("coffee","cafe")...:%timeitcompare([list("abc"),list("abc")],[list("abc"),list("acc"),list("xtz")],rep_rate=50)...:%timeitcompare(["abc","abc"],["abc","acc","xtz"],rep_rate=40)...:%timeitcompare(["abc","abc"],["abc","acc","xtz"],rep_rate=50)844ns±3.88nsperloop(mean±std.dev.of7runs,1000000loopseach)3.32µs±6.92nsperloop(mean±std.dev.of7runs,100000loopseach)1.16µs±3.94nsperloop(mean±std.dev.of7runs,1000000loopseach)1.3µs±31.5nsperloop(mean±std.dev.of7runs,1000000loopseach)