Extending WiMarka ================= This guide covers extending WiMarka with new features, languages, and custom evaluation logic. Adding New Languages -------------------- To add support for a new Philippine language: Step 1: Update Language Codes ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Add language code to ``config.py``: .. code-block:: python SUPPORTED_LANGUAGES = ['EN', 'CEB', 'ILO', 'TGT', 'HIL'] # Add HIL Step 2: Update Helper Functions ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Modify ``utils/helper.py`` to recognize the new language: .. code-block:: python LANGUAGE_NAMES = { 'EN': 'English', 'CEB': 'Cebuano', 'ILO': 'Ilocano', 'TGT': 'Tagalog', 'HIL': 'Hiligaynon' # Add new language } Step 3: Add Language-Specific Models ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ If using language-specific models, update ``model.py``: .. code-block:: python LANGUAGE_MODELS = { 'CEB': 'model-id-for-cebuano', 'ILO': 'model-id-for-ilocano', 'TGT': 'model-id-for-tagalog', 'HIL': 'model-id-for-hiligaynon' # Add new model } Step 4: Test ~~~~~~~~~~~~ Create test files and validate: .. code-block:: bash wimarka --src_file_path test_en.txt \\ --src_lang EN \\ --tgt_file_path test_hil.txt \\ --tgt_lang HIL Adding Custom Tasks ------------------- To add a new evaluation task: Step 1: Create Task Module ~~~~~~~~~~~~~~~~~~~~~~~~~~~ Create ``wimarka/tasks/sentiment_analysis.py``: .. code-block:: python def analyze_sentiment(src_line: str, tgt_line: str) -> str: """Analyze sentiment preservation in translation.""" # Implementation return sentiment_report Step 2: Integrate into Pipeline ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Modify ``main.py``: .. code-block:: python from wimarka.tasks import sentiment_analysis # In wmk_eval function sentiment = sentiment_analysis.analyze_sentiment(src_line, tgt_line) results['sentiment'].append(sentiment) Step 3: Update Results Structure ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Add new field to results dictionary: .. code-block:: python results = { 'source': [], 'target': [], # ... existing fields ... 'sentiment': [] # New field } Custom Scoring Algorithms -------------------------- To implement custom scoring: .. code-block:: python def custom_scoring(src: str, tgt: str, errors: List[str]) -> Tuple[float, float, float]: """Custom scoring logic.""" # Your algorithm fluency = calculate_custom_fluency(src, tgt) adequacy = calculate_custom_adequacy(src, tgt, errors) overall = (fluency + adequacy) / 2 return fluency, adequacy, overall # Replace in pipeline from wimarka.tasks import scoring scoring.scoring = custom_scoring Creating Plugins ---------------- For distributable extensions: .. code-block:: python # wimarka_plugin_myfeature/__init__.py def register_plugin(): """Register plugin with WiMarka.""" from wimarka import main main.register_task('myfeature', my_task_function) Alternative Interfaces ---------------------- Web API Example ~~~~~~~~~~~~~~~ .. code-block:: python from flask import Flask, request, jsonify from wimarka.main import wmk_eval, results app = Flask(__name__) @app.route('/evaluate', methods=['POST']) def evaluate(): data = request.json # Process and return results return jsonify(results) GUI Example ~~~~~~~~~~~ .. code-block:: python import tkinter as tk from wimarka.main import wmk_eval # Create GUI application # ... Best Practices -------------- * **Modular Design**: Keep extensions independent * **Documentation**: Document all custom features * **Testing**: Test extensions thoroughly * **Compatibility**: Ensure backwards compatibility See Also -------- * :doc:`architecture` - System architecture * :doc:`development` - Development guide * :doc:`api_reference` - API documentation