以文本方式查看主题 - 计算机科学论坛 (http://bbs.xml.org.cn/index.asp) -- 『 Semantic Web(语义Web)/描述逻辑/本体 』 (http://bbs.xml.org.cn/list.asp?boardid=2) ---- 公布基于wordnet的相似度计算算法的原代码!! (http://bbs.xml.org.cn/dispbbs.asp?boardid=2&rootid=&id=55435) |
-- 作者:gzfxxy1978 -- 发布时间:11/16/2007 11:31:00 AM -- 公布基于wordnet的相似度计算算法的原代码!! 以下是相关算法思想和相关的代码. 设计过程 计算相似度的准各下作: 首先处理义原部分‘建分_一个读入流InputStreamReader的 对象,将n: \ Whole. txt中的内客按行读入到程序中的字符串 数组nbread中,这个文件中的内客为义原和所对应的层数: InputStreamReader isread=new InputStreamReader(new I'ileInput- Strea m(" a\Whole. txt")): hufFeredReader bread=new hufFeredReader( isread): 接卜来是处理义原部分sub4中存放的内容即为各个义 原,之后获得分层数,劝int为分层数: nbint[ n]=Intener. value0f( sub2[ n]).intValue(): 从n: \ Glossary. dat中得到每个名词subob‘以及每个词 的义原submean得到各个义原放在数组stir 1中: InputStreamReader isr=new InputStreamReader(new P'ileInput- Stream ( " n\Glossary. dat")): BufferedReader br=new BufferedReader( isr): for( int ii= 0; ii< nbstrinn. lennth; ii++) { nbstrinn} ii}=br.readLine(): subnb} ;;}=nbstrinn} ii}.substrina(10).trim(): if(subab} ii}.startsWith(" N")) { subwhole} m}=nbstrinn} ii}: submean} m}=subnb} ;;} .substrina( 5).trim(): subob} m}=subwhole} m}.substrina(0, 12).trim): m+=1: } 这样就可以得到义原数组然后将得到的义原数组放在 stint中. 接卜来是对所输入的两个词语的处理下作 将名词转换成unicode存放在g\out. txt中‘首先建}%_ IiyteToCharConverter的对象‘利用该对象的convertAll方法将 拆分成两个字竹的中文巾一字转换成、micode表示的一进制 然后以十六进制的形式输出就得到中文的、micode编码形 式:IiyteToCharConverter convey= IiyteToCharConverter. getConve- rter(" Gh2312"): I'ileWriter fileWriter=new I'ileWriter(" g\out. txt"): byte」gbbytes= new bytes 2}: for( int a= 0; a< 31823; a++) { gbbytes= subob} a}.gethytes(" Gh2312"): char」c= convey. convertAll( gbbytes): for( int b= 0; b< c. length; b++) { fileWriter. write( Integer. toIIexString( c} b})): } fileWriter. write("\n"): } fileWriter. close(): 然后对输入的两个词语instr} 0}和instr} 1}进行处理‘得 到两个词语的义原数组: InputStreamReader istt=new InputStreamReader( new I'ileIn- putStream(" g\sty. txt")): IiufferedReader btt=new hufferedReader(istt): String」uniout= new String「 2」: int.」「」uniint= new into 2}「lob: for( int j= 0; j< 2; j++) { uniout} j}=btt. readLine(): for( int d= 0; d< unistr. length; d++) { iF( uniout} j}.equals( unistr} d})) { ttniint} j}=sting cl}: } } 在前文中处理得到的义原与层数的对应关系文件中查 找两个词语的义原数组所对应的层数关系按照对应的关系 赋子不同的参数后按照上文中的公式进行计算将结果存放 在双精度型变录sim中 while( IJverySim} simindex}!=0. 0) { for( int p1= 0; p1< simindex+ 1; p1++) { IJvery= IJvery* IJverySim} ply: } Sim} simindex}=betas simindex} * IJvery; simindex+=1: double SimRPSUIt= 0. 0: for( int vx= 0; vx< simindex; vx++ { SimRPSUIt= SimRPSUIt+ Sim} vx} } System. out. println("The Sim of two words is:”+SimResult): } |
-- 作者:bzbc -- 发布时间:11/16/2007 3:26:00 PM -- 多谢楼上了。但您的代码似乎又很多字符错误,比如“gh2312"应为”gb2312",还又str |
-- 作者:xiaohai5702 -- 发布时间:4/21/2009 9:39:00 AM -- 那你有没有 计算的完整的代码 你是在什么环境下编的啊 可不可以把代码给我啊 |
-- 作者:wangdong123xyz -- 发布时间:9/19/2009 10:44:00 PM -- 顶 !非常好的东东 |
-- 作者:Avansky -- 发布时间:4/8/2010 8:51:00 AM -- 知识共享的力量是伟大的! 互相帮助的力量是伟大的! 谢谢楼主! 有空多交流! |
-- 作者:lyfsemanticweb -- 发布时间:9/7/2010 8:14:00 PM -- 楼主能不能把你的源代码发一份给我,万分感谢! Email: lyf200581105@163.com |
-- 作者:lyzgz -- 发布时间:12/19/2010 12:08:00 PM -- lz给我发一份吧,谢谢了。ly_zgz@163.com |
-- 作者:zhoucqucs -- 发布时间:1/3/2011 11:30:00 AM -- 谢谢!!! |
-- 作者:hawood -- 发布时间:4/12/2011 6:48:00 PM -- 楼主能不能把你的源代码发一份给我,希望可以拜读一下完整篇,非常感谢! hawoodho@sina.com |
W 3 C h i n a ( since 2003 ) 旗 下 站 点 苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》 |
62.500ms |