5

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

依赖解析树

我想在 html 网页上可视化它,任何人都可以给我一些例子或指导吗?我熟悉 C/C++、Python,但不熟悉 html/javascript。

非常感谢!

4

2 回答 2

4

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

演示和参考

例如解析树

“我将在奥斯汀的 SXSW 举办 NLP 研讨会。”

将会

(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": []
            }]
        }]
    }]
}]

并且可以使用 d3 绘制

于 2015-04-12T18:28:24.627 回答
2

您应该能够使用Raphaël JS做到这一点

看看他们提供的演示,例如:带有曲线的演示等。这应该为您指明正确的方向。

注意:以上内容仍然需要您在 JS 中编写代码,但是非常直接地使用 JS。您可能可以直接从 Raphael 开始,然后随手拿起零件。

祝你好运。

于 2012-09-22T12:53:15.003 回答