
    -iJ                     J   d Z edk    r8ddlZej                            d           ej                            d           ddlmZ ddlZddlZddlZddl	m
Z
 ddlmZ ddlZddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ  G d d          Zd Zedk    r e             dS dS )z
Syntaxic Analysis
__main__    Nz../libz../)xor)arepr   )	syn_const)synnode)stemmedsynword)cache_pickledbc                       e Zd ZdZd!dZd Zd Zd Zd Zd Z	d	 Z
d
 Z	 	 d"dZd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd!dZd Zd!d ZdS )#SyntaxAnalyzerz$
        Arabic Syntax analyzer
    Fc                     t          j                    | _        d| _        || _        |rt          j        |          | _        nd | _        d S )NF)wordtag
WordTagger
wordtaggersyntax_train_enabled
cache_pathcache)selfr   s     M/var/www/html/speakWrite/venv/lib/python3.11/site-packages/sylajone/anasyn.py__init__zSyntaxAnalyzer.__init__.   sN    !,.. %*! % 	Z00DJJDJ
 	    c                 x    | j         r2| j                                         | j                                         d S )N)r   r   updatedisplay_allr   s    r   __del__zSyntaxAnalyzer.__del__?   s<     $ 	%JJ""$$$r   c                     |                                 }|                                 }| j                            |||           dS )zN
        Add relation between previous and current with realtion code
        N)get_originalr   add_relation)r   previouscurrentrelationpre_originalcur_originals         r   add_cache_relationz!SyntaxAnalyzer.add_cache_relationG   sF      ,,..++--
lHEEEEEr   c                 R   g }g }|D ]fdt          t                              D             }|st          j        d                   g}|                    |           |                    t          j        |                     |                     ||          \  }}||fS )a  
        Syntaxic analysis of stemming results.
        morphological Result is a list of stemmedword objects
         The syntaxic result have the same structure, 
         but we add a field named 'syntax' to every word steming dictioionary
        @param detailed_stemming_dict: detailed stemming dict.
        @type detailed_stemming_dict:list of list of stemmedword objects
        @return: detailed syntaxic result with syntaxic tags.
        @rtype: list of list of stemmedsynword
        c                 F    g | ]}t          j        |         |          S  )r	   StemmedSynWord).0orderstemming_lists     r   
<listcomp>z*SyntaxAnalyzer.analyze.<locals>.<listcomp>a   sA     @ @ @! &4]55I5QQ @ @ @r   r   )rangelenr	   r)   appendr   SynNodestudy_syntax_by_synode)r   detailed_stemming_dictstemmedsynwordlistlistsynnode_listtmplistr,   s        @r   analyzezSyntaxAnalyzer.analyzeP   s     "$ 4 	: 	:M@ @ @ @%*3}+=+=%>%>@ @ @G  M)8q9IJJL"))'222 8 89999/3/J/JKaco/p/p,%|33r   c                    d}d}t          t          t          ||                              D ]\  }\  }}|dz   t          |          k     r||dz            }nd}t          |          D ]\\  }	}
|s|                     d|
          d         }
$t          ||                   D ]"\  }}|                     ||
||	||          \  }}
#]|}|}||fS )zF
        Analyzing the texts words cases by one syntax node,

        NFr   )	enumeratelistzipr/   bigram_analyze)r   r4   r5   pre_nodeprevious_indexcurrent_indexstemmedsynwordlistcurrent_node	next_nodecurrent_case_indexstmwordprevious_case_indexr    s                r   r2   z%SyntaxAnalyzer.study_syntax_by_synodel   s2    CLTRUVlmyRzRzM{M{C|C| 	* 	*=M=.q 3|#4#444(q9		 	/89K/L/L Q Q+"G% Q"11$AA!DGG9BCYZhCi9j9j Q Q5+X,0,?,?'Sfhz  }E  GP  -Q  -Q)''Q +N)HH%|33r   c                    d}|                                 r|                                r	 t          t          |                                                    }n# t
          $ r d}Y nw xY w|dz  t          t          dd                    v s	|dz  dk    r!|                                rt          j
        }nK|dz  t          t          dd                    v s	|dz  dk    r |                                rt          j        }|S )zT
        Return the weight if the previous and current have number relation
        r   d      
      c   )is_noun	is_tanwinintfloatget_word
