delphin.scope¶
Structures and operations for quantifier scope in DELPH-IN semantics.
While the predicate-argument structure of a semantic representation is a directed-acyclic graph, the quantifier scope is a tree overlayed on the edges of that graph. In a fully scope-resolved structure, there is one tree spanning the entire graph, but in underspecified representations like MRS, there are multiple subtrees that span the graph nodes but are not all connected together. The components are then connected via qeq constraints which specify a partial ordering for the tree such that quantifiers may float in between the nodes connected by qeqs.
Each node in the scope tree (called a scopal position) may encompass multiple nodes in the predicate-argument graph. Nodes that share a scopal position are said to be in a conjunction.
The dependency representations EDS and DMRS develop the idea of scope representatives (called representative nodes or sometimes heads), whereby a single node is selected from a conjunction to represent the conjunction as a whole.
Classes¶
-
class
delphin.scope.
ScopingSemanticStructure
(top, index, predications, lnk, surface, identifier)[source]¶ Bases:
delphin.sembase.SemanticStructure
A semantic structure that encodes quantifier scope.
This is a base class for semantic representations, namely
MRS
andDMRS
, that distinguish scopal and non-scopal arguments. In addition to the attributes and methods of theSemanticStructure
class, it also includes anindex
which indicates the non-scopal top of the structure,scopes()
for describing the labeled scopes of a structure, andscopal_arguments()
for describing the arguments that select scopes.-
index
¶ The non-scopal top of the structure.
-
Module Functions¶
-
delphin.scope.
conjoin
(scopes, leqs)[source]¶ Conjoin multiple scopes with equality constraints.
- Parameters
scopes – a mapping of scope labels to predications
leqs – a list of pairs of equated scope labels
- Returns
A mapping of the labels to the predications of each conjoined scope. The conjoined scope labels are taken arbitrarily from each equated set).
Example
>>> conjoined = scope.conjoin(mrs.scopes(), [('h2', 'h3')]) >>> {lbl: [p.id for p in ps] for lbl, ps in conjoined.items()} {'h1': ['e2'], 'h2': ['x4', 'e6']}
-
delphin.scope.
descendants
(x, scopes=None)[source]¶ Return a mapping of predication ids to their scopal descendants.
- Parameters
x – an MRS or a DMRS
scopes – a mapping of scope labels to predications
- Returns
A mapping of predication ids to lists of predications that are scopal descendants.
Example
>>> m = mrs.MRS(...) # Kim didn't think that Sandy left. >>> descendants = scope.descendants(m) >>> for id, ds in descendants.items(): ... print(m[id].predicate, [d.predicate for d in ds]) ... proper_q ['named'] named [] neg ['_think_v_1', '_leave_v_1'] _think_v_1 ['_leave_v_1'] _leave_v_1 [] proper_q ['named'] named []
-
delphin.scope.
representatives
(x, priority=None)[source]¶ Find the scope representatives in x sorted by priority.
When predications share a scope, generally one takes another as a non-scopal argument. For instance, the ERG analysis of a phrase like “very old book” has the predicates
_very_x_deg
,_old_a_1
, and_book_n_of
which all share a scope, where_very_x_deg
takes_old_a_1
as itsARG1
and_old_a_1
takes_book_n_of
as itsARG1
. Predications that do not take any other predication within their scope as an argument (as_book_n_of
above does not) are scope representatives.priority is a function that takes a
Predication
object and returns a rank which is used to to sort the representatives for each scope. As the predication alone might not contain enough information for useful sorting, it can be helpful to create a function configured for the input semantic structure x. If priority isNone
, representatives are sorted according to the following criteria:Prefer predications that are quantifiers or instances (type ‘x’)
Prefer eventualities (type ‘e’) over other types
Prefer tensed over untensed eventualities
Finally, prefer prefer those appearing first in x
The definition of “tensed” vs “untensed” eventualities is grammar-specific, but it is used by several large grammars. If a grammar does something different, criterion (3) is ignored. Criterion (4) is not linguistically motivated but is used as a final disambiguator to ensure consistent results.
- Parameters
x – an MRS or a DMRS
priority – a function that maps an EP to a rank for sorting
Example
>>> sent = 'The new chef whose soup accidentally spilled quit.' >>> m = ace.parse(erg, sent).result(0).mrs() >>> # in this example there are 4 EPs in scope h7 >>> _, scopes = m.scopes() >>> [ep.predicate for ep in scopes['h7']] ['_new_a_1', '_chef_n_1', '_accidental_a_1', '_spill_v_1'] >>> # there are 2 representatives for scope h7 >>> reps = scope.representatives(m)['h7'] >>> [ep.predicate for ep in reps] ['_chef_n_1', '_spill_v_1']
Exceptions¶
-
exception
delphin.scope.
ScopeError
(*args, **kwargs)[source]¶ Bases:
delphin.exceptions.PyDelphinException
Raised on invalid scope operations.