oxinabox / DataDepsGenerators.jl

Utility for developers to help define DataDeps registration blocks, for reusing existing Data with DataDeps.jl
Other
18 stars 6 forks source link

Using JSONLD to retrieve information #43

Closed SebastinSanty closed 6 years ago

oxinabox commented 6 years ago

I am a fan of the handle_key method.

If you swap there argument order around, if has a really elegant way of writing it, using the splatting arguments. (I think they say varadic function?) (and follows the preferred order of collections before keys)

You can define it as

handle_key(json, key, otherkeys...) = get(json,  key) do  # do block is called when they is not found
     handle_key(json, otherkeys...) # This key missed, so try the others
end
handle_key(json) = nothing

Demo:

julia> foo = Dict("a"=>2)
Dict{String,Int64} with 1 entry:
  "a" => 2

julia> handle_key(foo, "a")  |> println
2

julia> handle_key(foo, "b") |> println
nothing

julia> handle_key(foo, "b", "a") |> println
2
codecov-io commented 6 years ago

Codecov Report

Merging #43 into master will increase coverage by 0.45%. The diff coverage is 96.29%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #43      +/-   ##
==========================================
+ Coverage   95.03%   95.49%   +0.45%     
==========================================
  Files          15       18       +3     
  Lines         302      355      +53     
==========================================
+ Hits          287      339      +52     
- Misses         15       16       +1
Impacted Files Coverage Δ
src/JSONLD/JSONLD_DOI.jl 100% <100%> (ø)
src/DataDepsGenerators.jl 91.42% <100%> (ø) :arrow_up:
src/utils.jl 100% <100%> (+10%) :arrow_up:
src/JSONLD/JSONLD_Web.jl 90% <90%> (ø)
src/JSONLD/JSONLD.jl 96.96% <96.96%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update c0b6dfc...a4929ff. Read the comment docs.

SebastinSanty commented 6 years ago

Right, I was thinking of adding kwargs like multiple arguments for handle_keys, which can check in the given order till the correct key is found.

oxinabox commented 6 years ago

which can check in the given order till the correct key is found.

That is what the code I posted does. It recursively peals off the first key until it is found, or until there is no keys left. It just does so via dispatch and splatting

oxinabox commented 6 years ago

We should probably check that the JSON-LD has the key-value pair

"@context": "http://schema.org",

And if it doesn't erroring out; or at least warning

I believe @context is JSON-LD for namespaces. Or something like that So if it doesn't have that we can't know that it is using the names we expect.

On the other hand we could just not worry about it: Garbage-in => garbage out

SebastinSanty commented 6 years ago

Kaggle for some reason is down. Will restart the tests once that works.