How to use the wikidataintegrator.wdi_core.WDTime 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 / ref_handlers / test_update_retrieved_if_new.py View on Github external
'sitelinks': {},
             'title': 'Q15397819',
             'type': 'item'
             }
        print("komt ie hier")
        d.update(claims)

        pprint.pprint(d)
        return self.parse_wd_json(d)


orig_statements1 = [wdi_core.WDExternalID(value="99999999999", prop_nr="P698", references=[
    [
        wdi_core.WDItemID(value="Q5412157", prop_nr="P248", is_reference=True),
        wdi_core.WDExternalID(value="99999999999", prop_nr="P698", is_reference=True),
        wdi_core.WDTime("+2017-01-01T00:00:00Z", prop_nr="P813", is_reference=True),
    ]
])]


def test_ref_custom():
    # custom ref mode, same retrieved date
    statements = copy.deepcopy(orig_statements1)
    item = fake_itemengine1(wd_item_id='Q20814663', global_ref_mode="CUSTOM", ref_handler=custom_ref_handler)
    orig = item.wd_json_representation['claims']['P698']
    item.update(data=statements)
    new = item.wd_json_representation['claims']['P698']
    require_write = not all(
        any(x.equals(y, include_ref=True) for y in item.original_statements) for x in item.statements)
    assert not require_write

    frc = frc_fake_query_data_paper1(base_data_type=wdi_core.WDBaseDataType, engine=wdi_core.WDItemEngine, use_refs=True,
github SuLab / WikidataIntegrator / wikidataintegrator / ref_handlers / test_update_retrieved_if_new.py View on Github external
def test_ref_custom_diff_date_month():
    # replace retrieved date, one month away, should not be updated
    statements = copy.deepcopy(orig_statements1)
    statements[0].references[0][2] = wdi_core.WDTime("+2017-02-01T00:00:00Z", prop_nr="P813", is_reference=True)
    item = fake_itemengine1(wd_item_id='Q20814663', global_ref_mode="CUSTOM", ref_handler=custom_ref_handler)
    orig = item.wd_json_representation['claims']['P698']
    item.update(data=statements)
    new = item.wd_json_representation['claims']['P698']
    require_write = not all(
        any(x.equals(y, include_ref=True) for y in item.original_statements) for x in item.statements)
    assert not require_write

    frc = frc_fake_query_data_paper1(base_data_type=wdi_core.WDBaseDataType, engine=wdi_core.WDItemEngine, use_refs=True,
                                    ref_handler=custom_ref_handler)
    frc.debug = True
    assert not frc.write_required(data=statements)
github SuLab / WikidataIntegrator / wikidataintegrator / ref_handlers / test_update_retrieved_if_new.py View on Github external
def test_ref_custom_diff_date_year():
    # replace retrieved date, one year away. should be updated
    statements = copy.deepcopy(orig_statements1)
    statements[0].references[0][2] = wdi_core.WDTime("+2018-04-24T00:00:00Z", prop_nr="P813", is_reference=True)
    item = fake_itemengine1(wd_item_id='Q20814663', global_ref_mode="CUSTOM", ref_handler=custom_ref_handler)
    orig = item.wd_json_representation['claims']['P698']
    item.update(data=statements)
    new = item.wd_json_representation['claims']['P698']
    require_write = not all(
        any(x.equals(y, include_ref=True) for y in item.original_statements) for x in item.statements)
    assert require_write

    frc = frc_fake_query_data_paper1(base_data_type=wdi_core.WDBaseDataType, engine=wdi_core.WDItemEngine, use_refs=True,
                                    ref_handler=custom_ref_handler)
    frc.debug = True
    assert frc.write_required(data=statements)
github SuLab / WikidataIntegrator / wikidataintegrator / wdi_helpers.py View on Github external
self.parse_metadata()
        if 'pmcid' in self.meta and self.meta['pmcid']:
            extid = wdi_core.WDString(value=self.meta['pmcid'], prop_nr=self.PROPS['PMCID'], is_reference=True)
            ref_url = wdi_core.WDUrl("http://europepmc.org/abstract/{}/{}".format("PMC", self.meta['pmcid']),
                                     self.PROPS['reference URL'], is_reference=True)
        elif 'pmid' in self.meta and self.meta['pmid']:
            extid = wdi_core.WDString(value=self.meta['pmid'], prop_nr=self.PROPS['PubMed ID'], is_reference=True)
            ref_url = wdi_core.WDUrl("http://europepmc.org/abstract/{}/{}".format("MED", self.meta['pmid']),
                                     self.PROPS['reference URL'], is_reference=True)
        elif 'doi' in self.meta and self.meta['doi']:
            extid = wdi_core.WDString(value=self.meta['doi'], prop_nr=self.PROPS['DOI'], is_reference=True)
            ref_url = None
        else:
            raise ValueError("ref needs a pmcid, pmid, or doi")
        stated_in = wdi_core.WDItemID(value='Q5412157', prop_nr='P248', is_reference=True)
        retrieved = wdi_core.WDTime(strftime("+%Y-%m-%dT00:00:00Z", gmtime()), prop_nr='P813', is_reference=True)
        self.reference = [stated_in, extid, retrieved]
        if ref_url:
            self.reference.append(ref_url)
github SuLab / WikidataIntegrator / wikidataintegrator / wdi_helpers / publication.py View on Github external
def make_statements(self):
        self.statements.append(
            wdi_core.WDItemID(self.instance_of_qid, PROPS['instance of'], references=[self.reference]))
        self.statements.append(wdi_core.WDMonolingualText(self.title, PROPS['title'], references=[self.reference]))

        if self.publication_date:
            date = self.publication_date.strftime("+%Y-%m-%dT00:00:00Z")
            self.statements.append(
                wdi_core.WDTime(date, PROPS['publication date'], references=[self.reference]))
        if self.published_in_qid:
            self.statements.append(
                wdi_core.WDItemID(self.published_in_qid, PROPS['published in'], references=[self.reference]))
        if self.volume:
            self.statements.append(wdi_core.WDString(self.volume, PROPS['volume'], references=[self.reference]))
        if self.pages:
            self.statements.append(wdi_core.WDString(self.pages, PROPS['page(s)'], references=[self.reference]))
        if self.issue:
            self.statements.append(wdi_core.WDString(self.issue, PROPS['issue'], references=[self.reference]))
github SuLab / WikidataIntegrator / wikidataintegrator / wdi_helpers / release.py View on Github external
def make_statements(self):
        s = []
        helper = self.helper
        # instance of edition
        s.append(wdi_core.WDItemID(helper.get_qid('Q3331189'), helper.get_pid("P31")))
        # edition or translation of
        s.append(wdi_core.WDItemID(self.edition_of_qid, helper.get_pid("P629")))
        # edition number
        s.append(wdi_core.WDString(self.edition, helper.get_pid("P393")))

        if self.archive_url:
            s.append(wdi_core.WDUrl(self.archive_url, helper.get_pid('P1065')))

        if self.pub_date:
            s.append(wdi_core.WDTime(self.pub_date, helper.get_pid('P577'), precision=self.date_precision))

        self.statements = s
github SuLab / WikidataIntegrator / wikidataintegrator / wdi_helpers.py View on Github external
def make_statements(self, ordinals=None):
        """

        :param ordinals: passed to self.make_author_statements
        :return:
        """
        self.make_reference()
        s = []

        ### Required statements
        for pubtype in self.meta['pubtype_qid']:
            s.append(wdi_core.WDItemID(pubtype, self.PROPS['instance of'], references=[self.reference]))
        s.append(wdi_core.WDMonolingualText(self.meta['title'], self.PROPS['title'], references=[self.reference]))
        s.append(wdi_core.WDTime(self.meta['date'], self.PROPS['publication date'], references=[self.reference]))
        s.append(wdi_core.WDItemID(self.meta['journal_wdid'], self.PROPS['published in'], references=[self.reference]))
        s.extend(self.make_author_statements(ordinals=ordinals))

        ### Optional statements
        if self.meta['pmid']:
            s.append(wdi_core.WDExternalID(self.meta['pmid'], self.PROPS['PubMed ID'], references=[self.reference]))
        if self.meta['volume']:
            s.append(wdi_core.WDString(self.meta['volume'], self.PROPS['volume'], references=[self.reference]))
        if self.meta['pages']:
            s.append(wdi_core.WDString(self.meta['pages'], self.PROPS['page(s)'], references=[self.reference]))
        if self.meta['issue']:
            s.append(wdi_core.WDString(self.meta['issue'], self.PROPS['issue'], references=[self.reference]))
        if self.meta['doi']:
            s.append(wdi_core.WDExternalID(self.meta['doi'].upper(), self.PROPS['DOI'], references=[self.reference]))
        if self.meta['pmcid']:
            s.append(wdi_core.WDExternalID(self.meta['pmcid'].replace("PMC", ""), self.PROPS['PMCID'],
github SuLab / WikidataIntegrator / wikidataintegrator / wdi_helpers / publication.py View on Github external
def make_reference(self):
        if self.source == "crossref":
            assert 'doi' in self.ids
            extid = wdi_core.WDString(self.ids['doi'], PROPS['DOI'], is_reference=True)
            ref_url = wdi_core.WDUrl(self.ref_url, PROPS['reference URL'], is_reference=True)
            stated_in = wdi_core.WDItemID(self.SOURCES[self.source], PROPS['stated in'], is_reference=True)
            retrieved = wdi_core.WDTime(strftime("+%Y-%m-%dT00:00:00Z", gmtime()), PROPS['retrieved'],
                                        is_reference=True)
            self.reference = [stated_in, extid, ref_url, retrieved]
        elif self.source == "europepmc":
            assert 'pmcid' in self.ids
            extid = wdi_core.WDString(self.ids['pmcid'], PROPS['PMCID'], is_reference=True)
            ref_url = wdi_core.WDUrl(self.ref_url, PROPS['reference URL'], is_reference=True)
            stated_in = wdi_core.WDItemID(self.SOURCES[self.source], PROPS['stated in'], is_reference=True)
            retrieved = wdi_core.WDTime(strftime("+%Y-%m-%dT00:00:00Z", gmtime()), PROPS['retrieved'],
                                        is_reference=True)
            self.reference = [stated_in, extid, ref_url, retrieved]