delphin.mrs.query

Functions for inspecting and interpreting the structure of an Xmrs.

delphin.mrs.query.select_nodeids(xmrs, iv=None, label=None, pred=None)[source]

Return the list of matching nodeids in xmrs.

Nodeids in xmrs match if their corresponding ElementaryPredication object matches its intrinsic_variable to iv, label to label, and pred to pred. The iv, label, and pred filters are ignored if they are None.

Parameters:
  • xmrs (Xmrs) – semantic structure to query
  • iv (str, optional) – intrinsic variable to match
  • label (str, optional) – label to match
  • pred (str, Pred, optional) – predicate to match
Returns:

list – matching nodeids

delphin.mrs.query.select_nodes(xmrs, nodeid=None, pred=None)[source]

Return the list of matching nodes in xmrs.

DMRS nodes for xmrs match if their nodeid matches nodeid and pred matches pred. The nodeid and pred filters are ignored if they are None.

Parameters:
  • xmrs (Xmrs) – semantic structure to query
  • nodeid (optional) – DMRS nodeid to match
  • pred (str, Pred, optional) – predicate to match
Returns:

list – matching nodes

delphin.mrs.query.select_eps(xmrs, nodeid=None, iv=None, label=None, pred=None)[source]

Return the list of matching elementary predications in xmrs.

ElementaryPredication objects for xmrs match if their nodeid matches nodeid, intrinsic_variable matches iv, label matches label, and pred to pred. The nodeid, iv, label, and pred filters are ignored if they are None.

Parameters:
  • xmrs (Xmrs) – semantic structure to query
  • nodeid (optional) – nodeid to match
  • iv (str, optional) – intrinsic variable to match
  • label (str, optional) – label to match
  • pred (str, Pred, optional) – predicate to match
Returns:

list – matching elementary predications

delphin.mrs.query.select_args(xmrs, nodeid=None, rargname=None, value=None)[source]

Return the list of matching (nodeid, role, value) triples in xmrs.

Predication arguments in xmrs match if the nodeid of the ElementaryPredication they are arguments of match nodeid, their role matches rargname, and their value matches value. The nodeid, rargname, and value filters are ignored if they are None.

Note

The value filter matches the variable, handle, or constant that is the overt value for the argument. If you want to find arguments that target a particular nodeid, look into Xmrs.incoming_args(). If you want to match a target value to its resolved object, see find_argument_target().

Parameters:
  • xmrs (Xmrs) – semantic structure to query
  • nodeid (optional) – nodeid to match
  • rargname (str, optional) – role name to match
  • value (str, optional) – argument value to match
Returns:

list – matching arguments as (nodeid, role, value) triples

Return the list of matching links for xmrs.

Link objects for xmrs match if their start matches start, end matches end, rargname matches rargname, and post matches post. The start, end, rargname, and post filters are ignored if they are None.

Parameters:
  • xmrs (Xmrs) – semantic structure to query
  • start (optional) – link start nodeid to match
  • end (optional) – link end nodeid to match
  • rargname (str, optional) – role name to match
  • post (str, optional) – Link post-slash label to match
Returns:

list – matching links

delphin.mrs.query.select_hcons(xmrs, hi=None, relation=None, lo=None)[source]

Return the list of matching HCONS for xmrs.

HandleConstraint objects for xmrs match if their hi matches hi, relation matches relation, and lo matches lo. The hi, relation, and lo filters are ignored if they are None.

Parameters:
  • xmrs (Xmrs) – semantic structure to query
  • hi (str, optional) – hi handle (hole) to match
  • relation (str, optional) – handle constraint relation to match
  • lo (str, optional) – lo handle (label) to match
Returns:

list – matching HCONS

delphin.mrs.query.select_icons(xmrs, left=None, relation=None, right=None)[source]

Return the list of matching ICONS for xmrs.

IndividualConstraint objects for xmrs match if their left matches left, relation matches relation, and right matches right. The left, relation, and right filters are ignored if they are None.

Parameters:
  • xmrs (Xmrs) – semantic structure to query
  • left (str, optional) – left variable to match
  • relation (str, optional) – individual constraint relation to match
  • right (str, optional) – right variable to match
Returns:

list – matching ICONS

delphin.mrs.query.find_argument_target(xmrs, nodeid, rargname)[source]

Return the target of an argument (rather than just the variable).

Note

If the argument value is an intrinsic variable whose target is an EP that has a quantifier, the non-quantifier EP’s nodeid will be returned. With this nodeid, one can then use Xmrs.nodeid() to get its quantifier’s nodeid.

Parameters:
  • xmrs (Xmrs) – semantic structure to use
  • nodeid – nodeid of the argument.
  • rargname – role name of the argument.
Returns:

The object that is the target of the argument. Possible values include:

Argument value e.g. Target
intrinsic variable x4 nodeid; of the EP with the IV
hole variable h0 nodeid; HCONS’s labelset head
label h1 nodeid; label’s labelset head
unbound variable i3 the variable itself
constant ”IBM” the constant itself

delphin.mrs.query.find_subgraphs_by_preds(xmrs, preds, connected=None)[source]

Yield subgraphs matching a list of predicates.

Predicates may match multiple EPs/nodes in the xmrs, meaning that more than one subgraph is possible. Also, predicates in preds match in number, so if a predicate appears twice in preds, there will be two matching EPs/nodes in each subgraph.

Parameters:
  • xmrs (Xmrs) – semantic structure to use
  • preds – iterable of predicates to include in subgraphs
  • connected (bool, optional) – if True, all yielded subgraphs must be connected, as determined by Xmrs.is_connected().
Yields:

A Xmrs object for each subgraphs found.

delphin.mrs.query.intrinsic_variables(xmrs)[source]

Return the list of all intrinsic variables in xmrs

delphin.mrs.query.bound_variables(xmrs)[source]

Return the list of all bound variables in xmrs

delphin.mrs.query.in_labelset(xmrs, nodeids, label=None)[source]

Test if all nodeids share a label.

Parameters:
  • nodeids – iterable of nodeids
  • label (str, optional) – the label that all nodeids must share
Returns:

boolTrue if all nodeids share a label, otherwise False