Exemplo n.º 1
0
    def _simsearch_to_simresult(self, sim_resp: Dict, method: SimAlgorithm,
                                limit: int) -> SimResult:
        """
        Convert owlsim json to SimResult object

        :param sim_resp: owlsim response from search_by_attribute_set()
        :param method: SimAlgorithm
        :param limit: int, number of results to return
        :return: SimResult object
        """

        sim_ids = get_nodes_from_ids(sim_resp['query_IRIs'])
        sim_resp['results'] = OwlSim2Api._rank_results(sim_resp['results'],
                                                       method)

        # get id type map:
        ids = [result['j']['id'] for result in sim_resp['results']]
        id_type_map = get_id_type_map(ids)

        matches = []
        counter = 0

        for result in sim_resp['results']:
            if counter == limit:
                break
            matches.append(
                SimMatch(
                    id=result['j']['id'],
                    label=result['j']['label'],
                    rank=result['rank'],
                    score=result[OwlSim2Api.method2key[method]],
                    type=id_type_map[result['j']['id']][0],
                    taxon=get_taxon(result['j']['id']),
                    significance="NaN",
                    pairwise_match=OwlSim2Api._make_pairwise_matches(result)))
            counter += 1

        return SimResult(
            query=SimQuery(ids=sim_ids,
                           unresolved_ids=sim_resp['unresolved'],
                           target_ids=[[]]),
            matches=matches,
            metadata=SimMetadata(max_max_ic=self.statistics.max_max_ic))
Exemplo n.º 2
0
    def _simcompare_to_simresult(self, sim_resp: Dict, method: SimAlgorithm) -> SimResult:
        """
        Convert owlsim json from compareAttributeSets to SimResult object

        In compare mode owlsim does not provide a id, label, and therefore
        we cannot infer type and taxon.

        :param sim_resp: owlsim response from compare_attribute_sets()
        :param method: SimAlgorithm
        :return: SimResult object
        """

        sim_ids = get_nodes_from_ids(sim_resp['query_IRIs'])
        sim_resp['results'] = OwlSim2Api._rank_results(sim_resp['results'], method)

        matches = []

        for result in sim_resp['results']:
            matches.append(
                SimMatch(
                    id="",
                    label="",
                    rank="NaN",
                    score=result[OwlSim2Api.method2key[method]],
                    significance="NaN",
                    pairwise_match=OwlSim2Api._make_pairwise_matches(result)
                )
            )

        return SimResult(
            query=SimQuery(
                ids=sim_ids,
                unresolved_ids=sim_resp['unresolved'],
                target_ids=[get_nodes_from_ids(sim_resp['target_IRIs'])]
            ),
            matches=matches,
            metadata=SimMetadata(
                max_max_ic=self.statistics.max_max_ic
            )
        )