Skip to content

Commit e029ba8

Browse files
author
MrCabss69
committed
Minor improvements: readability, styling
1 parent b9085a1 commit e029ba8

2 files changed

Lines changed: 14 additions & 13 deletions

File tree

rre-dataset-generator/src/model/query_rating_context.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def __init__(self, query: str, doc_id: str | None = None):
1616
self._id: str = str(uuid.uuid4())
1717
self._query: str = query
1818
self._doc_id_to_rating_score: Dict[str, int] = {}
19-
# HANDLING NONEs - thowed error in some tests
19+
# HANDLING NONEs - throwed error in some tests
2020
if doc_id is not None:
2121
self._doc_id_to_rating_score[doc_id] = self.DOC_NOT_RATED
2222

rre-dataset-generator/src/search_engine/data_store.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,23 @@ def __init__(self):
2424

2525
def _get_query_rating_context_by_id(self, query_id: str) -> QueryRatingContext:
2626
if query_id not in self._queries_by_id:
27-
log.error("Query id %s not found in DataStore", query_id)
28-
raise KeyError(f"Query id '{query_id}' not found in DataStore")
27+
_error_msg = f"Query id {query_id} not found in DataStore"
28+
log.error(_error_msg)
29+
raise KeyError(_error_msg)
2930
return self._queries_by_id[query_id]
3031

3132
def _get_document(self, doc_id: str) -> Optional[Document]:
3233
if doc_id not in self._documents:
33-
log.warning("Document id %s not found in DataStore", doc_id)
34+
_warning_msg = f"Detected an error when retrieving a document from the data store. Document {doc_id} not found in DataStore"
35+
log.warning(_warning_msg)
3436
return None
3537
return self._documents[doc_id]
3638

3739
def add_document(self, doc_id: str, document: Document) -> None:
3840
if doc_id in self._documents:
39-
log.error("Document id %s already exists in DataStore", doc_id)
40-
raise KeyError(f"Document id '{doc_id}' found in DataStore")
41+
_error_msg = f"Detected an error when adding document to the data store. Document {doc_id} already present."
42+
log.error(_error_msg)
43+
raise KeyError(_error_msg)
4144
self._documents[doc_id] = document
4245

4346
def has_document(self, doc_id: str) -> bool:
@@ -95,7 +98,6 @@ def add_rating_score(self, query_id: str, doc_id: str, rating_score: int) -> Non
9598
if the query_id is not found.
9699
"""
97100
context = self._get_query_rating_context_by_id(query_id)
98-
99101
context.add_rating_score(doc_id, rating_score)
100102
self._queries_by_id[query_id] = context
101103

@@ -134,7 +136,6 @@ def save_queries_and_docs(self, filepath: str | Path) -> None:
134136
def load_queries_and_docs(self, filepath: str | Path) -> None:
135137
"""
136138
Loads query contexts from a JSON file. Reconstructs query_id, query text, and associated doc_ids.
137-
NOTE: This assumes QueryRatingContext has a way to inject existing query_id and doc_ids.
138139
"""
139140
with open(filepath, "r", encoding="utf-8") as f:
140141
data = json.load(f)
@@ -153,13 +154,13 @@ def save_rating_triples(self, filepath: str | Path) -> None:
153154
Saves all (query_id, doc_id, score) triples to a JSON file.
154155
"""
155156
triples = []
156-
for ctx in self._queries_by_id.values():
157-
qid = ctx.get_query_id()
158-
for doc_id in ctx.get_doc_ids():
157+
for _context in self._queries_by_id.values():
158+
query_id = _context.get_query_id()
159+
for doc_id in _context.get_doc_ids():
159160
try:
160-
score = ctx.get_rating_score(doc_id)
161+
score = _context.get_rating_score(doc_id)
161162
triples.append({
162-
"query_id": qid,
163+
"query_id": query_id,
163164
"doc_id": doc_id,
164165
"score": score
165166
})

0 commit comments

Comments
 (0)