pytreebank︱情感分析可视化——情感结构树
2017-11-01 18:39
399 查看
效果如上,一句话用树状来表达,具体案例可查询stanford Sentiment Analysis网站
如何用py来画,主要参考自pytreebank-github
1 直接上案例,官网案例数据下载:
http://nlp.stanford.edu/sentiment/trainDevTestTrees_PTB.zipimport pytreebank dataset = pytreebank.load_sst("/path/to/sentiment/") pytreebank.LabeledTree.inject_visualization_javascript() # select and example to visualize example = dataset["train"][0] # display it in the page example.display()
load_sst时候需要写入官网下载数据的链接具体在哪。
2 那么案例里面的数据长什么样子:
for label, sentence in example.to_labeled_lines(): print("%s has sentiment label %s" % ( sentence, ["very negative", "negative", "neutral", "positive", "very positive"][label]))
具体如下:
The Rock is destined to be the 21st Century 's new `` Conan '' and that he 's going to make a splash even greater than Arnold Schwarzenegger , Jean-Claud Van Damme or Steven Segal . has sentiment label positive The Rock has sentiment label neutral The has sentiment label neutral Rock has sentiment label neutral is destined to be the 21st Century 's new `` Conan '' and that he 's going to make a splash even greater than Arnold Schwarzenegger , Jean-Claud Van Damme or Steven Segal . has sentiment label very positive is destined to be the 21st Century 's new `` Conan '' and that he 's going to make a splash even greater than Arnold Schwarzenegger , Jean-Claud Van Damme or Steven Segal has sentiment label positive is has sentiment label neutral destined to be the 21st Century 's new `` Conan '' and that he 's going to make a splash even greater than Arnold Schwarzenegger , Jean-Claud Van Damme or Steven Segal has sentiment label very positive destined has sentiment label neutral to be the 21st Century 's new `` Conan '' and that he 's going to make a splash even greater than Arnold Schwarzenegger , Jean-Claud Van Damme or Steven Segal has sentiment label neutral to be the 21st Century 's new `` Conan '' and has sentiment label neutral to be the 21st Century 's new `` Conan '' has sentiment label neutral to be the 21st Century 's new `` Conan has sentiment label neutral to has sentiment label neutral
3 那么自己咋画呢:
pytreebank.LabeledTree.inject_visualization_javascript() pytreebank.create_tree_from_string('(4 (0 你) (3 (2 是) (3 (3 (3 谁) (2 的)) (2 谁))))').display()
4代表总共有四个节点,
(0 你)代表,‘你’这个字的情感点;
编号的意义为:
0–>”very negative”,
1–> “negative”
2–>, “neutral”
3–>, “positive”
4–>, “very positive”
4 其他
pytreebank.create_tree_from_string('(4 (0 你) (3 (2 是) (3 (3 (3 谁) (2 的)) (2 谁))))').to_dict()
把结果导出成dict形式
pytreebank.create_tree_from_string('(4 (0 你) (3 (2 是) (3 (3 (3 谁) (2 的)) (2 谁))))').to_json()
把结果导出成json形式
pytreebank.create_tree_from_string('(4 (0 你) (3 (2 是) (3 (3 (3 谁) (2 的)) (2 谁))))').to_lines()
把结果导出成一列文字形式
pytreebank.create_tree_from_string('(4 (0 你) (3 (2 是) (3 (3 (3 谁) (2 的)) (2 谁))))').to_lines()
把结果导出成to_labeled_lines形式
相关文章推荐
- 结构分析可视化新书
- CTP源码分析7 CTP路由引擎结构及源码分析(一)----TreeRoute.h头文件解读和概要介绍
- STL源码分析之RB-tree结构简析
- VisualTreeHelper不仅仅只是用来查看可视化树结构的
- 可视化工具--D3--案例分析--Reingold Tilford Tree
- VisualTreeHelper不仅仅只是用来查看可视化树结构的
- 5.[数据结构和算法分析笔记]树 Tree
- 为什么事件或者消息通常被组织为“队列”?而游戏中可视化对象通常被组织为“list,map,tree"等非物理地址连续的结构?
- Tree树状结构显示(dtree、xtree、ExtTree、E3tree、ztree)
- 情感分析(Sentiment Analysis)的难题--转
- linux下怎么用tree命令以树形结构显示文件目录结构?
- Tree树状结构显示(dtree、xtree、ExtTree、E3tree、ztree)
- 可视化数据结构以及各种排序算法演示
- (二)nodejs入门之代码结构分析
- 面向数据流的分析方法VS面向数据结构的分析方法
- 20160328servlet学习笔记网站代码结构分析MVC结构
- Duwamish7分析——结构
- Writing Linux LCD drivers—深入分析framebuffer设备驱动的结构
- 内核LCD驱动结构分析及实例分析
- 关于索引的B tree B-tree B+tree B*tree 详解结构图