




已阅读5页,还剩6页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
信息处理模块要求:(1) 利用自然语言处理、数据挖掘技术对爬去的网站、论坛、博客、微博等进行文本挖掘,从各种网络信息中准确提取出用户关心事件的时间、地点、主体、行为和客体等要素;(2) 分析用户对事件要素的态度,构成特定的用户关注及态度模型。对大量不同类型网络信息的挖掘将形成具有差异性的模型库,同时也可以通过用户问卷调查的方式,获取更多具有差异性的关注模型作为补充。1. 自然语言处理工具包:fudannlpfudannlp主要是为中文自然语言处理而开发的工具包,也包含为实现这些任务的机器学习算法和数据集。本工具包及其包含数据集使用lgpl3.0许可证。开发语言为java。主要功能有:1. 文本分类 新闻聚类;2. 中文分词 词性标注 实体名识别 关键词抽取 依存句法分析 时间短语识别;3. 结构化学习 在线学习 层次分类 聚类 精确推理。inputstr1 = 甬温线特别重大铁路交通事故车辆经过近24小时的清理工作,26日深夜已经全部移出事故现场,之前埋下的d301次动车车头被挖出运走;inputstr2 = 甬温线|特别|重大|铁路交通事故车辆经过近24小时的清理工作,26日深夜已经全部移出事故现场,之前埋下的d301次动车车头被挖出运走;抽取top10:output1 = 甬温线=100, 运走=100, 事故=52, 工作=41, 深夜=36, 清理=36, 全部=33, 小时=30, 移出=30, 车辆=26;import java.util.arraylist; import java.util.map; import org.fnlp.app.keyword.abstractextractor; import org.fnlp.app.keyword.wordextract; import .tag.cwstagger; import edu.fudan.nlp.corpus.stopwords; public class getkeywords public arraylist getkeyword(string news,int keywordsnumber) throws exception arraylist keywords=new arraylist(); stopwords sw= new stopwords(models/stopwords); cwstagger seg = new cwstagger(models/seg.m); abstractextractor key = new wordextract(seg,sw); map ans = key.extract(news, keywordsnumber); for (map.entry entry : ans.entryset() string keymap = entry.getkey().tostring(); string value = entry.getvalue().tostring(); keywords.add(keymap); system.out.println(key + keymap + value + value); return keywords; 输出结果是这样:2. 关键字提取后对文本进行分类 第一步,对文档进行预处理过程。按照文本文档数据集(一般分目录放置文本文档)路径对所有训练文档扫描,分析出不同的单词。第二步,建立词频矩阵。预处理之后,将文章变为一个词集,单词也称为特征项或属性。把文档看成是一个词向量(wordvector),它的维数是所有不同的单词个数,词集中可以有数万个不同的单词。第三步,构造文本分类器。词频统计矩阵是算法建模的基础。在词频统计矩阵的基础上根据特定的算法构造分类器。主要任务是根据不同分类算法,计算词向量的权值。目前较为著名的文本分类算法包括支持向量机(supportvectormachine,svm),k近邻法(k-nearestneighbour,knn),朴素贝叶斯法(naivebayes,nb),神经网络法(neuralnetwork,nnet),线性最小二乘法(linearleastsquaresfit,llsf)等 在本次实验中我组将打算用神经网络法。其代码如下。ackagecom.mfsoft.ai.algorithm.imp;publicclassrbfnetextendsobjectintinnum;/输入接点数inthidenum;/隐含接点数intoutnum;/输出接点数doublec;/重心doubled;/距离(歪)intepochs;doublex;/输入向量doublex1;/隐含接点状态值doublex2;/输出接点状态值doubleo1;doubleo2;doublew;/隐含接点权值doublew1;/输出接点权值doublerate_w;/权值学习率(输入层-隐含层)doublerate_w1;/权值学习率(隐含层-输出层)doublerate_b1;/隐含层阀值学习率doublerate_b2;/输出层阀值学习率doubleb1;/隐含接点阀值double b2;/输出接点阀值doublepp;doubleqq;doubleyd;doublee;doublein_rate;/输入归一化比例系数publicrbfnet(intinnum,inthidenum,intoutnum,doublep)in_rate=1.0;/输入归一化系数/*doublepmax=0.0;for(intisamp=0;isampp.length;isamp+)for(inti=0;ipmax)pmax=math.abs(pisamp);/endforisampin_rate=pmax;for(intisamp=0;isampp.length;isamp+)for(inti=0;iinnum;i+)pisamp=pisamp/in_rate;/endforisamp3. 文本聚类文档聚类可以作为多文档自动文稿等自然语言处理应用的预处理步骤。其实现算法有apriori算法等。 apriori算法的基本思想是:首先找出所有的频集,这些项集出现的频繁性至少和预定义的最小支持度一样。然后由频集产生强关联规则,这些规则必须满足最小支持度和最小可信度。然后使用第1步找到的频集产生期望的规则,产生只包含集合的项的所有规则,其中每一条规则的右部只有一项,这里采用的是中规则的定义。一旦这些规则被生成,那么只有那些大于用户给定的最小可信度的规则才被留下来。为了生成所有频集,使用了递归的方法。其代码如下:package apr;import java.io.bufferedwriter;import java.io.filewriter;import java.util.*;public class apriori private double minsup = 0.6;/ 最小支持度 private double minconf = 0.2;/ 最小置信度 / 注意使用identityhashmap,否则由于关联规则产生存在键值相同的会出现覆盖 private identityhashmap rulemap = new identityhashmap(); private string transset = abc, abc, acde, bcdf, abcd, abcdf ;/ 事务集合,可以根据需要从构造函数里传入 private int itemcounts = 0;/ 候选1项目集大小,即字母的个数 private treeset frequencyset = new treeset40;/ 频繁项集数组,0:代表1频繁集. private treeset maxfrequency = new treeset();/ 最大频繁集 private treeset candidate = new treeset();/ 1候选集 private treeset candidateset = new treeset40;/ 候选集数组 private int frequencyindex; public apriori() maxfrequency = new treeset(); itemcounts = counts();/ 初始化1候选集的大小 / 初始化其他两个 for (int i = 0; i itemcounts; i+) frequencyseti = new treeset(); candidateseti = new treeset(); candidateset0 = candidate; public apriori(string transset) this.transset = transset; maxfrequency = new treeset(); itemcounts = counts();/ 初始化1候选集的大小 / 初始化其他两个 for (int i = 0; i itemcounts; i+) frequencyseti = new treeset(); candidateseti = new treeset(); candidateset0 = candidate; public int counts() string temp1 = null; char temp2 = a; / 遍历所有事务集string 加入集合,set自动去重了 for (int i = 0; i transset.length; i+) temp1 = transseti; for (int j = 0; j = minsup * transset.length) frequencyset0.add(temp1); public double count_sup(string x) int temp = 0; for (int i = 0; i transset.length; i+) for (int j = 0; j = c2) continue; else m = y + z; h.add(m); temp2 = frequencyset0.iterator(); candidatesetk - 1 = h; / k候选集=k频繁集 public void frequent_gen(int k) string s1 = ; iterator ix = candidatesetk - 1.iterator(); while (ix.hasnext() s1 = (string) ix.next(); if (count_sup(s1) = (minsup * transset.length) frequencysetk - 1.add(s1); public boolean is_frequent_empty(int k) if (frequencysetk - 1.isempty() return true; else return false; public boolean included(string s1, string s2) for (int i = 0; i s1.length(); i+) if (s2.indexof(s1.charat(i) = -1) return false; else if (i = s1.length() - 1) return true; return true; public void maxfrequent_gen() int i, j; iterator iterator, iterator1, iterator2; string temp = , temp1 = , temp2 = ; for (i = 1; i frequencyindex; i+) maxfrequency.addall(frequencyseti); / for (i = 0; i frequencyindex; i+) / iterator1 = frequencyseti.iterator(); / while (iterator1.hasnext() / temp1 = (string) iterator1.next(); / for (j = i + 1; j frequencyindex; j+) / iterator2 = frequencysetj.iterator(); / while (iterator2.hasnext() / temp2 = (string) iterator2.next(); / if (included(temp1, temp2) / maxfrequency.remove(temp1); / / / / public void print_maxfrequent() iterator iterator = maxfrequency.iterator(); system.out.print(产生规则频繁项集:); while (iterator.hasnext() system.out.print(todigit(string) iterator.next() + t); system.out.println(); public void ruleprint() string x, y; double temp = 0; set hs = rulemap.keyset(); iterator iterator = hs.iterator(); stringbuffer sb = new stringbuffer(); system.out.println(关联规则:); while (iterator.hasnext() x = (string) iterator.next(); y = (string) rulemap.get(x); temp = (count_sup(x + y) / count_sup(x); /x = todigit(x); /y = todigit(y); system.out.println(x + (x.length() + y + t + temp); sb.append( + x + (x.length() + y + t + temp + tn); bufferedwriter bw = null; try filewriter fw = new filewriter(asr.txt); bw = new bufferedwriter(fw); bw.write(最小支持度 minsup = + minsup); bw.newline(); bw.write(最小置信度 minconf = + minconf); bw.newline(); bw.write(产生关联规则如下: ); bw.newline(); bw.write(sb.tostring(); / bw.newline(); if (bw != null) bw.close(); catch (exception e) e.printstacktrace(); public void subgen(string s) string x = , y = ; for (int i = 1; i (1 s.length() - 1; i+) for (int j = 0; j s.length(); j+) if (1 j) & i) != 0) x += s.charat(j); for (int j = 0; j s.length(); j+) if (1 = minconf) rulemap.put(x, y); x = ; y = ; public void rulegen() string s; iterator iterator = maxfrequency.iterator(); while (iterator.hasnext() s = (string) iterator.next(); subgen(s); / for test public void print1() iterator temp = candidateset0.iterator(); while (temp.hasnext() system.out.println(temp.next(); / for test public void print2() iterator temp = frequencyset0.iterator(); while (temp.hasnext() system.out.println(string) temp.next(); / for test public void print3() canditate_gen(1); frequent_gen(2); iterator temp = candidateset1.iterator(); iterator temp1 = frequencyset1.iterator(); while (temp.hasnext() system.out.println(候选 + (string) temp.next(); while (temp1.hasnext() system.out.println(频繁 + (string) temp1.next(); public void print_canditate() for (int i = 0; i frequencyset0.size(); i+) iterator ix = candidateseti.iterator(); iterator iy = frequencyseti.iterator(); system.out.print(候选集 + (i + 1) + :); while (ix.hasnext() system.out.print(string) ix.next() + t); /system.out.print(todigit(string) ix.next() + t); system.out.print(n + 频繁集 + (i + 1) + :); while (iy.hasnext() system.out.print(string) iy.next() + t); /system.out.print(todigit(string) iy.next() + t); system.out.
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 高校招生复试面试技巧与自我介绍
- 初中数学勾股定理复习资料及练习题
- 创业篮球培训班详细商业计划
- 在线视频教育平台课程设计与开发
- 中小学教学质量分析报告模板
- 空调设备招标技术规范书范本
- 销售人员绩效考核细则解析
- 生产车间精益管理实务操作指南
- 房地产项目开发合同范本参考
- 初中物理力学专题题型归纳与高频考点
- 生物医学面试题及答案
- 银行贷款电子合同电子版(2025年版)
- 非物质文化遗产微短剧叙事策略与文化传承路径研究
- 胫腓骨骨折内固定术手术配合
- 2025版员工试用期延长协议书
- 有机磷农药中毒护理课件
- 农业补助申请书
- 《建筑施工安全文明工地标准》(DBJ13-81-2006)
- IP授权使用合作协议书范本
- 2025年汽车零部件企业公司组织架构图职能部门及工作职责
- 机械加工质量控制计划
评论
0/150
提交评论