Skip to content

Latest commit

 

History

History
1352 lines (940 loc) · 27.7 KB

File metadata and controls

1352 lines (940 loc) · 27.7 KB

MailHelper API-Dokumentation

Übersicht

Die MailHelper-API bietet eine umfassende Schnittstelle zur Integration in andere Systeme und zur Automatisierung von Mail-Verarbeitungsaufgaben. Die API ist modular aufgebaut und deckt alle Kernfunktionen der Anwendung ab.

Inhaltsverzeichnis

Core API

MailHelperEngine

Die zentrale Klasse zur Koordination aller Komponenten.

Initialisierung

from src.core.engine import MailHelperEngine

# Engine initialisieren
engine = MailHelperEngine()

# Mit Konfiguration initialisieren
config = {
    "llm": {
        "provider": "ollama",
        "model": "qwen2.5:latest",
        "temperature": 0.7
    },
    "exchange": {
        "autodiscover": True,
        "access_type": "delegate"
    }
}
engine = MailHelperEngine(config=config)

Methoden

initialize_all()

Initialisiert alle Komponenten der Anwendung.

engine.initialize_all()

Rückgabewert: bool - True bei Erfolg, False bei Fehler

get_status()

Gibt den aktuellen Status der Anwendung zurück.

status = engine.get_status()

Rückgabewert: Dict[str, Any] - Statusinformationen

{
    "status": "initialized",
    "components": {
        "mail_service": "connected",
        "llm_client": "ready",
        "clustering_engine": "ready",
        "storage_manager": "ready"
    },
    "last_updated": "2024-01-01T12:00:00Z"
}
get_component_status()

Gibt den Status einzelner Komponenten zurück.

component_status = engine.get_component_status()

Rückgabewert: Dict[str, str] - Status der einzelnen Komponenten

update_config(config_dict)

Aktualisiert die Konfiguration der Anwendung.

engine.update_config({
    "llm": {
        "temperature": 0.5
    },
    "frontend": {
        "port": 8080
    }
})

Parameter:

  • config_dict (Dict[str, Any]): Konfigurations-Dictionary

Rückgabewert: bool - True bei Erfolg, False bei Fehler

shutdown()

Fährt die Anwendung ordnungsgemäß herunter.

engine.shutdown()

Rückgabewert: None

Config

Konfigurationsverwaltung mit Pydantic-Validierung.

Klassen

CoreAppConfig

Hauptkonfigurationsklasse.

from src.core.config import CoreAppConfig

config = CoreAppConfig(
    theme="monochrome",
    title="MailHelper",
    port=7860,
    share=False,
    height=800,
    width=1200
)

Attribute:

  • theme (str): UI-Theme
  • title (str): Anwendungstitel
  • port (int): Port für Web-Interface
  • share (bool): Public Share aktivieren
  • height (int): Fensterhöhe
  • width (int): Fensterbreite
ExchangeConfig

Exchange-Server-Konfiguration.

from src.core.config import ExchangeConfig

exchange_config = ExchangeConfig(
    server="outlook.office365.com",
    username="user@company.com",
    password="password",
    use_ssl=True,
    timeout=30,
    autodiscover=True,
    access_type="delegate"
)

Attribute:

  • server (str): Exchange-Server-Adresse
  • username (str): Benutzername
  • password (str): Passwort
  • use_ssl (bool): SSL verwenden
  • timeout (int): Timeout in Sekunden
  • autodiscover (bool): Autodiscover verwenden
  • access_type (str): Zugriffstyp
LLMConfig

LLM-Konfiguration.

from src.core.config import LLMConfig

llm_config = LLMConfig(
    provider="ollama",
    base_url="http://localhost:11434/v1",
    model="qwen2.5:latest",
    temperature=0.7,
    api_key="",
    max_tokens=1000
)

Attribute:

  • provider (str): LLM-Provider
  • base_url (str): Basis-URL des LLM-Servers
  • model (str): Modellname
  • temperature (float): Temperatur für Zufälligkeit
  • api_key (str): API-Schlüssel
  • max_tokens (int): Maximale Token-Anzahl
StorageConfig

Speicher-Konfiguration.

from src.core.config import StorageConfig

storage_config = StorageConfig(
    storage_type="file",
    storage_path="storage",
    base_path="storage",
    backup_enabled=True,
    backup_interval=24,
    encryption_enabled=False,
    compression_enabled=True,
    retention_days=30
)

Attribute:

  • storage_type (str): Speichertyp
  • storage_path (str): Speicherpfad
  • base_path (str): Basispfad
  • backup_enabled (bool): Backup aktiviert
  • backup_interval (int): Backup-Intervall in Stunden
  • encryption_enabled (bool): Verschlüsselung aktiviert
  • compression_enabled (bool): Kompression aktiviert
  • retention_days (int): Aufbewahrungsfrist in Tagen
ClusteringConfig

Clustering-Konfiguration.

from src.core.config import ClusteringConfig

clustering_config = ClusteringConfig(
    algorithm="kmeans",
    n_clusters=5,
    min_cluster_size=3,
    max_cluster_size=100,
    similarity_threshold=0.7,
    enable_clustering=True,
    clustering_interval=24,
    auto_clustering=True,
    subject_weight=0.4,
    body_weight=0.6
)

Attribute:

  • algorithm (str): Clustering-Algorithmus
  • n_clusters (int): Anzahl der Cluster
  • min_cluster_size (int): Minimale Cluster-Größe
  • max_cluster_size (int): Maximale Cluster-Größe
  • similarity_threshold (float): Ähnlichkeitsschwelle
  • enable_clustering (bool): Clustering aktiviert
  • clustering_interval (int): Clustering-Intervall in Stunden
  • auto_clustering (bool): Automatisches Clustering
  • subject_weight (float): Gewichtung des Betreffs
  • body_weight (float): Gewichtung des Inhalts
PluginConfig

Plugin-Konfiguration.

from src.core.config import PluginConfig

plugin_config = PluginConfig(
    plugin_dir="plugins",
    enabled_plugins=[],
    disabled_plugins=[],
    auto_load=True,
    plugin_timeout=30
)

Attribute:

  • plugin_dir (str): Plugin-Verzeichnis
  • enabled_plugins (List[str]): Aktivierte Plugins
  • disabled_plugins (List[str]): Deaktivierte Plugins
  • auto_load (bool): Automatisches Laden von Plugins
  • plugin_timeout (int): Plugin-Timeout in Sekunden

Exceptions

Ausnahmeklassen für Fehlerbehandlung.

MailHelperException

Basisklasse für alle Anwendungsausnahmen.

from src.core.exceptions import MailHelperException

try:
    # Code, der eine Ausnahme auslösen kann
    pass
except MailHelperException as e:
    print(f"MailHelper Fehler: {e}")

ConfigurationError

Konfigurationsfehler.

from src.core.exceptions import ConfigurationError

try:
    # Konfigurationsfehler
    pass
except ConfigurationError as e:
    print(f"Konfigurationsfehler: {e}")

AuthenticationError

Authentifizierungsfehler.

from src.core.exceptions import AuthenticationError

try:
    # Authentifizierungsfehler
    pass
except AuthenticationError as e:
    print(f"Authentifizierungsfehler: {e}")

ExchangeConnectionError

Exchange-Verbindungsfehler.

from src.core.exceptions import ExchangeConnectionError

try:
    # Exchange-Verbindungsfehler
    pass
except ExchangeConnectionError as e:
    print(f"Exchange-Verbindungsfehler: {e}")

MailProcessingError

Mail-Verarbeitungsfehler.

from src.core.exceptions import MailProcessingError

try:
    # Mail-Verarbeitungsfehler
    pass
except MailProcessingError as e:
    print(f"Mail-Verarbeitungsfehler: {e}")

ClusteringError

Clustering-Fehler.

from src.core.exceptions import ClusteringError

try:
    # Clustering-Fehler
    pass
except ClusteringError as e:
    print(f"Clustering-Fehler: {e}")

LLMError

LLM-Verarbeitungsfehler.

from src.core.exceptions import LLMError

try:
    # LLM-Verarbeitungsfehler
    pass
except LLMError as e:
    print(f"LLM-Fehler: {e}")

StorageError

Speicherfehler.

from src.core.exceptions import StorageError

try:
    # Speicherfehler
    pass
except StorageError as e:
    print(f"Speicherfehler: {e}")

PluginError

Plugin-Fehler.

