File size: 5,065 Bytes
e007b04
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#!/usr/bin/python
# -*- coding=utf-8 -*-
#************************************************************************
# from arabic_const import *
from pyarabic.araby import *
from verb_const import *
class Stack :
	def __init__(self,text="") :
		self.items = list(text);

	def push(self, item) :
		self.items.append(item)

	def pop(self) :
		if not self.isEmpty():
			return self.items.pop()
		else:
			return None;

	def isEmpty(self) :
		return (self.items == [])


def separate(word):
	"""

	separate the letters from the vowels, in arabic word,

	if a letter hasn't a haraka, the not definited haraka is attributed.

	return ( letters,vowels);

	"""
	#debug=True;
	stack1=Stack(word)
	# the word is inversed in the stack
	stack1.items.reverse();
	letters=Stack()
	marks=Stack()
	vowels=('a','u')
	last1=stack1.pop();
	# if the last element must be a letter,
	# the arabic word can't starts with a haraka
	# in th stack the word is inversed
	while last1 in vowels: last1=stack1.pop();
	while  last1!=None:
		if last1 in vowels:
			# we can't have two harakats beside.
			# the shadda is considered as a letter
			marks.pop();
			marks.push(last1);
		elif last1==SHADDA:
			# is the element is a Shadda,
			# the previous letter must have a sukun as mark,
			# and the shadda take the indefinate  mark
			marks.pop();
			marks.push(SUKUN);
			marks.push(NOT_DEF_HARAKA);
			letters.push(SHADDA);
		else:
			marks.push(NOT_DEF_HARAKA);
			letters.push(last1);
		last1=stack1.pop();
	return (''.join(letters.items),''.join(marks.items))


def joint(letters,marks):
	"""

	joint the letters with the marks

	the length ot letters and marks must be equal

	return word;

	"""
	#debug=True;
	debug=False;
	# The length ot letters and marks must be equal
	if len(letters)!=len(marks): return "";

	stackLetter=Stack(letters)
	stackLetter.items.reverse();
	stackMark=Stack(marks)
	stackMark.items.reverse();
	wordStack=Stack();
	last1=stackLetter.pop();
	last2=stackMark.pop();

	vowels=('a','u','o','i',SUKUN)
	while  last1!=None and  last2!=None:
		if last1 == SHADDA:
			top=wordStack.pop();
			if top not in vowels:
				wordStack.push(top);
			wordStack.push(last1);
			if last2!= NOT_DEF_HARAKA:
				wordStack.push(last2);
		else:
			wordStack.push(last1);
			if last2!= NOT_DEF_HARAKA:
				wordStack.push(last2);

		last1=stackLetter.pop();
		last2=stackMark.pop();
	if not (stackLetter.isEmpty() and stackMark.isEmpty()):
		return False;
	else:
		#wordStack.items.reverse();
		return ''.join(wordStack.items);

def vocalizedlike(word1,word2):
	"""

	if the two words has the same letters and the same harakats, this fuction return True.

	The two words can be full vocalized, or partial vocalized

	"""
	debug=False;
	stack1=Stack(word1)
	stack2=Stack(word2)
	last1=stack1.pop();
	last2=stack2.pop();
	if debug: print "+0", stack1, stack2;
	vowels=('a','u')
	while  last1!=None and  last2!=None:
		if last1==last2:
			if debug: print "+2", stack1.items,last1, stack2.items,last2
			last1=stack1.pop();
			last2=stack2.pop();
		elif last1 in vowels and last2 not in vowels:
			if debug: print "+2", stack1.items,last1, stack2.items,last2
			last1=stack1.pop();
		elif last1 not in vowels and last2 in vowels:
			if debug: print "+2", stack1.items,last1, stack2.items,last2
			last2=stack2.pop();
		else:
			if debug: print "+2", stack1.items,last1, stack2.items,last2
			break;
	if not (stack1.isEmpty() and stack2.isEmpty()):
		return False;
	else: return True;
#-------------------------
# Function def vaznlike(word1,wazn):
#-------------------------
def waznlike(word1,wazn):
	"""

	if the  word1 is like a wazn (pattern),

	the letters must be equal,

	the wazn has FEH, AIN, LAM letters.

	this are as generic letters.

	The two words can be full vocalized, or partial vocalized

	"""
	debug=False;
	stack1=Stack(word1)
	stack2=Stack(wazn)
	root=Stack()
	last1=stack1.pop();
	last2=stack2.pop();
	if debug: print "+0", stack1, stack2;
	vowels=('a','u')
	while  last1!=None and  last2!=None:
		if last1==last2 and last2 not in (FEH, AIN,LAM):
			if debug: print "+2", stack1.items,last1, stack2.items,last2
			last1=stack1.pop();
			last2=stack2.pop();
		elif last1 not in vowels and last2 in (FEH, AIN,LAM):
			if debug: print "+2", stack1.items,last1, stack2.items,last2
			root.push(last1);
			print "t";
			last1=stack1.pop();
			last2=stack2.pop();
		elif last1 in vowels and last2 not in vowels:
			if debug: print "+2", stack1.items,last1, stack2.items,last2
			last1=stack1.pop();
		elif last1 not in vowels and last2 in vowels:
			if debug: print "+2", stack1.items,last1, stack2.items,last2
			last2=stack2.pop();
		else:
			if debug: print "+2", stack1.items,last1, stack2.items,last2
			break;
	# reverse the root letters
	root.items.reverse();
	print " the root is ", root.items#"".join(root.items);
	if not (stack1.isEmpty() and stack2.isEmpty()):
		return False;
	else: return True;