/usr/local/lib/python3.6/site-packages/sacremoses/__pycache__
NameSizeModeActions
chinese.cpython-36.pyc147100644editdlrm
cli.cpython-36.pyc65190644editdlrm
corpus.cpython-36.pyc49150644editdlrm
indic.cpython-36.pyc9490644editdlrm
normalize.cpython-36.pyc48290644editdlrm
sent_tokenize.cpython-36.pyc7210644editdlrm
subwords.cpython-36.pyc46500644editdlrm
tokenize.cpython-36.pyc165930644editdlrm
truecase.cpython-36.pyc117780644editdlrm
util.cpython-36.pyc51300644editdlrm
__init__.cpython-36.pyc2990644editdlrm
__main__.cpython-36.pyc2240644editdlrm
Edit: /usr/local/lib/python3.6/site-packages/sacremoses/__pycache__/truecase.cpython-36.pyc (11778B)
3 EgH@sddlmZddlZddlmZmZddlmZddlm Z ddl m Z ddl m Z ddlmZmZddlZejdd krddlZddlZejZejed e ZGd d d eZGd ddeZd dgZdS))print_functionN) defaultdictCounter)partial)chain) text_type) Perluniprops)parallelize_preprocessgrouperzTYou should really be using Python3!!! Tick tock, tick tock, https://pythonclock.org/cseZdZdZedjejdZedjejdZ edjejdZ d$fdd Z d%d d Z d&d dZ d'ddZd(ddZd)ddZd*ddZd+ddZeddZddZddZd d!Zd"d#ZZS),MosesTruecaserz This is a Python port of the Moses Truecaser from https://github.com/moses-smt/mosesdecoder/blob/master/scripts/recaser/train-truecaser.perl https://github.com/moses-smt/mosesdecoder/blob/master/scripts/recaser/truecase.perl Lowercase_LetterUppercase_LetterNutf8csztt|jtjdj|j|j|j|_ tjd|_ ddddh|_ ddd d d d d dh|_ ||_ ||_|rv|j||_dS)a. :param load_from: :type load_from: :param is_asr: A flag to indicate that model is for ASR. ASR input has no case, make sure it is lowercase, and make sure known are cased eg. 'i' to be uppercased even if i is known. :type is_asr: bool z[{}{}{}]z(<.*(?<=>))(.*)((?=]*>).:?!(["'z'z"z[z]N)superr __init__recompileformatrrTitlecase_LetterSKIP_LETTERS_REGEXZXML_SPLIT_REGXSENT_ENDDELAYED_SENT_STARTencodingis_asr _load_modelmodel)selfZ load_fromr#r") __class__=/usr/local/lib/python3.6/site-packages/sacremoses/truecase.pyr-s$  zMosesTruecaser.__init__FcCsd}g}xt|D]\}}tjd|r*qn ||jkr6q| rL||jkrLd}q|jj|s^d}qd}|sld}n"|r|djrd}n |dkrd}d}|dkr|j|j||fqW|S)z This function checks through each tokens in a sentence and returns the appropriate weight of each surface token form. Tz (<\S[^>]*>)Frg?) enumeratersearchr!r rislowerappendlower)r&tokenspossibly_use_first_token is_first_wordZtruecase_weightsitokenZcurrent_word_weightr(r(r)learn_truecase_weightsTs2    z%MosesTruecaser.learn_truecase_weightsr*c Csltt}t|j|d}tt||||d}x&|D]\} } } || | | 7<q0W|rb|j|||j|S)aN :param document_iterator: The input document, each outer list is a sentence, the inner list is the list of tokens for each sentence. :type document_iterator: iter(list(str)) :param possibly_use_first_token: When True, on the basis that the first word of a sentence is always capitalized; if this option is provided then: a) if a sentence-initial token is *not* capitalized, then it is counted, and b) if a capitalized sentence-initial token is the only token of the segment, then it is counted, but with only 10% of the weight of a normal token. :type possibly_use_first_token: bool :returns: A dictionary of the best, known objects as values from `_casing_to_model()` :rtype: {'best': dict, 'known': Counter} )r1) progress_bar)rrrr5rr _save_model_from_casing_casing_to_model) r&document_iteratorsave_tor1 processesr6casingZtrain_truecaserZ token_weightsZlowercase_tokenZ surface_tokenZweightr(r(r)_trains zMosesTruecaser._traincCs"d|_|j|||||d|_|jS)z\ Default duck-type of _train(), accepts list(list(str)) as input documents. N)r6)r%r=)r&Z documentsr:r1r;r6r(r(r)trains  zMosesTruecaser.traincCsNt||jd}dd|jD}WdQRXd|_|j|||||d|_|jS)zj Duck-type of _train(), accepts a filename to read as a `iter(list(str))` object. )r"css|]}|jVqdS)N)split).0liner(r(r) sz1MosesTruecaser.train_from_file..N)r6)openr" readlinesr%r=)r&filenamer:r1r;r6finr9r(r(r)train_from_files  zMosesTruecaser.train_from_filecCs4dd|jD}d|_|j|||||d|_|jS)zm Duck-type of _train(), accepts a file object to read as a `iter(list(str))` object. css|]}|jVqdS)N)r?)r@rAr(r(r)rBsz8MosesTruecaser.train_from_file_object..N)r6)rDr%r=)r&Z file_objectr:r1r;r6r9r(r(r)train_from_file_objects z%MosesTruecaser.train_from_file_objectc Cs(td}t|dst|d}g}|j|}xt|D]\}} tjd| rV|j| q6| dksh| jdrt|j| q6tjd| j \} } |j r| j } |j dj | j d} |j d j | d} |r| r| } n| r|r| n| } n| r| } | | } |j| | |jk}| |jkr6d }q6W|r$d j|S|S) a  Truecase a single sentence / line of text. :param text: A single string, i.e. sentence text. :type text: str :param use_known: Use the known case if a word is a known word but not the first word. :type use_known: bool zV Use Truecaser.train() to train a model. Or use Truecaser('modefile') to load a model.r%Tz (<\S[^>]*>)|z ^([^\|]+)(.*)bestNknownF )strhasattrAssertionError split_xmlr+rr,r. startswithgroupsr#r/r%getr r!join) r&text return_strZ use_knownZcheck_model_messager2truecased_tokensr0r3r4Z other_factorsZ best_caseZ known_caser(r(r)truecases<        zMosesTruecaser.truecaseTc csNt||jd6}x.|D]&}|j|j}|r6dj|n|VqWWdQRXdS)N)r"rL)rCr"rXstriprT)r&rErVrFrArWr(r(r) truecase_file>s zMosesTruecaser.truecase_filecCs0|j}g}x|r*tjd|}tjd|}tjd|}|r|j\}}tjd|rt|dkrtjd|d r|d |7<tjd|}|r|d|jd7<|jd }n|j|d |}nP|r|j|jd|jd }n0|r |j|jd|jd }ntd j||dj|d<qW|S)a  Python port of split_xml function in Moses' truecaser: https://github.com/moses-smt/mosesdecoder/blob/master/scripts/recaser/truecaser.perl :param line: Input string, should be tokenized, separated by space. :type line: str z^\s*(<\S[^>]*>)(.*)$z^\s*([^\s<>]+)(.*)$z^\s*(\S+)(.*)$z^\Srz\|$r*z ^(\|+)(.*)$rLzERROR: huh? {}r\r\r\r\) rYrr,rRlengroupr. Exceptionr)rAr0Zhas_xmlZ is_non_xmlZ xml_cognatesZ potential_xmlZ line_nextZ is_factorr(r(r)rPEs:              zMosesTruecaser.split_xmlc Csti}t}xX|D]P}||j}|dd||<|jsx(|ddD]\}}||d7<qDWqW|||d}|S)zg :returns: A tuple of the (best, known) objects. :rtype: tuple(dict, Counter) rr*N)rJrKr<)r most_commonr#) r&r<rJrKZ token_lowerr0r4countr%r(r(r)r8xs   zMosesTruecaser._casing_to_modelcCs|j|jd|dS)Nr<)r7r%)r&rEr(r(r) save_modelszMosesTruecaser.save_modelc Cst|d|jd}x|D]~}t||j}g}xPt||jD]<\}\}}|dkrfdj|||} ndj|||} |j| qBWtdj |d|dqWWd QRXd S) a" Outputs the truecaser model file in the same output format as https://github.com/moses-smt/mosesdecoder/blob/master/scripts/recaser/train-truecaser.perl :param casing: The dictionary of tokens counter from `train()`. :type casing: default(Counter) w)r"rz {} ({}/{})z{} ({})rL )endfileN) rCr"sumvaluesr+r`rr.printrT) r&r<rEZfoutr4Ztotal_token_countZ tokens_countsr3raZ out_tokenr(r(r)r7s z&MosesTruecaser._save_model_from_casingc Cstt}t||jd`}xX|D]P}|jj}x>t|dD]0\}}|jddjd}t|||j|<q:WqWWdQRX|j |S)z Loads pre-trained truecasing file. :returns: A dictionary of the best, known objects as values from `_casing_to_model()` :rtype: {'best': dict, 'known': Counter} )r"r[/rz()N) rrrCr"rYr?r intr/r8)r&rEr<rFrAr4rar(r(r)r$s  &zMosesTruecaser._load_model)NNr)F)NFr*F)NFr*F)NFr*F)NFr*F)FF)T)__name__ __module__ __qualname____doc__rrT perlunipropscharsrrrrr5r=r>rGrHrXrZ staticmethodrPr8rbr7r$ __classcell__r(r()r'r)r !s:' 1 '    H  3r cs&eZdZfddZdddZZS)MosesDetruecaserc#stt|jddddh|_ddddd d d d h|_d ddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/h#|_dS)0Nrrrrrrrrz'z"z[z]aafterZagainstzal-.+andanyasZatbeZbecauseZbetweenZbyZduringzel-.+forfromZhisinisZitslastnotZofoffonZthanZtheZtheirthisZtowaswerewhichZwillwith)rrtrr r! ALWAYS_LOWER)r&)r'r(r)rsZzMosesDetruecaser.__init__Fcsg}d}x\|jD]P}|r6|ddj|ddn|}|j||jkrTd}q|jkrd}qW|r|fdd|D}|rdj|S|S)z Detruecase the translated files from a model that learnt from truecased tokens. :param text: A single string, i.e. sentence text. :type text: str TNr*Fcs6g|].}|jkr|n|ddj|ddqS)Nr*)rupper)r@r4)r&r(r) sz/MosesDetruecaser.detruecase..rL)r?rr.r r!rT)r&rUZ is_headlinerVZ cased_tokensZsentence_startr4r()r&r) detruecases $    zMosesDetruecaser.detruecase)FF)rlrmrnrrrsr(r()r'r)rts 6rt) __future__rr collectionsrr functoolsr itertoolsrsixrZsacremoses.corpusrZsacremoses.utilr r sys version_infoiowarningsrCwarnrMrpobjectr rt__all__r(r(r(r)s,     T