Skip to content

glazing.verbnet.models

VerbNet core data models.

models

VerbNet core data models.

This module implements VerbNet verb classes, members, thematic roles, selectional restrictions, and frame models with support for role inheritance hierarchies.

CLASS DESCRIPTION
SelectionalRestriction

Single selectional restriction on a thematic role.

SelectionalRestrictions

Container for selectional restrictions with logical operators.

ThematicRole

Thematic role with selectional restrictions.

WordNetCrossRef

Cross-reference to WordNet from VerbNet.

VerbNetFrameNetRoleMapping

Role-level mapping between VerbNet and FrameNet.

VerbNetFrameNetMapping

VerbNet to FrameNet mapping with confidence.

MappingMetadata

Metadata for cross-dataset mappings.

Member

VerbNet member with cross-references.

VerbClass

A VerbNet verb class with members and frames.

VNFrame

Syntactic-semantic frame pattern.

FrameDescription

Frame syntactic pattern description.

Example

Frame example sentence.

Syntax

Syntactic structure of a frame.

SyntaxElement

Element in syntactic structure.

SyntacticRestriction

Syntactic restriction on an element.

Semantics

Semantic representation of a frame.

Predicate

Semantic predicate in frame representation.

PredicateArgument

Argument to a semantic predicate.

Examples:

>>> from glazing.verbnet.models import VerbClass, Member, ThematicRole
>>> verb_class = VerbClass(
...     id="give-13.1",
...     members=[],
...     themroles=[],
...     frames=[],
...     subclasses=[]
... )
>>> print(verb_class.id)
'give-13.1'

Classes

Example pydantic-model

Bases: GlazingBaseModel

Frame example sentence.

ATTRIBUTE DESCRIPTION
text

The example sentence text.

TYPE: str

Examples:

>>> example = Example(text="John gave Mary a book")

Fields:

  • text (str)

FrameDescription pydantic-model

Bases: GlazingBaseModel

Frame syntactic pattern description.

ATTRIBUTE DESCRIPTION
description_number

The description number (e.g., "0.2", "2.5.1").

TYPE: DescriptionNumber

primary

Raw primary pattern string.

TYPE: str

secondary

Raw secondary pattern string.

TYPE: str

xtag

XTag reference (usually empty, sometimes "0.1", "0.2", or preposition patterns).

TYPE: str, default=""

primary_elements

Computed list of primary pattern elements.

TYPE: list[str], default=[]

secondary_patterns

Computed list of secondary patterns.

TYPE: list[str], default=[]

Examples:

>>> desc = FrameDescription(
...     description_number="0.2",
...     primary="NP V NP",
...     secondary="Basic Transitive"
... )

Fields:

  • description_number (DescriptionNumber)
  • primary (str)
  • secondary (str)
  • xtag (str)
  • primary_elements (list[str])
  • secondary_patterns (list[str])

Validators:

Functions
model_post_init(_: dict[str, str | int | float | bool] | None) -> None

Parse primary and secondary patterns after initialization.

Source code in src/glazing/verbnet/models.py
def model_post_init(self, _: dict[str, str | int | float | bool] | None) -> None:
    """Parse primary and secondary patterns after initialization."""
    # Parse primary pattern into elements
    if self.primary:
        self.primary_elements = self.primary.split()

    # Parse secondary pattern (can be semicolon-separated)
    if self.secondary:
        if ";" in self.secondary:
            self.secondary_patterns = [p.strip() for p in self.secondary.split(";")]
        else:
            self.secondary_patterns = [self.secondary.strip()] if self.secondary.strip() else []
validate_description_number(v: str) -> DescriptionNumber pydantic-validator

Validate description number format.

PARAMETER DESCRIPTION
v

Description number to validate.

TYPE: str

RETURNS DESCRIPTION
str

Validated description number.

RAISES DESCRIPTION
ValueError

If description number format is invalid.

Source code in src/glazing/verbnet/models.py
@field_validator("description_number")
@classmethod
def validate_description_number(cls, v: str) -> DescriptionNumber:
    """Validate description number format.

    Parameters
    ----------
    v : str
        Description number to validate.

    Returns
    -------
    str
        Validated description number.

    Raises
    ------
    ValueError
        If description number format is invalid.
    """
    if v and not re.match(r"^[0-9]+(?:\.[0-9]+)*$", v):
        msg = f"Invalid description number format: {v}"
        raise ValueError(msg)
    return v
