delphin.tfs

Basic classes for modeling feature structures.

This module defines the FeatureStructure and TypedFeatureStructure classes, which model an attribute value matrix (AVM), with the latter including an associated type. They allow feature access through TDL-style dot notation regular dictionary keys.

In addition, the TypeHierarchy class implements a multiple-inheritance hierarchy with checks for type subsumption and compatibility.

class delphin.tfs.FeatureStructure(featvals=None)[source]

A feature structure.

This class manages the access of nested features using dot-delimited notation (e.g., SYNSEM.LOCAL.CAT.HEAD).

Parameters:featvals (dict, list) – a mapping or iterable of feature paths to feature values
features(expand=False)[source]

Return the list of tuples of feature paths and feature values.

Parameters:expand (bool) – if True, expand all feature paths

Example

>>> fs = FeatureStructure([('A.B', 1), ('A.C', 2)])
>>> fs.features()
[('A', <FeatureStructure object at ...>)]
>>> fs.features(expand=True)
[('A.B', 1), ('A.C', 2)]
get(key, default=None)[source]

Return the value for key if it exists, otherwise default.

class delphin.tfs.TypeHierarchy(top, hierarchy=None)[source]

A Type Hierarchy.

Type hierarchies have certain properties, such as a unique top node, multiple inheritance, and unique greatest-lower-bound (glb) types.

Note

Checks for unique glbs is not yet implemented.

Parameters:
  • top (str) – unique top type
  • hierarchy (dict) – mapping of {child: [parents]}
ancestors(typename)[source]

Return the ancestor types of typename.

compatible(a, b)[source]

Return True if type a is compatible with type b.

descendants(typename)[source]

Return the descendant types of typename.

subsumes(a, b)[source]

Return True if type a subsumes type b.

class delphin.tfs.TypedFeatureStructure(type, featvals=None)[source]

A typed FeatureStructure.

Parameters:
  • type (str) – type name
  • featvals (dict, list) – a mapping or iterable of feature paths to feature values