ValueErrorr:   r.   
is_majroursconstJarMajrourRelation
is_mansoubNasebMansoubRelation)r   r    r!   weightnumbers        r   is_number_relationz!SyntaxAnalyzer.is_number_relation   s    ?? 	9!2!2!4!4 	9U8#4#4#6#67788   }U1R[[ 1 111Vc\Q5F5F%%'' 7#6F3,$uR||"4"4448I8I%%'' 9#8Fs   .A A*)A*c                     |                                 o<|                                o(|                                 o|                                S )zY
        Return the weight if the previous and current have verb object relation
        )rL   rU   has_encleticis_transitiver   r    r!   s      r   is_verb_object_relationz&SyntaxAnalyzer.is_verb_object_relation   sX     !! Hg&8&8&:&: H((***H/7/E/E/G/G	Ir   c                 N   |                                 rdS |                                r}|                                ri|                                rU|                                rA|                                r-|                                s|                    |          rdS d S |                                r|                                r|                                r|                                r|                                r|                                s|                                |                                k    rY|	                                |	                                k    r/|
                                s|                    |          rdS dS dS dS dS )NFT)is_stopwordis_breakrL   has_procletichas_jonctionhas_jareq_caseis_verb	get_tenseget_pronoun
is_presentr]   s      r   is_jonction_relationz#SyntaxAnalyzer.is_jonction_relation   s    !! 	5 	'//"3"3 	9I9I9K9K 	##%%	*1*>*>*@*@	IPIZIZ	 x(( t  	GOO$5$5 	8;K;K;M;M 	##%%	*1*>*>*@*@	IPIZIZ	
 ""$$(:(:(<(<<<((**h.B.B.D.DDD))++  x00 %#t$u  4u5r   r   Nc                    d}|r|                                 r|                     ||||          S |s|                     ||||          S |                     ||          rD|                    |t
          j                   |                    |t
          j                   ||fS |                                r|	                                r$|                    |t
          j
                   ||fS |                                rp|                                s|                                rH|                                s|                                r |                                rt
          j        }|                                r<|                                dk    r$|                    |t
          j                   ||fS n|                                r|                     ||          }n*|                                r|                     ||          }|s*|                                r|                     ||          }|                                r|                     ||          }|rJ|                    ||           |                    ||           | j        r|                     |||           ||fS )a  
        Syntaxic analysis of stemming results, two words.
        the positions are use to join related cases.
        @param previous : the first item in bigram.
        @type previous  : stemmedSynWord
        @param current  : the second item in bigram.
        @type current   : stemmedSynWord
        @param currentSynode    : the current synode in The phrase.
        @type  currentSynode    : synnode object
        @param previous : the first item position in the word case list.
        @type previous  : stemmedSynWord
        @param current  : the second item position in the word case list.
        @type current   : stemmedSynWord
        @return: the updated previous and current stemmedSynWord.
        @rtype: (previous, current)
        r   u
   قَالَ)
