|
2 | 2 |
|
3 | 3 | from lark import v_args |
4 | 4 | from elasticsearch_dsl import Q, Text, Keyword, Integer, Field |
5 | | -from optimade.models import CHEMICAL_SYMBOLS, ATOMIC_NUMBERS |
6 | 5 | from optimade.filtertransformers import BaseTransformer |
7 | 6 | from optimade.server.exceptions import BadRequest |
8 | 7 |
|
|
14 | 13 | _has_operators = {"ALL": "must", "ANY": "should"} |
15 | 14 | _length_quantities = { |
16 | 15 | "elements": "nelements", |
17 | | - "elements_rations": "nelements", |
| 16 | + "elements_ratios": "nelements", |
18 | 17 | "dimension_types": "dimension_types", |
19 | 18 | } |
20 | 19 |
|
@@ -130,42 +129,50 @@ def _has_query_op(self, quantities, op, predicate_zip_list): |
130 | 129 | # in elastic search. Only supported for elements, where we can construct |
131 | 130 | # an anonymous "formula" based on elements sorted by order number and |
132 | 131 | # can do a = comparision to check if all elements are contained |
133 | | - if len(quantities) > 1: |
134 | | - raise NotImplementedError("HAS ONLY is not supported with zip") |
135 | | - quantity = quantities[0] |
136 | 132 |
|
137 | | - if quantity.has_only_quantity is None: |
138 | | - raise NotImplementedError( |
139 | | - "HAS ONLY is not supported by %s" % quantity.name |
140 | | - ) |
141 | | - |
142 | | - def values(): |
143 | | - for predicates in predicate_zip_list: |
144 | | - if len(predicates) != 1: |
145 | | - raise NotImplementedError("Tuples not supported in HAS ONLY") |
146 | | - op, value = predicates[0] |
147 | | - if op != "=": |
148 | | - raise NotImplementedError( |
149 | | - "Predicated not supported in HAS ONLY" |
150 | | - ) |
151 | | - if not isinstance(value, str): |
152 | | - raise NotImplementedError("Only strings supported in HAS ONLY") |
153 | | - yield value |
154 | | - |
155 | | - try: |
156 | | - order_numbers = list([ATOMIC_NUMBERS[element] for element in values()]) |
157 | | - order_numbers.sort() |
158 | | - value = "".join( |
159 | | - [CHEMICAL_SYMBOLS[number - 1] for number in order_numbers] |
160 | | - ) |
161 | | - except KeyError: |
162 | | - raise NotImplementedError( |
163 | | - "HAS ONLY is only supported for chemical symbols" |
164 | | - ) |
| 133 | + # @ml-evs: Disabling this HAS ONLY workaround as tests are not passing |
| 134 | + raise NotImplementedError( |
| 135 | + "HAS ONLY queries are not currently supported by the Elasticsearch backend." |
| 136 | + ) |
165 | 137 |
|
166 | | - return Q("term", **{quantity.has_only_quantity.name: value}) |
| 138 | + # from optimade.models import CHEMICAL_SYMBOLS, ATOMIC_NUMBERS |
| 139 | + |
| 140 | + # if len(quantities) > 1: |
| 141 | + # raise NotImplementedError("HAS ONLY is not supported with zip") |
| 142 | + # quantity = quantities[0] |
| 143 | + |
| 144 | + # if quantity.has_only_quantity is None: |
| 145 | + # raise NotImplementedError( |
| 146 | + # "HAS ONLY is not supported by %s" % quantity.name |
| 147 | + # ) |
| 148 | + |
| 149 | + # def values(): |
| 150 | + # for predicates in predicate_zip_list: |
| 151 | + # if len(predicates) != 1: |
| 152 | + # raise NotImplementedError("Tuples not supported in HAS ONLY") |
| 153 | + # op, value = predicates[0] |
| 154 | + # if op != "=": |
| 155 | + # raise NotImplementedError( |
| 156 | + # "Predicated not supported in HAS ONLY" |
| 157 | + # ) |
| 158 | + # if not isinstance(value, str): |
| 159 | + # raise NotImplementedError("Only strings supported in HAS ONLY") |
| 160 | + # yield value |
| 161 | + |
| 162 | + # try: |
| 163 | + # order_numbers = list([ATOMIC_NUMBERS[element] for element in values()]) |
| 164 | + # order_numbers.sort() |
| 165 | + # value = "".join( |
| 166 | + # [CHEMICAL_SYMBOLS[number - 1] for number in order_numbers] |
| 167 | + # ) |
| 168 | + # except KeyError: |
| 169 | + # raise NotImplementedError( |
| 170 | + # "HAS ONLY is only supported for chemical symbols" |
| 171 | + # ) |
| 172 | + |
| 173 | + # return Q("term", **{quantity.has_only_quantity.name: value}) |
167 | 174 | else: |
168 | | - raise NotImplementedError |
| 175 | + raise NotImplementedError(f"Unrecognised operation {op}.") |
169 | 176 |
|
170 | 177 | queries = [ |
171 | 178 | self._has_query(quantities, predicates) for predicates in predicate_zip_list |
@@ -320,12 +327,15 @@ def set_zip_op_rhs(self, args): |
320 | 327 | return lambda quantity: self._has_query_op([quantity] + add_on, op, values) |
321 | 328 |
|
322 | 329 | def property_zip_addon(self, args): |
| 330 | + raise NotImplementedError("Correlated list queries are not supported.") |
323 | 331 | return args |
324 | 332 |
|
325 | 333 | def value_zip(self, args): |
| 334 | + raise NotImplementedError("Correlated list queries are not supported.") |
326 | 335 | return self.value_list(args) |
327 | 336 |
|
328 | 337 | def value_zip_list(self, args): |
| 338 | + raise NotImplementedError("Correlated list queries are not supported.") |
329 | 339 | return args |
330 | 340 |
|
331 | 341 | def value_list(self, args): |
|
0 commit comments