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

format_value(fulltype, val[, allow_null])

Convert a filter value and translate neutral failures to HTTP errors.

translate_filter(filter_ast, entries, adapter[, sort])

Build one searcher per entry source, with the filter applied to each.

translate_filter_node(node, search_variable, entry, ...)

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 raises TranslatorError for its neutral FilterTranslationError failures.

Parameters:
  • fulltype (str) – Simplified OPTIMADE property type.

  • val (tuple[Any, Ellipsis]) – Parsed filter values.

  • allow_null (bool) – Allow a null value for the property.

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 filtering references.doi behaves exactly like filtering /references directly.

Parameters:
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_info maps property names to their property dictionaries (only their 'fulltype' keys are read) rather than straight to fulltypes, served_entries names the relationship targets, and failures surface as TranslatorError instead of the upstream neutral FilterTranslationError.

No related-property resolver is threaded through, so relationship-property filters other than <type>.id HAS ... raise a not-implemented (501) error. Use translate_filter() (which builds the resolver from its adapter) for full relationship-property filtering.

Parameters:
Returns:

Backend search expression.

Raises:

httk.serve.optimade.model.errors.TranslatorError – If the filter cannot be translated.

Return type:

httk.store.query.SearchExpression