ó ¥%zSc@s¹dZddlmZddlTddlTddlTddlTddlTddlTddl Tddl Tddl m Z m Z ddlTddlmZddlZdd d„ƒYZdS( t 17dec2013iÿÿÿÿ(tetree(t*(tCdependency_extractortCconstituency_extractor(t CreferencesNt KafNafParsercBs1eZd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Z d„Z d „Z d „Z d „Z d „Zd „Zd„Zd„Zejd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd d„Z!d„Z"d„Z#d„Z$RS(!c Csd|_||_tj|tjdtƒƒ|_|jjƒ|_|jj |_ d|_ d|_ d|_ d|_d|_d|_d|_d|_d|_d|_d|_d|_d|_|jjdƒ|_|jjdƒ|_|j dkr|jjdƒ}n$|j dkr;|jjdƒ}n|dk r_t||j ƒ|_ n|jjdƒ}|dk r›td |d |j ƒ|_ n|jjd ƒ}|dk r×td |d |j ƒ|_ n|jjd ƒ}|dk rt|d |j ƒ|_n|jjd ƒ}|dk rIt |d |j ƒ|_n|jjdƒ}|dk r‚t!|d |j ƒ|_n|jjdƒ}|dk r²t"|ƒ|_n|jjdƒ} | dk rât#| ƒ|_n|jjdƒ} | dk rt$| d |j ƒ|_ndS(Ntremove_blank_texts*{http://www.w3.org/XML/1998/namespace}langtversiontNAFt nafHeadertKAFt kafHeaderttexttnodettypettermstentitiestfeaturestopinionst constituencytdepst coreferences(%tNonettreetfilenameRtparset XMLParsertTruetgetroottrootttagRtheadert text_layert term_layert entity_layertfeatures_layert opinion_layertconstituency_layertdependency_layertcoreference_layertmy_dependency_extractortmy_constituency_extractortdict_tokens_for_tidtterms_for_tokentgettlangRtfindtCHeadertCtexttCtermst Centitiest Cfeaturest Copinionst Cconstituencyt Cdependenciest Ccoreferences( tselfRt node_headert node_textt node_termt node_entityt node_featurest node_opinionstnode_constituencytnode_dependencytnode_coreferences((s9/tmp/tmphMOK1S/lib/python/KafNafParser/KafNafParserMod.pyt__init__$sd  !                      cCs|jS(N(R(R9((s9/tmp/tmphMOK1S/lib/python/KafNafParser/KafNafParserMod.pytget_typemscCs|jS(N(R(R9((s9/tmp/tmphMOK1S/lib/python/KafNafParser/KafNafParserMod.pyt get_filenamepscCsB|jdkr'd|j_d|_n|jdk rF|jjƒn|jdk re|jjƒn|jdk r„|jjƒn|jdk r£|jjƒn|j dk rÂ|j jƒn|j dk rá|j jƒn|j dk r|j jƒn|j dk r|j jƒn|j dk r>|j jƒndS(NR R (RRRR Rtto_kafR!R"R#R$R%R&R'R((R9((s9/tmp/tmphMOK1S/lib/python/KafNafParser/KafNafParserMod.pyRFss*  cCs@|jdkr%d|j_|_n|jdk rD|jjƒn|jdk rc|jjƒn|jdk r‚|jjƒn|jdk r¡|jjƒn|j dk rÀ|j jƒn|j dk rß|j jƒn|j dk rþ|j jƒn|j dk r|j jƒn|j dk r<|j jƒndS(NR R (RRRR Rtto_nafR!R"R#R$R%R&R'R((R9((s9/tmp/tmphMOK1S/lib/python/KafNafParser/KafNafParserMod.pyRG£s(cCs |jGHdS(N(R&(R9((s9/tmp/tmphMOK1S/lib/python/KafNafParser/KafNafParserMod.pytprint_constituencyÖsccs5|jdk r1x|jjƒD] }|VqWndS(N(R&Rt get_trees(R9R((s9/tmp/tmphMOK1S/lib/python/KafNafParser/KafNafParserMod.pyRIÙsccs5|jdk r1x|jjƒD] }|VqWndS(N(R'Rtget_dependencies(R9tdep((s9/tmp/tmphMOK1S/lib/python/KafNafParser/KafNafParserMod.pyRJßscCs|jS(N(R.(R9((s9/tmp/tmphMOK1S/lib/python/KafNafParser/KafNafParserMod.pyt get_languageäsccsx|jD] }|Vq WdS(N(R!(R9ttoken((s9/tmp/tmphMOK1S/lib/python/KafNafParser/KafNafParserMod.pyt get_tokensçsccs/|jdk r+x|jD] }|VqWndS(N(R"R(R9tterm((s9/tmp/tmphMOK1S/lib/python/KafNafParser/KafNafParserMod.pyt get_termsëscCs'|jdk r|jj|ƒSdSdS(N(R!Rtget_wf(R9ttoken_id((s9/tmp/tmphMOK1S/lib/python/KafNafParser/KafNafParserMod.pyt get_tokenðscCs'|jdk r|jj|ƒSdSdS(N(R"Rtget_term(R9tterm_id((s9/tmp/tmphMOK1S/lib/python/KafNafParser/KafNafParserMod.pyRTösccs5|jdk r1x|jjƒD] }|VqWndS(N(R$Rtget_properties(R9tproperty((s9/tmp/tmphMOK1S/lib/python/KafNafParser/KafNafParserMod.pyRVüsccs/|jdk r+x|jD] }|VqWndS(N(R#R(R9tentity((s9/tmp/tmphMOK1S/lib/python/KafNafParser/KafNafParserMod.pyt get_entitiessccs5|jdk r1x|jjƒD] }|VqWndS(N(R%Rt get_opinions(R9topinion((s9/tmp/tmphMOK1S/lib/python/KafNafParser/KafNafParserMod.pyRZscCs&|jj|dddtdtƒdS(NtencodingsUTF-8t pretty_printtxml_declaration(RtwriteR(R9R((s9/tmp/tmphMOK1S/lib/python/KafNafParser/KafNafParserMod.pytdump scCsg|jdk rA|jjƒ}|jj|ƒd|_|_n|jdk rc|jjdƒndS(NR(R'Rtget_nodeRtremoveR)R t remove_lp(R9t this_node((s9/tmp/tmphMOK1S/lib/python/KafNafParser/KafNafParserMod.pytremove_dependency_layers cCs&|jdk r"|jj|ƒndS(N(R%Rtremove_this_opinion(R9t opinion_id((s9/tmp/tmphMOK1S/lib/python/KafNafParser/KafNafParserMod.pyRfscCs`|jdk r:|jjƒ}|jj|ƒd|_n|jdk r\|jjdƒndS(NR(R%RRaRRbR Rc(R9Rd((s9/tmp/tmphMOK1S/lib/python/KafNafParser/KafNafParserMod.pytremove_opinion_layers  cCsE|jdk r|jjƒn|jdk rA|jjdƒndS(NR(R$Rtremove_propertiesR Rc(R9((s9/tmp/tmphMOK1S/lib/python/KafNafParser/KafNafParserMod.pyRi&scCs‚|jdk r\|jjƒ}|jj|ƒd|_|jdk r\|jjdƒq\n|jdk r~|jjdƒndS(NR(R"RRaRRbR Rc(R9Rd((s9/tmp/tmphMOK1S/lib/python/KafNafParser/KafNafParserMod.pytremove_term_layer-s cCs?|jdk r7|jdkr0t|ƒ|_n|jSdSdS(N(R&RR*R(R9((s9/tmp/tmphMOK1S/lib/python/KafNafParser/KafNafParserMod.pytget_constituency_extractor:s cCs?|jdk r7|jdkr0t|ƒ|_n|jSdSdS(N(R'RR)R(R9((s9/tmp/tmphMOK1S/lib/python/KafNafParser/KafNafParserMod.pytget_dependency_extractorBs cCsT|jdkr@td|jƒ|_|jj|jjƒƒn|jj|ƒdS(NR(R!RR1RRtappendRatadd_wf(R9twf_obj((s9/tmp/tmphMOK1S/lib/python/KafNafParser/KafNafParserMod.pyRnKscCsK|jdkr7tƒ|_|jj|jjƒƒn|jj|ƒdS(N(R%RR5RRmRat add_opinion(R9t opinion_obj((s9/tmp/tmphMOK1S/lib/python/KafNafParser/KafNafParserMod.pyRpQs cCs|jj||ƒdS(N(R tadd_linguistic_processor(R9tlayertmy_lp((s9/tmp/tmphMOK1S/lib/python/KafNafParser/KafNafParserMod.pyRrWscCsK|jdkr7tƒ|_|jj|jjƒƒn|jj|ƒdS(N(R'RR7RRmRatadd_dependency(R9tmy_dep((s9/tmp/tmphMOK1S/lib/python/KafNafParser/KafNafParserMod.pyRu[s cCsZ|jdkr@td|jƒ|_|jj|jjƒƒn|jj|||ƒdS(NR(R$RR4RRRmRat add_property(R9tlabelt term_spantpid((s9/tmp/tmphMOK1S/lib/python/KafNafParser/KafNafParserMod.pyRwbscCsd|jdkrQi|_x6|jƒD]%}|jƒjƒ|j|jƒs