from src.core.exceptions import PluginError

try:
    # Plugin-Fehler
    pass
except PluginError as e:
    print(f"Plugin-Fehler: {e}")

Exchange API

ExchangeConnector

Verbindung zu Exchange-Servern.

Initialisierung

from src.exchange.connector import ExchangeConnector

connector = ExchangeConnector(
    server="outlook.office365.com",
    username="user@company.com",
    password="password",
    autodiscover=True,
    access_type="delegate"
)

Methoden

connect()

Stellt Verbindung zum Exchange-Server her.

connector.connect()

Rückgabewert: bool - True bei Erfolg, False bei Fehler

disconnect()

Trennt die Verbindung zum Exchange-Server.

connector.disconnect()

Rückgabewert: None

get_folders()

Ruft alle Ordner ab.

folders = connector.get_folders()

Rückgabewert: List[MailFolder] - Liste der Ordner

get_mails(folder, limit=None)

Ruft Mails aus einem Ordner ab.

mails = connector.get_mails(folder, limit=50)

Parameter:

  • folder (MailFolder): Zielordner
  • limit (int, optional): Limit der Mails

Rückgabewert: MailCollection - Sammlung von Mails

search_mails(criteria)

Sucht Mails basierend auf Kriterien.

from src.exchange.models import MailSearchCriteria

criteria = MailSearchCriteria(
    subject_contains="Angebot",
    date_from=datetime.now() - timedelta(days=7),
    date_to=datetime.now(),
    sender_contains="company.com"
)

results = connector.search_mails(criteria)

Parameter:

  • criteria (MailSearchCriteria): Suchkriterien

Rückgabewert: MailCollection - Suchergebnisse

get_mail_by_id(mail_id)

Ruft eine Mail per ID ab.

mail = connector.get_mail_by_id(mail_id)

Parameter:

  • mail_id (str): Mail-ID

Rückgabewert: MailItem - Mail-Objekt

send_mail(mail)

Sendet eine Mail.

from src.exchange.models import MailItem

mail = MailItem(
    subject="Test Mail",
    body="Dies ist eine Test-Mail",
    recipients=["recipient@company.com"]
)

connector.send_mail(mail)

Parameter:

  • mail (MailItem): Zu sendende Mail

Rückgabewert: bool - True bei Erfolg, False bei Fehler

move_mail(mail, target_folder)

Verschiebt eine Mail in einen anderen Ordner.

connector.move_mail(mail, target_folder)

Parameter:

  • mail (MailItem): Zu verschiebende Mail
  • target_folder (MailFolder): Zielordner

Rückgabewert: bool - True bei Erfolg, False bei Fehler

delete_mail(mail)

Löscht eine Mail.

connector.delete_mail(mail)

Parameter:

  • mail (MailItem): Zu löschende Mail

Rückgabewert: bool - True bei Erfolg, False bei Fehler

MailItem

Datenmodell für E-Mails.

Attribute

  • id (str): Eindeutige ID
  • subject (str): Betreff
  • body (str): Mail-Inhalt
  • sender (Dict[str, str]): Absender-Informationen
  • recipients (List[Dict[str, str]]): Empfänger
  • cc (List[Dict[str, str]]): CC-Empfänger
  • bcc (List[Dict[str, str]]): BCC-Empfänger
  • datetime_received (datetime): Empfangsdatum
  • datetime_sent (datetime): Sendedatum
  • attachments (List[Dict[str, Any]]): Anhänge
  • status (str): Status (z.B. "unread", "read")
  • folder (MailFolder): Ordner
  • thread_id (str): Thread-ID
  • importance (str): Wichtigkeit ("low", "normal", "high")
  • sensitivity (str): Vertraulichkeit ("normal", "personal", "private", "confidential")

Methoden

to_dict()

Konvertiert das Mail-Objekt in ein Dictionary.

mail_dict = mail.to_dict()

Rückgabewert: Dict[str, Any] - Mail-Daten als Dictionary

from_dict(data)

Erstellt ein Mail-Objekt aus einem Dictionary.

mail = MailItem.from_dict(mail_dict)

Parameter:

  • data (Dict[str, Any]): Mail-Daten

Rückgabewert: MailItem - Mail-Objekt

MailFolder

