json-ld - Json-ld 未按预期转换为 RDF
问题描述
我已经将一些 JSON-ld 转换为 RDF,但是它似乎没有像我期望的那样生成带有主题的 RDF。
所以,我的 JSON-ld 看起来像这样:
{
"@context":{
"personid":"http://schema.org/id",
"hasUpdateType":"http://schema.org/updateType"
},
"@type":"http://schema.org/Person",
"personid":"123456",
"hasUpdateType":{
"@type":"updateType",
"updateType":"Full"
}
}
而产生的RDF是
_:b0 <http://schema.org/id> "123456" .
_:b0 <http://schema.org/updateType> _:b1 .
_:b0 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Person> .
但是我期待类似的东西(语法不正确,只是想大致显示):
person hasUpdatetype Full
我的 json-ld 错了吗?
为了进行从 json-ld 到 rdf 的转换,我使用了toRDF()
这个库中的https://github.com/digitalbazaar/jsonld.js
任何帮助,将不胜感激。
谢谢。
解决方案
您需要使用@id
(或别名)来定义节点对象的主题。您可以@id
在上下文中定义“persondid”。
您将“hasUpdateTime”定义为扩展为“schema:updateTime”,因此扩展的 RDF 应该使用“ http://schema.org/updateType ”作为谓词。如果您希望该值是与“Full”关联的单个 URI,请对“hasUpdateType”使用类型强制。像下面这样的东西可能更接近你想要的。
{
"@context":{
"@base": "http://example.com/",
"personid":"@id",
"hasUpdateType": {"@id": "http://schema.org/updateType", "@type": "@id"}
},
"@type":"http://schema.org/Person",
"personid":"123456",
"hasUpdateType":"Full"
}
这将为您提供以下三元组:
<http://example.com/123456> <http://schema.org/updateType> <http://example.com/Full> .
<http://example.com/123456> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Person> .
推荐阅读
- python - 如何使用循环创建一个类的随机多个实例?
- c++ - Why does SetWindowRgn not work for static controls?
- python - 切片二维数组和跳过索引的有效方法;重复提取小片段
- python - Azure Cosmos DB,删除 IDS(肯定存在)
- flutter - Flutter Web - 迭代对象列表时如何保留绝对值?
- css - 如何阻止暗模式破坏我的 CSS
- python - 在 row[column] 上使用 pd.notnull() 检查时出现值错误。替代空检查?
- mysql - 加载只有 1 列的 tsv 会导致表中出现空格问题
- c# - 在 Linq 中使用表达式
- python - Python:将二维二进制值数组打包到 UINT64 数组中的最快方法