18 lines
430 B
Python
18 lines
430 B
Python
|
|
import difflib
|
|
|
|
def similarity(s1, s2):
|
|
if not s1 or not s2: return 0.0
|
|
return difflib.SequenceMatcher(None, s1, s2).ratio()
|
|
|
|
s1 = "技有限公司"
|
|
s2 = "威凯检测技术有限公司"
|
|
|
|
print(f"s1: '{s1}' (len={len(s1)})")
|
|
print(f"s2: '{s2}' (len={len(s2)})")
|
|
print(f"Ratio: {similarity(s1, s2):.4f}")
|
|
|
|
s3 = "检测技术有限"
|
|
print(f"\ns3: '{s3}' (len={len(s3)})")
|
|
print(f"Ratio s3 vs s2: {similarity(s3, s2):.4f}")
|