Datenmodell für Mail-Ordner.

Attribute

  • id (str): Eindeutige ID
  • name (str): Ordnername
  • display_name (str): Anzeigename
  • total_count (int): Gesamtzahl der Mails
  • unread_count (int): Anzahl ungelesener Mails
  • folder_path (str): Pfad zum Ordner
  • parent_folder (MailFolder): Übergeordneter Ordner
  • child_folders (List[MailFolder]): Unterordner
  • is_search_folder (bool): Ist ein Suchordner

Methoden

to_dict()

Konvertiert das Ordner-Objekt in ein Dictionary.

folder_dict = folder.to_dict()

Rückgabewert: Dict[str, Any] - Ordner-Daten als Dictionary

from_dict(data)

Erstellt ein Ordner-Objekt aus einem Dictionary.

folder = MailFolder.from_dict(folder_dict)

Parameter:

  • data (Dict[str, Any]): Ordner-Daten

Rückgabewert: MailFolder - Ordner-Objekt

MailSearchCriteria

Suchkriterien für Mail-Abfragen.

Attribute

  • subject_contains (str, optional): Betreff enthält
  • subject_equals (str, optional): Betreff gleich
  • body_contains (str, optional): Körper enthält
  • sender_contains (str, optional): Absender enthält
  • sender_equals (str, optional): Absender gleich
  • recipient_contains (str, optional): Empfänger enthält
  • recipient_equals (str, optional): Empfänger gleich
  • date_from (datetime, optional): Datum ab
  • date_to (datetime, optional): Datum bis
  • has_attachments (bool, optional): Hat Anhänge
  • attachment_contains (str, optional): Anhang enthält
  • status (str, optional): Status
  • importance (str, optional): Wichtigkeit
  • sensitivity (str, optional): Vertraulichkeit
  • folder_id (str, optional): Ordner-ID
  • limit (int, optional): Limit
  • offset (int, optional): Offset

Methoden

to_dict()

Konvertiert die Suchkriterien in ein Dictionary.

criteria_dict = criteria.to_dict()

Rückgabewert: Dict[str, Any] - Suchkriterien als Dictionary

from_dict(data)

Erstellt Suchkriterien aus einem Dictionary.

criteria = MailSearchCriteria.from_dict(criteria_dict)

Parameter:

  • data (Dict[str, Any]): Suchkriterien

Rückgabewert: MailSearchCriteria - Suchkriterien-Objekt

LLM API

LLMClient

OpenAI-kompatibler Client für verschiedene LLM-Provider.

Initialisierung

from src.llm.client import LLMClient, LLMConfig

config = LLMConfig(
    provider="ollama",
    base_url="http://localhost:11434/v1",
    model="qwen2.5:latest",
    temperature=0.7
)

client = LLMClient(config)

Methoden

chat_completion(messages, **kwargs)

Sendet Chat-Nachrichten und erhält eine Antwort.

messages = [
    {"role": "system", "content": "Du bist ein hilfreicher Assistent."},
    {"role": "user", "content": "Was ist Künstliche Intelligenz?"}
]

response = client.chat_completion(messages, temperature=0.5)

Parameter:

  • messages (List[Dict[str, str]]): Nachrichten
  • temperature (float, optional): Temperatur
  • max_tokens (int, optional): Maximale Token
  • top_p (float, optional): Top-P-Wert
  • frequency_penalty (float, optional): Frequency Penalty
  • presence_penalty (float, optional): Presence Penalty

Rückgabewert: Dict[str, Any] - API-Antwort

analyze_text(text, analysis_type)

Analysiert Text mit verschiedenen Analyse-Typen.

analysis = client.analyze_text(
    text="Dies ist ein Test-Text zur Sentiment-Analyse.",
    analysis_type="sentiment"
)

Parameter:

  • text (str): Zu analysierender Text
  • analysis_type (str): Analyse-Typ ("sentiment", "keywords", "categories", "urgency")

Rückgabewert: Dict[str, Any] - Analyse-Ergebnis

generate_response(prompt, context=None, **kwargs)

Generiert eine Antwort basierend auf einem Prompt.

response = client.generate_response(
    prompt="Erstelle eine professionelle Antwort auf folgende Anfrage:",
    context="Der Kunde möchte ein Angebot erhalten.",
    tone="professionell",
    max_length=200
)

