问题描述
我想在R中使用wordnet软件包来获得单词层次结构,例如:动物"是猫"的上位词,苹果"是水果"的下位词.但是我可以从R wordnet帮助文件中找到的代码如下所示,用于识别反义词:
I want to use the wordnet package in R to get the word hierarchies like: "animal" is the hypernym of "cat", and "apple" is the hyponym of "fruit". But the code I can find from R wordnet help file is like below to identify antonyms:
install.packages("wordnet", dependencies=TRUE)
library(wordnet)
filter <- getTermFilter("ExactMatchFilter", "cold", TRUE)
terms <- getIndexTerms("ADJECTIVE", 5, filter)
synsets <- getSynsets(terms[[1]])
related <- getRelatedSynsets(synsets[[1]],"!")
sapply(related, getWord)
如何使用R wordnet程序包查找单词的上位词和下位词?
How can I use the R wordnet package to find hypernyms and hyponyms of a word?
推荐答案
您可以在
related <- getRelatedSynsets(synsets[[1]],"!")
根据需要使用其他符号.
with other symbols depending on what you need.
查看此链接: http://wordnet.princeton.edu/man/wnsearch.3WN.html# sect4
高位字母为"@"
原始问题的扩展名:
我刚刚开始使用WordNet,并且正在寻找类似的东西.对于苹果",我想要一棵高个的树给我
I just started using WordNet and I am looking for something similar.For 'apple' I would like a hypernym tree giving me
- '水果'
- 食物"
- 固体物质"
- 物理实体"
- 等...
- 'fruit'
- 'food'
- 'solid matter'
- 'physical entity'
- etc...
在WordNet在线上单击
inherited hypernyms
时可以看到 http://wordnetweb.princeton.edu/perl/webwnas can be seen when clicking on
inherited hypernyms
on WordNet onlinehttp://wordnetweb.princeton.edu/perl/webwn但是,以下命令
filter <- getTermFilter(type="ExactMatchFilter", word="apple", ignoreCase=TRUE) terms <- getIndexTerms("NOUN", 15, filter) synsets <- getSynsets(terms[[1]]) related <- getRelatedSynsets(synsets[[1]], "@") sapply(related, getWord)
只会给我
[[1]] [1] "edible fruit" [[2]] [1] "pome" "false fruit"
因此无法为我提供较低级别的上位词
hence failing to provide me with lower levels of hypernyms
爬上上级树的关键是递归使用getRelatedSynsets().
继续上面的示例,从苹果的同义词集中提取同义词:
Continuing with the above example, extracting synsets from apple's synsets:
related_2 <- getRelatedSynsets(related[[1]], "@")
并收集相应的单词:
sapply(related_2, getWord)
将产生:
[[1]] [1] "produce" "green goods" "green groceries" "garden truck" [[2]] [1] "fruit"
并进一步:
related_3 <- getRelatedSynsets(related2[[1]], "@") sapply(related_3, getWord)
将导致:
[,1] [1,] "food" [2,] "solid food"
这篇关于如何在R中使用wordnet获取单词层次结构(例如,上位词,下位词)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
- 'physical entity'
- 'solid matter'
- 'food'
- 物理实体"
- 固体物质"
- 食物"