@@ -89,61 +89,44 @@ def _get_estimation_procedure_list():
8989 return procs
9090
9191
92- def list_tasks_by_type (task_type_id ):
93- """Return a list of all tasks for a given tasks type which are on OpenML.
92+ def list_tasks (task_type_id = None , offset = None , size = None , tag = None ):
93+ """Return a number of tasks having the given tag and task_type_id
9494
9595 Parameters
9696 ----------
97- task_type_id : int
97+ task_type_id : int, optional
9898 ID of the task type as detailed
9999 `here <http://www.openml.org/search?type=task_type>`_.
100+ offset : int, optional
101+ the number of tasks to skip, starting from the first
102+ size : int, optional
103+ the maximum number of tasks to show
104+ tag : str, optional
105+ the tag to include
100106
101107 Returns
102108 -------
103109 list
104- A list of all tasks of the given task type. Every task is represented by
105- a dictionary containing the following information: task id,
106- dataset id, task_type and status. If qualities are calculated for
107- the associated dataset, some of these are also returned.
110+ A list of all tasks having the given task_type_id and the give tag.
111+ Every task is represented by a dictionary containing the following
112+ information: task id, dataset id, task_type and status. If qualities
113+ are calculated for the associated dataset, some of these are also
114+ returned.
108115 """
109- try :
110- task_type_id = int (task_type_id )
111- except :
112- raise ValueError ("Task Type ID is neither an Integer nor can be "
113- "cast to an Integer." )
114- return _list_tasks ("task/list/type/%d" % task_type_id )
115-
116-
117- def list_tasks_by_tag (tag ):
118- """Return all tasks having the given tag
116+ api_call = "task/list"
117+ if task_type_id is not None :
118+ api_call += "/type/%d" % int (task_type_id )
119119
120- Parameters
121- ----------
122- tag : str
123-
124- Returns
125- -------
126- list
127- A list of all tasks having a give tag. Every task is represented by
128- a dictionary containing the following information: task id,
129- dataset id, task_type and status. If qualities are calculated for
130- the associated dataset, some of these are also returned.
131- """
132- return _list_tasks ("task/list/tag/%s" % tag )
120+ if offset is not None :
121+ api_call += "/offset/%d" % int (offset )
133122
123+ if size is not None :
124+ api_call += "/limit/%d" % int (size )
134125
135- def list_tasks () :
136- """Return a list of all tasks which are on OpenML.
126+ if tag is not None :
127+ api_call += "/tag/%s" % tag
137128
138- Returns
139- -------
140- list
141- A list of all tasks. Every task is represented by a
142- dictionary containing the following information: task id,
143- dataset id, task_type and status. If qualities are calculated for
144- the associated dataset, some of these are also returned.
145- """
146- return _list_tasks ('task/list' )
129+ return _list_tasks (api_call )
147130
148131
149132def _list_tasks (api_call ):
@@ -162,12 +145,15 @@ def _list_tasks(api_call):
162145 '"oml:runs"/@xmlns:oml is not '
163146 '"http://openml.org/openml": %s'
164147 % str (tasks_dict ))
148+
165149 try :
166- tasks = []
150+ tasks = dict ();
167151 procs = _get_estimation_procedure_list ()
168152 proc_dict = dict ((x ['id' ], x ) for x in procs )
169153 for task_ in tasks_dict ['oml:tasks' ]['oml:task' ]:
170- task = {'tid' : int (task_ ['oml:task_id' ]),
154+ tid = int (task_ ['oml:task_id' ])
155+ task = {'tid' : tid ,
156+ 'ttid' : int (task_ ['oml:task_type_id' ]),
171157 'did' : int (task_ ['oml:did' ]),
172158 'name' : task_ ['oml:name' ],
173159 'task_type' : task_ ['oml:task_type' ],
@@ -187,12 +173,10 @@ def _list_tasks(api_call):
187173 if abs (int (quality ['#text' ]) - quality ['#text' ]) < 0.0000001 :
188174 quality ['#text' ] = int (quality ['#text' ])
189175 task [quality ['@name' ]] = quality ['#text' ]
190- tasks . append ( task )
176+ tasks [ tid ] = task
191177 except KeyError as e :
192178 raise KeyError ("Invalid xml for task: %s" % e )
193179
194- tasks .sort (key = lambda t : t ['tid' ])
195-
196180 return tasks
197181
198182
@@ -262,7 +246,7 @@ def _create_task_from_xml(xml):
262246 estimation_parameters [name ] = text
263247
264248 return OpenMLTask (
265- dic ["oml:task_id" ], dic ["oml:task_type" ],
249+ dic ["oml:task_id" ], dic ['oml:task_type_id' ], dic [ "oml:task_type" ],
266250 inputs ["source_data" ]["oml:data_set" ]["oml:data_set_id" ],
267251 inputs ["source_data" ]["oml:data_set" ]["oml:target_feature" ],
268252 inputs ["estimation_procedure" ]["oml:estimation_procedure" ][
0 commit comments