Exemple #1
0
def get_closest_hyp(hyps : List[str], goal : str, max_length : int):
    if len(hyps) == 0:
        return ":"

    result = max(hyps, key=lambda hyp:
                 score_hyp_type(limitNumTokens(goal, max_length),
                                limitNumTokens(serapi_instance.get_hyp_type(hyp), max_length),
                                max_length))
    return result
Exemple #2
0
def get_closest_hyps(hyps : List[str], goal : str, num_hyps : int, max_length : int)\
                        -> List[Tuple[str, float]]:
    if len(hyps) == 0:
        return [Prediction(":", 0)] * num_hyps
    else:
        return list(sorted([(hyp, score_hyp_type(limitNumTokens(goal, max_length),
                                                 limitNumTokens(serapi_instance.get_hyp_type(hyp), max_length),
                                                 max_length))
                            for hyp in hyps],
                           reverse=True,
                           key=lambda hyp_and_score: hyp_and_score[0]))
Exemple #3
0
 def __call__(self, context: TacticContext) -> int:
     if len(context.hypotheses) == 0:
         return 0
     hyp_types = [
         limitNumTokens(serapi_instance.get_hyp_type(hyp), self.max_length)
         for hyp in context.hypotheses
     ]
     goal = limitNumTokens(context.goal, self.max_length)
     closest_hyp_type = max(hyp_types,
                            key=lambda x: SequenceMatcher(None, goal, x).
                            ratio() * len(get_symbols(x)))
     headToken = get_symbols(closest_hyp_type)[0]
     if headToken in self.headKeywords:
         return self.headKeywords.index(headToken) + 1
     else:
         return 0