How to use the wikidataintegrator.wdi_core.WDBaseDataType.__subclasses__ function in wikidataintegrator

To help you get started, we’ve selected a few wikidataintegrator examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github SuLab / WikidataIntegrator / wikidataintegrator / wdi_fastrun.py View on Github external
qid = matching_qids.pop()
        self.current_qid = qid
        reconstructed_statements = []

        for prop_nr, dt in self.prop_data[qid].items():
            all_uids = set([x['s2'] for x in dt])
            q_props = set([x['pr'] for x in dt if 'pr' in x])
            for q_prop in q_props:
                if q_prop not in self.prop_dt_map:
                    self.prop_dt_map.update({q_prop: FastRunContainer.get_prop_datatype(prop_nr=q_prop)})
            for uid in all_uids:
                qualifiers = [[x for x in wdi_core.WDBaseDataType.__subclasses__() if x.DTYPE ==
                               self.prop_dt_map[y['pr']]][0](value=y['q'], prop_nr=y['pr'], is_qualifier=True)
                              for y in dt if y['s2'] == uid and 'q' in y]

                stmts = [[x for x in wdi_core.WDBaseDataType.__subclasses__() if x.DTYPE ==
                          self.prop_dt_map[prop_nr]][0](value=y['v'], prop_nr=prop_nr, qualifiers=qualifiers)
                         for y in dt if y['s2'] == uid][0]

                reconstructed_statements.append(stmts)

        tmp_rs = copy.deepcopy(reconstructed_statements)

        # handle append properties
        for p in append_props:
            app_data = [x for x in data if x.get_prop_nr() == p]
            rec_app_data = [x for x in tmp_rs if x.get_prop_nr() == p]
            comp = [True for x in app_data for y in rec_app_data if x == y]
            if len(comp) != len(app_data):
                return True

        tmp_rs = [x for x in tmp_rs if x.get_prop_nr() not in append_props and x.get_prop_nr() in data_props]
github SuLab / WikidataIntegrator / wikidataintegrator / wdi_core.py View on Github external
def get_class_representation(self, jsn):
        data_type = [x for x in WDBaseDataType.__subclasses__() if x.DTYPE == jsn['datatype']][0]
        self.final = True
        self.current_type = data_type
        return data_type.from_json(jsn)
github SuLab / WikidataIntegrator / wikidataintegrator / wdi_core.py View on Github external
"""
        Parses a WD entity json and generates the datatype objects, sets self.wd_json_representation
        :param wd_json: the json of a WD entity
        :type wd_json: A Python Json representation of a WD item
        :return: returns the json representation containing 'labels', 'descriptions', 'claims', 'aliases', 'sitelinks'.
        """
        wd_data = {x: wd_json[x] for x in ('labels', 'descriptions', 'claims', 'aliases') if x in wd_json}
        wd_data['sitelinks'] = dict()
        self.entity_metadata = {x: wd_json[x] for x in wd_json if x not in
                                ('labels', 'descriptions', 'claims', 'aliases', 'sitelinks')}
        self.sitelinks = wd_json.get('sitelinks', dict())

        self.statements = []
        for prop in wd_data['claims']:
            for z in wd_data['claims'][prop]:
                data_type = [x for x in WDBaseDataType.__subclasses__() if x.DTYPE == z['mainsnak']['datatype']][0]
                statement = data_type.from_json(z)
                self.statements.append(statement)

        self.wd_json_representation = wd_data
        self.original_statements = copy.deepcopy(self.statements)

        return wd_data
github SuLab / WikidataIntegrator / wikidataintegrator / wdi_core.py View on Github external
def parse_wd_json(self, wd_json):
        """
        Parses a WD entity json and generates the datatype objects, sets self.wd_json_representation
        :param wd_json: the json of a WD entity
        :type wd_json: A Python Json representation of a WD item
        :return: returns the json representation containing 'labels', 'descriptions', 'claims', 'aliases', 'sitelinks'.
        """
        wd_data = {x: wd_json[x] for x in ('labels', 'descriptions', 'claims', 'aliases', 'sitelinks') if x in wd_json}
        self.entity_metadata = {x: wd_json[x] for x in wd_json if x not in
                                ('labels', 'descriptions', 'claims', 'aliases', 'sitelinks')}

        self.statements = []
        for prop in wd_data['claims']:
            for z in wd_data['claims'][prop]:
                data_type = [x for x in WDBaseDataType.__subclasses__() if x.DTYPE == z['mainsnak']['datatype']][0]
                statement = data_type.from_json(z)
                self.statements.append(statement)

        self.wd_json_representation = wd_data
        self.original_statments = copy.deepcopy(self.statements)

        return wd_data
github SuLab / WikidataIntegrator / wikidataintegrator / wdi_core.py View on Github external
def get_class_representation(self, jsn):
        data_type = [x for x in WDBaseDataType.__subclasses__() if x.DTYPE == jsn['datatype']][0]
        self.final = True
        self.current_type = data_type
        return data_type.from_json(jsn)