Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

more transformers with repr #289

Merged
merged 2 commits into from
Apr 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion pyterrier/rewrite.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ def __init__(self, verbose = 0, remove_stopwords = True, prox_model = None, **kw
assert check_version("5.3")
self.ApplyTermPipeline_stopsonly = pt.autoclass("org.terrier.querying.ApplyTermPipeline")("Stopwords")

def __repr__(self):
return "SDM()"

def transform(self, topics_and_res):
results = []
from .model import ranked_documents_to_queries, push_queries
Expand Down Expand Up @@ -184,6 +187,14 @@ def _populate_resultset(self, topics_and_res, qid, index):
raise ValueError("Input resultset has neither docid nor docno")
return QueryResultSet(docids, scores, occurrences)

def __repr__(self):
return "QueryExpansion(" + ",".join([
self.indexref.toString(),
str(self.fb_docs),
str(self.fb_terms),
str(self.qe)
]) + ")"

def _configure_request(self, rq):
rq.setControl("qe_fb_docs", str(self.fb_docs))
rq.setControl("qe_fb_terms", str(self.fb_terms))
Expand Down Expand Up @@ -407,7 +418,10 @@ def transform(self, topics_and_res: pd.DataFrame) -> pd.DataFrame:
for i in range(len(groupDf)):
groupDf.at[i, "stashed_results_0"] = docsDict
rtr.append(groupDf)
return pd.concat(rtr)
return pd.concat(rtr)

def __repr__(self):
return "pt.rewrite.stash_results()"

class _ResetResults(TransformerBase):

Expand All @@ -426,6 +440,9 @@ def transform(self, topics_with_saved_docs : pd.DataFrame) -> pd.DataFrame:
rtr.append(finaldf)
return pd.concat(rtr)

def __repr__(self):
return "pt.rewrite.reset_results()"

def linear(weightCurrent : float, weightPrevious : float, format="terrierql", **kwargs) -> TransformerBase:
"""
Applied to make a linear combination of the current and previous query formulation. The implementation
Expand Down Expand Up @@ -488,3 +505,6 @@ def transform(self, topics_and_res):
newDF = push_queries(topics_and_res)
newDF["query"] = newDF.apply(fn, axis=1)
return newDF

def __repr__(self):
return "pt.rewrite.linear()"
3 changes: 3 additions & 0 deletions pyterrier/transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,9 @@ def __init__(self, fn, *args, verbose=False, **kwargs):
self.fn = fn
self.verbose = verbose

def __repr__(self):
return "pt.apply.??()"

class ApplyForEachQuery(ApplyTransformerBase):
def __init__(self, fn, *args, add_ranks=True, **kwargs):
"""
Expand Down