Javascript 是否将JSON-LD转换为d3.js节点/链接格式?

Javascript 是否将JSON-LD转换为d3.js节点/链接格式?,javascript,json,node.js,d3.js,Javascript,Json,Node.js,D3.js,我正在尝试对猫头鹰本体进行可视化。我已经将其转换为JSON-LD,但现在需要将其转换为D3的节点/链接格式吗?作为参考,格式如下所示: { "nodes": [ {"x": 469, "y": 410}, {"x": 493, "y": 364}, {"x": 442, "y": 365}, {"x": 467, "y": 314}, {"x": 477, "y": 248}, {"x": 425, "y": 207}, {"x": 4

我正在尝试对猫头鹰本体进行可视化。我已经将其转换为JSON-LD,但现在需要将其转换为D3的节点/链接格式吗?作为参考,格式如下所示:

{
  "nodes": [
    {"x": 469, "y": 410},
    {"x": 493, "y": 364},
    {"x": 442, "y": 365},
    {"x": 467, "y": 314},
    {"x": 477, "y": 248},
    {"x": 425, "y": 207},
    {"x": 402, "y": 155},
    {"x": 369, "y": 196},
    {"x": 350, "y": 148},
    {"x": 539, "y": 222},
    {"x": 594, "y": 235},
    {"x": 582, "y": 185},
    {"x": 633, "y": 200}
  ],
  "links": [
    {"source":  0, "target":  1},
    {"source":  1, "target":  2},
    {"source":  2, "target":  0},
    {"source":  1, "target":  3},
    {"source":  3, "target":  2},
    {"source":  3, "target":  4},
    {"source":  4, "target":  5},
    {"source":  5, "target":  6},
    {"source":  5, "target":  7},
    {"source":  6, "target":  7},
    {"source":  6, "target":  8},
    {"source":  7, "target":  8},
    {"source":  9, "target":  4},
    {"source":  9, "target": 11},
    {"source":  9, "target": 10},
    {"source": 10, "target": 11},
    {"source": 11, "target": 12},
    {"source": 12, "target": 10}
  ]
}
我知道我可以使用d3.json打开一个json文件,但我不确定如何从json-LD转换为上述格式。有什么解决办法吗?谢谢

编辑:

我的owl本体在这里的pastebin上可用(json ld格式):。如果您在上下文中取得一个峰值,您可以看到我正在通过“isSubClass”属性对本体进行建模

我知道要在D3中读取json文件,我可以使用D3.json。我不确定如何准确地转换为上述格式


我发现这个github存储库说它应该能够转换成这种格式,但是我在运行它时遇到了很多麻烦,我还想把它保存在javascript中。有什么建议/解决方案吗?谢谢

假设您要做的是转换:

{
  "@id": "schema:Person"
  , "@type": "owl:Class"
  , "subClassOf": { 
    "@id": "gr:BusinessEntity"
  }
}
进入

您需要执行以下操作:

加载json数据后,通过将要编写的转换函数对其进行处理:

  • 循环遍历@graph数组
  • 在这个循环中,保存每个节点的记录,以及每个链接的记录。对于节点,请确保使用对象,以便获得唯一的节点

  • 循环遍历nodes对象,并基于它创建“nodes”数组

  • 通过查找节点数组中每个节点的索引来创建“链接”数组


  • 您可能需要查看d3.js邮件列表的存档,有些人已经问了与您类似的问题。

    假设您要做的是转换此文件:

    {
      "@id": "schema:Person"
      , "@type": "owl:Class"
      , "subClassOf": { 
        "@id": "gr:BusinessEntity"
      }
    }
    
    进入

    您需要执行以下操作:

    加载json数据后,通过将要编写的转换函数对其进行处理:

  • 循环遍历@graph数组
  • 在这个循环中,保存每个节点的记录,以及每个链接的记录。对于节点,请确保使用对象,以便获得唯一的节点

  • 循环遍历nodes对象,并基于它创建“nodes”数组

  • 通过查找节点数组中每个节点的索引来创建“链接”数组


  • 你可能想看看d3.js邮件列表的存档,有些人已经问了与你类似的问题。

    你能分享一个JSON-LD格式的数据样本吗?你的JSON-LD数据的这个子集:
    {@id:“schema:Person”,“@type:“owl:Class”,“subassof:{@id:“gr:BusinessEntity”}
    被翻译为两个节点之间的一条边
    schema:Person
    gr:BusinessEntity
    ?您可以共享JSON-LD格式的数据样本吗?您的JSON-LD数据的子集:
    {@id:“schema:Person”,“@type:“owl:Class”,“subassof:{@id:“gr:BusinessEntity”}
    可以翻译为两个节点之间的一条边
    schema:Person
    gr:BusinessEntity