Skip to content

Commit

Permalink
Support exists/missing DSL for number searches
Browse files Browse the repository at this point in the history
  • Loading branch information
danlamanna committed Oct 30, 2023
1 parent b3027b0 commit 472300c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
14 changes: 11 additions & 3 deletions isic/core/dsl.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ def to_q(self, key: SearchTermKey) -> Q:

class NumberValue(Value):
def __init__(self, toks) -> None:
self.value = toks[0]
if toks[0] == "*":
self.value = "*"
else:
self.value = toks[0]


class NumberRangeValue(Value):
Expand Down Expand Up @@ -124,9 +127,14 @@ def q_or(s, loc, toks):

# asterisks for wildcard, _ for ISIC ID search, - for license types
str_value = (Word(alphas + nums + "*" + "_" + "-") | QuotedString('"')).add_parse_action(StrValue)
number_value = pyparsing_common.number.add_parse_action(NumberValue)
number_value = (pyparsing_common.number.copy() | EXISTS).add_parse_action(NumberValue)
concrete_number_value = pyparsing_common.number.copy().add_parse_action(NumberValue)
number_range_value = (
one_of("[ {") + number_value + Suppress(Literal("TO")) + number_value + one_of("] }")
one_of("[ {")
+ concrete_number_value
+ Suppress(Literal("TO"))
+ concrete_number_value
+ one_of("] }")
).add_parse_action(NumberRangeValue)
bool_value = one_of("true false *").add_parse_action(BoolValue)

Expand Down
1 change: 1 addition & 0 deletions isic/core/tests/test_dsl.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# test negation and present/missing values
["-isic_id:*", ~Q(isic__id__isnull=False)],
["-lesion_id:*", ~Q(accession__lesion__id__isnull=False)],
["-mel_thick_mm:*", ~Q(accession__metadata__mel_thick_mm__isnull=False)],
[
"-diagnosis:* OR diagnosis:foobar",
~Q(accession__metadata__diagnosis__isnull=False)
Expand Down

0 comments on commit 472300c

Please sign in to comment.