The current implementation of hypernyms() allocates an array to hold the output of relation() but only takes the first element. It's quite a bit faster to just loop over the synset's pointers and return the first match. For example:
Setup:
julia> using WordNet, BenchmarkTools
julia> db = DB()
WordNet.DB
julia> s = synsets(db, db['n', "lemonade"])
1-element Array{Synset,1}:
(n) lemonade (sweetened beverage of diluted lemon juice)
There's probably a way to do this in one line with Base.Iterators, but the for loop is the fastest implementation I've found so far, and it doesn't allocate at all.
(This PR is based off of #12 )
The current implementation of
hypernyms()
allocates an array to hold the output ofrelation()
but only takes the first element. It's quite a bit faster to just loop over the synset's pointers and return the first match. For example:Setup:
Before:
After:
There's probably a way to do this in one line with
Base.Iterators
, but the for loop is the fastest implementation I've found so far, and it doesn't allocate at all.