73 lines
1.6 KiB
Python
73 lines
1.6 KiB
Python
"""Protocol definitions for the classification package"""
|
|
from typing import Protocol, Optional
|
|
from pathlib import Path
|
|
from dataclasses import dataclass
|
|
|
|
|
|
@dataclass
|
|
class ClassificationRule:
|
|
"""Rule for classifying files"""
|
|
name: str
|
|
category: str
|
|
patterns: list[str]
|
|
priority: int = 0
|
|
description: str = ""
|
|
|
|
|
|
class IClassifier(Protocol):
|
|
"""Protocol for classification operations"""
|
|
|
|
def classify(self, path: Path, file_type: Optional[str] = None) -> Optional[str]:
|
|
"""Classify a file path
|
|
|
|
Args:
|
|
path: Path to classify
|
|
file_type: Optional file type hint
|
|
|
|
Returns:
|
|
Category name or None if no match
|
|
"""
|
|
...
|
|
|
|
def get_category_rules(self, category: str) -> list[ClassificationRule]:
|
|
"""Get all rules for a category
|
|
|
|
Args:
|
|
category: Category name
|
|
|
|
Returns:
|
|
List of rules for the category
|
|
"""
|
|
...
|
|
|
|
|
|
class IRuleEngine(Protocol):
|
|
"""Protocol for rule-based classification"""
|
|
|
|
def add_rule(self, rule: ClassificationRule) -> None:
|
|
"""Add a classification rule
|
|
|
|
Args:
|
|
rule: Rule to add
|
|
"""
|
|
...
|
|
|
|
def remove_rule(self, rule_name: str) -> None:
|
|
"""Remove a rule by name
|
|
|
|
Args:
|
|
rule_name: Name of rule to remove
|
|
"""
|
|
...
|
|
|
|
def match_path(self, path: Path) -> Optional[str]:
|
|
"""Match path against rules
|
|
|
|
Args:
|
|
path: Path to match
|
|
|
|
Returns:
|
|
Category name or None if no match
|
|
"""
|
|
...
|