def __type_centric(self, query): """Type-centric TTI.""" types = dict() model = self.__config.get("model", TTI_MODEL_BM25) elastic = ElasticCache(self.__tc_config.get("index", DEFAULT_TTI_TC_INDEX)) if model == TTI_MODEL_BM25: print("TTI, TC, BM25") scorer = Scorer.get_scorer(elastic, query, self.__tc_config) types = Retrieval(self.__tc_config).retrieve(query, scorer) elif model == TTI_MODEL_LM: print("TTI, TC, LM") self.__tc_config["model"] = "lm" # Needed for 2nd-pass self.__tc_config["field"] = "content" # Needed for 2nd-pass self.__tc_config["second_pass"] = { "field": "content" } for param in ["smoothing_method", "smoothing_param"]: if self.__config.get(param, None) is not None: self.__tc_config["second_pass"][param] = self.__config.get(param) scorer = Scorer.get_scorer(elastic, query, self.__tc_config) types = Retrieval(self.__tc_config).retrieve(query, scorer) return types
def __get_scorer(self, query): """Factory method to get entity retrieval method.""" model = self.__config.get("model", None) if model == "elr": scorer = ELR(self.__config) else: # from core.retrieval elastic = ElasticCache(self.__config["index_name"]) scorer = Scorer.get_scorer(elastic, query, self.__config) return scorer
def retrieve(self, query, scorer=None): """Scores documents for the given query.""" query = self.__elastic.analyze_query(query) # 1st pass retrieval res1 = self._first_pass_scoring(query) if self.__model is None: return res1 # 2nd pass retrieval scorer = scorer if scorer else Scorer.get_scorer(self.__elastic, query, self.__config) res2 = self._second_pass_scoring(res1, scorer) return res2
def __get_scorer(self, query): """Factory method to get entity retrieval method.""" scorer = Scorer.get_scorer(self.__elastic, query, self.__config) return scorer