-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathprosody_u.py
92 lines (76 loc) · 3.04 KB
/
prosody_u.py
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright 2019 Abdelkrime Aries <[email protected]>
#
# ---- AUTHORS ----
# 2019 Abdelkrime Aries <[email protected]>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import os, sys
import pytest
import json
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
from aruudy.poetry import prosody
from aruudy.poetry.prosody import Shatr
from aruudy.poetry.meter import Bahr
def test_normalize():
assert prosody.normalize(u"تَطْوِيـــــــــــــــــــــل") == u"تَطْوِيل"
assert prosody.normalize(u"الأَول الشمس القمر") == u"اَلأَول الشّٓمس القٓمر"
assert prosody.normalize(u"ساح يسيح يسوح") == u"سَاح يٓسِيح يٓسُوح"
#private function
def test_prosody_del():
assert prosody._prosody_del(u"وَالشمس") == u"وَشمس"
assert prosody._prosody_del(u"فَالعلم") == u"فَلعلم"
assert prosody._prosody_del(u"فاستمعَ") == u"فستمعَ"
assert prosody._prosody_del(u"أَتَى المَظلوم إلَى القَاضِي فَأَنصفه قَاضِي العَدل") == u"أَتَ لمَظلوم إلَ لقَاضِي فَأَنصفه قَاضِ لعَدل"
assert prosody._prosody_del(u"رجعوا") == u"رجعُوْ"
#private function
#def test_prosody_add():
# assert meter._prosody_add(u"") == u""
def test_process_shatr ():
text = u"أَسِرْبَ القَطا هَلْ مَنْ يُعِيْرُ جَناحَهُ"
ameter = "wwswswwswswswwswwwswws"
s = prosody.process_shatr(text)
assert type(s) == Shatr
d = s.to_dict()
assert type(d) == dict
assert type(d["bahr"]) == Bahr
d = s.to_dict(bahr=True)
assert type(d["bahr"]) == dict
assert d["ameter"] == ameter
s = prosody.process_shatr("aaa")
assert not s.bahr
try:
UNICODE_EXISTS = bool(type(unicode))
except NameError:
unicode = lambda s: str(s)
def test_bahr_detection ():
script_dir = os.path.dirname(__file__) #<-- absolute dir the script is in
fpath = os.path.join(script_dir, "exp.json")
with open(fpath, "r") as f:
exps = json.load(f)["exp"]
for exp in exps:
"""
try:
txt = exp["shatr"].encode()
out = exp["bahr"].encode()
except:
txt = exp["shatr"]
out = exp["bahr"]
"""
txt = unicode(exp["shatr"])
out = unicode(exp["bahr"])
#print (txt)
s = prosody.process_shatr(txt)
assert s.bahr.name["arabic"] == out