Skip to content

Sourcery Starbot ⭐ refactored sarthak7gupta/SearchEngineForEnvironmentalNews#3

Open
SourceryAI wants to merge 1 commit into
sarthak7gupta:mainfrom
SourceryAI:main
Open

Sourcery Starbot ⭐ refactored sarthak7gupta/SearchEngineForEnvironmentalNews#3
SourceryAI wants to merge 1 commit into
sarthak7gupta:mainfrom
SourceryAI:main

Conversation

@SourceryAI

Copy link
Copy Markdown

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 main branch, then run:

git fetch https://github.com/sourcery-ai-bot/SearchEngineForEnvironmentalNews main
git merge --ff-only FETCH_HEAD
git reset HEAD^

Comment thread Engine.py

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):

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Engine.ranked_retrieval refactored with the following changes:

Comment thread metrics.py
for field in columns:
t[field] = None
return t
return {field: None for field in columns}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function genTemplate refactored with the following changes:

Comment thread metrics.py
Comment on lines -33 to +30
common = [value for value in docsSet1 if value in docsSet2]
return common
return [value for value in docsSet1 if value in docsSet2]

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Metrics.commonDocs refactored with the following changes:

Comment thread metrics.py
Comment on lines -45 to +41
for i in range(0, len(elasticDocs)):
for i in range(len(elasticDocs)):

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Metrics.formatResultElastic refactored with the following changes:

Comment thread metrics.py
Comment on lines -55 to +51
for i in range(0, len(elasticDocs)):
for i in range(len(elasticDocs)):

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Metrics.formatResult refactored with the following changes:

Comment thread metrics.py
Comment on lines -133 to +129
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]

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Metrics.pr_graph refactored with the following changes:

Comment thread metrics.py
Comment on lines -154 to +167
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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Metrics.MAP refactored with the following changes:

Comment thread metrics.py
Comment on lines -190 to +181
qps_val = time_taken / num_queries
return qps_val
return time_taken / num_queries

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Metrics.qps_elastic refactored with the following changes:

Comment thread metrics.py
Comment on lines -202 to +192
qps_val = time_taken / num_queries
return qps_val
return time_taken / num_queries

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Metrics.qps_index refactored with the following changes:

Comment thread metrics.py
Comment on lines +235 to +257
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()

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 264-328 refactored with the following changes:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant