Visualization of the parsing tree on a web page

The following is an example of a dependency parsing tree.

Dependency parsing tree

I want to visualize it on an html web page, can someone show me some examples or directions? I am familiar with C / C ++, Python, but not familiar with html / javascript.

Many thanks!

+5
source share
2 answers

Hide output in json and pass it to some library of js graphs like d3, raphael, etc.

Demo and link

For example, the Parse Tree for

"I'm going to host a NLP workshop at SXSW in Austin."

will be

(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))))))))
    (. .)))

can convert to

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

and can be done with d3 .

+4
source

, Raphaël JS

, , : .. .

. , JS, JS . , , , .

.

+2

All Articles