|
|
"""
|
|
|
Multilingual Processing Module
|
|
|
"""
|
|
|
|
|
|
import time
|
|
|
import re
|
|
|
|
|
|
class MultilingualProcessor:
|
|
|
def __init__(self):
|
|
|
self.initialized = False
|
|
|
self.supported_languages = ['english', 'luganda']
|
|
|
self.translation_models = {}
|
|
|
|
|
|
def initialize(self):
|
|
|
"""Initialize multilingual processor"""
|
|
|
print("Initializing Multilingual Processing Module...")
|
|
|
time.sleep(1)
|
|
|
self.initialized = True
|
|
|
print("Multilingual Processing Module initialized successfully")
|
|
|
|
|
|
def process(self, text):
|
|
|
"""Process text in multiple languages"""
|
|
|
if not self.initialized or not text:
|
|
|
return text
|
|
|
|
|
|
|
|
|
processed_text = self.normalize_text(text)
|
|
|
|
|
|
|
|
|
if self.is_luganda(text):
|
|
|
processed_text = self.process_luganda(text)
|
|
|
else:
|
|
|
processed_text = self.process_english(text)
|
|
|
|
|
|
return processed_text
|
|
|
|
|
|
... def normalize_text(self, text):
|
|
|
... """Normalize text for processing"""
|
|
|
...
|
|
|
... text = re.sub(r'\s+', ' ', text.strip())
|
|
|
... return text
|
|
|
...
|
|
|
... def is_luganda(self, text):
|
|
|
... """Simple Luganda detection"""
|
|
|
... luganda_indicators = ['naye', 'bwe', 'kye', 'gye', 'mwe', 'bwekiri']
|
|
|
... text_lower = text.lower()
|
|
|
...
|
|
|
... for indicator in luganda_indicators:
|
|
|
... if indicator in text_lower:
|
|
|
... return True
|
|
|
...
|
|
|
... return False
|
|
|
...
|
|
|
... def process_luganda(self, text):
|
|
|
... """Process Luganda text"""
|
|
|
...
|
|
|
... processed = text
|
|
|
...
|
|
|
...
|
|
|
... replacements = {
|
|
|
... 'naye': 'but',
|
|
|
... 'bwe': 'when',
|
|
|
... 'kye': 'what',
|
|
|
... 'gye': 'where'
|
|
|
... }
|
|
|
...
|
|
|
... for luganda_word, english_word in replacements.items():
|
|
|
... processed = processed.replace(luganda_word, english_word)
|
|
|
...
|
|
|
... return processed
|
|
|
...
|
|
|
... def process_english(self, text):
|
|
|
... """Process English text"""
|
|
|
...
|
|
|
... return text.strip()
|
|
|
|