Parameter:

  • prompt (str): Prompt-Text
  • context (str, optional): Kontext-Text
  • tone (str, optional): Ton ("professionell", "freundlich", "formell", "locker")
  • max_length (int, optional): Maximale Länge

Rückgabewert: str - Generierte Antwort

summarize_text(text, max_length=200)

Fasst Text zusammen.

summary = client.summarize_text(
    text="Langer Text, der zusammengefasst werden soll...",
    max_length=200
)

Parameter:

  • text (str): Zusammenzufassender Text
  • max_length (int, optional): Maximale Länge der Zusammenfassung

Rückgabewert: str - Zusammenfassung

extract_keywords(text, max_keywords=10)

Extrahiert Schlüsselwörter aus Text.

keywords = client.extract_keywords(
    text="Text, aus dem Schlüsselwörter extrahiert werden sollen...",
    max_keywords=10
)

Parameter:

  • text (str): Text zur Schlüsselwort-Extraktion
  • max_keywords (int, optional): Maximale Anzahl von Schlüsselwörtern

Rückgabewert: List[str] - Liste von Schlüsselwörtern

categorize_text(text)

Kategorisiert Text.

categories = client.categorize_text(
    text="Text, der kategorisiert werden soll..."
)

Parameter:

  • text (str): Zu kategorisierender Text

Rückgabewert: List[str] - Liste von Kategorien

translate_text(text, target_language, source_language=None)

Übersetzt Text.

translation = client.translate_text(
    text="Text, der übersetzt werden soll...",
    target_language="en",
    source_language="de"
)

Parameter:

  • text (str): Zu übersetzender Text
  • target_language (str): Zielsprache
  • source_language (str, optional): Quellsprache

Rückgabewert: str - Übersetzter Text

check_grammar(text)

Überprüft Grammatik.

grammar_check = client.check_grammar(
    text="Text, dessen Grammatik überprüft werden soll..."
)

Parameter:

  • text (str): Zu überprüfender Text

Rückgabewert: Dict[str, Any] - Grammatik-Prüfungsergebnis

get_model_info()

Ruft Informationen über das aktuelle Modell ab.

model_info = client.get_model_info()

Rückgabewert: Dict[str, Any] - Modell-Informationen

test_connection()

Testet die Verbindung zum LLM-Server.

is_connected = client.test_connection()

Rückgabewert: bool - True bei Erfolg, False bei Fehler

PromptManager

Verwaltung von Prompts für verschiedene Szenarien.

Initialisierung

from src.llm.prompts import PromptManager

prompt_manager = PromptManager()

Methoden

add_prompt(category, name, template)

Fügt einen neuen Prompt hinzu.

prompt_manager.add_prompt(
    category="response_generation",
    name="professional_email",
    template="Erstelle eine professionelle Antwort auf: {content}"
)

Parameter:

  • category (str): Kategorie des Prompts
  • name (str): Name des Prompts
  • template (str): Prompt-Vorlage

Rückgabewert: bool - True bei Erfolg, False bei Fehler

get_prompt(category, name, **kwargs)

Ruft einen Prompt ab.

prompt = prompt_manager.get_prompt(
    category="response_generation",
    name="professional_email",
    content="Der Kunde möchte ein Angebot erhalten."
)

Parameter:

  • category (str): Kategorie des Prompts
  • name (str): Name des Prompts
  • **kwargs: Variablen für die Prompt-Vorlage

Rückgabewert: str - Generierter Prompt

list_prompts(category=None)

Listet alle Prompts auf.

prompts = prompt_manager.list_prompts(category="response_generation")

Parameter:

  • category (str, optional): Kategorie zum Filtern

Rückgabewert: List[Dict[str, str]] - Liste von Prompts

remove_prompt(category, name)

Entfernt einen Prompt.

prompt_manager.remove_prompt(
    category="response_generation",
    name="professional_email"
)

Parameter:

  • category (str): Kategorie des Prompts
  • name (str): Name des Prompts

Rückgabewert: bool - True bei Erfolg, False bei Fehler

update_prompt(category, name, template)

Aktualisiert einen bestehenden Prompt.

prompt_manager.update_prompt(
    category="response_generation",
    name="professional_email",
    template="Aktualisierte Prompt-Vorlage: {content}"
)

