File size: 1,672 Bytes
31a6db1 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | import sys
import io
from pathlib import Path
# Force UTF-8 encoding for standard output
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
# Add src to python path
sys.path.insert(0, str(Path(r'c:\Users\dell\PycharmProjects\JupyterProject1\PythonProject\BAYAN\src')))
from app import app
client = app.test_client()
def test(text):
print(f"\n--- Testing: {text} ---")
resp = client.post('/api/analyze', json={'text': text})
data = resp.get_json()
if data and 'corrected' in data:
print(f"Corrected: {data['corrected']}")
if data and 'suggestions' in data:
for s in data['suggestions']:
print(f"[{s['type'].upper()}] '{s['original']}' -> '{s['correction']}'")
elif data and 'error' in data:
print("Error:", data['error'])
else:
print("Raw Data:", data)
if __name__ == "__main__":
# Test 1: Single Entity (Should not have punctuation added)
test("شركة أبل")
# Test 2: Short phrase (Should not have punctuation added)
test("مرحبا بكم في التطبيق")
# Test 3: Grammar error that gets fixed but then corrupted by punctuation
# "الى" is spelled wrong (needs hamza on alif below if it's إِلى or just remains الى depending on rules,
# but let's see what grammar does). Actually "يذهبون المهندسون" is a grammar error in Arabic
# (should be يذهب المهندسون).
test("يذهبون المهندسون الى الشركة")
# Test 4: Verify Grammar Model preserves punctuation
test("يذهبون المهندسون الى الشركة، أليس كذلك؟")
|