validate_xtag(v: str) -> str pydantic-validator

Validate xtag format.

PARAMETER DESCRIPTION
v

XTag value to validate.

TYPE: str

RETURNS DESCRIPTION
str

Validated xtag value.

Source code in src/glazing/verbnet/models.py
@field_validator("xtag")
@classmethod
def validate_xtag(cls, v: str) -> str:
    """Validate xtag format.

    Parameters
    ----------
    v : str
        XTag value to validate.

    Returns
    -------
    str
        Validated xtag value.
    """
    if v and not re.match(r"^([0-9]+(?:\.[0-9]+)?|[a-z/]+-PP)?$", v):
        # Don't fail validation, just log unusual values
        pass
    return v

Member pydantic-model

Bases: GlazingBaseModel

VerbNet member with cross-references.

ATTRIBUTE DESCRIPTION
name

Lemma form (validated).

TYPE: str

verbnet_key

Unique identifier with sense.

TYPE: VerbNetKey

framenet_mappings

FrameNet mappings with confidence.

TYPE: list[VerbNetFrameNetMapping], default=[]

propbank_mappings

PropBank roleset mappings.

TYPE: list[CrossReference], default=[]

wordnet_mappings

WordNet sense mappings.

TYPE: list[WordNetCrossRef], default=[]

features

Semantic features.

TYPE: dict[str, str], default={}

mapping_metadata

Metadata about mappings.

TYPE: MappingMetadata | None, default=None

inherited_from_class

If inherited from parent class.

TYPE: VerbClassID | None, default=None

METHOD DESCRIPTION
get_primary_framenet_frame

Get highest confidence FrameNet frame.

get_all_framenet_frames

Get all FrameNet frames with confidence scores.

get_wordnet_senses

Get WordNet senses in percentage notation.

get_propbank_rolesets

Get PropBank roleset IDs.

has_mapping_conflicts

Check if there are conflicting high-confidence mappings.

Examples:

>>> member = Member(
...     name="give",
...     verbnet_key="give#2",
...     framenet_mappings=[],
...     propbank_mappings=[],
...     wordnet_mappings=[]
... )
>>> print(member.verbnet_key)
'give#2'

Fields:

Validators:

Attributes
features: dict[str, str] pydantic-field

Semantic features

framenet_mappings: list[VerbNetFrameNetMapping] pydantic-field

FrameNet mappings with confidence

name: str pydantic-field

Lemma form

propbank_mappings: list[CrossReference] pydantic-field

PropBank roleset mappings

verbnet_key: VerbNetKey pydantic-field

Unique identifier with sense

wordnet_mappings: list[WordNetCrossRef] pydantic-field

WordNet sense mappings

Functions
get_all_framenet_frames() -> list[tuple[str, float | None]]

Get all FrameNet frames with confidence scores.

RETURNS DESCRIPTION
list[tuple[str, float | None]]

List of (frame_name, confidence_score) tuples.

Source code in src/glazing/verbnet/models.py
def get_all_framenet_frames(self) -> list[tuple[str, float | None]]:
    """Get all FrameNet frames with confidence scores.

    Returns
    -------
    list[tuple[str, float | None]]
        List of (frame_name, confidence_score) tuples.
    """
    frames = []
    for mapping in self.framenet_mappings:
        score = mapping.confidence.score if mapping.confidence else None
        frames.append((mapping.frame_name, score))
    return frames
get_primary_framenet_frame() -> str | None

Get highest confidence FrameNet frame.

RETURNS DESCRIPTION
str | None

Frame name or None if no mappings.

Source code in src/glazing/verbnet/models.py
def get_primary_framenet_frame(self) -> str | None:
    """Get highest confidence FrameNet frame.

    Returns
    -------
    str | None
        Frame name or None if no mappings.
    """
    if not self.framenet_mappings:
        return None
    best = max(
        self.framenet_mappings,
        key=lambda m: m.confidence.score if m.confidence else 0.0,
        default=None,
    )
    return best.frame_name if best else None
