summaryrefslogtreecommitdiff
path: root/logical_search.py
diff options
context:
space:
mode:
authorScott <[email protected]>2022-01-26 21:35:20 -0800
committerScott <[email protected]>2022-01-26 21:35:20 -0800
commite6f32fdd9b373dfcd100c7accb41f57d83c2f0a1 (patch)
treeeea4985bc43238fbd070c783441f08988f581973 /logical_search.py
parent36fea7f15ed17150691b5b3ead75450e575229ef (diff)
Ahem. Still running black?
Diffstat (limited to 'logical_search.py')
-rw-r--r--logical_search.py30
1 files changed, 7 insertions, 23 deletions
diff --git a/logical_search.py b/logical_search.py
index 85f9461..c324ff8 100644
--- a/logical_search.py
+++ b/logical_search.py
@@ -30,9 +30,7 @@ class Document(NamedTuple):
docid: str # a unique idenfier for the document
tags: Set[str] # an optional set of tags
- properties: List[
- Tuple[str, str]
- ] # an optional set of key->value properties
+ properties: List[Tuple[str, str]] # an optional set of key->value properties
reference: Any # an optional reference to something else
@@ -102,9 +100,7 @@ class Corpus(object):
def __init__(self) -> None:
self.docids_by_tag: Dict[str, Set[str]] = defaultdict(set)
- self.docids_by_property: Dict[Tuple[str, str], Set[str]] = defaultdict(
- set
- )
+ self.docids_by_property: Dict[Tuple[str, str], Set[str]] = defaultdict(set)
self.docids_with_property: Dict[str, Set[str]] = defaultdict(set)
self.documents_by_docid: Dict[str, Document] = {}
@@ -183,11 +179,7 @@ class Corpus(object):
"""Invert a set of docids."""
return set(
- [
- docid
- for docid in self.documents_by_docid.keys()
- if docid not in original
- ]
+ [docid for docid in self.documents_by_docid.keys() if docid not in original]
)
def get_doc(self, docid: str) -> Optional[Document]:
@@ -297,9 +289,7 @@ class Corpus(object):
ok = True
break
if not ok:
- raise ParseError(
- "Unbalanced parenthesis in query expression"
- )
+ raise ParseError("Unbalanced parenthesis in query expression")
# and, or, not
else:
@@ -376,23 +366,17 @@ class Node(object):
raise ParseError(f"Unexpected query {tag}")
elif self.op is Operation.DISJUNCTION:
if len(evaled_operands) != 2:
- raise ParseError(
- "Operation.DISJUNCTION (or) expects two operands."
- )
+ raise ParseError("Operation.DISJUNCTION (or) expects two operands.")
retval.update(evaled_operands[0])
retval.update(evaled_operands[1])
elif self.op is Operation.CONJUNCTION:
if len(evaled_operands) != 2:
- raise ParseError(
- "Operation.CONJUNCTION (and) expects two operands."
- )
+ raise ParseError("Operation.CONJUNCTION (and) expects two operands.")
retval.update(evaled_operands[0])
retval = retval.intersection(evaled_operands[1])
elif self.op is Operation.INVERSION:
if len(evaled_operands) != 1:
- raise ParseError(
- "Operation.INVERSION (not) expects one operand."
- )
+ raise ParseError("Operation.INVERSION (not) expects one operand.")
_ = evaled_operands[0]
if isinstance(_, set):
retval.update(self.corpus.invert_docid_set(_))