is_initialtreat_initialtreat_finalrj   add_nextrS   JonctionRelationadd_previousra   rM   TanwinRelationrf   r`   rd   is_indirect_transitive_stopwordis_indirect_transitiveVerbParticulRelation	is_pounctr   VerbObjectRelationrL   treat_previous_nountreat_previous_verbtreat_previous_stopword	is_numberrY   r   r%   )r   r    r!   previous_positioncurrent_positionr=   rB   rW   s           r   r<   zSyntaxAnalyzer.bigram_analyze   s   4   		'8..00 		'%%h9JL\]]] 	'##Hg7HJZ[[[&&x99 	'/1HIII  !2F4KLLLg&& &	D!!## +!!"2F4IJJJ '** !! 9w':':'<'< 9@Q@Q 9__&& 9'*Q*Q*S*S 9YaYxYxYzYz 9#8F  "" /((**m;;%%&68QRRR$g.. !! E11(GDD!!## E11(GDD  Ih2244 I 55hHH
 !!## D007CC 		C.777   !2F;;;( C'''6BBB  r   c                     |                                 s(|                                s|                                r |                    |t          j                   ||fS )aP  
        Treat Initial case, where the current case is the first in the list
        @param previous: the previous case
        @type previous: stemmedSynWord
        @param next: the current case
        @type current: stemmedSynWord
        @return: (previous, current) after treatment
        @rtype: tuple of stemmedSynWord
        )
is_marfou3is_pastr`   rq   rS   PrimateRelationr   r    r!   r|   r}   s        r   rm   zSyntaxAnalyzer.treat_initial+  sf      	L7??#4#4 	L8K8K8M8M 	L
   !2F4JKKK'""r   c                 r    |                                 r |                    |t          j                   ||fS )aI  
        Treat final cases, where the current case is the end of line
        @param previous: the previous case
        @type previous: stemmedSynWord
        @param next: the current case
        @type current: stemmedSynWord
        @return: (previous, current) after treatment
        @rtype: tuple of stemmedSynWord
        )rM   ro   rS   rr   r   s        r   rn   zSyntaxAnalyzer.treat_final>  s>    4  	G.0EFFF'""r   c                    d}|                                 s|                                sdS |                                r4|                                r |                                rt          j        }|                     ||          r!|                                rt          j        }n| 	                    ||          r|                                r|
                                r!|
                                rt          j        }n|                                r!|
                                rt          j        }nk|
                                r |                                rt          j        }n6|                                r"|                     ||          rt          j        }|s |                                rt          j        }|S )a;  
        Treat noun cases, where the previous is a noun
        @param previous: the previous case
        @type previous: stemmedSynWord
        @param next: the current case
        @type current: stemmedSynWord
        @return: (previous, current) after treatment
        @rtype: tuple of stemmedSynWord
        r   )ra   rL   need_additionis_additionablerS   AdditionRelationare_compatibleis_adjDescribedAdjectiveRelationare_nominal_compatibler   PrimatePredicateRelationrU   PrimateMansoubPredicateRelationPrimatePredicateMansoubRelationrf   compatible_subject_verbRafe3Marfou3Relationis_confirmationConfirmationRelationr   r    r!   rW   s       r   rx   z"SyntaxAnalyzer.treat_previous_noun]  s      	X%5%5%7%7 	1
 ?? $	5 %%'' 1G,C,C,E,E 10 ""8W55 H>>## ?#>F,,Xw?? 
H>>## 	H ++-- H'2D2D2F2F H!'!@"--// HG4F4F4H4H H!'!G"--// HG4F4F4H4H H!'!G __ 	5++Hg>> 54 	1'1133 	10Fr   c                    d}|                                 s|                                sdS |                                rK|                                r|                                r|                                r|                                s/	 |
                                rt          j        }nit          j        }n\|                                r|                                s(|                                s |	                                rt          j        }|                                s|                                rH|                                s4|                                s |                                rt          j        }|S )a;  
        Treat verb cases, where the previous is a noun
        @param previous: the previous case
        @type previous: stemmedSynWord
        @param next: the current case
        @type current: stemmedSynWord
        @return: (previous, current) after treatment
        @rtype: tuple of stemmedSynWord
        r   )ra   rf   rL   r   is3rdperson	is_single
is_passive
is_femininis3rdperson_femininis3rdperson_masculinis_kana_rafe3rS   KanaRafe3Marfou3RelationVerbSubjectRelationVerbPassiveSubjectRelationrU   is_mabnir[   r\   rw   r   s       r   ry   z"SyntaxAnalyzer.treat_previous_verb  s     	X%5%5%7%7 	1 ?? 	;!!## G'')) Gh.@.@.B.B G $..00 GD  (5577 D)/)H *0)C %//11 Gh6R6R6T6T G#*#5#5#7#7G<D<Y<Y<[<[G%+%FF !!## ;w'7'7'9'9 ;  **,, ;#0022 ;x7M7M7O7O ;!'!:r   c                 |   d}|                                 s|                                sdS |                                r|                                r!|                                rt
          j        }n|                                r!|                                rt
          j	        }n|
                                r!|                                rt
          j        }ni|                                r!|                                rt
          j        }n4|                                r |                                rt
          j        }|                                r|                                r"|                                rt
          j        }n|                                r"|                                rt
          j        }n|                                r |                                rt
          j        }n|                                r|                     ||          rt
          j        }|                                r|                                rZ|                                rF|                                dk    r!|                                rt
          j        }nt
          j        }n|                                r!|                                rt
          j        }nm|                                 rY|                                rE|                                dk    r!|                                st
          j        }nt
          j        }|!                                rt
          j"        }|#                                rt
          j$        }|%                                rt
          j&        }|S )aC  
        Treat stopword cases, where the previous is a stopword
        @param previous: the previous case
        @type previous: stemmedSynWord
        @param next: the current case
        @type current: stemmedSynWord
        @return: (previous, current) after treatment
        @rtype: tuple of stemmedSynWord
        r   u   لا)'ra   r`   rL   is_jarrR   rS   rT   is_nasebrU   InnaNasebMansoubRelationrl   r   r   r   r   is_rafe3r   is_substitutedSubstitutionMansoubRelationSubstitutionMarfou3RelationSubstitutionMajrourRelationrf   r   SubjectVerbRelationri   is_jazem
is_majzoumget_unvoriginalhas_imperative_pronounJazemMajzoumRelationis_verb_nasebrV   is_verb_rafe3is_condition_factorConditionVerbRelationis_verb_jobless_factorJoblessFactorVerbRelationis_jonctionrp   r   s       r   rz   z&SyntaxAnalyzer.treat_previous_stopword  s     	X%9%9%;%; 	1 ?? @	:   9%%'' 7#6F ""$$ 9%%'' =#<F$$&& 	9G,>,>,@,@ 	9/ '')) 9g.@.@.B.B 98""$$ 9%%'' 9#8F
 &&(( @'')) @g.@.@.B.B @#?FF))++ @0B0B0D0D @#?FF))++ @0B0B0D0D @#?F __ 	:++Hg>> 43 !!## =$$&& =7+=+=+?+? =  //11W<<"99;; @$*$?6!'!<++-- 	=73E3E3G3G 	=#8FF++-- ='2D2D2F2F =  //11W<<&==?? @$*$?6!'!<++-- 65..00 :9!! 	-,Fr   c                     |rT|rR|                                 |                                v r*|                                 |                                v rdS dS )ar  
        verify the syntaxic path from the previous to current stemmed word.
        If the current word is related with the previous word, return True.
        The previous word can contain a pointer to the next word. t
        he current can have a pointer to the previous if they ara realated
        @param previous: the previous stemmed word, 
        choosen by the tashkeel process.
        @type previous:stemmedSynWord class 
        @param current: the current stemmed word.
        @type current:stemmedSynWord class 
        @return: return if the two words are related syntaxicly.
        @rtype: boolean
        TF)	get_orderget_previousget_nextr]   s      r   
is_relatedzSyntaxAnalyzer.is_related  sg      	 	h&8&8&:&:' '#*#4#4#6#6(:K:K:M:M#M#M4Ur   c                 N   |                                 s|                                r|                                 sdS d}|                    |          rd}ndS |                    |          rd}|                    |          sP|                                r?|                                r+|                                r|                                rd}ndS |                    |          rd}ndS |	                                r|
                                dv rd}ndS |S )u  
        verify the gramatica relation between the two words.
        دراسة الترابط النخوي بين الكلمتين، اي توافقهما في الجمع والنوع، والحركة
        If the current word is related with the previous word, return True.
        The previous word can contain a pointer to the next word. 
        the current can have a pointer to the previous if they ara realated
        @param previous: the previous stemmed word, choosen by the tashkeel process.
        @type previous:stemmedSynWord class 
        @param current: the current stemmed word.
        @type current:stemmedSynWord class 
        @return: return if the two words are related syntaxicly.
        @rtype: boolean
        FT)u   الu   فالu   والu   وu   ف)rL   is_addition
