rics.mapping.heuristic_functions#
Functions which perform heuristics for score functions.
See also
The HeuristicScore class.
Module Attributes
If |
Functions
|
Return candidates formatted by fstring. |
|
Force lower-case in value and candidates. |
|
Try to make value look like the name of a database table. |
|
Short circuit candidates which match a given regex to a given to-candidate. |
|
Short circuit candidates which match a given regex a given to-value. |
|
Return a value formatted by fstring. |
- VERBOSE: bool = False#
If
Trueenable 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: Optional[ContextType]) 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: Optional[str], regex: Union[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: Optional[str], regex: Union[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: Optional[ContextType]) Tuple[str, Iterable[str]][source]#
Force lower-case in value and candidates.
- value_fstring_alias(value: str, candidates: Iterable[str], context: Optional[ContextType], fstring: str, for_value: Optional[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: Optional[ContextType], 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’.