get_propbank_rolesets() -> list[str]

Get PropBank roleset IDs.

RETURNS DESCRIPTION
list[str]

List of PropBank roleset IDs.

Source code in src/glazing/verbnet/models.py
def get_propbank_rolesets(self) -> list[str]:
    """Get PropBank roleset IDs.

    Returns
    -------
    list[str]
        List of PropBank roleset IDs.
    """
    result: list[str] = []
    for m in self.propbank_mappings:
        if m.target_dataset == "propbank":
            if isinstance(m.target_id, list):
                result.extend(m.target_id)
            else:
                result.append(m.target_id)
    return result
get_wordnet_senses() -> list[str]

Get WordNet senses in percentage notation.

RETURNS DESCRIPTION
list[str]

List of percentage notation strings.

Source code in src/glazing/verbnet/models.py
def get_wordnet_senses(self) -> list[str]:
    """Get WordNet senses in percentage notation.

    Returns
    -------
    list[str]
        List of percentage notation strings.
    """
    return [
        m.to_percentage_notation() for m in self.wordnet_mappings if m.to_percentage_notation()
    ]
has_mapping_conflicts() -> bool

Check if there are conflicting high-confidence mappings.

RETURNS DESCRIPTION
bool

True if multiple high-confidence FrameNet mappings exist.

Source code in src/glazing/verbnet/models.py
def has_mapping_conflicts(self) -> bool:
    """Check if there are conflicting high-confidence mappings.

    Returns
    -------
    bool
        True if multiple high-confidence FrameNet mappings exist.
    """
    high_conf_fn = [
        m for m in self.framenet_mappings if m.confidence and m.confidence.score > 0.7
    ]
    return len(high_conf_fn) > 1
validate_member_name(v: str) -> str pydantic-validator

Validate member name (verb lemma).

PARAMETER DESCRIPTION
v

Member name to validate.

TYPE: str

RETURNS DESCRIPTION
str

Validated member name.

RAISES DESCRIPTION
ValueError

If member name format is invalid.

Source code in src/glazing/verbnet/models.py
@field_validator("name")
@classmethod
def validate_member_name(cls, v: str) -> str:
    """Validate member name (verb lemma).

    Parameters
    ----------
    v : str
        Member name to validate.

    Returns
    -------
    str
        Validated member name.

    Raises
    ------
    ValueError
        If member name format is invalid.
    """
    if not re.match(r"^[a-zA-Z][a-zA-Z0-9_\-\.\s]*$", v):
        msg = f"Invalid member name format: {v}"
        raise ValueError(msg)
    return v
validate_verbnet_key(v: str) -> VerbNetKey pydantic-validator

Validate verbnet_key format.

PARAMETER DESCRIPTION
v

VerbNet key to validate.

TYPE: str

RETURNS DESCRIPTION
str

Validated VerbNet key.

RAISES DESCRIPTION
ValueError

If VerbNet key format is invalid.

Source code in src/glazing/verbnet/models.py
@field_validator("verbnet_key")
@classmethod
def validate_verbnet_key(cls, v: str) -> VerbNetKey:
    """Validate verbnet_key format.

    Parameters
    ----------
    v : str
        VerbNet key to validate.

    Returns
    -------
    str
        Validated VerbNet key.

    Raises
    ------
    ValueError
        If VerbNet key format is invalid.
    """
    if not re.match(VERBNET_KEY_PATTERN, v):
        msg = f"Invalid verbnet_key format: {v}"
        raise ValueError(msg)
    return v

Predicate pydantic-model

Bases: GlazingBaseModel

Semantic predicate in frame representation.

ATTRIBUTE DESCRIPTION
value

The predicate type (e.g., "motion", "cause", "transfer").

TYPE: PredicateType

args

Arguments to the predicate.

TYPE: list[PredicateArgument]

negated

Whether the predicate is negated (represents bool="!").

TYPE: bool, default=False

Examples:

>>> pred = Predicate(
...     value="motion",
...     args=[
...         PredicateArgument(type="Event", value="e1"),
...         PredicateArgument(type="ThemRole", value="Agent")
...     ]
... )

Fields:

Validators:

