+
    ÖÇÜh+"  ã                   ó�   € R t ^ RIt^ RIHt RR ltRR ltRR ltRR ltR tRR lt	R	 t
R
 t]R8X  d   ]! 4        ]
! 4        R# R# )zà
Utility functions for batch-processing sentences: parsing and
extraction of the semantic representation of the root node of the the
syntax tree, followed by evaluation of the semantic representation in
a first-order model.
N)Úevaluatec                óô   € ^ RI Hp ^ RIHpHp \        W4      '       d
   V! V4      pM	V! WR7      p. pV  F>  pVP                  4       p	\        VP                  V	4      4      p
VP                  V
4       K@  	  V# )ab  
Convert input sentences into syntactic trees.

:param inputs: sentences to be parsed
:type inputs: list(str)
:param grammar: ``FeatureGrammar`` or name of feature-based grammar
:type grammar: nltk.grammar.FeatureGrammar
:rtype: list(nltk.tree.Tree) or dict(list(str)): list(Tree)
:return: a mapping from input sentences to a list of ``Tree`` instances.
©ÚFeatureGrammar)ÚFeatureChartParserÚload_parser©Útrace)
Únltk.grammarr   Ú
nltk.parser   r   Ú
isinstanceÚsplitÚlistÚparseÚappend)ÚinputsÚgrammarr	   r   r   r   ÚcpÚparsesÚsentÚtokensÚsyntreess   &&&        Ú//usr/lib/python3/dist-packages/nltk/sem/util.pyÚparse_sentsr      si   € õ ,ß:ä�'×*Ò*Ù Ó(‰á˜Ô.ˆØ€FÛˆØ—‘“ˆÜ˜Ÿ™ Ó(Ó)ˆØ�‰�hÖñ ð €Mó    c                óÆ   € ^ RI Hp V P                  4       p\        W24      '       g   Q h W1,          #   \         d#    \        TRR7       \        RT,          4        h i ; i)zü
Find the semantic representation at the root of a tree.

:param syntree: a parse ``Tree``
:param semkey: the feature label to use for the root semantics in the tree
:return: the semantic representation at the root of a ``Tree``
:rtype: sem.Expression
)ÚFeatStructNonterminalÚ )Úendz'has no specification for the feature %s)r
   r   Úlabelr   ÚKeyErrorÚprint)ÚsyntreeÚsemkeyr   Únodes   &&  r   Úroot_semrepr%   4   s]   € õ 3à�=‰=‹?€DÜ�d×2Ò2Ð2Ð2ðBØ�|ÐøÜô BÜˆd˜ÕÜÐ7¸&Õ@ÕAØ	ðBús   «3 ³*A ÁA c                óŠ   € \        WVR7       UUu. uF  pV Uu. uF  qU\        WR4      3NK  	  upNK!  	  upp# u upi u uppi )a©  
Add the semantic representation to each syntactic parse tree
of each input sentence.

:param inputs: a list of sentences
:type inputs: list(str)
:param grammar: ``FeatureGrammar`` or name of feature-based grammar
:type grammar: nltk.grammar.FeatureGrammar
:return: a mapping from sentences to lists of pairs (parse-tree, semantic-representations)
:rtype: list(list(tuple(nltk.tree.Tree, nltk.sem.logic.ConstantExpression)))
r   )r   r%   )r   r   r#   r	   r   Úsyns   &&&&  r   Úinterpret_sentsr(   I   sJ   € ô $ F¸5ÕAôáAˆHñ 5=Ó=±H¨SŒ{˜3Ó'Ó	(±HÔ=ÙAòð ùÚ=ùós   ‘	?š:¯?º?c                ó¶   € \        W4       UUUu. uF3  pV UUu. uF!  w  rgWgVP                  RV,          W4R7      3NK#  	  uppNK5  	  uppp# u uppi u upppi )aõ  
Add the truth-in-a-model value to each semantic representation
for each syntactic parse of each input sentences.

:param inputs: a list of sentences
:type inputs: list(str)
:param grammar: ``FeatureGrammar`` or name of feature-based grammar
:type grammar: nltk.grammar.FeatureGrammar
:return: a mapping from sentences to lists of triples (parse-tree, semantic-representations, evaluation-in-model)
:rtype: list(list(tuple(nltk.tree.Tree, nltk.sem.logic.ConstantExpression, bool or dict(str): bool)))
z%sr   )r(   r   )r   r   ÚmodelÚ
assignmentr	   Úinterpretationsr'   Úsems   &&&&&   r   Úevaluate_sentsr.   [   si   € ô"  /¨vÔ?õñ
  @ˆOñ .ô	
