@@ -62,7 +62,7 @@ class SequenceMatcher:
62
62
notion, pairing up elements that appear uniquely in each sequence.
63
63
That, and the method here, appear to yield more intuitive difference
64
64
reports than does diff. This method appears to be the least vulnerable
65
- to synching up on blocks of "junk lines", though (like blank lines in
65
+ to syncing up on blocks of "junk lines", though (like blank lines in
66
66
ordinary text files, or maybe "<P>" lines in HTML files). That may be
67
67
because this is the only method of the 3 that has a *concept* of
68
68
"junk" <wink>.
@@ -115,38 +115,6 @@ class SequenceMatcher:
115
115
case. SequenceMatcher is quadratic time for the worst case and has
116
116
expected-case behavior dependent in a complicated way on how many
117
117
elements the sequences have in common; best case time is linear.
118
-
119
- Methods:
120
-
121
- __init__(isjunk=None, a='', b='')
122
- Construct a SequenceMatcher.
123
-
124
- set_seqs(a, b)
125
- Set the two sequences to be compared.
126
-
127
- set_seq1(a)
128
- Set the first sequence to be compared.
129
-
130
- set_seq2(b)
131
- Set the second sequence to be compared.
132
-
133
- find_longest_match(alo, ahi, blo, bhi)
134
- Find longest matching block in a[alo:ahi] and b[blo:bhi].
135
-
136
- get_matching_blocks()
137
- Return list of triples describing matching subsequences.
138
-
139
- get_opcodes()
140
- Return list of 5-tuples describing how to turn a into b.
141
-
142
- ratio()
143
- Return a measure of the sequences' similarity (float in [0,1]).
144
-
145
- quick_ratio()
146
- Return an upper bound on .ratio() relatively quickly.
147
-
148
- real_quick_ratio()
149
- Return an upper bound on ratio() very quickly.
150
118
"""
151
119
152
120
def __init__ (self , isjunk = None , a = '' , b = '' , autojunk = True ):
@@ -334,9 +302,11 @@ def __chain_b(self):
334
302
for elt in popular : # ditto; as fast for 1% deletion
335
303
del b2j [elt ]
336
304
337
- def find_longest_match (self , alo , ahi , blo , bhi ):
305
+ def find_longest_match (self , alo = 0 , ahi = None , blo = 0 , bhi = None ):
338
306
"""Find longest matching block in a[alo:ahi] and b[blo:bhi].
339
307
308
+ By default it will find the longest match in the entirety of a and b.
309
+
340
310
If isjunk is not defined:
341
311
342
312
Return (i,j,k) such that a[i:i+k] is equal to b[j:j+k], where
@@ -391,6 +361,10 @@ def find_longest_match(self, alo, ahi, blo, bhi):
391
361
# the unique 'b's and then matching the first two 'a's.
392
362
393
363
a , b , b2j , isbjunk = self .a , self .b , self .b2j , self .bjunk .__contains__
364
+ if ahi is None :
365
+ ahi = len (a )
366
+ if bhi is None :
367
+ bhi = len (b )
394
368
besti , bestj , bestsize = alo , blo , 0
395
369
# find longest junk-free match
396
370
# during an iteration of the loop, j2len[j] = length of longest
@@ -688,6 +662,7 @@ def real_quick_ratio(self):
688
662
689
663
__class_getitem__ = classmethod (GenericAlias )
690
664
665
+
691
666
def get_close_matches (word , possibilities , n = 3 , cutoff = 0.6 ):
692
667
"""Use SequenceMatcher to return list of the best "good enough" matches.
693
668
@@ -830,14 +805,6 @@ class Differ:
830
805
+ 4. Complicated is better than complex.
831
806
? ++++ ^ ^
832
807
+ 5. Flat is better than nested.
833
-
834
- Methods:
835
-
836
- __init__(linejunk=None, charjunk=None)
837
- Construct a text differencer, with optional filters.
838
-
839
- compare(a, b)
840
- Compare two sequences of lines; generate the resulting delta.
841
808
"""
842
809
843
810
def __init__ (self , linejunk = None , charjunk = None ):
@@ -870,7 +837,7 @@ def compare(self, a, b):
870
837
Each sequence must contain individual single-line strings ending with
871
838
newlines. Such sequences can be obtained from the `readlines()` method
872
839
of file-like objects. The delta generated also consists of newline-
873
- terminated strings, ready to be printed as-is via the writeline ()
840
+ terminated strings, ready to be printed as-is via the writelines ()
874
841
method of a file-like object.
875
842
876
843
Example:
0 commit comments