delphin.mrs.components¶
Classes and functions for working with the components of *MRS objects.
Variables and Predicates¶
-
delphin.mrs.components.
sort_vid_split
(vs)[source]¶ Split a valid variable string into its variable sort and id.
Examples
>>> sort_vid_split('h3') ('h', '3') >>> sort_vid_split('ref-ind12') ('ref-ind', '12')
-
delphin.mrs.components.
var_sort
(v)[source]¶ Return the sort of a valid variable string.
Examples
>>> var_sort('h3') 'h' >>> var_sort('ref-ind12') 'ref-ind'
-
delphin.mrs.components.
var_id
(v)[source]¶ Return the integer id of a valid variable string.
Examples
>>> var_id('h3') 3 >>> var_id('ref-ind12') 12
-
class
delphin.mrs.components.
Pred
[source]¶ A semantic predicate.
Abstract predicates don’t begin with an underscore, and they generally are defined as types in a grammar. Surface predicates always begin with an underscore (ignoring possible quotes), and are often defined as strings in a lexicon.
In PyDelphin, Preds are equivalent if they have the same lemma, pos, and sense, and are both abstract or both surface preds. Other factors are ignored for comparison, such as their being surface-, abstract-, or real-preds, whether they are quoted or not, whether they end with
_rel
or not, or differences in capitalization. Hashed Pred objects (e.g., in a dict or set) also use the normalized form. However, unlike with equality comparisons, Pred-formatted strings are not treated as equivalent in a hash.Parameters: - type – the type of predicate; valid values are Pred.ABSTRACT, Pred.REALPRED, and Pred.SURFACE, although in practice Preds are instantiated via classmethods that select the type
- lemma – the lemma of the predicate
- pos – the part-of-speech; a single, lowercase character
- sense – the (often omitted) sense of the predicate
Returns: a Pred object
-
type
¶ predicate type (Pred.ABSTRACT, Pred.REALPRED, and Pred.SURFACE)
-
lemma
¶ lemma component of the predicate
-
pos
¶ part-of-speech component of the predicate
-
sense
¶ sense component of the predicate
Example
Preds are compared using their string representations. Surrounding quotes (double or single) are ignored, and capitalization doesn’t matter. In addition, preds may be compared directly to their string representations:
>>> p1 = Pred.surface('_dog_n_1_rel') >>> p2 = Pred.realpred(lemma='dog', pos='n', sense='1') >>> p3 = Pred.abstract('dog_n_1_rel') >>> p1 == p2 True >>> p1 == '_dog_n_1_rel' True >>> p1 == p3 False
-
is_quantifier
()[source]¶ Return
True
if the predicate has a quantifier part-of-speech.Deprecated since v0.6.0
-
short_form
()[source]¶ Return the pred string without quotes or a
_rel
suffix.The short form is the same as the normalized form from
normalize_pred_string()
.Example
>>> p = Pred.surface('"_cat_n_1_rel"') >>> p.short_form() '_cat_n_1'
-
delphin.mrs.components.
is_valid_pred_string
(predstr)[source]¶ Return
True
if predstr is a valid predicate string.Examples
>>> is_valid_pred_string('"_dog_n_1_rel"') True >>> is_valid_pred_string('_dog_n_1') True >>> is_valid_pred_string('_dog_noun_1') False >>> is_valid_pred_string('dog_noun_1') True
-
delphin.mrs.components.
normalize_pred_string
(predstr)[source]¶ Normalize the predicate string predstr to a conventional form.
This makes predicate strings more consistent by removing quotes and the
_rel
suffix, and by lowercasing them.Examples
>>> normalize_pred_string('"_dog_n_1_rel"') '_dog_n_1' >>> normalize_pred_string('_dog_n_1') '_dog_n_1'
MRS and RMRS Components¶
-
class
delphin.mrs.components.
ElementaryPredication
[source]¶ An MRS elementary predication (EP).
EPs combine a predicate with various structural semantic properties. They must have a
nodeid
,pred
, andlabel
. Arguments and other properties are optional. Note nodeids are not a formal property of MRS (unlike DMRS, or the “anchors” of RMRS), but they are required for Pydelphin to uniquely identify EPs in anXmrs
. Intrinsic arguments (ARG0
) are not required, but they are important for many semantic operations, and therefore it is a good idea to include them.Parameters: -
nodeid
¶ a nodeid
-
lnk
¶ surface alignment
Type: Lnk
-
carg
¶ The value of the constant argument.
-
intrinsic_variable
¶ The value of the intrinsic argument (likely
ARG0
).
-
iv
¶ A synonym for
ElementaryPredication.intrinsic_variable
-
-
delphin.mrs.components.
elementarypredication
(xmrs, nodeid)[source]¶ Retrieve the elementary predication with the given nodeid.
Parameters: nodeid – nodeid of the EP to return Returns: ElementaryPredication
Raises: KeyError
– if no EP matches
-
delphin.mrs.components.
elementarypredications
(xmrs)[source]¶ Return the list of
ElementaryPredication
objects in xmrs.
DMRS and EDS Components¶
-
class
delphin.mrs.components.
Node
[source]¶ A DMRS node.
Nodes are very simple predications for DMRSs. Nodes don’t have arguments or labels like
ElementaryPredication
objects, but they do have a property for CARGs and contain their variable sort and properties insortinfo
.Parameters: - nodeid – node identifier
- pred (
Pred
) – semantic predicate - sortinfo (dict, optional) – mapping of morphosyntactic
properties and values; the
cvarsort
property is specified in this mapping - lnk (
Lnk
, optional) – surface alignment - surface (str, optional) – surface string
- base (str, optional) – base form
- carg (str, optional) – constant argument string
-
Attributes
¶
-
sortinfo
¶ mapping of morphosyntactic properties and values; the
cvarsort
property is specified in this mappingType: dict
-
lnk
¶ surface alignment
Type: Lnk
-
cvarsort
¶ The “variable” type of the predicate.
Note
DMRS does not use variables, but it is useful to indicate whether a node is an individual, eventuality, etc., so this property encodes that information.
-
class
delphin.mrs.components.
Link
[source]¶ DMRS-style dependency link.
Links are a way of representing arguments without variables. A Link encodes a start and end node, the role name, and the scopal relationship between the start and end (e.g. label equality, qeq, etc).
Parameters: -
start
¶ nodeid of the start of the Link
-
end
¶ nodeid of the end of the Link
-