Skip to content

Commit b7a530b

Browse files
author
Gerit Wagner
committed
use operator constants
1 parent 6f8d224 commit b7a530b

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

search_query/query.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,13 @@ def __init__(
7979
def selects(self, *, record_dict: dict) -> bool:
8080
"""Indicates whether the query selects a given record."""
8181

82-
if self.value == "NOT":
82+
if self.value == Operators.NOT:
8383
return not self.children[0].selects(record_dict=record_dict)
8484

85-
if self.value == "AND":
85+
if self.value == Operators.AND:
8686
return all(x.selects(record_dict=record_dict) for x in self.children)
8787

88-
if self.value == "OR":
88+
if self.value == Operators.OR:
8989
return any(x.selects(record_dict=record_dict) for x in self.children)
9090

9191
assert not self.operator

search_query/serializer_pubmed.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from search_query.constants import PLATFORM
88
from search_query.constants import PLATFORM_FIELD_MAP
9-
9+
from search_query.constants import Operators
1010
if typing.TYPE_CHECKING: # pragma: no
1111
from search_query.query import Query
1212

@@ -41,7 +41,7 @@ def to_string_pubmed(node: Query) -> str:
4141

4242
else:
4343
# node is operator node
44-
if child.value == "NOT":
44+
if child.value == Operators.NOT:
4545
# current element is NOT Operator -> no parenthesis in PubMed
4646
result = f"{result}{to_string_pubmed(child)}"
4747

@@ -50,7 +50,7 @@ def to_string_pubmed(node: Query) -> str:
5050
else:
5151
result = f"{result} {node.value} {to_string_pubmed(child)}"
5252

53-
if (child == node.children[-1]) & (child.value != "NOT"):
53+
if (child == node.children[-1]) & (child.value != Operators.NOT):
5454
result = f"{result})"
5555
return f"{result}"
5656

search_query/serializer_wos.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import typing
66

77
from search_query.constants import Fields
8+
from search_query.constants import Operators
89

910
if typing.TYPE_CHECKING: # pragma: no
1011
from search_query.query import Query
@@ -36,7 +37,7 @@ def to_string_wos(node: Query) -> str:
3637

3738
else:
3839
# node is operator node
39-
if child.value == "NOT":
40+
if child.value == Operators.NOT:
4041
# current element is NOT Operator -> no parenthesis in WoS
4142
result = f"{result}{to_string_wos(child)}"
4243

@@ -45,7 +46,7 @@ def to_string_wos(node: Query) -> str:
4546
else:
4647
result = f"{result} {node.value} {to_string_wos(child)}"
4748

48-
if (child == node.children[-1]) & (child.value != "NOT"):
49+
if (child == node.children[-1]) & (child.value != Operators.NOT):
4950
result = f"{result})"
5051
return f"{result}"
5152

0 commit comments

Comments
 (0)