java类库查询词典_JWNL是用JAVA语言编写的用于读取WordNet词典库的组件库。

JWNL是用JAVA语言编写的用于读取WordNet词典库的组件库。

此次采用JWNL1.4-RC2,最高支持WordNet2.1(WINDOWS),3.0(UNIX)。

1. 配置WordNet词典库。

配置文件位置:..\jwnl14-rc2\config\file_properties.xml中的D:\Programs\WordNet\2.1\dict"/>

2. 在Main函数中使用JWNL加载

1 String propsFile="..\jwnl14-rc2\config\file_properties.xml";2 JWNL.initialize(newFileInputStream(propsFile));

3. 获得某一单词,如dog

1 IndexWord DOG=Dictionary.getInstance().getIndexWord(POS.NOUN,"dog");

4. 获得单词的直接上义词(Hypernym)

使用PointerUtils.getInstance().getDirectHypernyms(Synset

synset)

1 this.demonstrateListOperation(DOG);

具体方法实现:

a4c26d1e5885305701be709a3d33442f.png

1 privatevoiddemonstrateListOperation(IndexWord word)throwsJWNLException {2 //Get all of the hypernyms (parents) of the first sense of word3 PointerTargetNodeList hypernyms=PointerUtils.getInstance().getDirectHypernyms(word.getSense(1));4 System.out.println("Direct hypernyms of ""+word.getLemma()+"":");5 for(intidx=0; idx<hypernyms.size(); idx++){6 PointerTargetNode nn=(PointerTargetNode)hypernyms.get(idx);7 for(intwrdIdx=0; wrdIdx<nn.getSynset().getWordsSize(); wrdIdx++){8 System.out.println("Syn"+idx+"of direct hypernyms of""+word.getLemma()+"" :"+9nn.getSynset().getWord(wrdIdx).getLemma());10}11}12hypernyms.print();13 }

a4c26d1e5885305701be709a3d33442f.png

5. 获得所有下义词树(Hyponym),包含了其下义词的下义词

5.1 直接使用JWNL的方法打印出,单词DOG所有的下义词

a4c26d1e5885305701be709a3d33442f.png

1 this.demonstrateListOperation(ACCOMPLISH);234 privatevoiddemonstrateTreeOperation(IndexWord word)throwsJWNLException {5 //Get all the hyponyms (children) of the first sense of word6 PointerTargetTree hyponyms=PointerUtils.getInstance().getHyponymTree(word.getSense(1));7 System.out.println("Hyponyms of ""+word.getLemma()+"":");8hyponyms.print();9 }

a4c26d1e5885305701be709a3d33442f.png

5.2 通过循环获得单词的下义词来遍历DOG的所有下义词

a4c26d1e5885305701be709a3d33442f.png

1 BMTreeNode root=newBMTreeNode(DOG.getLemma());2 demonstrateTreeOperation(DOG.getSense(1), root);3System.out.println(root.toString());456 privatevoiddemonstrateTreeOperation(Synset word, BMTreeNode myTreeNode)throwsJWNLException {7 //Get all the hyponyms (children) of the first sense of word8 PointerTargetNodeList hypernyms=PointerUtils.getInstance().getDirectHyponyms(word);9 System.out.println("Direct hypernyms of ""+getAllWordString(w

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值