微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用两个不同的@types压缩JSON-LD属性?

如何解决使用两个不同的@types压缩JSON-LD属性?

我正在尝试压缩JSON-LD文档,请参见下文(我们正在使用URN,但URL也会出现相同的问题)。我希望在以下两种用法中将"org:example:property:schema;2"压缩为schema,也要合理压缩schema属性的嵌套对象。可悲的是,这似乎到目前为止是不可能的。

[
  {
    "@id": "org:example:ExampleThing","org:example:property:contents;2": [
          {
        "@type": "org:example:class:Property;2","org:example:property:schema;2": {
          "@id": "org:example:instance:Schema:integer;2"
        }
      }
    ]
  },{
    "@id": "org:example:ExampleThing2","org:example:property:contents;2": [
      {
        "@type": "org:example:class:Property;2","org:example:property:schema;2": {
            "@type": "org:example:class:Enum;2","org:example:property:valueSchema;2": {
                "@id": "org:example:instance:Schema:string;2"
            }
        }
      }
    ]
  }
]

我想了解的内容如下:

[
    {
      "@id": "org:example:ExampleThing","contents": {
        "@type": "Property","schema": {
          "@id": "integer"
        }
      }
    },{
      "@id": "org:example:ExampleThing2","schema": {
          "@type": "Enum","valueSchema": "string"
        }
      }
    }
  ]

我得到的最接近的是以下上下文。但是,其中的org:example:instance:Schema:integer;2压缩。在"@type": "@vocab"定义中添加schema可以解决ExampleThing的问题,但是schema项与ExampleThing2属性用法不匹配,因此而不是在那里压实。

{
  "Property": { "@id": "org:example:class:Property;2" },"Enum": { "@id": "org:example:class:Enum;2" },"contents": { "@id": "org:example:property:contents;2" },"schema": { "@id": "org:example:property:schema;2" },"valueSchema": {
      "@id": "org:example:property:valueSchema;2","@type": "@vocab"
  },"integer": { "@id": "org:example:instance:Schema:integer;2" },"string": { "@id": "org:example:instance:Schema:string;2" }
}

解决方法

您拥有的东西与您想要的东西非常接近。您可以在此处查看playground link

主要问题是"org:example:instance:Schema:integer;2" @id的值无法进一步压缩,因为@id的值被视为相对于文档位置或{{1 }}。您可以在上下文中添加@base声明,这样可以使您更接近。您可以更好地使用范围上下文,并在@base@base范围内的上下文中使用其他Property

如果不这样做,压缩结果将如下所示:

schema

您可以在规范的Shortening IRIs部分中阅读更多内容。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。