示例#1
0
    def index_single_object(self, oparl_object, full_pass):
        oparl_id = oparl_object.get_id()

        if full_pass:
            claims = self.get_claims(oparl_object, debug_url=oparl_id)
        else:
            id_claim = WDUrl(value=oparl_id,
                             prop_nr=self.mapping["id"]["property"])
            type_claim = WDUrl(value=oparl_object.get_oparl_type(),
                               prop_nr=self.mapping["type"]["property"])
            claims = [id_claim, type_claim]

        if self.url_to_item_id.has(oparl_id):
            wd_item_id = self.url_to_item_id.get(oparl_id)
            item_name = None
            domain = ""
        else:
            print("Creating new item")
            wd_item_id = ""
            item_name = oparl_id
            domain = None

        wd_item = WDItemEngine(wd_item_id=wd_item_id,
                               item_name=item_name,
                               domain=domain,
                               data=claims,
                               server=self.server,
                               base_url_template=self.base_url_template)
        wd_item.set_label(oparl_id)
        returned = wd_item.write(self.wikibase_login)
        self.url_to_item_id.set(oparl_id, returned)

        print(oparl_id)
        print("http://{}/index.php?title=Item:{}".format(
            self.server, returned))
        print()
示例#2
0
文件: main.py 项目: konstin/demos
    def push_elem(self, oparl_object):
        print("PROESSING", oparl_object["id"])
        oparl_id = oparl_object["id"]

        if oparl_id in self.id_mapping.keys():
            wd_item_id = self.id_mapping.get(oparl_id)
            item_name = None
            domain = ""
        else:
            wd_item_id = ""
            item_name = oparl_id
            domain = None

        claims = self.get_claims(oparl_object)
        wd_item = WDItemEngine(wd_item_id=wd_item_id, item_name=item_name, domain=domain,
                               data=claims, server=self.server, base_url_template=self.base_url_template)
        wd_item.set_label(oparl_id)
        returned = wd_item.write(self.login)
        self.id_mapping[oparl_id] = returned

        if item_name:
            print("CREATED", "http://{}/index.php?title=Item:{}".format(self.server, returned))
        else:
            print("UPDATED", "http://{}/index.php?title=Item:{}".format(self.server, returned))
示例#3
0
 def _set_label(self, entity: wdi_core.WDItemEngine,
                objct: LiteralElement) -> wdi_core.WDItemEngine:
     lang = get_lang_from_literal(objct)
     logging.debug("Changing label @%s of %s", lang, entity)
     entity.set_label(objct.content, lang)
     return entity