
    ]^jm                        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mZ d dlmZ  ee	          
                                j        d         Zej        Zedz  Zedz  Zedz  Z ej        dej                  Zd	 Zd
 ZddZd Zedk    rS	  ej         e                       dS # e$ r0Z ede ej                    ej        d           Y dZ[dS dZ[ww xY wdS )    N)datetimetimezone)Path   story/story-canon.txtzscript/story-brief.jsonzstory/originality-report.jsonz[^\W_]+c                 r    t          j        |                                                                           S N)hashlibsha256
read_bytes	hexdigest)paths    script/validate-originality.pyshar      s(    >$//++,,66888    c                     t          j        d|                                           }t                              |          S )NNFC)unicodedata	normalizecasefoldTOKEN_REfindall)text
normalizeds     r   tokensr      s4    &ud33<<>>JJ'''r   
   c           	            fdt          t          dt                     z
  dz                       D             S )Nc                 P    h | ]"}d                      ||z                      #S ) )join).0indexitemswidths     r   	<setcomp>zshingles.<locals>.<setcomp>   s3    dddUCHHU5./00dddr   r   r   )rangemaxlen)r#   r$   s   ``r   shinglesr)      sE    dddddeC3u::X]K]`aKaDbDb>c>cddddr   c                     t                                           rt                                          st          d          t	          t                               d                    } t          |           }g }d}t          t          	                                          D ]+}|t          k    s|                                s#t          j        d|j                  }|r&t          |                    d                    dk     rf|dz  |d	z  g}t#          d
 |D             d           }|t          t	          |                    d                              }t%          ||z            }	|	t'          dt%          |                    z  }
t'          ||
          }|                    |j        t+          |          |	|
d           -t-          j        t                              d                    g d}t1          fd|D                       }|o|dk     }d||rdndt3          t                     dd|||t5          j        t8          j                                                  d
}t>                               t-          j!        |dd          dz   d           tE          t-          j!        |t%          |          |dd                     |rdndS )Nzcanon/brief missingzutf-8)encodingg        z^(\d+)r      r   zstory/spoken-narration.txtc              3   B   K   | ]}|                                 |V  d S r	   )is_file)r!   r   s     r   	<genexpr>zmain.<locals>.<genexpr>-   s/      DDtT\\^^DdDDDDDDr   )projectr   overlap_10gramscurrent_overlap_ratio)settingpremisedistinctive_enginemotifsendingc              3   B   K   | ]}                     |          V  d S r	   )get)r!   keybriefs     r   r/   zmain.<locals>.<genexpr>7   s-      EEUYYs^^EEEEEEr   gMb`?passedfailedz-normalized Unicode 10-word shingle comparison)
versionverifiedstatussource_canon_sha256method	thresholdworst_current_overlap_ratioauthority_axes_completecomparisons
checked_atF)ensure_asciiindent
)r?   rF   worst_ratio)rH   r   )#CANONr.   BRIEFRuntimeErrorr   	read_textr)   sortedPROJECTSiterdirPROJECTis_dirrematchnameintgroupnextr(   r'   appendstrjsonloadsallr   r   nowr   utc	isoformatRECEIPT
write_textdumpsprint)current_tokenscurrentrF   worst	directoryrV   
candidatesother	other_setoverlapratiorequired_axesauthority_completer?   receiptr;   s                  @r   mainrs      s   ==?? 2%--// 20111EOOWO==>>N~&&GKEH,,..// H H	y'7'7'9'9IN33 	EKKNN++a//"999Gc;cd
DDzDDDdKK=VEOOWO$E$EFFGG	g	)**#aW...E5!!y~s5zz^e  AF  G  G  	H  	H  	H  	HJu8899ETTTMEEEE}EEEEE!3eemH((6XhhPX"5zz5d5#5kl8<00::<< G tz'aHHH4OZabbb	$*(3{;K;K\abbqv
w
w
wxxx11ar   __main__zOriginality gate blocked: )file)r   )r
   r]   rU   sysr   r   r   pathlibr   __file__resolveparentsrS   parentrQ   rL   rM   rc   compileUNICODEr   r   r   r)   rs   __name__exit	Exceptionexcrf   stderr r   r   <module>r      s     				 



     ' ' ' ' ' ' ' '      
$x..
 
 
"
"
*1
->))++
3
32:j"*--9 9 9( ( (
e e e e#  #  # L z   0300szBBBB s   B% %C*%CC