I need to transform a source string to target string and express the same as an operation (D,A,TYPE) ie(deletion , addition, PREFIX\SUFFIX) to the source string which will transform it to target string on applying these operation to the suffix of the source string, or the prefix of the source string
eg:
activities->activity
(ies,y,suffix)
center->centre
(er,re,suffix)
solutions->solution
(s,None,suffix)
solution ->solutions
(None,s,suffix)
could->would
(c,w,prefix)
the following code does get the suffixes but also gets all other matches but I need this only for suffixes, beside it does not output the correct format as required by me.
from difflib import SequenceMatcher
a = "ACTIVITY"
b = "ACTIVITIES"
s = SequenceMatcher(None, a, b)
for tag, i1, i2, j1, j2 in s.get_opcodes():
print ("%7s a[%d:%d] (%s) b[%d:%d] (%s)" %
(tag, i1, i2, a[i1:i2], j1, j2, b[j1:j2]))
Also I don't need any corrections to be output if there is no sufficient suffix/prefix match eg: strings like enough, beyond should yield no match, Which can be possibly gleaned from:
difflib.SequenceMatcher(None,'especially','particularly').ratio()