Parameter:

  • category (str): Kategorie des Prompts
  • name (str): Name des Prompts
  • template (str): Neue Prompt-Vorlage

Rückgabewert: bool - True bei Erfolg, False bei Fehler

LLMConfig

Konfiguration für LLM-Parameter.

Attribute

  • provider (str): LLM-Provider ("ollama", "openai", "onnx")
  • base_url (str): Basis-URL des LLM-Servers
  • model (str): Modellname
  • temperature (float): Temperatur für Zufälligkeit
  • api_key (str): API-Schlüssel
  • max_tokens (int): Maximale Token-Anzahl
  • timeout (int): Timeout in Sekunden
  • retry_attempts (int): Wiederholungsversuche
  • retry_delay (float): Verzögerung zwischen Wiederholungen

Methoden

to_dict()

Konvertiert die Konfiguration in ein Dictionary.

config_dict = llm_config.to_dict()

Rückgabewert: Dict[str, Any] - Konfiguration als Dictionary

from_dict(data)

Erstellt eine Konfiguration aus einem Dictionary.

llm_config = LLMConfig.from_dict(config_dict)

Parameter:

  • data (Dict[str, Any]): Konfigurationsdaten

Rückgabewert: LLMConfig - Konfigurationsobjekt

validate()

Validiert die Konfiguration.

is_valid = llm_config.validate()

Rückgabewert: bool - True bei gültiger Konfiguration, False bei ungültiger

get_provider_class()

Ruft die Provider-Klasse ab.

provider_class = llm_config.get_provider_class()

Rückgabewert: Type - Provider-Klasse

Clustering API

ClusteringEngine

Implementiert fortschrittliche Mail-Clustering-Algorithmen.

Initialisierung

from src.clustering.engine import ClusteringEngine, ClusterConfig

config = ClusterConfig(
    num_clusters=10,
    subject_weight=0.3,
    body_weight=0.7,
    min_cluster_size=2,
    max_cluster_size=100,
    algorithm="kmeans"
)

engine = ClusteringEngine(config)

Methoden

cluster_mails(mails)

Führt Clustering auf Mails durch.

clusters = engine.cluster_mails(mails)

Parameter:

  • mails (List[MailItem]): Liste von Mails

Rückgabewert: Dict[str, Any] - Cluster-Ergebnisse

{
    "clusters": [
        {
            "id": "cluster_1",
            "mails": [MailItem, MailItem, ...],
            "keywords": ["angebot", "preis", "konditionen"],
            "centroid": [0.1, 0.2, 0.3, ...],
            "size": 15,
            "similarity": 0.85
        }
    ],
    "statistics": {
        "total_mails": 100,
        "total_clusters": 10,
        "average_cluster_size": 10,
        "silhouette_score": 0.75
    }
}
optimize_cluster_count(mails, max_clusters=20)

Optimiert die Anzahl der Cluster.

optimal_count = engine.optimize_cluster_count(mails, max_clusters=20)

Parameter:

  • mails (List[MailItem]): Liste von Mails
  • max_clusters (int): Maximale Anzahl von Clustern

Rückgabewert: int - Optimale Cluster-Anzahl

get_cluster_statistics()

Ruft Cluster-Statistiken ab.

stats = engine.get_cluster_statistics()

Rückgabewert: Dict[str, Any] - Cluster-Statistiken

get_cluster_by_id(cluster_id)

Ruft einen Cluster per ID ab.

cluster = engine.get_cluster_by_id("cluster_1")

Parameter:

  • cluster_id (str): Cluster-ID

Rückgabewert: Dict[str, Any] - Cluster-Informationen

get_similar_mails(mail, threshold=0.8)

Findet ähnliche Mails.

similar_mails = engine.get_similar_mails(mail, threshold=0.8)

Parameter:

  • mail (MailItem): Referenz-Mail
  • threshold (float): Ähnlichkeitsschwelle

Rückgabewert: List[MailItem] - Liste ähnlicher Mails

export_cluster_data(cluster_id, format="json")

Exportiert Cluster-Daten.

export_data = engine.export_cluster_data("cluster_1", format="json")

Parameter:

  • cluster_id (str): Cluster-ID
  • format (str): Export-Format ("json", "csv", "excel")

