未提供项目描述
项目描述
wikibase-sync
许可证 |
|
构建状态 |
|
覆盖率 |
|
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的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 0371c62d571a7158095e08a0565a9507241bf929aef48dd57443ccbb13c86355 |
|
MD5 | 341cd0afcac0b4977a24ccb7dfd8765b |
|
BLAKE2b-256 | 8c7a2aaafdce186021df220acce8990784b1860e56a4b26b8efe41cef3b5bfb6 |