text: # copyright (c) 2021 PaddlePaddle Authors. All Rights Reserve.
  #
  # Licensed under the Apache License, Version 2.0 (the "License");
  # you may not use this file except in compliance with the License.
  # You may obtain a copy of the License at
  #
  #    http://www.apache.org/licenses/LICENSE-2.0
  #
  # Unless required by applicable law or agreed to in writing, software
  # distributed under the License is distributed on an "AS IS" BASIS,
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  # See the License for the specific language governing permissions and
  # limitations under the License.
  
  use_poster = False
  if use_poster:
      rating_path = "./work/ml-1m/new_rating.txt"
  else:
      rating_path = "./work/ml-1m/ratings.dat"
  # 打开文件，读取所有行到data中
  with open(rating_path, 'r') as f:
      data = f.readlines()
  # 打印data的数据长度，以及第一条数据中的用户ID、电影ID和评分信息   
  item = data[0]
  
  print(item)
  
  item = item.strip().split("::")
  usr_id,movie_id,score = item[0],item[1],item[2]
  print("评分数据条数：", len(data))
  print("用户ID：", usr_id)
  print("电影ID：", movie_id)
  print("用户对电影的评分：", score)
  
  
  def get_rating_info(path):
      # 打开文件，读取所有行到data中
      with open(path, 'r') as f:
          data = f.readlines()
      # 创建一个字典
      rating_info = {}
      for item in data:
          item = item.strip().split("::")
          # 处理每行数据，分别得到用户ID，电影ID，和评分
          usr_id,movie_id,score = item[0],item[1],item[2]
          if usr_id not in rating_info.keys():
              rating_info[usr_id] = {movie_id:float(score)}
          else:
              rating_info[usr_id][movie_id] = float(score)
      return rating_info
  
  # 获得评分数据
  #rating_path = "./work/ml-1m/ratings.dat"
  rating_info = get_rating_info(rating_path)
  print("ID为1的用户一共评价了{}个电影".format(len(rating_info['1'])))
  
  
  