Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement haskey & get for DB #11

Merged
merged 2 commits into from
Feb 16, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)