Reputation: 333
I'm currently working with wordnet in R (I'm using RStudio for Windows (64bit)) and created a data.frame
containing synset_offset
, ss_type
and word
from the data.x files (where x is noun, adj, etc) of the wordnet database.
A sample can be created like this:
wnet <- data.frame(
"synset_offset" = c(02370954,02371120,02371337),
"ss_type" = c("VERB","VERB","VERB"),
"word" = c("fill", "depute", "substitute")
)
My issue happens when using the wordnet package to get the list of synonyms that I'd like to add as an additional column.
library(wordnet)
wnet$synonyms <- synonyms(wnet$word,wnet$ss_type)
I receive the following error.
Error in .jnew(paste("com.nexagis.jawbone.filter", type, sep = "."), word, :
java.lang.NoSuchMethodError: <init>
If I apply the function with defined values, it works.
> synonyms("fill","VERB")
[1] "fill" "fill up" "fulfil" "fulfill" "make full" "meet" "occupy" "replete" "sate" "satiate" "satisfy"
[12] "take"
Any suggestions to solve my issue are welcome.
Upvotes: 1
Views: 1988
Reputation: 47330
I can't install the wordnet package on my computer for some reason, but it seems you're giving the synonyms function array arguments and you can't, you should be able to solve it with apply.
syn_list <- apply(wnet,by=1,function(row){synonyms(row["word"],row["ss_type"])})
it will return the output of the synonyms function for each row of the wnet data.frame
it's not clear what you want to do with:
wnet$synonyms <- synonyms(wnet$word,wnet$ss_type)
as for each row you will have an array of synonyms, that don't fit in the 3 rows of your data.frame.
maybe something like this will work for you:
wnet$synonyms <- sapply(syn_list,paste,collapse=", ")
EDIT - Here is a working solution to the problem above.
wnet$synset <- mapply(synonyms, as.character(wnet$word), as.character(wnet$ss_type))
Upvotes: 3