Sourcery Starbot ⭐ refactored sarthak7gupta/SearchEngineForEnvironmentalNews#3
Sourcery Starbot ⭐ refactored sarthak7gupta/SearchEngineForEnvironmentalNews#3SourceryAI wants to merge 1 commit into
Conversation
|
|
||
| def ranked_retrieval(self, query: List[str]) -> List[doc_id_type]: | ||
| if not any(term in self.all_terms for term in query): | ||
| if all(term not in self.all_terms for term in query): |
There was a problem hiding this comment.
Function Engine.ranked_retrieval refactored with the following changes:
- Invert any/all to simplify comparisons (
invert-any-all)
| for field in columns: | ||
| t[field] = None | ||
| return t | ||
| return {field: None for field in columns} |
There was a problem hiding this comment.
Function genTemplate refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable) - Convert for loop into dictionary comprehension (
dict-comprehension)
| common = [value for value in docsSet1 if value in docsSet2] | ||
| return common | ||
| return [value for value in docsSet1 if value in docsSet2] |
There was a problem hiding this comment.
Function Metrics.commonDocs refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| for i in range(0, len(elasticDocs)): | ||
| for i in range(len(elasticDocs)): |
There was a problem hiding this comment.
Function Metrics.formatResultElastic refactored with the following changes:
- Replace range(0, x) with range(x) (
remove-zero-from-range)
| for i in range(0, len(elasticDocs)): | ||
| for i in range(len(elasticDocs)): |
There was a problem hiding this comment.
Function Metrics.formatResult refactored with the following changes:
- Replace range(0, x) with range(x) (
remove-zero-from-range)
| top_k_docs = docs[0:i] | ||
| top_k_docs = docs[:i] | ||
| top_k_docs = self.formatResult(top_k_docs, self.cols) | ||
| top_k_elastic = elasticResults[0:i] | ||
| top_k_elastic = elasticResults[:i] |
There was a problem hiding this comment.
Function Metrics.pr_graph refactored with the following changes:
- Replace a[0:x] with a[:x] and a[x:len(a)] with a[x:] [×2] (
remove-redundant-slice-index)
| for i in range(0, len(docsSet)): | ||
| for i in range(len(docsSet)): | ||
| docsSet[i] = self.formatResult(docsSet[i], self.cols) | ||
| queryAverages = [] | ||
| for i in range(0, len(queriesSet)): | ||
| for i in range(len(queriesSet)): | ||
| queryPrecisions = [] | ||
| for j in range(0, k): | ||
| for j in range(k): | ||
| if docsSet[i][j] in elasticResultsSet[i]: | ||
| top_k_docs = docsSet[i][0:j + 1] | ||
| top_k_elastic = elasticResultsSet[i][0:j + 1] | ||
| top_k_docs = docsSet[i][:j + 1] | ||
| top_k_elastic = elasticResultsSet[i][:j + 1] | ||
| numRelevantItemsRetreived = len( | ||
| self.commonDocs(top_k_docs, top_k_elastic) | ||
| ) | ||
| k_prec_value = numRelevantItemsRetreived / (j + 1) | ||
| queryPrecisions.append(k_prec_value) | ||
| avg_precision = 0.0 | ||
| if len(queryPrecisions) != 0: | ||
| if queryPrecisions: | ||
| avg_precision = sum(queryPrecisions) / len(queryPrecisions) | ||
| queryAverages.append(avg_precision) | ||
| print("Query:", queriesSet[i], " Average Precision: ", avg_precision) | ||
| if len(queryAverages) != 0: | ||
| map_val = sum(queryAverages) / len(queryAverages) | ||
| return map_val | ||
| return 0.0 | ||
| return sum(queryAverages) / len(queryAverages) if queryAverages else 0.0 |
There was a problem hiding this comment.
Function Metrics.MAP refactored with the following changes:
- Replace range(0, x) with range(x) [×3] (
remove-zero-from-range) - Replace a[0:x] with a[:x] and a[x:len(a)] with a[x:] [×2] (
remove-redundant-slice-index) - Simplify sequence length comparison [×2] (
simplify-len-comparison) - Lift code into else after jump in control flow (
reintroduce-else) - Replace if statement with if expression (
assign-if-exp) - Inline variable that is immediately returned (
inline-immediately-returned-variable)
| qps_val = time_taken / num_queries | ||
| return qps_val | ||
| return time_taken / num_queries |
There was a problem hiding this comment.
Function Metrics.qps_elastic refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| qps_val = time_taken / num_queries | ||
| return qps_val | ||
| return time_taken / num_queries |
There was a problem hiding this comment.
Function Metrics.qps_index refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| elif metric == 10: | ||
| print( | ||
| "[MESSAGE]This metric requires a text file containing multiple queries" | ||
| ) | ||
| file_name = session.prompt(">> Enter filename(with .txt): ") | ||
| queryList = mymetrics.getQueriesFile(file_name) | ||
| qps = mymetrics.qps_elastic(queryList) | ||
| print("Number of queries given: ", len(queryList)) | ||
| print("Queries Per Second for ElasticSearch: ", qps) | ||
| elif metric == 11: | ||
| print( | ||
| "[MESSAGE]This metric requires a text file containing multiple queries" | ||
| ) | ||
| file_name = session.prompt(">> Enter filename(with .txt): ") | ||
| queryList = mymetrics.getQueriesFile(file_name) | ||
| qps = mymetrics.qps_index(queryList) | ||
| print("Number of queries given: ", len(queryList)) | ||
| print("Queries Per Millisecond for Index: ", max(qps, len(queryList))) | ||
| elif metric == 12: | ||
| results = mymetrics.getElasticSearchResults(session.prompt(">> Enter Query: ")) | ||
| print() | ||
| [pprint(result) for result in results] | ||
| print() |
There was a problem hiding this comment.
Lines 264-328 refactored with the following changes:
- Convert for loop into list comprehension [×2] (
list-comprehension) - Simplify conditional into switch-like form [×5] (
switch) - Replace unused for index with underscore (
for-index-underscore) - Replace range(0, x) with range(x) (
remove-zero-from-range)
Thanks for starring sourcery-ai/sourcery ✨ 🌟 ✨
Here's your pull request refactoring your most popular Python repo.
If you want Sourcery to refactor all your Python repos and incoming pull requests install our bot.
Review changes via command line
To manually merge these changes, make sure you're on the
mainbranch, then run: