From d7c657274654a29ebc9c3216755958e566133cea Mon Sep 17 00:00:00 2001 From: Jem Date: Tue, 17 Sep 2019 11:09:18 +0800 Subject: [PATCH] refactor(scorefn): move query coord into doc indexer --- gnes/score_fn/doc.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/gnes/score_fn/doc.py b/gnes/score_fn/doc.py index 7c49009e..e87ec9e3 100644 --- a/gnes/score_fn/doc.py +++ b/gnes/score_fn/doc.py @@ -35,13 +35,10 @@ class CoordDocScoreFn(CombinedScoreFn): def __call__(self, last_score: 'gnes_pb2.Response.QueryResponse.ScoredResult.Score', doc: 'gnes_pb2.Document', *args, **kwargs): - d_weight = get_unary_score(value=self._cal_query_coord(last_score, doc), + total_chunks = len(doc.chunks) + recall_chunks = len(json.loads(last_score.explained)['operands']) + query_coord = 1 if total_chunks == 0 else recall_chunks / total_chunks + d_weight = get_unary_score(value=query_coord, name='query coordination') return super().__call__(last_score, d_weight) - @staticmethod - def _cal_query_coord(last_score: 'gnes_pb2.Response.QueryResponse.ScoredResult.Score', - doc: 'gnes_pb2.Document'): - total_chunks = len(doc.chunks) - recall_chunks = len(json.loads(last_score.explained)['operands']) - return recall_chunks / total_chunks