Functions
parse_bool_attr(v: str | bool | int | None) -> bool pydantic-validator

Parse XML bool attribute.

PARAMETER DESCRIPTION
v

Value to parse.

TYPE: str | bool | int | None

RETURNS DESCRIPTION
bool

True if value is "!", False otherwise.

Source code in src/glazing/verbnet/models.py
@field_validator("negated", mode="before")
@classmethod
def parse_bool_attr(cls, v: str | bool | int | None) -> bool:
    """Parse XML bool attribute.

    Parameters
    ----------
    v : str | bool | int | None
        Value to parse.

    Returns
    -------
    bool
        True if value is "!", False otherwise.
    """
    if isinstance(v, str):
        return v == "!"
    return bool(v)

PredicateArgument pydantic-model

Bases: GlazingBaseModel

Argument to a semantic predicate.

ATTRIBUTE DESCRIPTION
type

Type of argument (Event, ThemRole, etc.).

TYPE: ArgumentType

value

Argument value (e.g., "e1", "Agent", "?Theme").

TYPE: str

Examples:

>>> arg = PredicateArgument(type="ThemRole", value="Agent")
>>> event_arg = PredicateArgument(type="Event", value="e1")

Fields:

  • type (ArgumentType)
  • value (str)

Validators:

Functions
validate_arg_value(v: str, info: ValidationInfo) -> str pydantic-validator

Validate argument values based on type.

PARAMETER DESCRIPTION
v

Value to validate.

TYPE: str

info

Validation context.

TYPE: ValidationInfo

RETURNS DESCRIPTION
str

Validated value.

RAISES DESCRIPTION
ValueError

If event variable format is invalid.

Source code in src/glazing/verbnet/models.py
@field_validator("value")
@classmethod
def validate_arg_value(cls, v: str, info: ValidationInfo) -> str:
    """Validate argument values based on type.

    Parameters
    ----------
    v : str
        Value to validate.
    info : ValidationInfo
        Validation context.

    Returns
    -------
    str
        Validated value.

    Raises
    ------
    ValueError
        If event variable format is invalid.
    """
    arg_type = info.data.get("type")
    if arg_type == "Event" and not re.match(r"^[eEë]\d*$", v):
        msg = f"Invalid event variable format: {v}"
        raise ValueError(msg)
    return v

SelectionalRestriction pydantic-model

Bases: GlazingBaseModel

Single selectional restriction.

ATTRIBUTE DESCRIPTION
value

Restriction polarity ("+" or "-").

TYPE: RestrictionValue

type

Type of selectional restriction (e.g., "animate", "concrete").

TYPE: SelectionalRestrictionType

Examples:

>>> restriction = SelectionalRestriction(value="+", type="animate")
>>> print(restriction.type)
'animate'

Fields:

  • value (RestrictionValue)
  • type (SelectionalRestrictionType)

SelectionalRestrictions pydantic-model

Bases: GlazingBaseModel

Container for selectional restrictions with logic.

ATTRIBUTE DESCRIPTION
logic

Logical operator ("or", "and", or None for implicit AND).

TYPE: LogicType | None, default=None

restrictions

List of restrictions or nested restriction groups.

TYPE: list[SelectionalRestriction | SelectionalRestrictions]

METHOD DESCRIPTION
is_complex

Check if this contains nested restrictions.

Examples:

>>> restrictions = SelectionalRestrictions(
...     logic="or",
...     restrictions=[
...         SelectionalRestriction(value="+", type="animate"),
...         SelectionalRestriction(value="+", type="human")
...     ]
... )
>>> print(restrictions.is_complex())
False

Fields:

Attributes
logic: LogicType | None = None pydantic-field

Logical operator for combining restrictions

restrictions: list[SelectionalRestriction | SelectionalRestrictions] pydantic-field

List of restrictions or nested groups

Functions
check_contradiction() -> bool

Check if restrictions contain contradictions.

RETURNS DESCRIPTION
bool

True if contradictions are found (e.g., +animate and -animate).

Source code in src/glazing/verbnet/models.py
def check_contradiction(self) -> bool:
    """Check if restrictions contain contradictions.

    Returns
    -------
    bool
        True if contradictions are found (e.g., +animate and -animate).
    """
    if self.logic == "and" or self.logic is None:
        # For AND logic, check for direct contradictions
        flat = self.flatten_restrictions()
        type_values: dict[SelectionalRestrictionType, RestrictionValue] = {}
        for restriction in flat:
            if restriction.type in type_values:
                if type_values[restriction.type] != restriction.value:
                    return True  # Found contradiction
            else:
                type_values[restriction.type] = restriction.value
    return False
flatten_restrictions() -> list[SelectionalRestriction]

Flatten nested restrictions into a single list.

RETURNS DESCRIPTION
list[SelectionalRestriction]

Flattened list of all restrictions.

Source code in src/glazing/verbnet/models.py
def flatten_restrictions(self) -> list[SelectionalRestriction]:
    """Flatten nested restrictions into a single list.

    Returns
    -------
    list[SelectionalRestriction]
        Flattened list of all restrictions.
    """
    result = []
    for restriction in self.restrictions:
        if isinstance(restriction, SelectionalRestriction):
            result.append(restriction)
        else:
            # Recursively flatten nested restrictions
            result.extend(restriction.flatten_restrictions())
    return result
is_complex() -> bool

Check if this contains nested restrictions.

RETURNS DESCRIPTION
bool

True if any restriction is a SelectionalRestrictions object.

Source code in src/glazing/verbnet/models.py
def is_complex(self) -> bool:
    """Check if this contains nested restrictions.

    Returns
    -------
    bool
        True if any restriction is a SelectionalRestrictions object.
    """
    return any(isinstance(r, SelectionalRestrictions) for r in self.restrictions)
validate_logic_consistency() -> bool

Validate that logic operators are used consistently.

RETURNS DESCRIPTION
bool

True if logic is consistent throughout the structure.

Source code in src/glazing/verbnet/models.py
def validate_logic_consistency(self) -> bool:
    """Validate that logic operators are used consistently.

    Returns
    -------
    bool
        True if logic is consistent throughout the structure.
    """
    if not self.restrictions:
        return True

    # Check that nested restrictions don't conflict
    for restriction in self.restrictions:
        if (
            isinstance(restriction, SelectionalRestrictions)
            and not restriction.validate_logic_consistency()
        ):
            return False
    return True

Semantics pydantic-model

Bases: GlazingBaseModel

Semantic representation of a frame.

ATTRIBUTE DESCRIPTION
predicates

List of semantic predicates.

TYPE: list[Predicate]

Examples:

>>> semantics = Semantics(predicates=[
...     Predicate(
...         value="motion",
...         args=[PredicateArgument(type="Event", value="e1")]
...     )
... ])

Fields:

SyntacticRestriction pydantic-model

Bases: GlazingBaseModel

Syntactic restriction on an element.

ATTRIBUTE DESCRIPTION
type

The type of syntactic restriction.

TYPE: SyntacticRestrictionType

value

The restriction value ("+" or "-").

TYPE: RestrictionValue

Examples:

>>> restriction = SyntacticRestriction(
...     type="be_sc_ing",
...     value="+"
... )

Fields:

  • type (SyntacticRestrictionType)
  • value (RestrictionValue)

Syntax pydantic-model

Bases: GlazingBaseModel

Syntactic structure of a frame.

ATTRIBUTE DESCRIPTION
elements

List of syntactic elements in order.

TYPE: list[SyntaxElement]

Examples:

>>> syntax = Syntax(elements=[
...     SyntaxElement(pos="NP", value="Agent"),
...     SyntaxElement(pos="VERB"),
...     SyntaxElement(pos="NP", value="Theme")
... ])

Fields:

SyntaxElement pydantic-model

Bases: GlazingBaseModel

Element in syntactic structure.

ATTRIBUTE DESCRIPTION
pos

Part of speech (NP, VERB, PREP, ADV, ADJ, LEX, ADVP, S, SBAR).

TYPE: SyntacticPOS

value

Role name or specific preposition values.

TYPE: str | None, default=None

synrestrs

Syntactic restrictions on this element.

TYPE: list[SyntacticRestriction], default=[]

selrestrs

Selectional restrictions (for PREP).

TYPE: list[SelectionalRestriction], default=[]

