o
    (1Êj/.  ã                   @   s$  d dl Z d dlZd dlZd dlZd dlZd dlZd dlZdddddddd	d
ddddœZdd„ e 	¡ D ƒZe
eƒZdZdZdQdd„Zddddddddddd d!dœZd"d„ e 	¡ D ƒZd#d$„ Zd%d&„ Zd'd(„ Zd)d*„ Zd+Zd,Zd-Zd.d/„ Zd0d1„ Zd2d3„ Zed4k�re ¡ Zejd5d6d7� ejd8d9d:� ejd;ed<d=d>� ejd?d@dAdB� e  ¡ Z!eZ"e#e  $dCd„ e" 	¡ D ƒeeej %¡ j&dDdE�e!j'rÃdFndGdHœ¡dIdJ� e!j(D ]9Z)e!j* +dK¡D ]0Z,e-e!j.ƒD ](Z/dLD ]#Z0ee)e,e0e/e/d krîdMndNe"ƒZ1e!j'r÷dFndGe1dO< e#e  $e1¡dIdJ� qáqÝqÖqÎe#dPdIdJ� dS dS )Ré    NzTmad fear hate rage temper fury ire wrath happy fight hatred mean calm emotion enragezVwhite dark cat charred night funeral color grief blue death ink bottom coal brown grayzSbutter food eat sandwich rye jam milk flour jelly dough crust slice wine loaf toastz\table sit legs seat couch desk recliner sofa wood cushion swivel stool sitting rocking benchzVhot snow warm winter ice wet frigid chilly heat weather freeze air shiver arctic frostzonurse sick lawyer medicine health hospital dentist physician ill patient office stethoscope surgeon clinic curezPshoe hand toe kick sandals soccer yard walk ankle arm boot inch sock smell mouthzaapple vegetable orange kiwi citrus ripe pear banana berry cherry basket juice salad bowl cocktailz]boy dolls female young dress pretty hair niece dance beautiful cute date aunt daughter sisterzVlow clouds up tall tower jump above building noon cliff sky over airplane dive elevatezgqueen england crown prince george dictator palace throne chess rule subjects monarch royal leader reignz^woman husband uncle lady mouse male father strong friend beard person handsome muscle suit old)ÚangerÚblackÚbreadÚchairÚcoldÚdoctorÚfootÚfruitÚgirlÚhighÚkingÚmanc                 C   s   i | ]	\}}||  ¡ “qS © )Úsplit©Ú.0ÚkÚvr   r   ú1/home/Ace/liberation/same-standard/drm/drm_run.pyÚ
<dictcomp>#   ó    r   )r   é   é	   é<   éê  c                    s°   ddl m‰m} ttƒdd„ t ¡ D ƒB ‰‡fdd„|ddƒD ƒ}t | ¡}i ‰ tD ]+}ˆ|dƒ‰‡ ‡‡fd	d„|D ƒ}| 	|¡ |d t
ˆd
ƒt
ˆ|d dƒd
ƒfˆ |< q*ˆ S )Nr   )Úzipf_frequencyÚ
top_n_listc                 S   s   h | ]	}|D ]}|’qqS r   r   )r   r   Úwr   r   r   Ú	<setcomp>+   r   zpick_fillers.<locals>.<setcomp>c                    s,   g | ]}|  ¡ rt|ƒd kr|ˆ vr|‘qS )é   )ÚisalphaÚlen©r   r   )Úusedr   r   Ú
<listcomp>,   s   , z pick_fillers.<locals>.<listcomp>Úeni N  c                    s2   g | ]}t ˆ|d ƒˆ ƒdkr|ˆ  ¡ vr|‘qS )r%   gš™™™™™É?)ÚabsÚvaluesr"   )ÚfillersÚzr   r   r   r$   0   s   2 é   )Úwordfreqr   r   ÚsetÚLURESÚLISTSr'   ÚrandomÚRandomÚshuffleÚround)Úseedr   ÚpoolÚrngÚlureÚcandsr   )r(   r#   r)   r   r   Úpick_fillers)   s   

*r8   )Úsoldierz$kept: no ordinary phrase / associate)ÚcomingÚkept)Úbehalfr;   )Úexcuser;   )Ú	challengez.REPLACED 'drink' (ordinary phrase: cold drink))Úsouthernr;   )Ú	performedr;   )Úenjoyedr;   )Úhearr;   )Ú
governmentzÁREPLACED 'god' (ordinary phrase: God on high / most high); rejected next: 'little' (size associate of tall/low), 'long' (dimension associate of tall), 'off' (spatial associate of up/over/above))Údecisionr;   )Úwhilez/REPLACED 'money' (ordinary compound: money man)c                 C   s    i | ]\}\}}||d d f“qS ©Nr   )r   r6   r   Ú_whyr   r   r   r   I   s     c                 C   s’   | dkr
t d d… nt dd … }g }t D ]0}||v }| ||r!dndf¡ tD ]}| t| | |r4dndf¡ q'| || d df¡ q||fS )	NÚXé   Úlure_studiedÚlure_unstudiedÚtargetÚassoc_unstudiedr   Úfiller)r-   ÚappendÚTEST_POSITIONSr.   )Úformr(   ÚstudiedÚitemsr6   ÚsÚpr   r   r   Ú	items_forL   s     rV   c                 C   s   d  dd„ | D ƒ¡S )Nz

c                 s   s   � | ]
}d   t| ¡V  qdS )ú N)Újoinr.   ©r   Úlr   r   r   Ú	<genexpr>X   s   € zstudy_block.<locals>.<genexpr>)rX   )rR   r   r   r   Ústudy_blockW   ó   r\   c              	   C   s€   t  | |d||ddœdœ¡ ¡ }tjjd|ddid�}tjj|dd	��}t  | ¡ ¡d
 d W  d   ƒ S 1 s9w   Y  d S )NFi„  )Útemperaturer3   Únum_predict)ÚmodelÚmessagesÚstreamÚoptionszhttp://localhost:11434/api/chatzContent-Typezapplication/json)ÚdataÚheaders)ÚtimeoutÚmessageÚcontent)	ÚjsonÚdumpsÚencodeÚurllibÚrequestÚRequestÚurlopenÚloadsÚread)r`   ra   r^   r3   ÚbodyÚreqÚrr   r   r   Úchat[   s   

ÿÿ$ÿru   c                 C   s2   |  d|dœ¡ t| |||ƒ}|  d|dœ¡ |S )NÚuser©Úrolerh   Ú	assistant)rO   ru   )r`   ra   Útextr^   r3   Úreplyr   r   r   Úturnb   s   r|   uM   Before the test, solve these: 17+26, 43-19, 8Ã—7, 96Ã·4, 35+48. Answers only.zfFree recall: write every word you can remember from the study list, separated by commas. Nothing else.z¢Recognition test. For each word below, answer Old if it was on the study list, New if it was not. One per line, `word: Old` or `word: New`, nothing else.

{words}c                 C   sB  t ||ƒ\}}t |d |dk ¡}|d d … }	| |	¡ dt|ƒ d }
| ||||dœ}g }t| ||
||ƒ |dkr>|}n0|dkrWt| |dt› d	�||ƒ|d
< d|d
  }nd}d|d dœg}| dt| |||ƒdœ¡ t| |t	||ƒ t| |t
||ƒ|d< t| |tjd dd„ |	D ƒ¡d�||ƒ|d< | t|||ƒ¡ |S )Née   ÚYzhYou are taking part in a memory study. Read this study list carefully; you will be tested on it later.

z

Reply only: ready)r`   ÚarmrQ   r3   r^   ÚAÚBzcYou will not see this list again. Write notes for your later self to use on a memory test, at most z words.ÚnotezœEarlier, in a separate session, you studied a list of words and wrote these notes for yourself. You cannot see the list now; these notes are all you have:

zyEarlier, in a separate session, you studied a list of words. You cannot see that list now, and you have no notes from it.rv   rw   ry   Ú
recall_rawÚ
c                 s   s   � | ]\}}|V  qd S rF   r   )r   r   Ú_r   r   r   r[   ƒ   s   € zrun_trial.<locals>.<genexpr>)ÚwordsÚ	recog_raw)rV   r/   r0   r1   r\   r|   ÚNOTE_BUDGETrO   ru   ÚARITHÚRECALLÚRECOGÚformatrX   ÚupdateÚscore)r`   r   rQ   r3   r^   r(   rR   rS   r5   ÚtestÚstudyÚoutÚm1Úm2Úopenerr   r   r   Ú	run_trialm   s2   ,ÿÿÿ,r•   c                 C   s   t t d|  ¡ ¡ƒS )Nz[a-z]+)r,   ÚreÚfindallÚlower)rz   r   r   r   Úwords_in‡   r]   r™   c                    s˜  i }dd„ ˆD ƒ}d| v rBt | d ƒ‰t‡fdd„ˆD ƒƒ|d< t|ˆ@ ƒ|d< t|ƒ|d< tt d	| d ¡ƒ|d
< |d
 tk|d< t | d ƒ‰t|ˆ@ ƒ|d< t‡fdd„ˆD ƒƒ|d< t‡‡fdd„tD ƒƒ|d< i ‰ |D ] \}‰t dt |¡ | d tj	¡}|r‹| 
d¡ ¡ nd ˆ |< qodD ]7‰‡fdd„|D ƒ}t‡ fdd„|D ƒƒ|dˆ› d�< t|ƒ|dˆ› d�< t‡ fdd„|D ƒƒ|dˆ› d�< q’|S )Nc                 S   s   h | ]}t | D ]}|’qqS r   )r.   )r   rZ   r   r   r   r   r   Œ   s    zscore.<locals>.<setcomp>r‚   c                 3   ó   � | ]	}|ˆ v r|V  qd S rF   r   rY   )Únwr   r   r[   �   ó   € zscore.<locals>.<genexpr>Únote_lures_studiedÚnote_studied_keptÚnote_studied_totalz\S+Ú
note_wordsÚnote_over_budgetrƒ   Úrecall_studied_hitc                 3   rš   rF   r   rY   )Úrwr   r   r[   ™   rœ   Úrecall_lure_studiedc                 3   s$   � | ]}|ˆvr|ˆ v r|V  qd S rF   r   rY   )r£   rR   r   r   r[   š   s   €" Úrecall_lure_unstudiedz\b%s\b\W{0,6}(old|new)\br‡   é   )rL   rJ   rM   rK   rN   c                    s   g | ]
\}}|ˆ kr|‘qS r   r   )r   r   r   )Úkindr   r   r$       s    zscore.<locals>.<listcomp>c                 3   s   � | ]	}ˆ | d kV  qdS )ÚoldNr   r"   ©Úansr   r   r[   ¡   rœ   Úrecog_Ú_oldÚ_nc                 3   s   � | ]	}ˆ | d u V  qd S rF   r   r"   r©   r   r   r[   £   rœ   Ú	_unparsed)r™   Úsortedr!   r–   r—   rˆ   r-   ÚsearchÚescapeÚIÚgroupr˜   Úsum)r‘   rR   rS   rT   Ústudied_wordsr   ÚmÚwsr   )rª   r§   r›   r£   rR   r   rŽ   Š   s.   "$rŽ   Ú__main__Úmodelsú+)Únargsz--armszA,B,C)Údefaultz--seedsrI   z seed 0 at T=0, the rest at T=0.8)Útyper¼   Úhelpz--dryrunÚ
store_truez,label rows DRYRUN: plumbing test, never data)Úactionr¾   c                 C   s   i | ]	\}}||d  “qS )r   r   r   r   r   r   r   ®   r   Úseconds)ÚtimespecÚDRYRUNÚ
PREREG_RUN)r(   Úfiller_auditÚnote_budgetÚstampÚlabelT)Úflushú,)rH   r~   g        gš™™™™™é?rÈ   zDONE (search complete))r   )2ri   r/   r–   ÚsysÚargparseÚdatetimeÚurllib.requestrl   r.   rS   Úlistr-   rP   rˆ   r8   ÚFILLER_AUDITÚFROZEN_FILLERSrV   r\   ru   r|   r‰   rŠ   r‹   r•   r™   rŽ   Ú__name__ÚArgumentParserÚapÚadd_argumentÚintÚ
parse_argsÚar(   Úprintrj   ÚnowÚ	isoformatÚdryrunr¹   r`   Úarmsr   r   ÚrangeÚseedsr3   rQ   rt   r   r   r   r   Ú<module>   sˆ   8ô
ô
*ÿÿ
ýÿÿï