Module clu.phontools.alignment.parser.actions

Expand source code
from __future__ import annotations
from enum import Enum
from typing import Text, Tuple

__all__ = ["Actions"]


class Actions(Enum):
    """
    The actions used by the parser.
    """

    # NOTE: previously DISCARD_T and DISCARD_G; now SHIFT_* AND DISCARD_T
    DISCARD = "DISCARD"
    SHIFT_T = "SHIFT-T"
    SHIFT_G = "SHIFT-G"
    STACK_SWAP = "STACK-SWAP"
    INSERTION_PRESERVE_CHILD = "INSERTION-PRESERVE-CHILD"
    INSERTION_PRESERVE_PARENT = "INSERTION-PRESERVE-PARENT"
    # NOTE: previously had a DISCARD action as well
    DELETION_PRESERVE_CHILD = "DELETION-PRESERVE-CHILD"
    DELETION_PRESERVE_PARENT = "DELETION-PRESERVE-PARENT"
    ALIGN = "ALIGN"
    SUBSTITUTION = "SUBSTITUTION"

    def describe(self) -> Tuple[Text, Text]:
        return (self.name, self.value)

    def simple(self) -> Text:
        """A simplified/more coarse-grained version of the label."""
        label = self.value
        for prefix in [
            "INSERT",
            "ALIGN",
            "DELETION",
            "SUBSTITUTION",
            "SHIFT",
            "DISCARD",
        ]:
            if label.startswith(prefix):
                return prefix
        return label

Classes

class Actions (value, names=None, *, module=None, qualname=None, type=None, start=1)

The actions used by the parser.

Expand source code
class Actions(Enum):
    """
    The actions used by the parser.
    """

    # NOTE: previously DISCARD_T and DISCARD_G; now SHIFT_* AND DISCARD_T
    DISCARD = "DISCARD"
    SHIFT_T = "SHIFT-T"
    SHIFT_G = "SHIFT-G"
    STACK_SWAP = "STACK-SWAP"
    INSERTION_PRESERVE_CHILD = "INSERTION-PRESERVE-CHILD"
    INSERTION_PRESERVE_PARENT = "INSERTION-PRESERVE-PARENT"
    # NOTE: previously had a DISCARD action as well
    DELETION_PRESERVE_CHILD = "DELETION-PRESERVE-CHILD"
    DELETION_PRESERVE_PARENT = "DELETION-PRESERVE-PARENT"
    ALIGN = "ALIGN"
    SUBSTITUTION = "SUBSTITUTION"

    def describe(self) -> Tuple[Text, Text]:
        return (self.name, self.value)

    def simple(self) -> Text:
        """A simplified/more coarse-grained version of the label."""
        label = self.value
        for prefix in [
            "INSERT",
            "ALIGN",
            "DELETION",
            "SUBSTITUTION",
            "SHIFT",
            "DISCARD",
        ]:
            if label.startswith(prefix):
                return prefix
        return label

Ancestors

  • enum.Enum

Class variables

var ALIGN
var DELETION_PRESERVE_CHILD
var DELETION_PRESERVE_PARENT
var DISCARD
var INSERTION_PRESERVE_CHILD
var INSERTION_PRESERVE_PARENT
var SHIFT_G
var SHIFT_T
var STACK_SWAP
var SUBSTITUTION

Methods

def describe(self) ‑> Tuple[str, str]
Expand source code
def describe(self) -> Tuple[Text, Text]:
    return (self.name, self.value)
def simple(self) ‑> str

A simplified/more coarse-grained version of the label.

Expand source code
def simple(self) -> Text:
    """A simplified/more coarse-grained version of the label."""
    label = self.value
    for prefix in [
        "INSERT",
        "ALIGN",
        "DELETION",
        "SUBSTITUTION",
        "SHIFT",
        "DISCARD",
    ]:
        if label.startswith(prefix):
            return prefix
    return label