eq_defined	eq_gender	eq_numberr   r   	is_pluralre   rb   get_procleticr   r    r!   
compatibles       r   r   zSyntaxAnalyzer.are_compatible1  sf     ""$$ 	(<(<(>(> 		5
 h'' 	JJ5 X&& 	 J X&& 	7+<+<+>+> 	7CUCUCWCW 	!!	&.&9&9&;&;	JJ5 ??8$$ 	JJ5 $$&& 	'*?*?*A*A F. +. +.JJ5 r   c                 \   |                                 sdS d}|                                 r|                                s|                                rd}ndS |                                r|                                sP|                                r|                                s(|                                r|                                rd}ndS |                                sd}ndS |                                sd}ndS |                    |          rd}ndS |                    |          rd}ndS |                                r|                                rd}ndS |                                sd}ndS |                                sd}ndS |                    |          rd}ndS |	                    |          rd}ndS |                    |          rd}ndS |
                                s(|                                r|                                rd}ndS |S )u,  
        verify the gramatica relation between the two words, 
        for nominal relational المبتدأ والخبر
        دراسة الترابط النخوي بين الكلمتين، اي توافقهما في الجمع والنوع، والحركة
        If the current word is related with the previous word, return True.
        The previous word can contain a pointer to the next word. 
        the current can have a pointer to the previous if they ara realated
        @param previous: the previous stemmed word, 
        choosen by the tashkeel process.
        @type previous:stemmedSynWord class 
        @param current: the current stemmed word.
        @type current:stemmedSynWord class 
        @return: return if the two words are related syntaxicly.
        @rtype: boolean
        FT)rL   
is_definedrU   r   rb   rM   r   r   rf   	eq_personr   ri   r   s       r   r   z%SyntaxAnalyzer.are_nominal_compatible  s     !! 	5 
?? v	 &&(( X-@-@-B-B !

u $$&& 7+=+=+?+? $$&&+2+=+=+?+? ##%%	 +2*<*<*>*>	
 "

u ((** !

u%%'' !

u   ** !

u   ** !

__ :	 ""$$ !

u ((** !

u%%'' !

u
   ** !

u   ** !

   ** !

    W%7%7%9%9 !!!

ur   c                    d}|                                 s|                                rdS |                                r|                                rr|                                r^|                                rJt
          j                            |                                g           }|	                                |v rd}|
                                rJt
          j                            |                                g           }|                                |v rd}n|                                s(|                                s|                                rd}ndS |                    |          rd}ndS |                    |          rd}ndS |                    |          rd}ndS |                                s(|                                r|                                rd}ndS |S )u  
        verify the gramatical relation between the two words, 
        for subject and verb 
        دراسة الترابط بين الفاعل والفعل، حين يسبق الفاعل الفعل
        If the current word is related with the previous word, return True.
        The previous word can contain a pointer to the next word. 
        the current can have a pointer to the previous if they ara realated
        @param previous: the previous stemmed word, 
        choosen by the tashkeel process.
        @type previous:stemmedSynWord class 
        @param current: the current stemmed word.
        @type current:stemmedSynWord class 
        @return: return if the two words are related syntaxicly.
        @rtype: boolean
        FT)r   rU   r`   
is_pronounrf   rS   TABLE_PRONOUNgetrh   r   is_addedget_encleticr   rM   r[   r   r   r   r   ri   r   )r   r    r!   r   expected_pronounss        r   r   z&SyntaxAnalyzer.compatible_subject_verb  s"     
  	7#5#5#7#7 	5!! ;	##%% *'//*;*; *&&(( *(.(<(@(@ATATAVAVXZ([([%,,..2CCC%)

   "" &$*$8$<$<W=P=P=R=RTV$W$W!((**.???!%J ##%% ););)=)= (BWBWBYBY !

u
   ** !

u   ** !

   ** !

    W%7%7%9%9 !!!

ur   c                    |t           j        k    r&dt           j                            |d          v rdS dS |t           j        k    r&dt           j                            |d          v rdS dS |t           j        k    r&dt           j                            |d          v rdS dS |t           j        k    r|t           j        k    rdS |t           j        k    r|t           j        k    rdS |t           j	        k    r|t           j
        k    sdS |t           j        k    r|t           j        k    sdS |t           j        k    r$|t           j
        k    rdS |t           j        k    rdS dS )um  
        verify the gramatica relation between three words are compatible.
           دراسة الترابط النحوي بين ثلاث كلمات بواسطة علاقتها، اي توافق العلاقتين، لا سيما في التبعية والبدل.
        If the current relation can be compatible with the previous relation
        @param previous: the relation choosen by the tashkeel process.
        @type previous:int 
        @param current: the current relation.
        @type current: int 
        @return: return if the two relations are compatible syntaxicly.
        @rtype: boolean
        u   جر TFu   نصبu   رفع)rS   r   RELATIONS_TAGSr   r   r   r   r   r   r   r   r   r   r   r]   s      r   are_compatible_relationsz'SyntaxAnalyzer.are_compatible_relationso  sm    f888&/33HR@@@@tuf888F155hrBBBBtuf888F155hrBBBBtu f000XA[5[5[5 222x6C_7_7_5
 f<<<XQWQpEpEp5 >>>xSYSrGrGr5 f5556:::u V<<<utr   c                     g }|D ]-}d|                                 v r|                    |           .t          |          dk    r|S |S )z
        exclode imcompatible cases
        @param word_result: The steming dict of the previous word.
        @type word_result: list of dict
        @return: the filtred word result dictionary with related tags.
        @rtype: list of dict
        #r   )
get_syntaxr0   r/   )r   word_resultnew_word_resultstemming_dicts       r   exclode_caseszSyntaxAnalyzer.exclode_cases  sc     ( 	6 	6Mm..0000&&}555!!""r   c                    g }|D ]}g }g }|                                 r|                    d           |                                r|                    d           |                                r|                    d           |                                r|                    d           |s|}n"|D ]}|D ]}|                    ||z               |r|}dS )z
        Detect Possible syntaxical nodes sequences
        @param synnode_list: list of synNode.
        @type synnode_list:  list of synNode.
        VNS.T)hasVerbr0   hasNounhasStopword
has_pounct)r   r5   grammar_listsndr6   taglistgrmtags           r   detect_accepted_gammarz%SyntaxAnalyzer.detect_accepted_gammar  s     	' 	'CGG{{}} $s###{{}} $s###   $s###~~ $s### 0&' 0 0C& 0 0s3w////0 '&tr   c                 b    d| _         | j        s t          j        | j                  | _        dS dS )zD
        Allow the anasyntax to use Cache to reduce calcul.
        TN)r   r   Cacher   r   s    r   enable_allow_cache_usez%SyntaxAnalyzer.enable_allow_cache_use  s7     %)!z 	6T_55DJJJ	6 	6r   c                     d| _         dS )zH
        Not allow the anasyntax to use Cache to reduce calcul.
        FN)r   r   s    r   disable_allow_cache_usez&SyntaxAnalyzer.disable_allow_cache_use  s     %*!!!r   c                 \    t          j        t          j        |          }d |D             }|S )a/  
        Decode objects result from analysis. helps to display result.
        @param stemmed_synwordlistlist: list of  list of StemmedSynWord.
        @type word_result: list of  list of StemmedSynWord
        @return: the list of list of dict to display.
        @rtype: list of  list of dict
        c                     g | ]	}|j         
S r(   )__dict__)r*   xs     r   r-   z)SyntaxAnalyzer.decode.<locals>.<listcomp>  s    444AQZ444r   )	functoolsreduceoperatorconcatr   stemmed_synwordlistlist	flat_lists      r   decodezSyntaxAnalyzer.decode  s2     $X_6MNN	44444	r   c           	          d}|D ]X}|dz  }|D ]I}|dz  }|j         }t          |                                          D ]}|d|d||         dz  }|dz  }J|dz  }Y|d	z  }|S )
z
        display objects result from analysis
        @param stemmed_synwordlistlist: list of  list of StemmedSynWord.
        @type word_result: list of  list of StemmedSynWord
        [z
	[z
		{z
		u'z' = u'z',z
		}z
	]z
])r   sortedkeys)r   r   textrlistitemrD   keys          r   displayzSyntaxAnalyzer.display  s     , 	 	EHD # #
"-!',,..11 J JCDsssGCLLLIIDD
"HDDr   c                 t   g }g }g }d}|D ]g}|                     |d                                                    |D ]-}|                                r|                     d            n:.|r"|d         dk    r|                     d           n|                     d           g }	|D ]}|                                r|r|j        }
|D ]}|                                }||
v rv|	                     |                                |                                |                                |                                |
                    |d          g           |                     |	           |}it          t          |||                    }g }|s"|D ]\  }}}|r|                     |           |}|S )a  
        display objects result from analysis
        @param stemmed_synwordlistlist: list of  list of StemmedSynWord.
        @type word_result: list of  list of StemmedSynWord
        @param all: display all words with tags
        @type all: boolean (default False)
        Nr   BIOi'  )r0   rP   has_nexthas_previousr    r   get_vocalizedr   r   r:   r;   )r   r   allwordsemlistwordlisttag_listprevious_rlistr   r   
forms_listsyn_prevwordstemr+   resulttmp_listwordr   syns                     r   display_synzSyntaxAnalyzer.display_syn  s     , 	# 	#E OOE!H--//000 	) 	)==?? OOC(((E
  ) 3 3OOC((((OOC(((J ; ;$$&& ;> ;#}H$2 ; ; ( 2 2 4 4 H,,&--t/A/A/C/CXE[E[E]E]!..00(2G2G2I2I&ll5%88/: ; ; ; z***"NNc(Hk::;; 	"( ) )c3 )OOC(((Fr   c                 X    |                      |          }t          j        |           dS )z
        print objects result from analysis
        @param stemmed_synwordlistlist: list of  list of StemmedSynWord.
        @type word_result: list of  list of StemmedSynWord
        N)r   pprintr   s      r   r  zSyntaxAnalyzer.pprintK  s,     KK 788	i     r   c                     t           j                            d          }|                    |          }|                     |          \  }}|r||fS |S )zg
        Text Analysis syntacticly
        @param text: input text
        @type text: unicode
        here)qalsadianalexAnalex
check_textr7   )r   r   synodesr  r  
synodelists         r   analyze_textzSyntaxAnalyzer.analyze_textV  sZ     >((00&&t,,#||F33
 	:%%Mr   )F)r   r   NN) __name__
__module____qualname____doc__r   r   r%   r7   r2   rY   r^   rj   r<   rm   rn   rx   ry   rz   r   r   r   r   r   r   r   r   r   r   r  r  r  r!  r(   r   r   r   r   *   s            "  F F F4 4 48$4 $4 $4T  &I I I  > EF?CY! Y! Y! Y!x# # #&# # #>; ; ;z- - -^S S Sj  &T T TnL L LbS S Sl9 9 9v  &  <6 6 6* * **
 
 
  (1 1 1 1f	! 	! 	!     r   r   c                     d} ddl }g }|j                                        }t                      }|                    |           }|                    |          \  }}|                    |          }	 t          t          |                     dS # t          $ r& t          |
                    d                     Y dS w xY w)z
    main test
    u   إلى البيتr   Nutf8)qalsadi.analexr  r  r   r  r7   r  printstrUnicodeEncodeErrorencode)r   r  r  analyzeranasyntr   text2displays          r   mainlyr0  d  s    
  DF~$$&&HG  &&F!//&11FJ??6**L+c,      + + +l!!&))******+s   3B ,C C)r%  r"  syspathr0   r   r   r   r  pyarabic.arabyarabynaftawayh.wordtagr   r(  r  pyarabic.arabreprr   r   r   rS   r   r	   r
   r   r   r0  r(   r   r   <module>r7     sm    zJJJHOOHHOOE                   # # # # # #     # # # # # # # " " " " "             % % % % % %x x x x x x x xt!+ + +& z
FHHHHH r   