You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在JSON-LD框架中为id-value属性映射的子元素指定@embed规则

解决JSON-LD框架中子属性next-step的@embed: @never配置问题

要实现你需要的序列化效果,不能直接在顶层pwo:Workflow的框架里嵌套给next-step设置规则,得通过类型子框架单独定义pwo:Step的序列化规则,再关联到顶层框架中。

核心逻辑

JSON-LD框架要求针对每个节点类型单独配置序列化规则,你之前直接在steps属性下嵌套next-step的规则会触发语法错误——因为框架的属性配置仅能针对当前类型的直接属性,嵌套属性的规则需要通过目标类型的子框架来指定。

具体配置示例

假设你的原始JSON-LD结构(steps以ID-值映射存储)如下:

{
  "@context": {
    "pwo": "http://purl.org/spar/pwo/",
    "first-step": "pwo:firstStep",
    "next-step": "pwo:nextStep",
    "steps": "pwo:hasStep"
  },
  "@id": "workflow:1",
  "@type": "pwo:Workflow",
  "first-step": "#step1",
  "steps": {
    "#step1": {"@type": "pwo:Step", "next-step": "#step2"},
    "#step2": {"@type": "pwo:Step", "next-step": "#step3"},
    "#step3": {"@type": "pwo:Step"}
  }
}

对应的正确JSON-LD框架配置如下:

{
  "@context": {
    "pwo": "http://purl.org/spar/pwo/",
    "first-step": "pwo:firstStep",
    "next-step": "pwo:nextStep",
    "steps": "pwo:hasStep"
  },
  "@type": "pwo:Workflow",
  "first-step": {"@embed": "@never"},
  "steps": {
    "@type": "pwo:Step",
    "next-step": {"@embed": "@never"}
  }
}

配置细节说明

  • 顶层框架针对pwo:Workflow类型,直接给first-step设置@embed: @never,避免该属性嵌入节点。
  • 针对steps属性关联的pwo:Step类型,在steps的配置块中通过@type指定目标类型,同时给next-step设置@embed: @never——这样所有Step节点的next-step都会只输出ID引用,不会嵌套嵌入。
  • 确保@context的命名空间统一,避免属性名与URI不匹配导致的解析错误。

通过这个配置,无论是原始RDF还是其他来源的RDF,都会被序列化为你需要的ID-值映射结构,不会出现next-step嵌套嵌入的问题。

内容的提问来源于stack exchange,提问作者qqq

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.28 11:32:57