[英]Convert JSON-LD to d3.js node/links format?
我正在嘗試對OWL本體進行可視化。 我已經將其轉換為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轉換為上述格式。 有什么辦法嗎? 謝謝。
編輯:
我的貓頭鷹本體可以在這里的pastebin(以json-ld格式)上找到: http : //pastebin.com/g7ggDyFX 。 如果您在上下文中達到頂峰,則可以看到我正在通過“ isSubClass”屬性對本體建模。
我知道要讀取D3中的json文件,可以使用d3.json。 我不確定如何准確轉換為上述格式。
我找到了這個github存儲庫https://github.com/uf6/ottograf ,它說它應該能夠轉換為格式,但是我在運行它時遇到很多麻煩,並且我也想將其保存在javascript中。 任何提示/解決方案? 謝謝!
假設您要執行的操作是將其轉換為:
{
"@id": "schema:Person"
, "@type": "owl:Class"
, "subClassOf": {
"@id": "gr:BusinessEntity"
}
}
成
{
"nodes": [
{ "@id": "schema:Person", "@type": "owl:Class"}
{ "@id": "gr:BusinessEntity"}
]
, "links": [
{"source": 0, "target": 1}
]
}
您需要執行以下操作:
加載json數據后,通過以下轉換函數對其進行處理:
在此循環中,保留每個節點的記錄以及每個鏈接的記錄。 對於節點,請確保使用一個對象,以便獲得唯一的節點。
循環遍歷節點對象,並基於該對象創建“節點”數組
通過在節點數組中查找每個節點的索引來創建“鏈接”數組...
您可能想看看d3.js郵件列表的檔案,有些人已經問過與您類似的問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.