rics.mapping.heuristic_functions#

Functions which perform heuristics for score functions.

See also

The HeuristicScore class.

Module Attributes

VERBOSE

If True enable optional DEBUG-level log messages on each heuristic function invocation.

Functions

candidate_fstring_alias(value, candidates, ...)

Return candidates formatted by fstring.

force_lower_case(value, candidates, context)

Force lower-case in value and candidates.

like_database_table(name, candidates, context)

Try to make value look like the name of a database table.

short_circuit_to_candidate(value, ...)

Short circuit candidates which match a given regex to a given to-candidate.

short_circuit_to_value(value, candidates, ...)

Short circuit candidates which match a given regex a given to-value.

value_fstring_alias(value, candidates, ...)

Return a value formatted by fstring.

Classes

Any(*args, **kwargs)

Special type indicating an unconstrained type.

VERBOSE: bool = False#

If True enable optional DEBUG-level log messages on each heuristic function invocation.

Notes

Not all functions have verbose messages.

like_database_table(name: str, candidates: Iterable[str], context: ContextType | None) Tuple[str, List[str]][source]#

Try to make value look like the name of a database table.

short_circuit_to_value(value: str, candidates: Iterable[str], context: str | None, regex: str | Pattern[str], target: str) Set[str][source]#

Short circuit candidates which match a given regex a given to-value.

Parameters:
  • value – A value to map.

  • candidates – Candidates for value.

  • context – Context in which the function is being called.

  • regex – A pattern in candidates which should trigger forced short-circuit matching.

  • target – The target value. If value != target, an empty set is always returned.

Returns:

Candidates which match regex, or an empty set.

Notes

This is technically a filter function and may be used as such.

short_circuit_to_candidate(value: str, candidates: Iterable[str], context: str | None, regex: str | Pattern[str], target: str) Set[str][source]#

Short circuit candidates which match a given regex to a given to-candidate.

Parameters:
  • value – A value to map.

  • candidates – Candidates for value.

  • context – Context in which the function is being called.

  • regex – A pattern in candidates which should trigger forced short-circuit matching.

  • target – A target candidate. Must be present in candidates, or empty set is always returned.

Returns:

Candidates which match regex, or an empty set.

Notes

This is technically a filter function and may be used as such.

force_lower_case(value: str, candidates: Iterable[str], context: ContextType | None) Tuple[str, Iterable[str]][source]#

Force lower-case in value and candidates.

value_fstring_alias(value: str, candidates: Iterable[str], context: ContextType | None, fstring: str, for_value: str = None, **kwargs: Any) Tuple[str, Iterable[str]][source]#

Return a value formatted by fstring.

Parameters:
  • value – An element to find matches for.

  • candidates – Potential matches for value. Not used (returned as given).

  • context – Context in which the function is being called.

  • fstring – The format string to use. Can use value and context as placeholders.

  • for_value – If given, apply only if value == for_value. When if_value_equals is given, fstring arguments which do not use the value as a placeholder key are permitted.

  • **kwargs – Additional keyword placeholders in fstring.

Returns:

A tuple (formatted_value, candidates).

Raises:

ValueError – If fstring does not contain a placeholder ‘value’ and for_value is not given.

candidate_fstring_alias(value: str, candidates: Iterable[str], context: ContextType | None, fstring: str, **kwargs: Any) Tuple[str, Iterable[str]][source]#

Return candidates formatted by fstring.

Parameters:
  • value – An element to find matches for. Not used (returned as given).

  • candidates – Potential matches for value.

  • context – Context in which the function is being called.

  • fstring – The format string to use. Can use value, context, and elements of candidates as placeholders.

  • **kwargs – Additional keyword placeholders in fstring.

Returns:

A tuple (value, formatted_candidates).

Raises:

ValueError – If fstring does not contain a placeholder ‘candidate’.