Coverage for nltk.sem.cooper_storage : 56%
![](keybd_closed.png)
Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# Natural Language Toolkit: Cooper storage for Quantifier Ambiguity # # Copyright (C) 2001-2012 NLTK Project # Author: Ewan Klein <ewan@inf.ed.ac.uk> # URL: <http://www.nltk.org/> # For license information, see LICENSE.TXT
""" A container for handling quantifier ambiguity via Cooper storage. """ """ :param featstruct: The value of the ``sem`` node in a tree from ``parse_with_bindops()`` :type featstruct: FeatStruct (with features ``core`` and ``store``)
""" except KeyError: print("%s is not a Cooper storage structure" % featstruct)
""" :return: An iterator over the permutations of the input list :type lst: list :rtype: iter """
""" 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) """ # we just want the arguments that are wrapped by the 'bo' predicate # use var to make an abstraction over the current term and then # apply the quantifier to it
""" Use a grammar with Binding Operators to parse a sentence. """ grammar = 'grammars/book_grammars/storage.fcfg' # Parse the sentence.
from nltk.sem import cooper_storage as cs sentence = "every girl chases a dog" #sentence = "a man gives a bone to every dog" print() print("Analyis of sentence '%s'" % sentence) print("=" * 50) trees = cs.parse_with_bindops(sentence, trace=0) for tree in trees: semrep = cs.CooperStore(tree.node['SEM']) print() print("Binding operators:") print("-" * 15) for s in semrep.store: print(s) print() print("Core:") print("-" * 15) print(semrep.core) print() print("S-Retrieval:") print("-" * 15) semrep.s_retrieve(trace=True) print("Readings:") print("-" * 15)
for i, reading in enumerate(semrep.readings): print("%s: %s" % (i+1, reading))
demo() |