o
    "j#                     @   s  d Z ddlZddlZddlZddlZddlZddlm	Z	 g Z
g dZdZdZG dd dZG d	d
 d
Zdadadadadd Zd1ddZe	ddddddd ZejeddZejeddZe	ddddddd Zdd Ze	ddddddd Ze	dddddd d! Zd"d# Ze	dddddd$d% Ze	dddddd&d' Z e	dddddd(d) Z!e	dddddd*d+ Z"d,d- Z#e	dddddd.d/ Z$e%d0kre#  dS dS )2aD  
Movielens 1-M dataset.

Movielens 1-M dataset contains 1 million ratings from 6000 users on 4000
movies, which was collected by GroupLens Research. This module will download
Movielens 1-M dataset from
http://files.grouplens.org/datasets/movielens/ml-1m.zip and parse training
set and test set into paddle reader creators.

    N)
deprecated)         #   -   2   8   z3https://dataset.bj.bcebos.com/movielens%2Fml-1m.zipZ c4d9eecfca2ab87c1945afe126590906c                   @   0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )	MovieInfozM
    Movie id, title and categories information are stored in MovieInfo.
    c                 C   s   t || _|| _|| _d S N)intindex
categoriestitle)selfr   r   r    r   Y/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/paddle/dataset/movielens.py__init__0   s   

zMovieInfo.__init__c                 C   s(   | j dd | jD dd | j D gS )z/
        Get information from a movie.
        c                 S   s   g | ]}t | qS r   )CATEGORIES_DICT).0cr   r   r   
<listcomp>;   s    z#MovieInfo.value.<locals>.<listcomp>c                 S   s   g | ]}t |  qS r   )MOVIE_TITLE_DICTlower)r   wr   r   r   r   <   s    )r   r   r   splitr   r   r   r   value5   s   zMovieInfo.valuec                 C   s   d| j | j| jf S )Nz-<MovieInfo id(%d), title(%s), categories(%s)>)r   r   r   r   r   r   r   __str__?   s
   zMovieInfo.__str__c                 C   s   |   S r   )r   r   r   r   r   __repr__F      zMovieInfo.__repr__N__name__
__module____qualname____doc__r   r   r   r    r   r   r   r   r   +   s    
r   c                   @   r
   )UserInfozK
    User id, gender, age, and job information are stored in UserInfo.
    c                 C   s2   t || _|dk| _tt || _t || _d S )NM)r   r   is_male	age_tableagejob_id)r   r   genderr+   r,   r   r   r   r   O   s   

zUserInfo.__init__c                 C   s   | j | jrdnd| j| jgS )z.
        Get information from a user.
        r   r   )r   r)   r+   r,   r   r   r   r   r   U   s   zUserInfo.valuec                 C   s$   d| j | jrdndt| j | jf S )Nz/<UserInfo id(%d), gender(%s), age(%d), job(%d)>r(   F)r   r)   r*   r+   r,   r   r   r   r   r   [   s   zUserInfo.__str__c                 C   s   t | S r   )strr   r   r   r   r    c   r!   zUserInfo.__repr__Nr"   r   r   r   r   r'   J   s    r'   c               
   C   s  t jjtdt} td u rtd}t	j
| d}| D ]}t|t	js'J i at }t }|dQ}t|D ]D\}}|jdd}| d\}	}
}|d}|D ]}|| qT||
d	}
t|	||
d
tt|	< |
 D ]	}||  qsq9W d    n1 sw   Y  i at|D ]\}}|t|< qi at|D ]\}}|t|< qi a|d+}|D ] }|jdd}| d\}}}}}t||||dtt|< qW d    n1 sw   Y  qW d    | S 1 sw   Y  | S )N	movielensz^(.*)\((\d+)\)$filezml-1m/movies.datlatinencoding::|r   )r   r   r   zml-1m/users.dat)r   r-   r+   r,   )paddledatasetcommondownloadURLMD5
MOVIE_INFOrecompilezipfileZipFileinfolist
isinstanceZipInfosetopen	enumeratedecodestripr   addmatchgroupr   r   r   r   r   	USER_INFOr'   )fnpatternpackageinfoZtitle_word_setZcategories_setZ
movie_fileilineZmovie_idr   r   r   r   Z	user_fileuidr-   r+   Zjob_r   r   r   __initialize_meta_info__m   s^   




''rW   皙?Fc              	   c   s   t  }tj|  tj|dj}|dL}|D ]A}|jdd}tj |k |krZ| 	d\}}}}	t
|}t
|}t|d d }t| }
t| }| |
  |gg V  qW d    n1 sew   Y  W d    d S W d    d S 1 s}w   Y  d S )Nr1   zml-1m/ratings.datr3   r4   r6      g      @)rW   nprandomseedrA   rB   rG   rI   rJ   r   r   floatr>   rN   r   )Z	rand_seedZ
test_ratiois_testrO   rQ   ZratingrT   rU   Zmov_idrV   Zmovusrr   r   r   
__reader__   s*   "r`   z2.0.0zpaddle.text.datasets.Movielensr   z>Please use new dataset API which supports paddle.io.DataLoader)ZsinceZ	update_tolevelreasonc                     s    fddS )Nc                      s   t di  S )Nr   )r`   r   kwargsr   r   <lambda>   s    z$__reader_creator__.<locals>.<lambda>r   rc   r   rc   r   __reader_creator__   s   rf   )r^   Tc                   C   
   t   tS )z%
    Get movie title dictionary.
    )rW   r   r   r   r   r   get_movie_title_dict      
rh   c                 C      | j |j kr| S |S r   )r   abr   r   r   __max_index_info__      rn   c                   C      t   tttt jS )z,
    Get the maximum value of movie id.
    )rW   	functoolsreducern   listr>   valuesr   r   r   r   r   max_movie_id      
ru   c                   C   rp   )z+
    Get the maximum value of user id.
    )rW   rq   rr   rn   rs   rN   rt   r   r   r   r   r   max_user_id   rv   rw   c                 C   rj   r   )r,   rk   r   r   r   __max_job_id_impl__   ro   rx   c                   C   rp   )z*
    Get the maximum value of job id.
    )rW   rq   rr   rx   rs   rN   rt   r,   r   r   r   r   
max_job_id   s   
ry   c                   C   rg   )z*
    Get movie categories dictionary.
    )rW   r   r   r   r   r   movie_categories  ri   rz   c                   C   rg   )z#
    Get user info dictionary.
    )rW   rN   r   r   r   r   	user_info  ri   r{   c                   C   rg   )z$
    Get movie info dictionary.
    )rW   r>   r   r   r   r   
movie_info   ri   r|   c                  C   s:   t t  D ]\} }qt t  D ]\}}qt| | d S r   )rH   traintestprint)Ztrain_countrV   Z
test_countr   r   r   unittest.  s
   r   c                   C   s   t jjtdt d S )Nr0   )r8   r9   r:   r;   r<   r=   r   r   r   r   fetch7  s   r   __main__)r   rX   F)&r&   rq   r?   rA   numpyrZ   Zpaddle.dataset.commonr8   Zpaddle.utilsr   __all__r*   r<   r=   r   r'   r>   r   r   rN   rW   r`   rf   partialr}   r~   rh   rn   ru   rw   rx   ry   rz   r{   r|   r   r   r#   r   r   r   r   <module>   s   
/








	