Rückgabewert: str - Exportierte Daten

import_cluster_data(data)

Importiert Cluster-Daten.

engine.import_cluster_data(export_data)

Parameter:

  • data (str): Zu importierende Daten

Rückgabewert: bool - True bei Erfolg, False bei Fehler

clear_clusters()

Löscht alle Cluster.

engine.clear_clusters()

Rückgabewert: None

ClusterConfig

Konfiguration für Clustering-Parameter.

Attribute

  • num_clusters (int): Anzahl der Cluster
  • subject_weight (float): Gewichtung des Betreffs
  • body_weight (float): Gewichtung des Inhalts
  • min_cluster_size (int): Minimale Cluster-Größe
  • max_cluster_size (int): Maximale Cluster-Größe
  • algorithm (str): Clustering-Algorithmus ("kmeans", "lda", "hierarchical")
  • similarity_threshold (float): Ähnlichkeitsschwelle
  • max_features (int): Maximale Anzahl von Features
  • random_state (int): Zufallszustand
  • n_init (int): Anzahl der Initialisierungen
  • max_iter (int): Maximale Iterationen
  • tol (float): Toleranz für Konvergenz

Methoden

to_dict()

Konvertiert die Konfiguration in ein Dictionary.

config_dict = cluster_config.to_dict()

Rückgabewert: Dict[str, Any] - Konfiguration als Dictionary

from_dict(data)

Erstellt eine Konfiguration aus einem Dictionary.

cluster_config = ClusterConfig.from_dict(config_dict)

Parameter:

  • data (Dict[str, Any]): Konfigurationsdaten

Rückgabewert: ClusterConfig - Konfigurationsobjekt

validate()

Validiert die Konfiguration.

is_valid = cluster_config.validate()

Rückgabewert: bool - True bei gültiger Konfiguration, False bei ungültiger

Preprocessor

Textvorverarbeitung für Mails.

Initialisierung

from src.clustering.preprocessing import Preprocessor

preprocessor = Preprocessor()

Methoden

preprocess_mail(mail, subject_weight=0.3, body_weight=0.7)

Verarbeitet eine einzelne Mail.

processed_mail = preprocessor.preprocess_mail(mail, subject_weight=0.3, body_weight=0.7)

Parameter:

  • mail (MailItem): Zu verarbeitende Mail
  • subject_weight (float): Gewichtung des Betreffs
  • body_weight (float): Gewichtung des Inhalts

Rückgabewert: Dict[str, Any] - Verarbeitete Mail-Daten

preprocess_mails(mails, subject_weight=0.3, body_weight=0.7)

Verarbeitet eine Liste von Mails.

processed_mails = preprocessor.preprocess_mails(mails, subject_weight=0.3, body_weight=0.7)

Parameter:

  • mails (List[MailItem]): Liste von Mails
  • subject_weight (float): Gewichtung des Betreffs
  • body_weight (float): Gewichtung des Inhalts

Rückgabewert: List[List[str]] - Liste von verarbeiteten Mails

tokenize_text(text)

Tokenisiert Text.

tokens = preprocessor.tokenize_text("Dies ist ein Test-Text.")

Parameter:

  • text (str): Zu tokenisierender Text

Rückgabewert: List[str] - Liste von Tokens

remove_stopwords(tokens)

Entfernt Stop-Wörter.

filtered_tokens = preprocessor.remove_stopwords(tokens)

Parameter:

  • tokens (List[str]): Liste von Tokens

Rückgabewert: List[str] - Gefilterte Tokens

stem_tokens(tokens)

Führt Wortstamm-Reduktion durch.

stemmed_tokens = preprocessor.stem_tokens(tokens)

Parameter:

  • tokens (List[str]): Liste von Tokens

Rückgabewert: List[str] - Gestemmte Tokens

extract_keywords(text, max_keywords=10)

Extrahiert Schlüsselwörter.

keywords = preprocessor.extract_keywords("Text, aus dem Schlüsselwörter extrahiert werden sollen...", max_keywords=10)

Parameter:

  • text (str): Text zur Schlüsselwort-Extraktion
  • max_keywords (int): Maximale Anzahl von Schlüsselwörtern

Rückgabewert: List[str] - Liste von