{"id":23200,"library":"affinegap","title":"affinegap","description":"A Cython implementation of the affine gap string distance for measuring string similarity with affine gap penalties. Current version 1.12, stable but rarely updated.","status":"active","version":"1.12","language":"python","source_language":"en","source_url":"https://github.com/datamade/affinegap","tags":["string-distance","affine-gap","cython"],"install":[{"cmd":"pip install affinegap","lang":"bash","label":"Install from PyPI"}],"dependencies":[],"imports":[{"note":"affinegap is the module itself, not a function named affinegap; the main function is accessed as affinegap.affineGapDistance","wrong":"from affinegap import affinegap","symbol":"affinegap","correct":"import affinegap"}],"quickstart":{"code":"import affinegap\n\n# Compute affine gap distance between two strings\ndist = affinegap.affineGapDistance(\"string1\", \"string2\")\nprint(dist)\n\n# With custom gap penalties\ndist = affinegap.affineGapDistance(\"hello\", \"hallo\", match_weight=0, mismatch_weight=1, gap_weight=1, spatial_gap_weight=1)\nprint(dist)","lang":"python","description":"Basic usage: compute affine gap string distance. The function returns an integer distance or similarity score depending on penalties."},"warnings":[{"fix":"Use `affinegap.affineGapDistance(s1, s2)`","message":"The function is named `affineGapDistance` (capital G) not `affinegap`. Many users mistakenly try `affinegap.distance()`.","severity":"gotcha","affected_versions":"all"},{"fix":"Adjust parameters: e.g., match_weight=-1, mismatch_weight=1, gap_weight=-1 for similarity-like scores.","message":"Default behavior: by default, match_weight=0, mismatch_weight=1, gap_weight=1, spatial_gap_weight=1. This means identical strings get distance 0, but a single mismatch or gap adds 1. This may not be what you expect for 'similarity'.","severity":"gotcha","affected_versions":"all"},{"fix":"Ensure both arguments are strings.","message":"Affine gap distance is not symmetric? Actually it is symmetric, but careful: the function expects two strings; if you pass integer or None, it may throw TypeError.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Replace with `import affinegap` and use `affinegap.affineGapDistance`.","cause":"Trying to do `from affinegap import affinegap` instead of `import affinegap`.","error":"ImportError: cannot import name 'affinegap'"},{"fix":"Use `affinegap.affineGapDistance`.","cause":"Same as above - the module does not contain a function named affinegap.","error":"AttributeError: module 'affinegap' has no attribute 'affinegap'"},{"fix":"Convert arguments to strings: `affinegap.affineGapDistance(str(a), str(b))`","cause":"Passing a non-string (e.g., integer) to affineGapDistance.","error":"TypeError: expected string or Unicode object"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}