JL ilddlmZddlmZddlmZmZmZGddZd dZ dZ e d k(re yy) ) load_parser)InstantiateVarsChart)ApplicationExpressionLambdaExpressionVariablec$eZdZdZdZdZddZy) CooperStorezK A container for handling quantifier ambiguity via Cooper storage. c||_g|_ |d|_|d|_y#t$rt d|zYywxYw)z :param featstruct: The value of the ``sem`` node in a tree from ``parse_with_bindops()`` :type featstruct: FeatStruct (with features ``core`` and ``store``) CORESTOREz$%s is not a Cooper storage structureN) featstructreadingscorestoreKeyErrorprint)selfr s ]/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/nltk/sem/cooper_storage.py__init__zCooperStore.__init__sO%  G"6*DI#G,DJ G 8:E F Gs %??c#Kd}|r9t|D]*\}}|j|||D] }|f|z ,ydyw)z{ :return: An iterator over the permutations of the input list :type lst: list :rtype: iter c|d|||dzdzS)N)lst0indexs rz&CooperStore._permute..'sT&5\D4E%ErN) enumerate_permute)rlstremoverxys rrzCooperStore._permute!sY F %cN #qvc5'9:#A$(N# #HsAAc t|j|jD]\}}|rtd|dzz|j}|D]X}t |j \}}t|t|j|}|r td||j}Z|jj|y)aI Carry out S-Retrieval of binding operators in store. If hack=True, serialize the bindop and core as strings and reparse. Ugh. Each permutation of the store (i.e. list of binding operators) is taken to be a possible scoping of quantifiers. We iterate through the binding operators in each permutation, and successively apply them to the current term, starting with the core semantic representation, working from the inside out. Binding operators are of the form:: bo(\P.all x.(man(x) -> P(x)),z1) zPermutation %srz N) rrrrrtupleargsrrvariablesimplifyrappend)rtraceperm store_permtermbindopquantvarexs r s_retrievezCooperStore.s_retrieve/s!*$-- *C D ' D*&$(3499D$ '$V[[1 u-+ENNDA$%}} ' MM  & 'rN)F)__name__ __module__ __qualname____doc__rrr1rrrr r s G 'rr Nc|sd}t||t}|j}t|j |S)zC Use a grammar with Binding Operators to parse a sentence. z#grammars/book_grammars/storage.fcfg)r* chart_class)rrsplitlistparse)sentencegrammarr*parsertokenss rparse_with_bindopsr?Ps; 7 ;O PF ^^ F  V$ %%rcddlm}d}ttd|ztd|j|d}|D]}|j |j d}ttdtd |j D] }t|ttd td t|jttd td |jd td td t|jD]\}}t|dzd|y)Nr)cooper_storagezevery girl chases a dogzAnalysis of sentence '%s'z2==================================================)r*SEMzBinding operators:z---------------zCore:z S-Retrieval:Tz Readings:rz: ) nltk.semrArr?r labelrrr1rr)csr;treestreesemrepsireadings rdemorL\s-(H G % 01 (O  ! !(! ! 4E) U 34  "# h A !H   g h fkk  n h% k h#FOO4 )JAw QUG2gY' ( )%)r__main__)Nr) nltk.parsernltk.parse.featurechartrnltk.sem.logicrrrr r?rLr2rrrrQs>#8LL@'@'F &)> zFr