á-‘
�ð �u—~‘~ d¨S¥j°*�~ÓJÓKÙ-õ	
ñ  @óð ùó	
ùôs   �
Aš'AÁAÁAc                  ó  € RRRRRRRRR03RRR03R	RR03R
RR03R0 Rm3R0 Rm3R0 Rm3R0 Rm3R0 Rm3.p \         P                  ! V 4      pVP                  p\         P                  ! W!4      s\         P
                  ! V4      sR# )ÚjohnÚb1Úg1Úg2Úd1Úd2ÚgirlÚboyÚb2ÚdogÚbarkÚwalkÚchaseÚseeÚinÚwithN)r0   r1   )Úmaryr2   )Úsuzier3   )Úfidor4   )Útessr5   )ÚnoosaÚn>   r1   r4   r3   >   ©r1   r2   ©r8   r2   ©r2   r4   ©r3   r5   >   rF   ©r8   r5   ©r5   r1   ©r2   r1   ©r3   rE   >   ©r1   rE   ©r8   rE   ©r5   rE   >   ©r1   r4   rF   ©r4   r1   rL   )r   Ú	ValuationÚdomainÚModelÚm0Ú
AssignmentÚg0)ÚvÚvalÚdoms      r   Údemo_model0r\   p   s·   € ð 	ØØØØØØ	�$˜�ÐØ	��t�ÐØ	��t�ÐØ	�$˜�ÐØ	Ò#Ð$Ø	ÒJÐKàÚQð	
ð 
Ò6Ð7Ø	ÒIÐJð%	€Aô* ×
Ò
˜QÓ
€Cà
�*‰*€Cä	�Š˜Ó	!€Bä	×	Ò	˜SÓ	!‚Br   c                 ó^  € \         P                  ! V R V4      ;_uu_ 4       pV Uu. uF  q3P                  4       NK  	  ppRRR4       X Uu. uF  p\        V4      ^ 8”  g   K  VNK  	  ppV Uu. uF  q3^ ,          R8X  d   K  VNK  	  ppV# u upi   + '       g   i     LZ; iu upi u upi )ÚrNÚ#)ÚcodecsÚopenÚrstripÚlen)ÚfilenameÚencodingÚfpÚlÚsentss   &&   r   Ú
read_sentsri   ‘   sŽ   € Ü	�Š�X˜s H×	-Ô	-°Ù%'Ó(¡R —‘–¡RˆÐ(÷ 
.ñ Ó,™�1¤ Q£¨!¡�QˆQ™€EÐ,ÙÓ1™�1 q¥T¨S¡[�QˆQ™€EÐ1Ø€Lùò )÷ 
.×	-üò -ùÚ1s3   ¡B¦B¾BÁB%Á#B%Á/B*ÂB*ÂBÂB"	c                 óÜ   € ^ RI Hp  V P                  R4      p\        RV,          4       \        R	4       \	        R.VRR7       F$  pV^ ,          w  r4\        4        \        RV4       K&  	  R# )
zŽ
Check that interpret_sents() is compatible with legacy grammars that use
a lowercase 'sem' feature.

Define 'test.fcfg' to be the following

r   z1
    % start S
    S[sem=<hello>] -> 'hello'
    zReading grammar: %sÚhellor-   )r#   zoutput: Nz********************)r
   r   Ú
fromstringr!   r(   )r   ÚgÚreadingr'   r-   s        r   Údemo_legacy_grammarro   ›   sb   € õ ,à×!Ñ!ð	ó	€Aô 
Ð
 !Õ
#Ô$Ü	ˆ(„OÜ" G 9¨a¸×>ˆØ˜1•:‰ˆÜŒÜˆj˜#Öó ?r   c            
      óZ  € ^ RI p ^ RIHp RpV! VR7      pVP                  RR^ ^ RRRR7       VP	                  R	R
