跳转到主要内容

未提供项目描述

项目描述

wikibase-sync

许可证 license
构建状态 travis build status
覆盖率 coverage

Python库,用于在RDF文件和Wikibase实例之间同步数据。

它根据RDF本体中的更改更新您的Wikibase实例。

如何安装

您可以从源代码手动安装它

git clone https://github.com/weso/wikibase-sync
cd wikibase-sync
python setup.py install

建议使用Python 3.7+。

示例

以下代码可以同步两个RDF文件到给定的Wikibase实例的更改

from wbsync.triplestore import WikibaseAdapter
from wbsync.synchronization import GraphDiffSyncAlgorithm, OntologySynchronizer

mediawiki_api_url='wikibase_api_endpoint'
sparql_endpoint_url='wikibase_sparql_endpoint'
username='wikibase_username'
password='wikibase_password'
adapter = WikibaseAdapter(mediawiki_api_url, sparql_endpoint_url, username, password)

algorithm = GraphDiffSyncAlgorithm()
synchronizer = OntologySynchronizer(algorithm)

source_content = "original rdf content goes here"
target_content = "final rdf content goes here"
ops = synchronizer.synchronize(source_content, target_content)
for op in ops:
    res = op.execute(adapter)
    if not res.successful:
        print(f"Error synchronizing triple: {res.message}")

如果source_content为空,则相当于将target contents添加到Wikibase,而如果target_content为空,则相当于如果存在,则从Wikibase中删除source_content。有关使用Wikibase实例同步RDF文件的更多示例,请参阅同步笔记本

执行批处理操作

可以进行批处理操作(一次性执行给定实体的所有语句)。这种同步类型将具有更好的性能,但风险是无效的语句将取消整个批处理操作。以下代码可用于执行批处理操作

from wbsync.synchronization.operations import optimize_ops

def execute_batch_synchronization(source_content, target_content, synchronizer, adapter):
    ops = synchronizer.synchronize(source_content, target_content)
    batch_ops = optimize_ops(ops)
    for op in batch_ops:
        res = op.execute(adapter)
        if not res.successful:
            print(f"Error synchronizing triple: {res.message}")

有关这些操作和由此获得的时间的信息,可以在基准测试笔记本中探索。

项目详情


下载文件

下载适合您平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。

源分布

wbsync-0.1.4.tar.gz (13.9 kB 查看哈希值)

上传时间

支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页面