httk.serve.optimade.backend.translation¶
Translation of OPTIMADE filter syntax trees into backend search expressions.
The generic translation is implemented in httk.store.query.optimade_filters;
translate_filter() delegates to
translate_filter_ast() and wraps its neutral
FilterTranslationError failure categories
into TranslatorError HTTP errors.
format_value() and translate_filter_node() are thin
OPTIMADE-side wrappers over the upstream functions.
Functions¶
|
Convert a filter value and translate neutral failures to HTTP errors. |
|
Build one searcher per entry source, with the filter applied to each. |
|
Translate one filter node against an OPTIMADE entry-info property mapping. |
Module Contents¶
- httk.serve.optimade.backend.translation.format_value(fulltype, val, allow_null=False)[source]¶
Convert a filter value and translate neutral failures to HTTP errors.
Delegates to
httk.store.query.optimade_filters.format_value()and raisesTranslatorErrorfor its neutralFilterTranslationErrorfailures.- Parameters:
- Returns:
Backend-ready filter value.
- Raises:
httk.serve.optimade.model.errors.TranslatorError – If the value cannot be translated.
- Return type:
Any
- httk.serve.optimade.backend.translation.translate_filter(filter_ast, entries, adapter, sort=None)[source]¶
Build one searcher per entry source, with the filter applied to each.
Relationship-property filters (dotted identifiers over served entry types) are resolved through the adapter’s related-property resolver (built by
_related_property_resolver), so filteringreferences.doibehaves exactly like filtering/referencesdirectly.- Parameters:
filter_ast (httk.core.optimade.FilterAst | None) – Parsed filter, or
Nonefor an unfiltered query.adapter (httk.serve.optimade.backend.adapter.BackendAdapter) – Backend adapter supplying sources and handlers.
sort (collections.abc.Sequence[tuple[str, bool]] | None) – Response fields and descending flags for sorting.
- Returns:
Source/searcher pairs with the filter and sort applied.
- Raises:
httk.serve.optimade.model.errors.TranslatorError – If the filter cannot be translated.
- Return type:
list[tuple[httk.serve.optimade.backend.adapter.EntrySource, httk.store.query.Searcher]]
- httk.serve.optimade.backend.translation.translate_filter_node(node, search_variable, entry, entry_info, handlers, recognized_prefixes, served_entries=())[source]¶
Translate one filter node against an OPTIMADE entry-info property mapping.
An OPTIMADE-side adaptation of
translate_filter_ast():entry_infomaps property names to their property dictionaries (only their'fulltype'keys are read) rather than straight to fulltypes,served_entriesnames the relationship targets, and failures surface asTranslatorErrorinstead of the upstream neutralFilterTranslationError.No related-property resolver is threaded through, so relationship-property filters other than
<type>.id HAS ...raise a not-implemented (501) error. Usetranslate_filter()(which builds the resolver from its adapter) for full relationship-property filtering.- Parameters:
node (httk.core.optimade.FilterAst) – Filter node to translate.
search_variable (httk.store.query.SearchVariable) – Backend variable used by the expression.
entry (str) – Entry endpoint being filtered.
entry_info (collections.abc.Mapping[str, Any]) – Simplified property metadata for the entry.
handlers (httk.store.query.optimade_filters.HandlerTable) – Property handlers used for translation.
recognized_prefixes (tuple[str, Ellipsis]) – Property-definition prefixes accepted by the filter.
served_entries (tuple[str, Ellipsis]) – Entry types available as relationship targets.
- Returns:
Backend search expression.
- Raises:
httk.serve.optimade.model.errors.TranslatorError – If the filter cannot be translated.
- Return type: