def test_get_most_similar_top_n_entity(self):
     sim_matrix=np.matrix(np.array([[1, 2, 3, 4],[6,6,1,5]]))
     one_hot_result= MatrixCalculation.get_most_similar_top_n_entity_as_matrix(top_n=3,s_e_similarity_matrix=sim_matrix)
     print(one_hot_result)
     one_hot_result = MatrixCalculation.get_most_similar_top_n_entity_as_matrix(top_n=5,
                                                                                s_e_similarity_matrix=sim_matrix)
     print(one_hot_result)
    def sort_sentence_by_build_average_graph_vector_for_query(self, question, sentence_list, entity_list,
                                                              weight_context_sim=0.5, weight_graph_sim=0.5
                                                              ):
        self._logger.info(
            "run sort_sentence_by_build_average_graph_vector_for_query get sentence_list=%d" % len(sentence_list))

        kg_models = self.kg_models
        question_context_vec = kg_models.get_question_entity_vector(question)
        entity_vec_list, entity_graph_vec_list = self.kg_models.get_vectors_for_entity_list(entity_list)
        sentence_vec_list, sentence_graph_vec_list = self.kg_models.get_vectors_for_entity_list(sentence_list)

        entity_list, entity_vec_list, entity_graph_vec_list = self.remove_the_not_related_entity(entity_graph_vec_list,
                                                                                                 entity_list,
                                                                                                 entity_vec_list,
                                                                                                 question_context_vec)

        query_graph_vector = kg_models.get_question_graph_vector_by_average_all_entities(
            question=question,
            entity_graph_vec_list=entity_graph_vec_list)

        qs_context_sim = MatrixCalculation.compute_cossin_for_vec_to_matrix_normalize(question_context_vec,
                                                                                      sentence_vec_list)

        qs_graph_sim = MatrixCalculation.compute_cossin_for_vec_to_matrix_normalize(query_graph_vector,
                                                                                    sentence_graph_vec_list)
        qs_context_sim = weight_context_sim * qs_context_sim

        qs_graph_sim = weight_graph_sim * qs_graph_sim

        qs_sim = qs_context_sim + qs_graph_sim

        qs_sim = qs_sim.tolist()[0]
        qs_context_sim = qs_context_sim.tolist()[0]
        qs_graph_sim = qs_graph_sim.tolist()[0]

        for sum_sim, sentence, context_sim, graph_sim in zip(qs_sim, sentence_list, qs_context_sim, qs_graph_sim):
            sentence["qs_sim"] = sum_sim
            sentence["qs_context_sim"] = context_sim
            sentence["qs_graph_sim"] = graph_sim

        result = []
        for sentence in sentence_list:
            result.append({
                "kg_id": self.defaultAccessor.get_id_for_node(sentence),
                "sentence_id": sentence["sentence_id"],
                "text": sentence["sentence_text"],
                "sentence_type": sentence["sentence_type_code"],
                "qs_sim": sentence["qs_sim"],
                "qs_context_sim": sentence["qs_context_sim"],
                "qs_graph_sim": sentence["qs_graph_sim"]

            })
        self._logger.info("run sort_sentence_by_build_average_graph_vector_for_query get result num=%d" % len(result))
        result.sort(key=lambda k: (k.get('qs_sim', 0)), reverse=True)

        return result
    def sort_sentence_by_entities_for_graph_similarity_as_bridge(self, question,
                                                                 sentence_list,
                                                                 entity_list,
                                                                 weight_context_sim=0.5,
                                                                 weight_graph_sim=0.5
                                                                 ):
        self._logger.info(
            "run sort_sentence_by_entities_for_graph_similarity_as_bridge get result=%d" % len(sentence_list))

        question_context_vec = self.kg_models.get_question_entity_vector(question)

        entity_vec_list, entity_graph_vec_list = self.kg_models.get_vectors_for_entity_list(entity_list)
        sentence_vec_list, sentence_graph_vec_list = self.kg_models.get_vectors_for_entity_list(sentence_list)

        qe_sim_np = np.ones((1, len(entity_list)))
        qe_sim_np = qe_sim_np / qe_sim_np.sum()
        qs_context_sim = MatrixCalculation.compute_cossin_for_vec_to_matrix_normalize(question_context_vec,
                                                                                      sentence_vec_list)

        kg_graph_sim = MatrixCalculation.compute_cossin_for_matrix_to_matrix_normalize(entity_graph_vec_list,
                                                                                       sentence_graph_vec_list)

        qs_context_sim = weight_context_sim * qs_context_sim
        qs_graph_sim = weight_graph_sim * qe_sim_np * kg_graph_sim

        qs_sim = qs_context_sim + qs_graph_sim
        qs_sim = qs_sim.tolist()[0]
        qs_context_sim = qs_context_sim.tolist()[0]
        qs_graph_sim = qs_graph_sim.tolist()[0]

        for sum_sim, sentence, context_sim, graph_sim in zip(qs_sim, sentence_list, qs_context_sim, qs_graph_sim):
            sentence["qs_sim"] = sum_sim
            sentence["qs_context_sim"] = context_sim
            sentence["qs_graph_sim"] = graph_sim

        result = []
        for sentence in sentence_list:
            result.append({
                "kg_id": self.defaultAccessor.get_id_for_node(sentence),
                "sentence_id": sentence["sentence_id"],
                "sentence_type": sentence["sentence_type_code"],
                "text": sentence["sentence_text"],
                "qs_sim": sentence["qs_sim"],
                "qs_context_sim": sentence["qs_context_sim"],
                "qs_graph_sim": sentence["qs_graph_sim"]

            })
        self._logger.info("run sort_sentence_by_entities_as_bridge get result num=%d" % len(result))
        result.sort(key=lambda k: (k.get('qs_sim', 0)), reverse=True)

        print("sorted result")
        for t in result:
            print("test sort", t)
        print(result[:100])

        return result
def calculate_matrix(selected_data_list, vector_map):
    vector_list = []
    for i in range(0, len(selected_data_list)):
        paragraph_id = str(selected_data_list[i]["paragraph_id"])
        vector = vector_map[paragraph_id]
        vector_list.append(vector)
    return MatrixCalculation.cosine_matrix(vector_list, vector_list)
 def get_graph_similarity_by_average_entity_graph_vector(
         self, entity_graph_vec_list, question, sentence_graph_vec_list):
     query_graph_vector = self.kg_models.get_question_graph_vector_by_average_all_entities(
         question=question, entity_graph_vec_list=entity_graph_vec_list)
     qs_graph_sim = MatrixCalculation.compute_cossin_for_vec_to_matrix_normalize(
         query_graph_vector, sentence_graph_vec_list)
     return qs_graph_sim
    def fill_each_entity_with_similary_to_question(self, question_context_vec):
        entity_context_vec_list = self.get_entity_context_list()
        qe_sim_np = MatrixCalculation.compute_cossin_for_vec_to_matrix_normalize(question_context_vec,
                                                                                 entity_context_vec_list)

        for entity_info, sim in zip(self.api_info_list, qe_sim_np.getA()[0]):
            entity_info.qe_sim = sim
 def get_graph_similarity_average_entity_graph_vector_similarity(self, entity_graph_vec_list, question,
                                                                 sentence_graph_vec_list):
     # query_graph_vector = self.kg_models.get_question_graph_vector_by_average_all_entities(
     #     question=question,
     #     entity_graph_vec_list=entity_graph_vec_list)
     qs_graph_sim = MatrixCalculation.compute_cossin_for_matrix_to_matrix_normalize(sentence_graph_vec_list,
                                                                                    entity_graph_vec_list)
     return np.mean(qs_graph_sim, axis=1)
    def get_question_graph_vector_by_semantic_weight_all_entities(self, question_context_vec, entity_context_vec_list,
                                                                  entity_graph_vec_list):
        qe_sim_np = MatrixCalculation.compute_cossin_for_vec_to_matrix_normalize(question_context_vec,
                                                                                 entity_context_vec_list)
        qe_sim_np = qe_sim_np / qe_sim_np.sum()

        question_graph_vec = (qe_sim_np * np.matrix(entity_graph_vec_list)).getA()[0]
        return question_graph_vec
    def get_query_to_sentence_graph_sim_by_select_top_enttity(self, entity_graph_vec_list, entity_list, entity_vec_list,
                                                              sentence_graph_vec_list, sentence_vec_list):
        # kg_se_graph_sim = MatrixCalculation.compute_cossin_for_matrix_to_matrix_normalize(sentence_graph_vec_list,
        #                                                                                   entity_graph_vec_list,
        #                                                                                   )
        kg_se_context_sim = MatrixCalculation.compute_cossin_for_matrix_to_matrix_normalize(
            sentence_vec_list,
            entity_vec_list)
        # TODO
        # kg_se_sim = 0.5 * kg_se_graph_sim + 0.5 * kg_se_context_sim
        kg_se_sim = kg_se_context_sim

        print("final entity list", len(entity_list), entity_list)
        select_linking_entity_num = min(5, len(entity_list))
        onehot_maxsim_se_matrix = MatrixCalculation.get_most_similar_top_n_entity_as_matrix(
            top_n=select_linking_entity_num, s_e_similarity_matrix=kg_se_sim)
        s_query_graph_vec_matrix = onehot_maxsim_se_matrix * np.matrix(
            entity_graph_vec_list) / select_linking_entity_num
        qs_graph_sim = MatrixCalculation.compute_cossin_for_one_to_one_in_two_list_normalize(sentence_graph_vec_list,
                                                                                             s_query_graph_vec_matrix.getA())
        return qs_graph_sim
    def remove_the_not_related_entity_by_only_save_one_for_each(
            self, entity_graph_vec_list, entity_list, entity_vec_list,
            question_context_vec, qa_info_manager):
        chunk_to_related_entity_list_map = qa_info_manager.keyword_2_entitynodemap
        qe_sim_np = MatrixCalculation.compute_cossin_for_vec_to_matrix_normalize(
            question_context_vec, entity_vec_list)

        entity_info_sumary_list = []
        for (entity, sim, entity_vec,
             entity_graph_vec) in zip(entity_list,
                                      qe_sim_np.getA()[0], entity_vec_list,
                                      entity_graph_vec_list):
            # print("after first removing sim=", sim, "entity=", entity)
            entity_info_sumary_list.append({
                "entity": entity,
                "sim": sim,
                "entity_vec": entity_vec,
                "entity_graph_vec": entity_graph_vec
            })

        entity_info_sumary_list.sort(key=lambda k: (k.get('sim', 0)),
                                     reverse=True)

        valid_word_set = set([])
        word_to_related_entity_list_map = {}

        for chunk, related_entity_list in chunk_to_related_entity_list_map.items(
        ):
            word = chunk
            if word not in valid_word_set:
                valid_word_set.add(word)
                word_to_related_entity_list_map[word] = related_entity_list
            else:
                word_to_related_entity_list_map[word].extend(
                    related_entity_list)

        # clean_entity_info_list = self.get_clean_entity_for_each_word_by_max_similarity(entity_info_sumary_list,
        #                                                                                word_to_related_entity_list_map)
        #
        clean_entity_info_list = self.get_clean_entity_for_each_word_by_max_n_similarity(
            entity_info_sumary_list, word_to_related_entity_list_map)

        new_entity_list = []
        new_entity_graph_vec_list = []
        new_entity_vec_list = []
        for entity_info_sumary in clean_entity_info_list:
            new_entity_list.append(entity_info_sumary["entity"])
            new_entity_graph_vec_list.append(
                entity_info_sumary["entity_graph_vec"])
            new_entity_vec_list.append(entity_info_sumary["entity_vec"])
            # print("final save sim=", entity_info_sumary["sim"], "entity=", entity_info_sumary["entity"])

        return new_entity_list, new_entity_vec_list, new_entity_graph_vec_list
    def sort_api_by_select_part_entity_as_bridge(
        self,
        question,
        qa_info_manager,
        weight_context_sim=0.6,
        weight_graph_sim=0.4,
    ):

        api_info_collection = qa_info_manager.get_api_info_collection()

        api_entity_list = api_info_collection.get_entity_list()
        api_context_vec_list = api_info_collection.get_entity_context_list()
        api_graph_vec_list = api_info_collection.get_entity_graph_list()
        question_context_vec = self.kg_models.get_question_entity_vector(
            question)

        entity_info_collection = qa_info_manager.get_top_related_entity_info_collection(
        )
        entity_list = entity_info_collection.get_entity_list()
        entity_context_vec_list = entity_info_collection.get_entity_context_list(
        )
        entity_graph_vec_list = entity_info_collection.get_entity_graph_list()

        qe_context_sim = MatrixCalculation.compute_cossin_for_vec_to_matrix_normalize(
            question_context_vec, api_context_vec_list)

        # todo:change to the average graph similarity
        qe_graph_sim = self.get_graph_similarity_by_average_entity_graph_vector(
            entity_graph_vec_list, question, api_graph_vec_list)

        # qe_graph_sim = self.get_query_to_sentence_graph_sim_by_select_top_enttity(entity_graph_vec_list, entity_list,
        #                                                                           entity_context_vec_list,
        #                                                                           api_graph_vec_list,
        #                                                                           api_context_vec_list)
        #
        qe_context_sim = weight_context_sim * qe_context_sim
        qe_graph_sim = weight_graph_sim * qe_graph_sim

        qe_sim = qe_context_sim + qe_graph_sim
        qe_sim = qe_sim.tolist()[0]
        qe_context_sim = qe_context_sim.tolist()[0]
        qe_graph_sim = qe_graph_sim.tolist()[0]

        for api_info, sum_sim, sentence, context_sim, graph_sim in zip(
                qa_info_manager.get_api_info_collection().api_info_list,
                qe_sim, api_entity_list, qe_context_sim, qe_graph_sim):
            api_info.qe_sim = sum_sim
            api_info.qe_context_sim = context_sim
            api_info.qe_graph_sim = graph_sim

        qa_info_manager.get_api_info_collection().sort_by_qe_sim()

        return qa_info_manager
    def sort_sentences_for_one_api_class(
        self,
        question,
        qa_info_manager,
        sentence_info_collection,
        weight_context_sim=0.6,
        weight_graph_sim=0.4,
    ):

        sentence_info_collection.init_vectors(self.kg_models)
        sentence_list = sentence_info_collection.get_entity_list()
        sentence_vec_list = sentence_info_collection.get_entity_context_list()
        sentence_graph_vec_list = sentence_info_collection.get_entity_graph_list(
        )

        question_context_vec = self.kg_models.get_question_entity_vector(
            question)

        entity_info_collection = qa_info_manager.get_top_related_entity_info_collection(
        )
        entity_graph_vec_list = entity_info_collection.get_entity_graph_list()

        qs_context_sim = MatrixCalculation.compute_cossin_for_vec_to_matrix_normalize(
            question_context_vec, sentence_vec_list)
        qs_graph_sim = self.get_graph_similarity_by_average_entity_graph_vector(
            entity_graph_vec_list, question, sentence_graph_vec_list)

        qs_context_sim = weight_context_sim * qs_context_sim
        qs_graph_sim = weight_graph_sim * qs_graph_sim

        qs_sim = qs_context_sim + qs_graph_sim
        qs_sim = qs_sim.tolist()[0]
        qs_context_sim = qs_context_sim.tolist()[0]
        qs_graph_sim = qs_graph_sim.tolist()[0]

        for sentence_info, sum_sim, sentence, context_sim, graph_sim in zip(
                sentence_info_collection.sentence_info_list, qs_sim,
                sentence_list, qs_context_sim, qs_graph_sim):
            sentence_info.qs_sim = sum_sim
            sentence_info.qs_context_sim = context_sim
            sentence_info.qs_graph_sim = graph_sim

        sentence_info_collection.sort_by_qs_sim()

        return sentence_info_collection
    def remove_the_not_related_entity(self, entity_graph_vec_list, entity_list, entity_vec_list, question_context_vec):

        qe_sim_np = MatrixCalculation.compute_cossin_for_vec_to_matrix_normalize(question_context_vec,
                                                                                 entity_vec_list)
        print("qeustion to entity similary")

        new_entity_list = []
        new_entity_vec_list = []
        new_entity_graph_vec_list = []
        qe_sim_clean = []
        for (entity, sim, entity_vec, entity_graph_vec) in zip(entity_list, qe_sim_np.getA()[0], entity_vec_list,
                                                               entity_graph_vec_list):
            print("sim=", sim, "entity=", entity)
            if sim > MIN_RELATED_ENTITY_SIMILARITY:
                print("adding ", entity)
                new_entity_list.append(entity)
                new_entity_vec_list.append(entity_vec)
                new_entity_graph_vec_list.append(entity_graph_vec)
                qe_sim_clean.append(sim)

        entity_list = new_entity_list
        entity_vec_list = new_entity_vec_list
        entity_graph_vec_list = new_entity_graph_vec_list

        new_entity_list = []
        new_entity_vec_list = []
        new_entity_graph_vec_list = []

        entity_info_sumary_list = []

        for (entity, sim, entity_vec, entity_graph_vec) in zip(entity_list, qe_sim_clean, entity_vec_list,
                                                               entity_graph_vec_list):
            print("after first removing sim=", sim, "entity=", entity)
            entity_info_sumary_list.append({"entity": entity,
                                            "sim": sim,
                                            "entity_vec": entity_vec,
                                            "entity_graph_vec": entity_graph_vec
                                            })

        entity_info_sumary_list.sort(key=lambda k: (k.get('sim', 0)), reverse=True)

        api_class_name_set = set([])

        new_entity_info_sumary_list = []
        for entity_info_sumary in entity_info_sumary_list:
            if entity_info_sumary["entity"].has_label("api"):
                qualified_name = entity_info_sumary["entity"]["qualified_name"]
                if qualified_name in api_class_name_set:
                    continue
                if "(" in qualified_name:
                    simple_name = qualified_name.split("(")[0]

                    class_name = ".".join(simple_name.split(".")[:-1])
                    if class_name in api_class_name_set:
                        continue
                    else:
                        api_class_name_set.add(class_name)
                        new_entity_info_sumary_list.append(entity_info_sumary)
                else:
                    api_class_name_set.add(qualified_name)
                    new_entity_info_sumary_list.append(entity_info_sumary)
            else:
                new_entity_info_sumary_list.append(entity_info_sumary)

        for entity_info_sumary in new_entity_info_sumary_list:
            new_entity_list.append(entity_info_sumary["entity"])
            new_entity_graph_vec_list.append(entity_info_sumary["entity_graph_vec"])
            new_entity_vec_list.append(entity_info_sumary["entity_vec"])
            print("final save sim=", entity_info_sumary["sim"], "entity=", entity_info_sumary["entity"])

        return new_entity_list, new_entity_vec_list, new_entity_graph_vec_list
    def sort_sentence_by_select_part_entity_as_bridge(self, question,
                                                      qa_info_manager,
                                                      # sentence_list,
                                                      # entity_list,
                                                      weight_context_sim=0.6,
                                                      weight_graph_sim=0.4,
                                                      # chunk_to_related_entity_list_map=None,
                                                      ):
        self._logger.info(
            "run sort part entity result=%d" % qa_info_manager.get_sentence_size())

        print("entity for node")
        qa_info_manager.print_entities()
        print("sentence for node")
        # qa_info_manager.print_sentences()

        entity_info_collection = qa_info_manager.get_entity_info_collection()
        sentence_info_collection = qa_info_manager.get_sentence_info_collection()
        entity_info_collection.init_vectors(self.kg_models)
        sentence_info_collection.init_vectors(self.kg_models)
        sentence_list = sentence_info_collection.get_entity_list()
        entity_vec_list = entity_info_collection.get_entity_context_list()
        entity_graph_vec_list = entity_info_collection.get_entity_graph_list()
        entity_list = entity_info_collection.get_entity_list()
        sentence_vec_list = sentence_info_collection.get_entity_context_list()
        sentence_graph_vec_list = sentence_info_collection.get_entity_graph_list()

        question_context_vec = self.kg_models.get_question_entity_vector(question)

        entity_list, entity_vec_list, entity_graph_vec_list = self.get_top_related_entity_info_list(
            question_context_vec=question_context_vec, qa_info_manager=qa_info_manager)

        # entity_list, entity_vec_list, entity_graph_vec_list = self.remove_the_not_related_entity_by_only_save_one_for_each(
        #     entity_graph_vec_list=entity_graph_vec_list, entity_vec_list=entity_vec_list, entity_list=entity_list,
        #     question_context_vec=question_context_vec,
        #     qa_info_manager=qa_info_manager
        #
        # )

        qs_context_sim = MatrixCalculation.compute_cossin_for_vec_to_matrix_normalize(question_context_vec,
                                                                                      sentence_vec_list)
        # todo:change to the average graph similarity
        # qs_graph_sim = self.get_graph_similarity_by_average_entity_graph_vector(entity_graph_vec_list, question,
        #                                                                         sentence_graph_vec_list)

        qs_graph_sim = self.get_query_to_sentence_graph_sim_by_select_top_enttity(entity_graph_vec_list, entity_list,
                                                                                  entity_vec_list,
                                                                                  sentence_graph_vec_list,
                                                                                  sentence_vec_list)

        qs_context_sim = weight_context_sim * qs_context_sim
        qs_graph_sim = weight_graph_sim * qs_graph_sim

        qs_sim = qs_context_sim + qs_graph_sim
        qs_sim = qs_sim.tolist()[0]
        qs_context_sim = qs_context_sim.tolist()[0]
        qs_graph_sim = qs_graph_sim.tolist()[0]

        for sum_sim, sentence, context_sim, graph_sim in zip(qs_sim, sentence_list, qs_context_sim, qs_graph_sim):
            sentence["qs_sim"] = sum_sim
            sentence["qs_context_sim"] = context_sim
            sentence["qs_graph_sim"] = graph_sim

        result = []
        for sentence in sentence_list:
            result.append({
                "kg_id": self.defaultAccessor.get_id_for_node(sentence),
                "sentence_id": sentence["sentence_id"],
                "sentence_type": sentence["sentence_type_code"],
                "text": sentence["sentence_text"],
                "qs_sim": sentence["qs_sim"],
                "qs_context_sim": sentence["qs_context_sim"],
                "qs_graph_sim": sentence["qs_graph_sim"]

            })
        self._logger.info("run sort_sentence_by_entities_as_bridge get result num=%d" % len(result))
        result.sort(key=lambda k: (k.get('qs_sim', 0)), reverse=True)

        print(result[:100])

        return result
    def sort_sentence_by_select_part_entity_as_bridge(
        self,
        question,
        qa_info_manager,
        weight_context_sim=0.6,
        weight_graph_sim=0.4,
    ):
        self._logger.info("run sort part entity result=%d" %
                          qa_info_manager.get_sentence_size())

        sentence_info_collection = qa_info_manager.get_sentence_info_collection(
        )
        sentence_info_collection.init_vectors(self.kg_models)
        sentence_list = sentence_info_collection.get_entity_list()
        sentence_vec_list = sentence_info_collection.get_entity_context_list()
        sentence_graph_vec_list = sentence_info_collection.get_entity_graph_list(
        )

        question_context_vec = self.kg_models.get_question_entity_vector(
            question)

        entity_info_collection = qa_info_manager.get_top_related_entity_info_collection(
        )
        entity_list = entity_info_collection.get_entity_list()
        entity_context_vec_list = entity_info_collection.get_entity_context_list(
        )
        entity_graph_vec_list = entity_info_collection.get_entity_graph_list()

        # entity_list, entity_vec_list, entity_graph_vec_list = self.remove_the_not_related_entity_by_only_save_one_for_each(
        #     entity_graph_vec_list=entity_graph_vec_list, entity_vec_list=entity_vec_list, entity_list=entity_list,
        #     question_context_vec=question_context_vec,
        #     qa_info_manager=qa_info_manager
        #
        # )

        qs_context_sim = MatrixCalculation.compute_cossin_for_vec_to_matrix_normalize(
            question_context_vec, sentence_vec_list)
        # todo:change to the average graph similarity
        qs_graph_sim = self.get_graph_similarity_by_average_entity_graph_vector(
            entity_graph_vec_list, question, sentence_graph_vec_list)

        # qs_graph_sim = self.get_query_to_sentence_graph_sim_by_select_top_enttity(entity_graph_vec_list, entity_list,
        #                                                                           entity_vec_list,
        #                                                                           sentence_graph_vec_list,
        #                                                                           sentence_vec_list)

        qs_context_sim = weight_context_sim * qs_context_sim
        qs_graph_sim = weight_graph_sim * qs_graph_sim

        qs_sim = qs_context_sim + qs_graph_sim
        qs_sim = qs_sim.tolist()[0]
        qs_context_sim = qs_context_sim.tolist()[0]
        qs_graph_sim = qs_graph_sim.tolist()[0]

        for sentence_info, sum_sim, sentence, context_sim, graph_sim in zip(
                sentence_info_collection.sentence_info_list, qs_sim,
                sentence_list, qs_context_sim, qs_graph_sim):
            sentence_info.qs_sim = sum_sim
            sentence_info.qs_context_sim = context_sim
            sentence_info.qs_graph_sim = graph_sim

        sentence_info_collection.sort_by_qs_sim()

        return qa_info_manager