Skip to content

Commit

Permalink
Merge pull request #11 from chengchingwen/master
Browse files Browse the repository at this point in the history
implement haskey & get for DB
  • Loading branch information
oxinabox authored Feb 16, 2018
2 parents 057986c + 34459fc commit 7d886ef
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/db.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ end
function load_synsets(base_dir)
synsets = Dict{Char, Dict{Int, Synset}}()

for pos in ['n', 'v', 'a', 'r']
for pos in ('n', 'v', 'a', 'r')
d = Dict{Int, Synset}()

open(path_to_data_file(base_dir, pos)) do f
Expand Down Expand Up @@ -87,3 +87,9 @@ end
function path_to_index_file(base_dir, pos)
joinpath(base_dir, "dict", "index.$(SYNSET_TYPES[pos])")
end

Base.haskey(db::DB, pos::Char) = haskey(db.lemmas, pos)
Base.haskey(db::DB, pos::Char, word::AbstractString) = haskey(db, pos) ? haskey(db.lemmas[pos], word) : false

Base.get(db::DB, pos::Char, word::AbstractString, default) = haskey(db, pos, word) ? db.lemmas[pos][word] : default
Base.get(db::DB, word::AbstractString, pos::Char, default) = get(db, pos, word, default)

0 comments on commit 7d886ef

Please sign in to comment.