RRRR7       VP	                  RRRRRR7       VP	                  RRRRRR7       VP	                  RRRRRR7       VP	                  RRR R!R"R#7       VP	                  R$R%R R&R'R#7       VP	                  R(R)R*R+R,R#7       VP	                  R-R.R*R/R0R#7       VP                  4       w  rER6p\        4        . R7OpR1pVP                  '       d   VP                  p	VP                  '       d   VP                  pVP                  '       d   \        R2VP                  ,          4       Vf   \        X	4      p\        p
\        pVP                  '       d   \        WxW«VP                   R37      pM\#        WxVP$                  R37      p\'        V4       FÓ  w  rï^p\)        R4V,          4       \)        V4       VP                  '       dn   XV,           F^  w  ppp\+        V\,        4      '       d   \/        VP1                  4       4      p\)        R5VV3,          4       \)        V4       V^,          pK`  	  K£  XV,           F#  w  pp\)        R5VV3,          4       V^,          pK%  	  KÕ  	  R# )8é    N)ÚOptionParserz,
    Parse and evaluate some sentences.
    )ÚdescriptionTÚdefaultÚ )r   ÚbetaÚsyntraceÚsemtraceÚdemor   Ú	sentencesz-dz--demory   zBchoose demo D; omit this for the default demo, or specify 'chat80'ÚD)ÚdestÚhelpÚmetavarz-gz--gramr   zread in grammar GÚGz-mz--modelr*   z"import model M (omit '.py' suffix)ÚMz-sz--sentencesrz   z"read in a file of test sentences SÚSz-ez	--no-evalÚstore_falser   zjust do a syntactic analysis)Úactionr|   r}   z-bz--no-beta-reductionrv   zdon't carry out beta-reductionz-tz
--syntraceÚcountrw   z.set syntactic tracing on; requires '-e' optionz-Tz
--semtracerx   zset semantic tracing onz"grammars/sample_grammars/sem2.fcfgzimport %s as modelr   z
Sentence: %sz%d:  %sz------------------------------)zFido sees a boy with MaryzJohn sees Maryzevery girl chases a dogzevery boy chases a girlzJohn walks with a girl in Noosaz	who walks)ÚsysÚoptparserr   Úset_defaultsÚ
add_optionÚ
parse_argsr\   rz   r   r*   Úexecri   rV   rX   r   r.   rx   r(   rw   Ú	enumerater!   r   ÚdictÚsetÚkeys)r…   rr   rs   ÚoptsÚoptionsÚargsÚSPACERrh   ÚgramfileÚ	sentsfiler*   rm   ÚevaluationsÚsemrepsÚir   rE   r"   ÚsemrepÚvalues                       r   ry   ry   ³   sÅ  € ÛÝ%ð€Kñ  KÔ0€Dà×ÑØØØØØØØð ô ð 	‡O�OØØØØQØð ô ð 	‡O�OØˆh˜YÐ-@È#ð ô ð 	‡O�OØØØØ1Øð ô ð 	‡O�OØØØØ1Øð ô ð 	‡O�OØØØØØ+ð ô ð 	‡O�OØØØØØ-ð ô ð 	‡O�OØØØØØ=ð ô ð 	‡O�OØØØØØ&ð ô ð —o‘oÓ'�O€Wà€Fä„Mò€Eð 4€Hà××ÐØ×%Ñ%ˆ	Ø‡‡€Ø—?‘?ˆØ‡}‡}€}ÜÐ! G§M¡MÕ1Ô2à‚}Ü˜9Ó%ˆô €EÜ
€Aà××ÐÜ$ U°eÀg×FVÑFVÔW‰ä! %¸×9IÑ9IÔJˆä˜UÖ#‰ˆØˆÜÐ Õ%Ô&ÜˆfŒØ××ÐØ*5°a¯.¨.Ñ&�˜ Ü˜e¤T×*Ò*Ü §
¡
£Ó-�EÜ�i 1 f +Õ-Ô.Ü�e”Ø�Q•’ó +9ð $+¨1§: :‘�˜Ü�i 1 f +Õ-Ô.Ø�Q•’ó $.ó $r   Ú__main__)rq   )ÚSEM)r›   rq   )Úutf8)Ú__doc__r`   Únltk.semr   r   r%   r(   r.   r\   ri   ro   ry   Ú__name__© r   r   Ú<module>r¡      sW   ðñó å ôô6
ô*ô$ò*"ôBòò0{ð| ˆzÔÙ„FÙÖñ r   