ó <¿CVc@s”ddlmZddlmZmZmZddlmZddlm Z de fd„ƒYZ d dd„Z d „Zed kreƒnd S( iÿÿÿÿ(tprint_function(tLambdaExpressiontApplicationExpressiontVariable(t load_parser(tInstantiateVarsChartt CooperStorecBs,eZdZd„Zd„Zed„ZRS(sK A container for handling quantifier ambiguity via Cooper storage. cCsV||_g|_y|d|_|d|_Wntk rQtd|ƒnXdS(sà :param featstruct: The value of the ``sem`` node in a tree from ``parse_with_bindops()`` :type featstruct: FeatStruct (with features ``core`` and ``store``) tCOREtSTOREs$%s is not a Cooper storage structureN(t featstructtreadingstcoretstoretKeyErrortprint(tselfR ((si/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/sem/cooper_storage.pyt__init__s    ccsgd„}|r^xQt|ƒD];\}}x,|j|||ƒƒD]}|f|VqAWqWndVdS(s{ :return: An iterator over the permutations of the input list :type lst: list :rtype: iter cSs|| ||dS(Ni((tlst0tindex((si/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/sem/cooper_storage.pyt&sN((t enumeratet_permute(RtlsttremoveRtxty((si/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/sem/cooper_storage.pyR s  cCsÄx½t|j|jƒƒD]£\}}|r@td|dƒn|j}x`|D]X}t|jƒ\}}t|t|j |ƒƒ}|rœtd|ƒn|j ƒ}qPW|j j |ƒqWdS(sI 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) sPermutation %sis N( RRR RR ttupletargsRRtvariabletsimplifyR tappend(Rttracetpermt store_permttermtbindoptquanttvarex((si/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/sem/cooper_storage.pyt s_retrieve-s%  (t__name__t __module__t__doc__RRtFalseR&(((si/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/sem/cooper_storage.pyR s  icCsF|sd}nt|d|dtƒ}|jƒ}t|j|ƒƒS(sC Use a grammar with Binding Operators to parse a sentence. s#grammars/book_grammars/storage.fcfgRt chart_class(RRtsplittlisttparse(tsentencetgrammarRtparserttokens((si/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/sem/cooper_storage.pytparse_with_bindopsLs   cCsTddlm}d}tƒtd|ƒtddƒ|j|ddƒ}xÿ|D]÷}|j|jƒd ƒ}tƒtd ƒtdƒx|jD]}t|ƒq™Wtƒtd ƒtdƒt|jƒtƒtdƒtdƒ|jdt ƒtdƒtdƒx5t |j ƒD]$\}}td|d|fƒq$WqUWdS(Niÿÿÿÿ(tcooper_storagesevery girl chases a dogsAnalyis of sentence '%s't=i2RitSEMsBinding operators:t-isCore:s S-Retrieval:s Readings:s%s: %sis---------------s---------------s---------------s---------------( tnltk.semR4RR3RtlabelR R R&tTrueRR (tcsR/ttreesttreetsemreptstitreading((si/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/sem/cooper_storage.pytdemoXs2          t__main__N(t __future__Rtnltk.sem.logicRRRt nltk.parseRtnltk.parse.featurechartRtobjectRtNoneR3RBR'(((si/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/sem/cooper_storage.pyts?