ó i;sSc@s†dZddlmZddlmZddlmZddlmZm Z ddl m Z ddl m Z d efd „ƒYZd S( s'Josu Bermudez i(tSyntacticTreeUtils(t GraphWrapper(tGenderNumberExtractor(tpronounst stopwords(tner_tagsiÿÿÿÿ(t getLoggertSievecBsVeZdZeZeZeZeZe j e j e j gZed„eDƒƒZ d„Zd„Zd„Zd„Zd„Zd„Zed„ƒZd „Zd „Zed „Zd „Zed „ƒZed„ƒZed„ƒZed„ƒZed„ƒZ ed„ƒZ!d„Z"d„Z#d„Z$d„Z%ed„ƒZ&d„Z'RS(tXXXccs|] }|VqdS(N((t.0tx((s$corefgraph/multisieve/sieves/base.pys scCsytdƒ|_||_|jj|_tj|jdƒ|_||_td|jƒ|_ d|k|_ g|_ dS(Ntsievest graph_buildertgraphtNO_DISCOURSE_SALIENCE( Rtloggertmulti_sieve_processorR Rtget_graph_propertyR toptionsRt tree_utilst discoursetclusters(tselfRR((s$corefgraph/multisieve/sieves/base.pyt__init__ s  cCsø|d|kr(|jd|dƒtS|drY|j|ƒrY|jd|dƒtS|djƒdkr¢|jj||ƒdkr¢|jd|dƒtS|jj|d |d ƒsÜ|jj|d |d ƒrô|jd |dƒtStS( Ntids-LINK FILTERED already linked. Candidate: -%s-tformtgenerics0LINK FILTERED Generic Candidate. Candidate: -%s-tthisis+LINK FILTERED too far this. Candidate: -%s-tspans%LINK FILTERED Inside. Candidate: -%s-(tdebugtFalsetis_youtlowerR tsentence_distancet is_insidetTrue(Rtentitytmentiont candidate((s$corefgraph/multisieve/sieves/base.pytare_coreferent*s$    1    cCsZg}d}xG|D]?}|j|jj|d|ƒr|d7}|j|ƒqqW|S(Nit mention_indexi(tvalidateR tnodetappend(RR$tmentionsR(R%((s$corefgraph/multisieve/sieves/base.pyt valid_mentionCs  c CsR|jr-|dkr-|jd|dƒtS|jr]|j|ƒr]|jd|dƒtS|jd|ƒr‡|jd|dƒtS|dr©|jd|dƒtS|jrã|djƒtj krã|jd |dƒtS|j rN|j |ƒr|jd |dƒtS|d  rN|d  rN|d rN|jd|dƒtSnt S(Nis"MENTION FILTERED Not first one: %sRs!MENTION FILTERED Is a pronoun: %sR%s'MENTION FILTERED is a narrative you: %sRsMENTION FILTERED is generic: %ss#MENTION FILTERED is a stop word: %ss!MENTION FILTERED is undefined: %st appositivetpredicative_nominativetstarted_by_undefined_mentions*MENTION FILTERED starts with undefined: %s( tONLY_FIRST_MENTIONRRt NO_PRONOUNt is_pronount narrative_yout NO_STOP_WORDSR Rt stop_wordstDISCOURSE_SALIENCEt is_undefinedR#(RR%R(((s$corefgraph/multisieve/sieves/base.pyR)Os0 "  c sìd}xß|D]×}|d}xº||D]®}x›|D]“}||kr5xI|D]A}||krN|j|ƒ||cˆjd||7s(R+t sort_nametsort( RRt registerstindexR$t forward_indext new_entityR%t new_mention((Rs$corefgraph/multisieve/sieves/base.pytmergets"       & c CsN||_|jdt|ƒddƒxt|ƒD]\}}|jd|ddƒ|j|ƒ}|jd|ddƒxº|D]²}|jj|}|j|ƒ} |jd|d | |d |d ddƒ|jd ||ddƒxE||D]9} |j|||jj| ƒrõ|j || ƒPqõqõWq€Wq2W|j ||ƒ|S( NsResolving %d clusterstindentisResolving cluster: -%s-isValid mentions: -%s-is$Mention-%s- speaker %s utt %s quo %sRt utterancetquotedscandidates: -%s-( RRtlent enumerateR-R R*tget_speaker_idR't_linkRC( RRtcandidates_per_mentiontregistert cluster_indexR$R,t mention_idR%tspeakerR&((s$corefgraph/multisieve/sieves/base.pytresolves&   cCs|j|ƒdS(N(R+(R$R&((s$corefgraph/multisieve/sieves/base.pyRJ¾scCs*g|jD]}|d|kr |^q S(NR(R(RR%R$((s$corefgraph/multisieve/sieves/base.pytentities_of_a_mentionÆscs?t‡‡fd†|Dƒƒ}d|kr;|jdƒn|S(Nc3s+|]!}ˆjj|jˆdƒVqdS(N(R R*tgettNone(R R%(t property_nameR(s$corefgraph/multisieve/sieves/base.pys Õs(tsetRStremove(RR$RTtcombined_property((RTRs$corefgraph/multisieve/sieves/base.pytentity_propertyÎs   csft‡‡fd†ˆj|ƒDƒƒ}|rbt|ƒdkrbˆj|krb|jˆjƒn|S(Nc3s.|]$}ˆj|ˆƒD] }|VqqdS(N(RX(R tentity_involvedtproperty_value(RTR(s$corefgraph/multisieve/sieves/base.pys åsi(RURQRGtUNKNOWNRV(RR&RTtcleanRW((RTRs$corefgraph/multisieve/sieves/base.pytcandidate_propertyÝs 'cCs0|ddko/|ddko/|jd|ƒS(Ntdoc_typetarticleROtPER0R%(R(RR%((s$corefgraph/multisieve/sieves/base.pyR4íscCs,|djƒ}|tjko+|tjkS(NR(R Rt first_persontsingular(R%R((s$corefgraph/multisieve/sieves/base.pytis_first_personóscCs,|djƒ}|tjko+|tjkS(NR(R RRatplural(R%R((s$corefgraph/multisieve/sieves/base.pytis_weüscCs|djƒtjkS(NR(R Rt second_person(R%((s$corefgraph/multisieve/sieves/base.pyRscCs|ddkS(NR%tpronoun_mention((R%((s$corefgraph/multisieve/sieves/base.pyR3 scCs|ddkS(NR%tundefined_mention((R%((s$corefgraph/multisieve/sieves/base.pyR8scCstj|jdtjƒƒS(Ntner(RtlocationRRtno_ner(R%((s$corefgraph/multisieve/sieves/base.pyt is_locationsc Cs°|j|dƒ}|j|dƒ}|jj|ƒoE|jj|ƒ sg|j|ƒrk|j|ƒrktS|j|dƒ}|j|dƒ}|jj|ƒp°|jj|ƒ sÒ|j|ƒrÖ|j|ƒrÖtS|j|dƒ}|j|dƒ}|jj|ƒp|jj|ƒ s=|j|ƒrA|j|ƒrAtS|j|dƒ} |j|dƒ} |jj| ƒp†|jj| ƒ s¨| j| ƒr¬| j| ƒr¬tStS(NtgendertnumbertanimacyRi(R]RXR[t intersectionRR#( RR$R&tcandidate_gendert entity_gendertcandidate_numbert entity_numbertcandidate_animacytentity_animacyt candidate_nert entity_ner((s$corefgraph/multisieve/sieves/base.pytagree_attributes%s2%%%%cCsÉ|jj||ƒstS|jj|ƒrA|jj|ƒrAtS|jj||ƒsk|jj||ƒrotS|jj||ƒrÅ|jj|d|dƒs¾|jj|d|dƒrÅtSntS(NR(R t same_sentenceRRt is_appositive_construction_childtis_relative_pronounR"R#(Rt mention_at mention_b((s$corefgraph/multisieve/sieves/base.pyt i_within_iNscCsˆ|d}|d}|o|s$tSt|ƒtkrXt|ƒtkrX||krXtS|j||ƒrntS|j||ƒr„tStS(NRO(RttypetstrR#t_check_speaker(RR}R~t speaker_at speaker_b((s$corefgraph/multisieve/sieves/base.pyt same_speakerds   0cCspt|ƒtk r|d}n|jj|ƒd}||krEtSx$|jƒD]}||krRtSqRWtS(NR(R€RR t get_head_wordR#tsplitR(RROR%tmention_head_formt speaker_token((s$corefgraph/multisieve/sieves/base.pyR‚ys   cCs4y|dd}Wntk r/|d}nX|S(NROR(t TypeError(R&RO((s$corefgraph/multisieve/sieves/base.pyRIŠs  cOs9|jjdj|jd|jddƒ|ƒ|ŒdS(Ns {0:5}{1}{2}s RDi(RRtformatR<RR(Rtmessagetargstkwargs((s$corefgraph/multisieve/sieves/base.pyR—s((t__name__t __module__R<R#R1R2R7RR5RR[RRktothert unknown_arrayRURR'R-R)RCRPt staticmethodRJRQRXR]R4RcReRR3R8RlRyRR…R‚RIR(((s$corefgraph/multisieve/sieves/base.pyRs<  % ) !       )    N(t __author__t graph.kafxRt graph.xutilsRtfeatures.grendelRtresources.dictionariesRRtresources.tagsetRtloggingRtobjectR(((s$corefgraph/multisieve/sieves/base.pyts