@@ -0,0 +1,1670 @@
+#%0A# Copyright 2016 The BigDL Authors.%0A#%0A# Licensed under the Apache License, Version 2.0 (the %22License%22);%0A# you may not use this file except in compliance with the License.%0A# You may obtain a copy of the License at%0A#%0A#     http://www.apache.org/licenses/LICENSE-2.0%0A#%0A# Unless required by applicable law or agreed to in writing, software%0A# distributed under the License is distributed on an %22AS IS%22 BASIS,%0A# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A# See the License for the specific language governing permissions and%0A# limitations under the License.%0A#%0A%0Aimport os%0A%0Aimport zipfile%0Aimport numpy as np%0A%0Afrom bigdl.dataset import base%0A%0ASOURCE_URL = 'http://files.grouplens.org/datasets/movielens/'%0A%0Adef read_data_sets(data_dir):%0A    %22%22%22%0A    Parse or download movielens 1m  data if train_dir is empty.%0A%0A    :param data_dir: The directory storing the movielens data%0A    :return: a 2D numpy array with user index and item index in each row %0A    %22%22%22%0A%0A    WHOLE_DATA = 'ml-1m.zip'%0A    local_file = base.maybe_download(WHOLE_DATA, data_dir, SOURCE_URL + WHOLE_DATA)%0A    zip_ref = zipfile.ZipFile(local_file, 'r')%0A    extracted_to = os.path.join(data_dir, %22ml-1m%22)%0A    if not os.path.exists(extracted_to):%0A        print(%22Extracting %25s to %25s%22 %25 (local_file, data_dir))%0A        zip_ref.extractall(data_dir)%0A        zip_ref.close()%0A    rating_files = os.path.join(extracted_to,%22ratings.dat%22)%0A    rating_list = %5Bi.strip().split(%22::%22)%5B:2%5D for i in open(rating_files,%22r%22).readlines()%5D    %0A    movielens_data = np.array(rating_list).astype(int)%0A    return movielens_data %0A%0Aif __name__ == %22__main__%22:%0A    movielens_data = read_data_sets(%22/tmp/movielens/%22)%0A

add movielens (#1027)