如何使用pywikibot处理自定义Wikibase?

huangapple go评论56阅读模式
英文:

how to work with custom wikibase using pywikibot

问题

I have my family file, user-config.py, and user-password.py in the directory that I am running the following script from:

import os, sys
import pywikibot as pwb
pwb.config.register_families_folder(os.getcwd())
pwb.login.ClientLoginManager().login()
os.environ['PYWIKIBOT_DIR'] = os.getcwd()
site = pwb.Site()
repo = site.data_repository()
pg = pwb.ItemPage(repo, 'Q1')
pg.get()

But I get the following error:

AttributeError: DataSite instance has no attribute 'entity_sources'

How do I resolve this?

英文:

I have my family file, user-config.py and user-password.py in the directory that i am running the following script from

import os, sys
import pywikibot as pwb
pwb.config.register_families_folder(os.getcwd())
pwb.login.ClientLoginManager().login()
os.environ['PYWIKIBOT_DIR'] = os.getcwd()
site = pwb.Site()
repo = site.data_repository()
pg = pwb.ItemPage(repo, 'Q1')
pg.get()

But i get the following error

AttributeError: DataSite instance has no attribute 'entity_sources'

How do i resolve this ?

答案1

得分: 0

在Pywikibot 8中实现了federated WikibaseDataSite.get_repo_for_entity_type()方法在您的wikibase家族文件中需要一个entity_sources()方法。要解决数据存储库的此问题,您可以执行以下操作:

Pywikibot版本7.7.3及以下

由于扩展的federated Wikibase在这里不可用,降级版本可能会解决此问题,但不建议这样做,因为Pywikibot 8带来了许多改进和错误修复。有关更多信息,请参阅更新日志

Pywikibot版本8.0和8.1

您只需要将以下行添加到您的wikibase家族文件中:

def entity_sources(self, code: str) -> Dict[str, Tuple[str, str]]:
    """为实体类型提供存储库站点信息。"""
    return {}

有关更多信息,请参考手册

Pywikibot版本8.2

如果您的wikibase存储库处理所有实体类型,您可以从family.WikibaseFamily继承您的家族(可能还要额外继承)。如果不同实体类型使用不同的存储库(即federated Wikibase),则必须在您的wikibase家族文件中定义自己的“entity_sources”方法,就像“Pywikibot版本8.0和8.1”部分中描述的那样。

提示

对于federated Wikibase设置,您可以使用commons_family其代码作为示例。

英文:

In Pywikibot 8 federated Wikibase was implemented. The DataSite.get_repo_for_entity_type() method expects a entity_sources() method in your wikibase family file. To solve this issue with your data repository you can do the following:

Pywikibot release 7.7.3 and below

Since the extension federated Wikibase is not available here, a release downgrade could solve it but it is not recommended because Pywikibot 8 comes with a lot of improvements and bugfixes. See the changelog for more information.

Pywikibot release 8.0 and 8.1

All you have to do is to add the following lines into your wikibase family file:

def entity_sources(self, code: str) -> Dict[str, Tuple[str, str]]:
"""Provide repository site information for entity types."""
    return {}

For more information refer the manual.

Pywikibot release 8.2

If all entity types are handled by your wikibase repository given by your wikibase family file you can just inherit your family (maybe additionally) from family.WikibaseFamily. If you have different repositories for different entity types (i.e. federated Wikibase), you have to define your own entity_sources method in your wikibase family file like described in the Pywikibot release 8.0 and 8.1 section.

Hint

For a federated Wikibase setting you can use commons_family and its code as a sample.

huangapple
  • 本文由 发表于 2023年7月4日 20:50:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/76612838.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定