|
1 | 1 | const API_URL = "https://www.openml.org/api/v1/json"
|
2 | 2 |
|
3 |
| -# Data API |
4 |
| -# The structures are based on these descriptions |
5 |
| -# https://github.com/openml/OpenML/tree/master/openml_OS/views/pages/api_new/v1/xsd |
6 |
| -# https://www.openml.org/api_docs#!/data/get_data_id |
| 3 | +struct OpenMLAPIError <: Exception |
| 4 | + msg::String |
| 5 | +end |
| 6 | +function Base.showerror(io::IO, e::OpenMLAPIError) |
| 7 | + print(io, e.msg) |
| 8 | +end |
7 | 9 |
|
8 | 10 |
|
9 |
| -function get(query; extra_error_message = "") |
| 11 | +# Data API. See REST API on https://www.openml.org/apis |
| 12 | +function get(query) |
10 | 13 | try
|
11 | 14 | r = HTTP.request("GET", string(API_URL, query))
|
12 | 15 | return JSON.parse(String(r.body))
|
13 | 16 | catch e
|
14 | 17 | if isa(e, HTTP.StatusError) && e.status == 412
|
15 |
| - try |
16 |
| - err = JSON.parse(String(e.response.body))["error"] |
17 |
| - msg = err["message"] |
18 |
| - code = err["code"] |
19 |
| - additional_msg = haskey(err, "additional_message") ? err["additional_message"] : "" |
20 |
| - @error msg * " " * additional_msg * "(error code $code)" |
| 18 | + error_string = String(e.response.body) |
| 19 | + err = try |
| 20 | + JSON.parse(error_string)["error"] |
21 | 21 | catch
|
22 |
| - @error e |
| 22 | + @error(error_string) |
| 23 | + throw(OpenMLAPIError("Malformed query \"$query\".")) |
23 | 24 | end
|
24 |
| - extra_error_message != "" && println(extra_error_message) |
| 25 | + msg = err["message"] |
| 26 | + code = err["code"] |
| 27 | + additional_msg = haskey(err, "additional_message") ? err["additional_message"] : "" |
| 28 | + if code == "111" |
| 29 | + additional_msg *= "Check if there is a dataset with id $(last(split(query, '/'))).\nSee e.g. OpenML.list_datasets(). " |
| 30 | + end |
| 31 | + throw(OpenMLAPIError(msg * ". " * additional_msg * "(error code $code)")) |
25 | 32 | else
|
26 |
| - throw(e) |
| 33 | + rethrow() |
27 | 34 | end
|
28 | 35 | end
|
29 | 36 | return nothing
|
|
35 | 42 | Returns information about a dataset. The information includes the name,
|
36 | 43 | information about the creator, URL to download it and more.
|
37 | 44 | """
|
38 |
| -function load_Dataset_Description(id::Int) |
39 |
| - get("/data/$id", |
40 |
| - extra_error_message = "Check if there is a dataset with id $id.\nSee e.g. OpenML.list_datasets()\n") |
41 |
| -end |
| 45 | +load_Dataset_Description(id::Int) = get("/data/$id") |
42 | 46 |
|
43 | 47 | """
|
44 | 48 | OpenML.load(id; maxbytes = nothing)
|
|
0 commit comments