zoukankan      html  css  js  c++  java
  • GitHub:如何构建一个股票市场知识图谱?(附代码&链接)

    <div class="rich_media_content" id="js_content">
                    
    
                    
    
                    
                    
                    <p style="min-height:1em;font-family:'-apple-system-font', BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif;letter-spacing:.544px;line-height:27.2px;"><img class="rich_pages" style="font-size:16px;letter-spacing:.544px;text-align:center;" src="https://img2018.cnblogs.com/blog/1112483/201908/1112483-20190813161236583-1770923137.png" alt="640?wx_fmt=png"></p><p style="min-height:1em;line-height:1.5em;">来源:专知</p><p style="min-height:1em;line-height:1.5em;"><span style="letter-spacing:1px;">本文约<strong><span style="color:rgb(166,91,203);">2600</span></strong><span style="color:rgb(166,91,203);"><strong>字,</strong></span>建议阅读<span style="color:rgb(166,91,203);"><strong>5</strong></span><strong><span style="color:rgb(166,91,203);">分钟。</span></strong></span></p><p>如何利用网络上的公开数据构建一个自己的股票证券知识图谱呢?</p><p style="line-height:1.5em;text-align:left;"><br></p><p style="line-height:1.5em;text-align:left;"><strong><span style="font-size:15px;">[ 导读 ]</span></strong><span style="font-size:15px;">你不理财财不理你,理财是大家早就达成共识的事情。作为新时代的五好青年,又身具机器学习、深度学习、知识图谱的能力,以自己的专业知识创造财富,应该更有意思。但是,股票证券市场信息繁杂,如何利用网络上的公开数据构建一个自己的股票证券知识图谱呢?GitHub的lemonhu同学,开源了一套解决方案。</span></p><p style="line-height:1.5em;text-align:left;"><br></p><blockquote><p style="line-height:1.5em;text-align:left;">github地址:</p><p style="line-height:1.5em;text-align:left;">https://github.com/lemonhu/stock-knowledge-graph</p><p style="line-height:1.5em;text-align:left;">作者:lemonhu</p></blockquote><p><br></p><h2 style="line-height:1.5em;text-align:center;"><a name="t0"></a><strong><span style="font-size:15px;color:rgb(166,91,203);">结果预览</span></strong></h2><p><br></p><p style="line-height:1.5em;text-align:left;"><img class="rich_pages" src="https://img2018.cnblogs.com/blog/1112483/201908/1112483-20190813161257981-144727933.png" alt="640?wx_fmt=png"></p><p><br></p><h2 style="line-height:1.5em;text-align:center;"><a name="t1"></a><strong><span style="font-size:15px;color:rgb(166,91,203);">数据源</span></strong></h2><p><br></p><p style="line-height:1.5em;text-align:left;"><span style="font-size:15px;">本项目需要用到两种数据源:一种是公司董事信息,另一种是股票的行业以及概念信息。</span></p><p style="line-height:1.5em;text-align:left;"><br></p><ul class="list-paddingleft-2"><li><p style="line-height:1.5em;text-align:left;"><span style="font-size:15px;">公司董事信息</span></p><p style="line-height:1.5em;text-align:left;"><span style="font-size:15px;">这部分数据包含在data目录下的stockpage压缩文件中,⾥面的每一个文件是以XXXXXX.html命名,其中XXXXXX是股票代码。这部分数据是由同花顺个股的⽹页爬取而来的,执行解压缩命令unzip stockpage.zip即可获取。比如对于600007.html,这部分内容来自于:</span><span style="font-size:14px;color:rgb(136,136,136);">http://stockpage.10jqka.com.cn/600007/company/#manager</span><span style="font-size:15px;"></span></p></li><li><p style="line-height:1.5em;text-align:left;"><span style="font-size:15px;">股票行业以及概念信息</span></p></li><li><p style="line-height:1.5em;text-align:left;"><span style="font-size:15px;">这部分信息也可以通过⽹上公开的信息得到。在这里,我们使用Tushare工具来获得,详细细节见之后具体的任务部分。</span></p></li></ul><p><br></p><h2 style="line-height:1.5em;text-align:center;"><a name="t2"></a><strong><span style="font-size:15px;color:rgb(166,91,203);">从⽹页中抽取董事会的信息</span></strong></h2><p><br></p><p style="line-height:1.5em;text-align:left;"><span style="font-size:15px;">在我们给定的html文件中,需要对每一个股票/公司抽取董事会成员的信息,这部分信息包括董事会成员“姓名”、“职务”、“性别”、“年龄”共四个字段。首先,姓名和职务的字段来自于:</span></p><p style="line-height:1.5em;text-align:left;"><br></p><p style="line-height:1.5em;text-align:left;"><img class="rich_pages" src="https://img2018.cnblogs.com/blog/1112483/201908/1112483-20190813161411830-773823730.png" alt="640?wx_fmt=png"></p><p style="line-height:1.5em;text-align:left;"><br></p><p style="line-height:1.5em;text-align:left;"><span style="font-size:15px;">在这里总共有12位董事成员的信息,都需要抽取出来。另外,性别和年龄字段也可以从下附图里抽取出来:</span></p><p style="line-height:1.5em;text-align:left;"><br></p><p style="line-height:1.5em;text-align:left;"><img class="rich_pages" src="https://img2018.cnblogs.com/blog/1112483/201908/1112483-20190813161440588-624461431.png" alt="640?wx_fmt=png"></p><p style="line-height:1.5em;text-align:left;"><br></p><p style="line-height:1.5em;text-align:left;"><span style="font-size:15px;">最后,生成一个 executive_prep.csv文件,格式如下:</span></p><p><br></p><p><br></p><div class="table-box"><table width="556"><thead><tr style="border-top:1px solid rgb(198,203,209);"><th align="center" style="border-top-1px;border-color:rgb(223,226,229);"><span style="font-size:15px;">高管姓名</span></th><th align="center" style="border-top-1px;border-color:rgb(223,226,229);"><span style="font-size:15px;">性别</span></th><th align="center" style="border-top-1px;border-color:rgb(223,226,229);"><span style="font-size:15px;">年龄</span></th><th align="center" style="border-top-1px;border-color:rgb(223,226,229);"><span style="font-size:15px;">股票代码</span></th><th align="center" style="border-top-1px;border-color:rgb(223,226,229);"><span style="font-size:15px;">职位</span></th></tr></thead><tbody><tr style="border-top:1px solid rgb(198,203,209);"><td align="center" style="border-color:rgb(223,226,229);"><span style="font-size:15px;">朴明志</span></td><td align="center" style="border-color:rgb(223,226,229);"><span style="font-size:15px;">男</span></td><td align="center" style="border-color:rgb(223,226,229);"><span style="font-size:15px;">51</span></td><td align="center" style="border-color:rgb(223,226,229);"><span style="font-size:15px;">600007</span></td><td align="center" style="border-color:rgb(223,226,229);"><span style="font-size:15px;">董事⻓/董事</span></td></tr><tr style="border-top:1px solid rgb(198,203,209);"><td align="center" style="border-color:rgb(223,226,229);"><span style="font-size:15px;">高燕</span></td><td align="center" style="border-color:rgb(223,226,229);"><span style="font-size:15px;">女</span></td><td align="center" style="border-color:rgb(223,226,229);"><span style="font-size:15px;">60</span></td><td align="center" style="border-color:rgb(223,226,229);"><span style="font-size:15px;">600007</span></td><td align="center" style="border-color:rgb(223,226,229);"><span style="font-size:15px;">执⾏董事</span></td></tr><tr style="border-top:1px solid rgb(198,203,209);"><td align="center" style="border-color:rgb(223,226,229);"><span style="font-size:15px;">刘永政</span></td><td align="center" style="border-color:rgb(223,226,229);"><span style="font-size:15px;">男</span></td><td align="center" style="border-color:rgb(223,226,229);"><span style="font-size:15px;">50</span></td><td align="center" style="border-color:rgb(223,226,229);"><span style="font-size:15px;">600008</span></td><td align="center" style="border-color:rgb(223,226,229);"><span style="font-size:15px;">董事⻓/董事</span></td></tr><tr style="border-top:1px solid rgb(198,203,209);"><td align="center" style="border-color:rgb(223,226,229);"><span style="font-size:15px;">···</span></td><td align="center" style="border-color:rgb(223,226,229);"><span style="font-size:15px;">···</span></td><td align="center" style="border-color:rgb(223,226,229);"><span style="font-size:15px;">···</span></td><td align="center" style="border-color:rgb(223,226,229);"><span style="font-size:15px;">···</span></td><td align="center" style="border-color:rgb(223,226,229);"><span style="font-size:15px;">···</span></td></tr></tbody></table></div><p style="line-height:1.5em;"><br></p><p style="line-height:1.5em;"><span style="font-size:15px;">注:建议表头最好用相应的英文表示。</span></p><p style="line-height:1.5em;text-align:center;"><br></p><p style="line-height:1.5em;text-align:center;"><strong><span style="font-size:15px;color:rgb(166,91,203);">获取股票行业和概念的信息</span></strong></p><p style="line-height:1.5em;"><br></p><p style="line-height:1.5em;"><span style="font-size:15px;">对于这部分信息,我们可以利⽤工具Tushare来获取,官网为</span><span style="color:rgb(136,136,136);font-size:12px;">http://tushare.org/</span><span style="font-size:15px;">&nbsp;,使用pip命令进行安装即可。下载完之后,在python里即可调用股票行业和概念信息。</span></p><p style="line-height:1.5em;"><span style="font-size:15px;"><br></span></p><p style="line-height:1.5em;"><span style="font-size:15px;"></span><span style="font-size:14px;color:rgb(136,136,136);">参考链接:</span></p><p style="line-height:1.5em;"><span style="font-size:14px;color:rgb(136,136,136);"></span><span style="font-size:14px;color:rgb(136,136,136);">http://tushare.org/classifying.html#id2</span><span style="font-size:12px;color:rgb(136,136,136);"></span><span style="font-size:15px;"></span></p><p style="line-height:1.5em;"><span style="font-size:12px;color:rgb(136,136,136);"><br></span></p><p style="line-height:1.5em;"><span style="font-size:15px;">通过以下的代码获得股票行业信息,并把返回的信息直接存储在stock_industry_prep.csv文件里。</span></p><p style="line-height:1.5em;"><br></p><p style="line-height:1.5em;"><img class="rich_pages" src="https://img2018.cnblogs.com/blog/1112483/201908/1112483-20190813162018660-1290145485.png"></p><p style="line-height:1.5em;"><br></p><p style="line-height:1.5em;"><span style="font-size:15px;">类似的,可以通过以下代码即可获得股票概念信息,并把它们存储在stock_concept_prep.csv文件里。</span><br></p><p style="line-height:1.5em;"><br></p><p style="line-height:1.5em;"><img class="rich_pages" src="https://img2018.cnblogs.com/blog/1112483/201908/1112483-20190813162038171-1072692412.png" alt="640?wx_fmt=png"></p><p><br></p><h2 style="line-height:1.5em;text-align:center;"><a name="t3"></a><strong><span style="font-size:15px;color:rgb(166,91,203);">设计知识图谱</span></strong></h2><p><br></p><p style="line-height:1.5em;"><span style="font-size:15px;">设计一个这样的图谱:</span></p><p style="line-height:1.5em;"><br></p><ul class="list-paddingleft-2"><li><p style="line-height:1.5em;"><span style="font-size:15px;">创建“人”实体,这个人拥有姓名、性别、年龄</span></p></li><li><p style="line-height:1.5em;"><span style="font-size:15px;">创建“公司”实体,除了股票代码,还有股票名称</span></p></li><li><p style="line-height:1.5em;"><span style="font-size:15px;">创建“概念”实体,每个概念都有概念名</span></p></li><li><p style="line-height:1.5em;"><span style="font-size:15px;">创建“行业”实体,每个行业都有⾏业名</span></p></li><li><p style="line-height:1.5em;"><span style="font-size:15px;">给“公司”实体添加“ST”的标记,这个由LABEL来实现</span></p></li><li><p style="line-height:1.5em;"><span style="font-size:15px;">创建“人”和“公司”的关系,这个关系有董事长、执行董事等等</span></p></li><li><p style="line-height:1.5em;"><span style="font-size:15px;">创建“公司”和“概念”的关系</span></p></li><li><p style="line-height:1.5em;"><span style="font-size:15px;">创建“公司”和“行业”的关系</span></p></li></ul><p style="line-height:1.5em;"><br></p><p style="line-height:1.5em;"><span style="font-size:15px;">把设计图存储为design.png文件。</span></p><p style="line-height:1.5em;"><br></p><p style="line-height:1.5em;"><span style="font-size:15px;">注:实体名字和关系名字需要易懂,对于上述的要求,并不一定存在唯一的设计,只要能够覆盖上面这些要求即可。“ST”标记是用来刻画⼀个股票严重亏损的状态,这个可以从给定的股票名字前缀来判断,背景知识可参考百科ST股票,“ST”股票对应列表为['*ST', 'ST', 'S*ST', 'SST']。</span></p><p style="line-height:1.5em;"><br></p><p style="line-height:1.5em;text-align:center;"><strong><span style="font-size:15px;color:rgb(166,91,203);">创建可以导⼊Neo4j的csv文件</span></strong></p><p style="line-height:1.5em;text-align:left;"><br></p><p style="line-height:1.5em;text-align:left;"><span style="font-size:15px;">在前两个任务里,我们已经分别生成了 executive_prep.csv, stock_industry_prep.csv, stock_concept_prep.csv,但这些文件不能直接导入到Neo4j数据库。</span></p><p style="line-height:1.5em;"><br></p><p style="line-height:1.5em;"><span style="font-size:15px;">所以需要做⼀些处理,并生成能够直接导入Neo4j的csv格式。</span><span style="font-size:15px;">我们需要生成这⼏个文件:</span></p><p style="line-height:1.5em;text-align:left;"><br></p><p style="line-height:1.5em;text-align:left;"><span style="font-size:15px;">executive.csv, stock.csv, concept.csv, industry.csv, executive_stock.csv, stock_industry.csv, stock_concept.csv。</span></p><p style="line-height:1.5em;"><br></p><p style="line-height:1.5em;text-align:left;"><span style="font-size:15px;">对于格式的要求,请参考:</span><span style="font-size:14px;color:rgb(136,136,136);">https://neo4j.com/docs/operations-manual/current/tutorial/import-tool/</span><span style="font-size:15px;"></span></p><p style="line-height:1.5em;"><br></p><p style="line-height:1.5em;text-align:center;"><strong><span style="font-size:15px;color:rgb(166,91,203);">利用上面的csv文件生成数据库</span></strong></p><p style="line-height:1.5em;"><br></p><p style="min-height:1em;text-align:center;"><img class="rich_pages" src="https://img2018.cnblogs.com/blog/1112483/201908/1112483-20190813162057051-1134500933.png" alt="640?wx_fmt=png"></p><p><br></p><p style="line-height:1.5em;"><span style="font-size:15px;">这个命令会把所有的数据导入到Neo4j中,数据默认存放在 graph.db 文件夹里。</span><span style="font-size:15px;">如果graph.db文件夹之前已经有数据存在,则可以选择先删除再执行命令。</span></p><p style="line-height:1.5em;"><br></p><p style="line-height:1.5em;"><span style="font-size:15px;">把Neo4j服务重启之后,就可以通过localhost:7474观察到知识图谱了。</span></p><p><br></p><p style="line-height:1.5em;text-align:center;"><strong><span style="font-size:15px;color:rgb(166,91,203);">查询分析</span></strong></p><p style="line-height:1.5em;"><br></p><p style="line-height:1.5em;"><span style="font-size:15px;">基于构建好的知识图谱,通过编写Cypher语句回答如下问题:</span><br></p><p style="line-height:1.5em;"><br></p><ul class="list-paddingleft-2"><li><p style="line-height:1.5em;"><span style="font-size:15px;">有多少个公司目前是属于“ST”类型的?</span></p></li><li><p style="line-height:1.5em;"><span style="font-size:15px;">“600519”公司的所有独立董事人员中,有多少人同时也担任别的公司的独立董事职位?</span></p></li><li><p style="line-height:1.5em;"><span style="font-size:15px;">有多少公司既属于环保行业,又有外资背景?</span></p></li><li><p style="line-height:1.5em;"><span style="font-size:15px;">对于有锂电池概念的所有公司,独⽴董事中女性⼈员⽐例是多少?</span></p></li></ul><p style="line-height:1.5em;"><br></p><p><span style="font-size:15px;">请提供对应的Cypher语句以及答案,并把结果写在result.txt。</span></p><p><br></p><p style="line-height:1.5em;text-align:center;"><strong><span style="font-size:15px;color:rgb(166,91,203);">实施问题</span></strong></p><p style="line-height:1.5em;text-align:center;"><br></p><ul class="list-paddingleft-2"><li><p style="line-height:1.5em;"><span style="font-size:15px;">构建人的实体时,重名问题具体怎么解决?</span><br></p></li><li><p style="line-height:1.5em;"><span style="font-size:15px;">把简单思路写在result.txt文件中。</span></p></li></ul><p><br></p><p style="line-height:1.5em;text-align:center;"><strong><span style="font-size:15px;color:rgb(166,91,203);">工程目录</span></strong></p><p style="line-height:1.5em;text-align:center;"><br></p><p style="line-height:1.5em;"><img class="rich_pages" src="https://img2018.cnblogs.com/blog/1112483/201908/1112483-20190813162118733-275139296.png" alt="640?wx_fmt=png"></p><p style="min-height:1em;text-align:center;"><br></p><blockquote style="color:rgba(0,0,0,.498);"><p style="min-height:1em;">具体内容,请到Github库进行查看。</p></blockquote><p><br></p><p style="min-height:1em;font-family:'-apple-system-font', BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif;letter-spacing:.544px;text-align:right;"><span style="color:rgb(136,136,136);font-size:14px;">编辑:王菁</span></p><p style="min-height:1em;font-family:'-apple-system-font', BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif;letter-spacing:.544px;text-align:right;"><span style="color:rgb(136,136,136);font-size:14px;">校对:洪舒越</span></p><p style="min-height:1em;font-family:'-apple-system-font', BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif;letter-spacing:.544px;text-align:right;"><span style="color:rgb(136,136,136);font-size:14px;"><br></span></p><p style="min-height:1em;font-family:'-apple-system-font', BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif;letter-spacing:.544px;text-align:right;"><span style="color:rgb(136,136,136);font-size:14px;"><strong style="font-size:15px;text-align:center;color:rgb(60,60,60);line-height:25.5px;letter-spacing:1px;"><strong style="line-height:25.5px;"><strong style="line-height:25.5px;"><strong style="line-height:25.5px;"><strong style="line-height:25.5px;"><strong style="line-height:25.5px;"><strong style="line-height:25.5px;"><strong style="line-height:25.5px;"><strong style="line-height:25.5px;"><strong style="line-height:25.5px;"></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></span></p>
                </div>原文地址:https://blog.csdn.net/eNohtZvQiJxo00aTz3y8/article/details/96055187
                                      </div>
  • 相关阅读:
    Android 主题theme说明 摘记
    Android开发 去掉标题栏方法 摘记
    安卓项目五子棋代码详解(二)
    关于 ake sure class name exists, is public, and has an empty constructor that is public
    百度地图3.0实现图文并茂的覆盖物
    android onSaveInstanceState()及其配对方法。
    关于集成科大讯飞语音识别的 一个问题总结
    android 关于 webview 控制其它view的显示 以及更改view数据失败的问题总结
    C# 解析 json Newtonsoft果然强大,代码写的真好
    c#数据类型 与sql的对应关系 以及 取值范围
  • 原文地址:https://www.cnblogs.com/jpfss/p/11346597.html
Copyright © 2011-2022 走看看