def get_best_n_sentences()

in Medical_Text_Analysis_Resources/docker_containers/model_container/model_scripts/hosted_model.py [0:0]


    def get_best_n_sentences(self,corpus,distances,max_to_return=5):
        '''get the top n closest sentences; where lower distance is better'''
        max_to_return=5
        if len(corpus) <5: #
            max_to_return=len(corpus) 
        the_indices=numpy.argsort(distances)
        top_n_indices=the_indices[0:max_to_return]
        top_n_dist=[distances[i] for i in top_n_indices]
        logger.debug(corpus)
        top_n_corpus=[corpus[i] for i in top_n_indices]
        top_n_pvalues=[]
        if self.run_null_model==True:
            for i in range(0,len(top_n_dist)):
                temp_result=self.run_null(score=top_n_dist[i])
                top_n_pvalues.append(temp_result)	
        list_to_return=[]
        for i in range(0,len(top_n_indices)):
            if self.run_null_model==True:
                the_dict={"rank":i+1,"matching_sentence":top_n_corpus[i],"pvalue":top_n_pvalues[i],"distance":top_n_dist[i]}
            else:
                the_dict={"rank":i+1,"matching_sentence":top_n_corpus[i],"distance":top_n_dist[i]}
            list_to_return.append(the_dict)
        return(list_to_return)