Skip to content

Commit

Permalink
implement haskey & get for DB
Browse files Browse the repository at this point in the history
  • Loading branch information
chengchingwen committed Feb 7, 2018
1 parent 49b38ae commit d6df620
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/db.jl
Original file line number Diff line number Diff line change
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 d6df620

Please sign in to comment.