delphin.variable

Functions for working with MRS variables.

This module contains functions to inspect the type and identifier of variables (split(), type(), id()) and check if a variable string is well-formed (is_valid()). It additionally has constants for the standard variable types: UNSPECIFIC, INDIVIDUAL, INSTANCE_OR_HANDLE, EVENTUALITY, INSTANCE, and HANDLE. Finally, the VariableFactory class may be useful for tasks like DMRS to MRS conversion for managing the creation of new variables.

Variables in MRS

Variables are a concept in Minimal Recursion Semantics coming from formal semantics. Consider this logical form for a sentence like “the dog barks”:

∃x(dog(x) ^ bark(x))

Here x is a variable that represents an entity that has the properties that it is a dog and it is barking. Davidsonian semantics introduce variables for events as well:

∃e∃x(dog(x) ^ bark(e, x))

MRS uses variables in a similar way to Davidsonian semantics, except that events are not explicitly quantified. That might look like the following (if we ignore quantifier scope underspecification):

the(x4) [dog(x4)] {bark(e2, x4)}

“Variables” are also used for scope handles and labels, as in this minor modification that indicates the scope handles:

h3:the(x4) [h6:dog(x4)] {h1:bark(e2, x4)}

There is some confusion of terminology here. Sometimes “variable” is contrasted with “handle” to mean an instance (x) or eventuality (e) variable, but in this module “variable” means the identifiers used for instances, eventualities, handles, and their supertypes.

The form of MRS variables is the concatenation of a variable type (also called a sort) with a variable id. For example, the variable type e and id 2 form the variable e2. Generally in MRS the variable ids, regardless of the type, are unique, so for instance one would not see x2 and e2 in the same structure.

The variable types are arranged in a hierarchy. While the most accurate variable type hierarchy for a particular grammar is obtained via its SEM-I (see delphin.semi), in practice the standard hierarchy given below is used by all DELPH-IN grammars. The hierarchy in TDL would look like this (with an ASCII rendering in comments on the right):

u := *top*.  ;     u
i := u.      ;    / \
p := u.      ;   i   p
e := i.      ;  / \ / \
x := i & p.  ; e   x   h
h := p.

In PyDelphin the equivalent hierarchy could be created as follows with a delphin.hierarchy.MultiHierarchy:

>>> from delphin import hierarchy
>>> h = hierarchy.MultiHierarchy(
...     '*top*',
...     {'u': '*top*',
...      'i': 'u',
...      'p': 'u',
...      'e': 'i',
...      'x': 'i p',
...      'h': 'p'}
... )

Module Constants

delphin.variable.UNSPECIFIC

u – The unspecific (or unbound) top-level variable type.

delphin.variable.INDIVIDUAL

i – The variable type that generalizes over eventualities and instances.

delphin.variable.INSTANCE_OR_HANDLE

p – The variable type that generalizes over instances and handles.

delphin.variable.EVENTUALITY

e – The variable type for events and other eventualities (adjectives, adverbs, prepositions, etc.).

delphin.variable.INSTANCE

x – The variable type for instances and nominal things.

delphin.variable.HANDLE

h – The variable type for scope handles and labels.

Module Functions

delphin.variable.split(var)[source]

Split a valid variable string into its variable type and id.

Examples

>>> variable.split('h3')
('h', '3')
>>> variable.split('ref-ind12')
('ref-ind', '12')
delphin.variable.type(var)[source]

Return the type (i.e., sort) of a valid variable string.

sort() is an alias for type().

Examples

>>> variable.type('h3')
'h'
>>> variable.type('ref-ind12')
'ref-ind'
delphin.variable.sort(var)

sort() is an alias for type().

delphin.variable.id(var)[source]

Return the integer id of a valid variable string.

Examples

>>> variable.id('h3')
3
>>> variable.id('ref-ind12')
12
delphin.variable.is_valid(var)[source]

Return True if var is a valid variable string.

Examples

>>> variable.is_valid('h3')
True
>>> variable.is_valid('ref-ind12')
True
>>> variable.is_valid('x')
False

Classes

class delphin.variable.VariableFactory(starting_vid=1)[source]

Simple class to produce variables by incrementing the variable id.

This class is intended to be used when creating an MRS from a variable-less representation like DMRS where the variable types are known but no variable id is assigned.

Parameters

starting_vid (int) – the id of the first variable

vid

the id of the next variable produced by new()

Type

int

index

a mapping of ids to variables

Type

dict

store

a mapping of variables to associated properties

Type

dict

new(type, properties=None)[source]

Create a new variable for the given type.

Parameters
  • type (str) – the type of the variable to produce

  • properties (list) – properties to associate with the variable

Returns

A (variable, properties) tuple