id_translation.mapping.score_functions#

Functions which return a likeness score.

See also

The HeuristicScore class.

Functions

disabled(value, candidates, context[, strict])

Special value to indicate that scoring logic has been disabled.

equality(value, candidates, context)

Return 1.0 if k == c_i, 0.0 otherwise.

modified_hamming(name, candidates, context, *)

Compute hamming distance modified by length ratio, from the back.

disabled(value, candidates, context, strict=True)[source]#

Special value to indicate that scoring logic has been disabled.

This is a workaround to allow users to indicate that the scoring logic is disabled, and that overrides should be used instead. The disabled-function has no special meaning to the mapper, and will be called as any other scoring function.

Returns:

If strict is False, negative infinity for all candidates, serving as a catch-all removal filter.

Raises:

ScoringDisabledError – If strict is True.

See also

The Override-only mapping documentation.

equality(value, candidates, context)[source]#

Return 1.0 if k == c_i, 0.0 otherwise.

Examples

>>> from id_translation.mapping.score_functions import equality
>>> list(equality("a", "aAb", context=None))
[1.0, 0.0, 0.0]
modified_hamming(name, candidates, context, *, add_length_ratio_term=True, positional_penalty=0.001)[source]#

Compute hamming distance modified by length ratio, from the back. Score range is [0, 1].

Parameters:
  • name – A name that should be mapped one of the sources in candidates.

  • candidates – Candidate sources.

  • context – Should be None. Always ignored, exists for compatibility.

  • add_length_ratio_term – If True, score is divided by abs(len(name) - len(candidate)).

  • positional_penalty – A penalty applied to prefer earlier candidates, according to the formulare penalty = index(candidate) * positional_penalty).

Examples

>>> from id_translation.mapping.score_functions import modified_hamming
>>> list(modified_hamming("aa", ["aa", "a", "ab", "aa"], context=None))
[1.0, 0.499, 0.498, 0.997]
>>> list(
...     modified_hamming(
...         "aa", ["aa", "a", "ab", "aa"], context=None, positional_penalty=0
...     )
... )
[1.0, 0.5, 0.5, 1.0]
>>> list(modified_hamming("face", ["face", "FAce", "race", "place"], context=None))
[1.0, 0.499, 0.748, 0.372]