Examples:

>>> element = SyntaxElement(
...     pos="NP",
...     value="Agent"
... )
>>> prep_element = SyntaxElement(
...     pos="PREP",
...     value="to for at"
... )

Fields:

Validators:

Functions
validate_prep_value(v: str | None, info: ValidationInfo) -> str | None pydantic-validator

Validate preposition values.

PARAMETER DESCRIPTION
v

Value to validate.

TYPE: str | None

info

Validation context.

TYPE: ValidationInfo

RETURNS DESCRIPTION
str | None

Validated value.

RAISES DESCRIPTION
ValueError

If preposition value format is invalid.

Source code in src/glazing/verbnet/models.py
@field_validator("value")
@classmethod
def validate_prep_value(cls, v: str | None, info: ValidationInfo) -> str | None:
    """Validate preposition values.

    Parameters
    ----------
    v : str | None
        Value to validate.
    info : ValidationInfo
        Validation context.

    Returns
    -------
    str | None
        Validated value.

    Raises
    ------
    ValueError
        If preposition value format is invalid.
    """
    if (
        v
        and info.data.get("pos") == "PREP"
        and not re.match(r"^[a-zA-Z_?|\-]+(?:\s[a-zA-Z_?|\-]+)*$", v)
    ):
        msg = f"Invalid preposition value format: {v}"
        raise ValueError(msg)
    return v

ThematicRole pydantic-model

Bases: GlazingBaseModel

Thematic role with selectional restrictions.

ATTRIBUTE DESCRIPTION
type

Type of thematic role (e.g., "Agent", "Theme", "Patient").

TYPE: ThematicRoleType

sel_restrictions

Selectional restrictions on this role.

TYPE: SelectionalRestrictions | None, default=None

ATTRIBUTE DESCRIPTION
_class_id

The class ID this role belongs to (set during parsing).

TYPE: str | None

METHOD DESCRIPTION
class_id

Get the class ID this role belongs to.

Examples:

>>> role = ThematicRole(
...     type="Agent",
...     sel_restrictions=SelectionalRestrictions(
...         restrictions=[SelectionalRestriction(value="+", type="animate")]
...     )
... )
>>> print(role.type)
'Agent'

Fields:

Attributes
sel_restrictions: SelectionalRestrictions | None = None pydantic-field

Selectional restrictions on this role

Functions
class_id() -> str | None

Get the class ID this role belongs to (for inheritance).

RETURNS DESCRIPTION
str | None

The class ID if set, None otherwise.

Source code in src/glazing/verbnet/models.py
def class_id(self) -> str | None:
    """Get the class ID this role belongs to (for inheritance).

    Returns
    -------
    str | None
        The class ID if set, None otherwise.
    """
    return getattr(self, "_class_id", None)

VNFrame pydantic-model

Bases: GlazingBaseModel

Syntactic-semantic frame pattern.

ATTRIBUTE DESCRIPTION
description

Frame syntactic pattern description.

TYPE: FrameDescription

examples

Example sentences for this frame.

TYPE: list[Example]

syntax

Syntactic structure.

TYPE: Syntax

semantics

Semantic representation.

TYPE: Semantics

Examples:

>>> frame = VNFrame(
...     description=FrameDescription(
...         description_number="0.1",
...         primary="NP V NP",
...         secondary="Basic Transitive"
...     ),
...     examples=[Example(text="John hit the ball")],
...     syntax=Syntax(elements=[...]),
...     semantics=Semantics(predicates=[...])
... )

Fields:

VerbClass pydantic-model

Bases: GlazingBaseModel

A VerbNet verb class with members and frames.

ATTRIBUTE DESCRIPTION
id

Validated VerbNet class ID (e.g., "give-13.1").

TYPE: VerbClassID

members

Verb members in this class.

TYPE: list[Member]

themroles

Thematic roles (may be empty for inheritance).

TYPE: list[ThematicRole]

frames

Frame specifications.

TYPE: list[VNFrame]

subclasses

Recursive subclasses.

TYPE: list[VerbClass]

parent_class

Parent class ID for subclasses.

TYPE: VerbClassID | None, default=None

METHOD DESCRIPTION
get_effective_roles

Get effective roles considering inheritance from parent classes.

get_all_members

Get all members including those from subclasses.

get_member_by_key

Find a member by its VerbNet key.

has_subclasses

Check if this class has subclasses.

Examples:

>>> verb_class = VerbClass(
...     id="give-13.1",
...     members=[],
...     themroles=[
...         ThematicRole(type="Agent"),
...         ThematicRole(type="Theme"),
...         ThematicRole(type="Recipient")
...     ],
...     frames=[],
...     subclasses=[]
... )
>>> roles = verb_class.get_effective_roles()
>>> print(len(roles))
3

Fields:

Validators:

Attributes
frames: list[VNFrame] pydantic-field

Frame specifications

id: VerbClassID pydantic-field

VerbNet class ID

members: list[Member] pydantic-field

Verb members

parent_class: VerbClassID | None = None pydantic-field

Parent class ID for subclasses

subclasses: list[VerbClass] pydantic-field

Recursive subclasses

themroles: list[ThematicRole] pydantic-field

Thematic roles (empty for inheritance)

Functions
get_all_members(include_subclasses: bool = True) -> list[Member]

Get all members including those from subclasses.

PARAMETER DESCRIPTION
include_subclasses

Whether to include members from subclasses.

TYPE: bool DEFAULT: True

RETURNS DESCRIPTION
list[Member]

All members in this class and optionally its subclasses.

Source code in src/glazing/verbnet/models.py
def get_all_members(self, include_subclasses: bool = True) -> list[Member]:
    """Get all members including those from subclasses.

    Parameters
    ----------
    include_subclasses : bool, default=True
        Whether to include members from subclasses.

    Returns
    -------
    list[Member]
        All members in this class and optionally its subclasses.
    """
    members = self.members.copy()
    if include_subclasses:
        for subclass in self.subclasses:
            members.extend(subclass.get_all_members(include_subclasses=True))
    return members
get_effective_roles(parent_roles: list[ThematicRole] | None = None) -> list[ThematicRole]

Get effective roles considering inheritance from parent classes.

PARAMETER DESCRIPTION
parent_roles

Roles from parent class.

TYPE: list[ThematicRole] | None DEFAULT: None

RETURNS DESCRIPTION
list[ThematicRole]

Effective roles after applying inheritance rules.

Notes

If themroles is empty and parent_roles is provided, inherits all parent roles. Otherwise, subclass roles override parent roles of the same type.

Source code in src/glazing/verbnet/models.py
def get_effective_roles(
    self, parent_roles: list[ThematicRole] | None = None
) -> list[ThematicRole]:
    """Get effective roles considering inheritance from parent classes.

    Parameters
    ----------
    parent_roles : list[ThematicRole] | None, default=None
        Roles from parent class.

    Returns
    -------
    list[ThematicRole]
        Effective roles after applying inheritance rules.

    Notes
    -----
    If themroles is empty and parent_roles is provided, inherits all parent roles.
    Otherwise, subclass roles override parent roles of the same type.
    """
    if not self.themroles and parent_roles:
        return parent_roles
    if parent_roles:
        final_roles = self.themroles.copy()
        for parent_role in parent_roles:
            if not any(r.type == parent_role.type for r in self.themroles):
                final_roles.append(parent_role)
        return final_roles
    return self.themroles
get_member_by_key(verbnet_key: str) -> Member | None

Find a member by its VerbNet key.

PARAMETER DESCRIPTION
verbnet_key

The VerbNet key to search for.

TYPE: str

RETURNS DESCRIPTION
Member | None

The member if found, None otherwise.

Source code in src/glazing/verbnet/models.py
def get_member_by_key(self, verbnet_key: str) -> Member | None:
    """Find a member by its VerbNet key.

    Parameters
    ----------
    verbnet_key : str
        The VerbNet key to search for.

    Returns
    -------
    Member | None
        The member if found, None otherwise.
    """
    for member in self.get_all_members():
        if member.verbnet_key == verbnet_key:
            return member
    return None
has_subclasses() -> bool

Check if this class has subclasses.

RETURNS DESCRIPTION
bool

True if the class has subclasses.

Source code in src/glazing/verbnet/models.py
def has_subclasses(self) -> bool:
    """Check if this class has subclasses.

    Returns
    -------
    bool
        True if the class has subclasses.
    """
    return len(self.subclasses) > 0
validate_verbclass_id(v: str) -> VerbClassID pydantic-validator

Validate VerbNet class ID format.

PARAMETER DESCRIPTION
v

Class ID to validate.

TYPE: str

RETURNS DESCRIPTION
str

Validated class ID.

RAISES DESCRIPTION
ValueError

If class ID format is invalid.

Source code in src/glazing/verbnet/models.py
@field_validator("id")
@classmethod
def validate_verbclass_id(cls, v: str) -> VerbClassID:
    """Validate VerbNet class ID format.

    Parameters
    ----------
    v : str
        Class ID to validate.

    Returns
    -------
    str
        Validated class ID.

    Raises
    ------
    ValueError
        If class ID format is invalid.
    """
    if not re.match(VERBNET_CLASS_PATTERN, v):
        msg = f"Invalid VerbNet class ID format: {v}"
        raise ValueError(msg)
    return v

WordNetCrossRef pydantic-model

Bases: GlazingBaseModel

Cross-reference to WordNet from VerbNet.

ATTRIBUTE DESCRIPTION
sense_key

WordNet sense key (preferred, stable across versions).

TYPE: WordNetSense | None, default=None

synset_offset

WordNet synset offset (version-specific).

TYPE: str | None, default=None

lemma

The lemma form.

TYPE: str

pos

Part of speech ("n", "v", "a", "r", "s").

TYPE: str

sense_number

Sense number in WordNet.

TYPE: int | None, default=None

METHOD DESCRIPTION
to_percentage_notation

Convert to VerbNet percentage notation.

from_percentage_notation

Parse VerbNet percentage notation.

Examples:

>>> ref = WordNetCrossRef.from_percentage_notation("give%2:40:00")
>>> print(ref.lemma)
'give'

Fields:

  • sense_key (WordNetSense | None)
  • synset_offset (str | None)
  • lemma (str)
  • pos (str)
  • sense_number (int | None)
Functions
from_percentage_notation(notation: str) -> Self classmethod

Parse VerbNet percentage notation.

PARAMETER DESCRIPTION
notation

Percentage notation string (e.g., "word%2:40:00").

TYPE: str

RETURNS DESCRIPTION
WordNetCrossRef

Parsed cross-reference.

RAISES DESCRIPTION
ValueError

If notation format is invalid.

Source code in src/glazing/verbnet/models.py
@classmethod
def from_percentage_notation(cls, notation: str) -> Self:
    """Parse VerbNet percentage notation.

    Parameters
    ----------
    notation : str
        Percentage notation string (e.g., "word%2:40:00").

    Returns
    -------
    WordNetCrossRef
        Parsed cross-reference.

    Raises
    ------
    ValueError
        If notation format is invalid.
    """
    match = re.match(r"^([a-z_-]+)%([1-5]):([0-9]{2}):([0-9]{2})$", notation)
    if not match:
        msg = f"Invalid percentage notation: {notation}"
        raise ValueError(msg)

    lemma = match.group(1)
    ss_type = int(match.group(2))
    lex_filenum = match.group(3)
    lex_id = match.group(4)

    pos_map = {1: "n", 2: "v", 3: "a", 4: "r", 5: "s"}
    pos = pos_map[ss_type]

    sense_key = f"{lemma}%{ss_type}:{lex_filenum}:{lex_id}::"

    return cls(sense_key=sense_key, lemma=lemma, pos=pos)
to_percentage_notation() -> str

Convert to VerbNet percentage notation.

RETURNS DESCRIPTION
str

Percentage notation string or empty string if incomplete.

Source code in src/glazing/verbnet/models.py
def to_percentage_notation(self) -> str:
    """Convert to VerbNet percentage notation.

    Returns
    -------
    str
        Percentage notation string or empty string if incomplete.
    """
    if self.sense_key and "%" in self.sense_key:
        after_percent = self.sense_key.split("%")[1]
        parts = after_percent.split(":")
        if len(parts) >= 3:
            return f"{self.lemma}%{parts[0]}:{parts[1]}:{parts[2]}"
    return ""