gpt4 book ai didi

html - 网页依赖解析树可视化

转载 作者:太空狗 更新时间:2023-10-29 15:51:18 24 4
gpt4 key购买 nike

下面是一个依赖解析树的例子。

Dependency Parsing Tree

我想在 html 网页上将其可视化,任何人都可以给我一些示例或说明吗?我熟悉C/C++、Python,但不熟悉html/javascript。

非常感谢!

最佳答案

将输出转换为 json 并将其传递给一些 js 图形库,如 d3、raphael 等。

Demo & Reference

例如解析树

"I am going to do a seminar on NLP at SXSW in Austin."

会是

(ROOT
(S
(NP (PRP I))
(VP (VBP am)
(VP (VBG going)
(S
(VP (TO to)
(VP (VB do)
(NP
(NP (DT a) (NN seminar))
(PP (IN on)
(NP (NNP NLP))))
(PP (IN at)
(NP (NNP SXSW)))
(PP (IN in)
(NP (NNP Austin))))))))
(. .)))

可以转化为

[{
"data": {
"type": "ROOT"
},
"children": [{
"data": {
"type": "S"
},
"children": [{
"data": {
"type": "NP"
},
"children": [{
"data": {
"type": "PRP"
},
"children": [{
"data": {
"ne": "O",
"word": "I",
"type": "TK",
"pos": "PRP"
},
"children": []
}]
}]
}, {
"data": {
"type": "VP"
},
"children": [{
"data": {
"type": "VBP"
},
"children": [{
"data": {
"ne": "O",
"word": "am",
"type": "TK",
"pos": "VBP"
},
"children": []
}]
}, {
"data": {
"type": "VP"
},
"children": [{
"data": {
"type": "VBG"
},
"children": [{
"data": {
"ne": "O",
"word": "going",
"type": "TK",
"pos": "VBG"
},
"children": []
}]
}, {
"data": {
"type": "S"
},
"children": [{
"data": {
"type": "VP"
},
"children": [{
"data": {
"type": "TO"
},
"children": [{
"data": {
"ne": "O",
"word": "to",
"type": "TK",
"pos": "TO"
},
"children": []
}]
}, {
"data": {
"type": "VP"
},
"children": [{
"data": {
"type": "VB"
},
"children": [{
"data": {
"ne": "O",
"word": "do",
"type": "TK",
"pos": "VB"
},
"children": []
}]
}, {
"data": {
"type": "NP"
},
"children": [{
"data": {
"type": "NP"
},
"children": [{
"data": {
"type": "DT"
},
"children": [{
"data": {
"ne": "O",
"word": "a",
"type": "TK",
"pos": "DT"
},
"children": []
}]
}, {
"data": {
"type": "NN"
},
"children": [{
"data": {
"ne": "O",
"word": "seminar",
"type": "TK",
"pos": "NN"
},
"children": []
}]
}]
}, {
"data": {
"type": "PP"
},
"children": [{
"data": {
"type": "IN"
},
"children": [{
"data": {
"ne": "O",
"word": "on",
"type": "TK",
"pos": "IN"
},
"children": []
}]
}, {
"data": {
"type": "NP"
},
"children": [{
"data": {
"type": "NN"
},
"children": [{
"data": {
"ne": "ORGANIZATION",
"word": "NLP",
"type": "TK",
"pos": "NN"
},
"children": []
}]
}]
}]
}]
}, {
"data": {
"type": "PP"
},
"children": [{
"data": {
"type": "IN"
},
"children": [{
"data": {
"ne": "O",
"word": "at",
"type": "TK",
"pos": "IN"
},
"children": []
}]
}, {
"data": {
"type": "NP"
},
"children": [{
"data": {
"type": "NNP"
},
"children": [{
"data": {
"ne": "ORGANIZATION",
"word": "SXSW",
"type": "TK",
"pos": "NNP"
},
"children": []
}]
}]
}]
}, {
"data": {
"type": "PP"
},
"children": [{
"data": {
"type": "IN"
},
"children": [{
"data": {
"ne": "O",
"word": "in",
"type": "TK",
"pos": "IN"
},
"children": []
}]
}, {
"data": {
"type": "NP"
},
"children": [{
"data": {
"type": "NNP"
},
"children": [{
"data": {
"ne": "LOCATION",
"word": "Austin",
"type": "TK",
"pos": "NNP"
},
"children": []
}]
}]
}]
}]
}]
}]
}]
}]
}, {
"data": {
"type": "."
},
"children": [{
"data": {
"ne": "O",
"word": ".",
"type": "TK",
"pos": "."
},
"children": []
}]
}]
}]
}]

can be drawn using d3 .

关于html - 网页依赖解析树可视化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12543911/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com