Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add validators #9

Open
github-actions bot opened this issue May 17, 2023 · 0 comments
Open

Add validators #9

github-actions bot opened this issue May 17, 2023 · 0 comments
Assignees
Labels

Comments

@github-actions
Copy link

Add validators

def check_are_file_extensions(cls, v):

if not v.startswith("."):

raise ValueError(f"{v} is not a valid file extension")

return v

# TODO: Add validators

from typing import Any
from pydantic import (
    BaseModel,
    BaseSettings,
    Field,
    ValidationError,
    validator,
)

# TODO: Fix typing for Punctuation rules

# TODO: Add validators

class SplitByGap(BaseModel):
    """
    Split (in-place) any segment into multiple segments where the duration in between two words > [max_gap]
    """
    max_gap: float = Field(
        ...,
        description="The point between any two words greater than this value (seconds) will be split."
    )
    lock: bool = Field(
        ...,
        description="Whether to prevent future splits from altering changes made by this function."

    )


class SplitByPunctuation(BaseModel):
    """
    Split (in-place) any segment into multiple segments where the duration in between two words > [max_gap]
    """
    punctuation: list[Any] = Field(
        ...,
        description="Punctuation(s) to split segments by."

    )
    lock: bool = Field(
        ...,
        description="Whether to prevent future splits from altering changes made by this function."

    )


class SplitByLength(BaseModel):
    """
    Split (in-place) any segment into multiple segments where the duration in between two words > [max_gap]
    """
    max_chars: int = Field(
        ...,
        description="Maximum number of characters allowed in segment."

    )
    max_words: int = Field(
        ...,
        description="Maximum number of words allowed in segment."

    )
    force_len: bool = Field(
        ...,
        description="Maintain a relatively constant length for each segment"

    )
    lock: bool = Field(
        ...,
        description="Whether to prevent future splits/merges from altering changes made by this function."
    )


class MergeByGap(BaseModel):
    """
    Merge (in-place) any pair of adjacent segments if the duration in between the pair <= [min_gap]
    """
    min_gap: float = Field(
        ...,
        description="Any gaps below or equal to this value (seconds) will be merged."

    )
    max_words: int = Field(
        ...,
        description="Maximum number of words allowed."

    )
    is_sum_max: bool = Field(
        ...,
        description="Whether [max_words] and [max_chars] are applied to the merged segment "
                    "instead of the individual segments to be merged."

    )
    lock: bool = Field(
        ...,
        description="Whether to prevent future splits/merges from altering changes made by this function."

    )


class MergeByPunctuation(BaseModel):
    """
    Merge (in-place) any two segments that has specified punctuation(s) inbetween them
    """
    punctuation: list[Any] = Field(
        ...,
        description="Punctuation(s) to split segments by."

    )
    max_chars: int = Field(
        ...,
        description="Maximum number of characters allowed in segment."

    )
    max_words: int = Field(
        ...,
        description="Maximum number of words allowed."

    )
    is_sum_max: bool = Field(
        ...,
        description="Whether [max_words] and [max_chars] are applied to the merged segment "
                    "instead of the individual segments to be merged."

    )
    lock: bool = Field(
        ...,
        description="Whether to prevent future splits/merges from altering changes made by this function."

    )


class MergeAllSegments(BaseModel):
  """
  Merge all segments into one segment.
  """
  enabled: bool = Field(
      ...,
      description="Whether to merge all segments into one"
  )


# @validator("extension_whitelist", each_item=True)
# def check_are_file_extensions(cls, v):
#     if not v.startswith("."):
#         raise ValueError(f"{v} is not a valid file extension")
#     return v

7f47697acfbf85e6fdf9dd38bfde5808b3329a44

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant