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)
How can I use the R wordnet package to find hypernyms and hyponyms of a word?
you can replace
"!"
(which is for antonyms) inwith other symbols depending on what you need.
See this link: http://wordnet.princeton.edu/man/wnsearch.3WN.html#sect4
Hypernyms would be
"@"
Extension to original question:
I just started using WordNet and I am looking for something similar. For 'apple' I would like a hypernym tree giving me
as can be seen when clicking on
inherited hypernyms
on WordNet online http://wordnetweb.princeton.edu/perl/webwnHowever, the following commands
will only give me
hence failing to provide me with lower levels of hypernyms
The key to climbing the hypernym tree is to use getRelatedSynsets( ) recursively.
Continuing with the above example, extracting synsets from apple's synsets:
And collecting the corresponding words:
will yield:
And going on step further:
will result in: