Ë
    çÍ:jV  ã                   óB  — d Z ddlZddlmZmZ ddlmZ ddlmZm	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 ddlmZmZ ddlmZ ddlmZ ddlmZ  G d„ de¬«      Z G d„ de«      Z G d„ de«      Z G d„ d«      Z d„ Z!dd„Z"dd„Z#dd„Z$d„ Z%e&dk(  r e%«        yy) aô  
Module for incrementally developing simple discourses, and checking for semantic ambiguity,
consistency and informativeness.

Many of the ideas are based on the CURT family of programs of Blackburn and Bos
(see http://homepages.inf.ed.ac.uk/jbos/comsem/book1.html).

Consistency checking is carried out  by using the ``mace`` module to call the Mace4 model builder.
Informativeness checking is carried out with a call to ``Prover.prove()`` from
the ``inference``  module.

``DiscourseTester`` is a constructor for discourses.
The basic data structure is a list of sentences, stored as ``self._sentences``. Each sentence in the list
is assigned a "sentence ID" (``sid``) of the form ``s``\ *i*. For example::

    s0: A boxer walks
    s1: Every boxer chases a girl

Each sentence can be ambiguous between a number of readings, each of which receives a
"reading ID" (``rid``) of the form ``s``\ *i* -``r``\ *j*. For example::

    s0 readings:

    s0-r1: some x.(boxer(x) & walk(x))
    s0-r0: some x.(boxerdog(x) & walk(x))

A "thread" is a list of readings, represented as a list of ``rid``\ s.
Each thread receives a "thread ID" (``tid``) of the form ``d``\ *i*.
For example::

    d0: ['s0-r0', 's1-r0']

The set of all threads for a discourse is the Cartesian product of all the readings of the sequences of sentences.
(This is not intended to scale beyond very short discourses!) The method ``readings(filter=True)`` will only show
those threads which are consistent (taking into account any background assumptions).
é    N)ÚABCMetaÚabstractmethod)Úreduce)ÚaddÚand_)Úshow_cfg)ÚMaceCommand)ÚProver9Command)Úload_parser)Ú
MaltParser)ÚAnaphoraResolutionExceptionÚresolve_anaphora)ÚDrtGlue©Ú
Expression)ÚRegexpTaggerc                   óB   — e Zd Zed„ «       Zd„ Zed„ «       Zed„ «       Zy)ÚReadingCommandc                  ó   — y)zS
        :param sentence: the sentence to read
        :type sentence: str
        N© ©ÚselfÚsentences     úm/home/mcse/projects/srt_converter/srt-converter-venv/lib/python3.12/site-packages/nltk/inference/discourse.pyÚparse_to_readingsz ReadingCommand.parse_to_readings?   ó   � ó    c                 ó   — |S )a9  
        This method should be used to handle dependencies between readings such
        as resolving anaphora.

        :param sentence_readings: readings to process
        :type sentence_readings: list(Expression)
        :return: the list of readings after processing
        :rtype: list(Expression)
        r   ©r   Úsentence_readingss     r   Úprocess_threadzReadingCommand.process_threadF   s
   € ð !Ð r   c                  ó   — y)z 
        :param readings: readings to combine
        :type readings: list(Expression)
        :return: one combined reading
        :rtype: Expression
        Nr   ©r   Úreadingss     r   Úcombine_readingszReadingCommand.combine_readingsR   r   r   c                  ó   — y)zï
        Convert this expression into a First-Order Logic expression.

        :param expression: an expression
        :type expression: Expression
        :return: a FOL version of the input expression
        :rtype: Expression
        Nr   ©r   Ú
expressions     r   Úto_folzReadingCommand.to_fol[   r   r   N)Ú__name__Ú
__module__Ú__qualname__r   r   r!   r%   r)   r   r   r   r   r   >   sA   „ Øñó ðò
!ð ñó ðð ñó ñr   r   )Ú	metaclassc                   ó&   — e Zd Zdd„Zd„ Zd„ Zd„ Zy)ÚCfgReadingCommandNc                 óN   — |r|nd| _         t        | j                   «      | _        y)zg
        :param gramfile: name of file where grammar can be loaded
        :type gramfile: str
        z%grammars/book_grammars/discourse.fcfgN)Ú	_gramfiler   Ú_parser)r   Úgramfiles     r   Ú__init__zCfgReadingCommand.__init__h   s%   € ñ !‰HÐ&Mð 	Œô # 4§>¡>Ó2ˆ�r   c                 óš   — ddl m} |j                  «       }| j                  j	                  |«      }|D �cg c]
  } ||«      ‘Œ c}S c c}w )ú(:see: ReadingCommand.parse_to_readings()r   )Úroot_semrep)Únltk.semr7   Úsplitr2   Úparse)r   r   r7   ÚtokensÚtreesÚtrees         r   r   z#CfgReadingCommand.parse_to_readingsr   s>   € å(à—‘Ó!ˆØ—‘×"Ñ" 6Ó*ˆØ.3Ö4 d‘˜DÕ!Ò4Ð4ùÒ4s   ¶Ac                 ó"   — t        t        |«      S ©z':see: ReadingCommand.combine_readings())r   r   r#   s     r   r%   z"CfgReadingCommand.combine_readingsz   s   € ä”d˜HÓ%Ð%r   c                 ó   — |S ©z:see: ReadingCommand.to_fol()r   r'   s     r   r)   zCfgReadingCommand.to_fol~   s   € àÐr   ©N)r*   r+   r,   r4   r   r%   r)   r   r   r   r/   r/   g   s   „ ó3ò5ò&ór   r/   c                   ó,   — e Zd Zdd„Zd„ Zd„ Zd„ Zd„ Zy)ÚDrtGlueReadingCommandNc                 óp   — |€!t         j                  j                  ddd«      }t        |||¬«      | _        y)z¿
        :param semtype_file: name of file where grammar can be loaded
        :param remove_duplicates: should duplicates be removed?
        :param depparser: the dependency parser
        NÚgrammarsÚsample_grammarszdrt_glue.semtype)Úsemtype_fileÚremove_duplicatesÚ	depparser)ÚosÚpathÚjoinr   Ú_glue)r   rH   rI   rJ   s       r   r4   zDrtGlueReadingCommand.__init__„   s<   € ð ÐÜŸ7™7Ÿ<™<ØÐ-Ð/AóˆLô Ø%Ø/Øô
ˆ�
r   c                 ó8   — | j                   j                  |«      S )r6   )rN   Úparse_to_meaningr   s     r   r   z'DrtGlueReadingCommand.parse_to_readings”   s   € à�z‰z×*Ñ*¨8Ó4Ð4r   c                 óJ   — 	 | j                  |«      gS # t        $ r g cY S w xY w)z%:see: ReadingCommand.process_thread())r%   r   r   s     r   r!   z$DrtGlueReadingCommand.process_thread˜   s0   € ð	Ø×)Ñ)Ð*;Ó<Ð=Ð=øÜ*ò 	ØŠIð	ús   ‚ ”"¡"c                 óT   — t        t        |«      }t        |j                  «       «      S r?   )r   r   r   Úsimplify)r   r$   Úthread_readings      r   r%   z&DrtGlueReadingCommand.combine_readingsŸ   s"   € ä¤ XÓ.ˆÜ × 7Ñ 7Ó 9Ó:Ð:r   c                 ó"   — |j                  «       S rA   )Úfolr'   s     r   r)   zDrtGlueReadingCommand.to_fol¤   s   € à�~‰~ÓÐr   )NFN)r*   r+   r,   r4   r   r!   r%   r)   r   r   r   rD   rD   ƒ   s   „ ó
ò 5òò;ó
 r   rD   c                   óž   — e Zd ZdZdd„Zd„ Zdd„Zdd„Zd„ Zd„ Z	d	„ Z
d
„ Zdd„Zdd„Z	 	 	 	 	 dd„Zdd„Zdd„Zdd„Zdd„Zd„ Zed„ «       Zy)ÚDiscourseTesterz3
    Check properties of an ongoing discourse.
    Nc                 ó"  — || _         t        |«      D ��ci c]  \  }}d|z  |“Œ c}}| _        d| _        i | _        |r|n	t        «       | _        i | _        i | _        |�#ddl	m
} |D ]  }t        ||«      rŒJ ‚ || _        yg | _        yc c}}w )z÷
        Initialize a ``DiscourseTester``.

        :param input: the discourse sentences
        :type input: list of str
        :param background: Formulas which express background assumptions
        :type background: list(Expression)
        ús%sNr   r   )Ú_inputÚ	enumerateÚ
_sentencesÚ_modelsÚ	_readingsr/   Ú_reading_commandÚ_threadsÚ_filtered_threadsÚnltk.sem.logicr   Ú
isinstanceÚ_background)r   ÚinputÚreading_commandÚ
backgroundÚiÚsentr   Úes           r   r4   zDiscourseTester.__init__®   sž   € ð ˆŒÜ:CÀEÓ:J×K©w¨q°$˜5 1™9 d™?ÓKˆŒØˆŒØˆŒá.‰OÔ4EÓ4Gð 	Ôð ˆŒØ!#ˆÔØÐ!Ý1àò 1�Ü! ! ZÕ0Ð0Ð0ð1à)ˆDÕà!ˆDÕùó Ls   –Bc                 ór   — t        | j                  «      D ]  }t        |› d| j                  |   › �«       Œ! y)zI
        Display the list of sentences in the current discourse.
        ú: N)Úsortedr]   Úprint)r   Úids     r   Ú	sentenceszDiscourseTester.sentencesÍ   s9   € ô ˜Ÿ™Ó)ò 	2ˆBÜ�R�D˜˜4Ÿ?™?¨2Ñ.Ð/Ð0Õ1ñ	2r   c           
      ó|  — |r»| j                  d¬«       t        | j                  «      D ]‘  }| j                  |«      D ��cg c]  \  }}|‘Œ	 }}}|| j                  z  }| j                  |«      D ]I  }t        ||¬«      }	|	j                  «       sŒ!t        d|›dt        |«      ›d�«       t        d|z  «       ŒK Œ“ | j                  j                  |«       t        | j                  «      D �
�ci c]  \  }
}d|
z  |“Œ c}}
| _        |r%| j                  d¬«       | j                  d¬	«       y
y
c c}}w c c}}
w )aÊ  
        Add a sentence to the current discourse.

        Updates ``self._input`` and ``self._sentences``.
        :param sentence: An input sentence
        :type sentence: str
        :param informchk: if ``True``, check that the result of adding the sentence is thread-informative. Updates ``self._readings``.
        :param consistchk: if ``True``, check that the result of adding the sentence is thread-consistent. Updates ``self._readings``.

        F©Úverbose)ÚgoalÚassumptionsz
Sentence 'z' under reading 'z':z'Not informative relative to thread '%s'rZ   )ÚshowN)r$   rn   ra   Úexpand_threadsre   Ú_get_readingsr
   Úprovero   Ústrr[   Úappendr\   r]   Úmodels)r   r   Ú	informchkÚ
consistchkÚtidÚridÚreadingrv   Úsent_readingÚtpri   rj   s               r   Úadd_sentencezDiscourseTester.add_sentenceÔ   s'  € ñ Ø�M‰M %ˆMÔ(Ü˜dŸm™mÓ,ò 
O�Ø=A×=PÑ=PÐQTÓ=U×V©>¨C°šwÐV�ÑVØ˜t×/Ñ/Ñ/�Ø$(×$6Ñ$6°xÓ$@ò O�LÜ'¨\À{ÔS�BØ—x‘x•zÝâ'¬¨\Õ):ð<ôô ÐGÈ#ÑMÕNñOð
Oð 	�‰×Ñ˜8Ô$Ü:CÀDÇKÁKÓ:P×Q©w¨q°$˜5 1™9 d™?ÓQˆŒñ Ø�M‰M %ˆMÔ(Ø�K‰K˜UˆKÕ#ð ùó Wùó Rs   ÁD2Ã1D8c                 ód  — 	 | j                   j                  |«       t        | j                   «      D ��ci c]  \  }}d|z  |“Œ c}}| _        | j                  d¬«       |rt        d«       | j	                  «        yy# t        $ r! t        d|z  «       | j	                  «        Y yw xY wc c}}w )a#  
        Remove a sentence from the current discourse.

        Updates ``self._input``, ``self._sentences`` and ``self._readings``.
        :param sentence: An input sentence
        :type sentence: str
        :param verbose: If ``True``,  report on the updated list of sentences.
        zJRetraction failed. The sentence '%s' is not part of the current discourse:NrZ   Frs   zCurrent sentences are )r[   ÚremoveÚ
ValueErrorro   rq   r\   r]   r$   )r   r   rt   ri   rj   s        r   Úretract_sentencez DiscourseTester.retract_sentenceö   s¤   € ð	Ø�K‰K×Ñ˜xÔ(ô ;DÀDÇKÁKÓ:P×Q©w¨q°$˜5 1™9 d™?ÓQˆŒØ�‰˜eˆÔ$ÙÜÐ*Ô+Ø�N‰NÕð øô ò 	ÜØ\Øñôð �N‰NÔÙð	üó Rs   ‚A? µB,Á?'B)Â(B)c                 óB   — t        | j                  j                  «       y)zJ
        Print out the grammar in use for parsing input sentences
        N)r   r`   r1   )r   s    r   ÚgrammarzDiscourseTester.grammar  s   € ô 	�×&Ñ&×0Ñ0Õ1r   c                 ó8   — | j                   j                  |«      S )ze
        Build a list of semantic readings for a sentence.

        :rtype: list(Expression)
        )r`   r   r   s     r   ry   zDiscourseTester._get_readings  s   € ð ×$Ñ$×6Ñ6°xÓ@Ð@r   c                 ó.  — i | _         t        | j                  «      D ]p  }| j                  |   }| j                  |«      }t	        t        |t
        ¬«      «      D ��ci c]  \  }}|› d|› �|j                  «       “Œ c}}| j                   |<   Œr yc c}}w )zV
        Use ``self._sentences`` to construct a value for ``self._readings``.
        )Úkeyz-rN)r_   rn   r]   ry   r\   r{   rS   )r   Úsidr   r$   r�   r‚   s         r   Ú_construct_readingsz#DiscourseTester._construct_readings   s‘   € ð
 ˆŒÜ˜$Ÿ/™/Ó*ò 	ˆCØ—‘ sÑ+ˆHØ×)Ñ)¨(Ó3ˆHô %.¬f°XÄ3Ô.GÓ$H÷#á �C˜ð �%�r˜#˜� ×!1Ñ!1Ó!3Ñ3ó#ˆD�N‰N˜3Òñ	ùó#s   Á Bc                 óœ  — g g}t        | j                  «      D ]*  }| j                  |t        | j                  |   «      «      }Œ, t        |«      D ��ci c]  \  }}d|z  |“Œ c}}| _        i | _        | j                  | j                  «      }| j                  j                  «       D ]  \  }}|df|v sŒ|| j
                  |<   Œ yc c}}w )z©
        Use ``self._readings`` to construct a value for ``self._threads``
        and use the model builder to construct a value for ``self._filtered_threads``
        zd%sTN)rn   r_   Úmultiplyr\   ra   rb   Ú_check_consistencyÚitems)r   Úthread_listr�   r€   ÚthreadÚconsistency_checkeds         r   Ú_construct_threadsz"DiscourseTester._construct_threads.  sÇ   € ð
 �dˆÜ˜$Ÿ.™.Ó)ò 	RˆCØŸ-™-¨´V¸D¿N¹NÈ3Ñ<OÓ5PÓQ‰Kð	Rä@IÈ+Ó@V×W±°°f˜ ™ fÑ,ÓWˆŒà!#ˆÔà"×5Ñ5°d·m±mÓDÐØŸ=™=×.Ñ.Ó0ò 	5‰KˆC�Ø�Tˆ{Ð1Ò1Ø.4�×&Ñ& sÒ+ñ	5ùó Xs   ÁCc                 ó¸  — |�Jt        d|z  «       | j                  |«      D �cg c]  }t        |«      ‘Œ c}D ]  }t        d|z  «       Œ yt        | j                  «      D ]q  }t        «        t        d|z  «       t        «        t        | j                  |   «      D ]2  }| j                  |   |   }t        |› d|j                  «       › �«       Œ4 Œs yc c}w )zS
        Print out the readings for  the discourse (or a single sentence).
        Nz%The sentence '%s' has these readings:z    %sz%s readings:rm   )ro   ry   r{   rn   r_   Ú	normalize)r   r   r‚   Úrr�   r�   Úlfs          r   Ú_show_readingszDiscourseTester._show_readings?  sÎ   € ð ÐÜÐ9¸HÑDÔEØ37×3EÑ3EÀhÓ3OÖQ w”c˜'•lÒQò $�Ü�h ‘lÕ#ñ$ô ˜dŸn™nÓ-ò 6�Ü”Ü�n sÑ*Ô+Ü”Ü! $§.¡.°Ñ"5Ó6ò 6�CØŸ™¨Ñ,¨SÑ1�BÜ˜S˜E  B§L¡L£NÐ#3Ð4Õ5ñ6ñ	6ùò Rs   ¤Cc                 óÚ  — |r| j                   n| j                  }t        |«      D ]�  }|rl| j                  |   D �cg c]&  }| j                  |j	                  d«      d      |   ‘Œ( }}	 d| j
                  j                  |«      j                  «       z  }nd}t        d|z  | j                  |   |«       Œ‘ yc c}w # t        $ r#}d|j                  j                  z  }Y d}~ŒLd}~ww xY w)zW
        Print out the value of ``self._threads`` or ``self._filtered_hreads``
        ú-r   z: %sz: INVALID: %sNÚ z%s:)rb   ra   rn   r_   r9   r`   r%   rš   Ú	ExceptionÚ	__class__r*   ro   )	r   ÚfilterÚshow_thread_readingsÚthreadsr€   r�   r$   rT   rk   s	            r   Ú_show_threadszDiscourseTester._show_threadsP  sì   € ñ -3�$×(Ò(¸¿¹ˆÜ˜'“?ò 	CˆCÙ#àFJÇmÁmÐTWÑFXöØ?B�D—N‘N 3§9¡9¨S£>°!Ñ#4Ñ5°cÓ:ð�ð ðLàØ×/Ñ/×@Ñ@ÀÓJ×TÑTÓVñWñ #ð "$�ä�%˜#‘+˜tŸ}™}¨SÑ1°>ÕBñ	Cùòøô !ò LØ%4°q·{±{×7KÑ7KÑ%K•NûðLús   ¼+B9Á*,B>Â>	C*ÃC%Ã%C*c                 ó¦   — | j                  «        | j                  «        |s|rd}|r)|s| j                  |¬«       y| j                  ||¬«       yy)a^  
        Construct and show the readings of the discourse (or of a single sentence).

        :param sentence: test just this sentence
        :type sentence: str
        :param threaded: if ``True``, print out each thread ID and the corresponding thread.
        :param filter: if ``True``, only print out consistent thread IDs and threads.
        T)r   ©r£   r¤   N)r�   r˜   r�   r¦   )r   r   Úthreadedrt   r£   r¤   s         r   r$   zDiscourseTester.readingsf  s^   € ð  	× Ñ Ô"Ø×ÑÔ!ñ Ñ)ØˆHáÙØ×#Ñ#¨XÐ#Õ6à×"Ñ"Ø!Ð8Lð #õ ð	 r   c                 óª   — |€| j                   }||   D ��cg c]/  }|j                  d«      dd D ]  }|| j                  |   |   f‘Œ Œ1 c}}S c c}}w )aÄ  
        Given a thread ID, find the list of ``logic.Expression`` objects corresponding to the reading IDs in that thread.

        :param thread_id: thread ID
        :type thread_id: str
        :param threads: a mapping from thread IDs to lists of reading IDs
        :type threads: dict
        :return: A list of pairs ``(rid, reading)`` where reading is the ``logic.Expression`` associated with a reading ID
        :rtype: list of tuple
        NrŸ   é   )ra   r9   r_   )r   Ú	thread_idr¥   r�   r�   s        r   rx   zDiscourseTester.expand_threads…  sp   € ð ˆ?Ø—m‘mˆGð ˜yÑ)÷
àØ—y‘y “~ b qÐ)ò
ð ð �$—.‘. Ñ% cÑ*Ò+ð
Ø+ó
ð 	
ùó 
s   —4Ac           	      ór  — g }t        |«      D �]  }| j                  ||¬«      D ��cg c]  \  }}|‘Œ	 }}}t        t        | j                  j
                  | j                  j                  |«      «      «      }|r.|| j                  z  }t        d |d¬«      }	|	j                  «       }
nd}
|j                  ||
f«       |sŒ³t        d«       t        d|z  «       t        d«       |r|D ]  }t        |«       Œ t        d«       |
rt        	j                  d¬«      «       �Œt        d	«       �Œ" |S c c}}w )
N)r¥   é   )Ú
max_modelsFéP   zModel for Discourse Thread %sÚcooked)ÚformatzNo model found!
)rn   rx   ÚlistÚmapr`   r)   r!   re   r	   Úbuild_modelr|   Úspacerro   Úmodel)r   r¥   rw   rt   Úresultsr€   r�   r‚   rv   ÚmbÚ
modelfoundÚas               r   r“   z"DiscourseTester._check_consistencyœ  s.  € ØˆÜ˜'“?ó 	/ˆCà.2×.AÑ.AÀ#ÈwÐ.AÓ.W÷Ù*˜S '’ðˆKñ ô ÜØ×)Ñ)×0Ñ0Ø×)Ñ)×8Ñ8¸ÓEóóˆKñ Ø˜t×/Ñ/Ñ/�ä   {¸rÔB�ØŸ^™^Ó-‘
à"�
Ø�N‰N˜C Ð,Ô-ÚÜ�r”
ÜÐ5¸Ñ;Ô<Ü�r”
ÙØ(ò !˜Ü˜a�ð!ä˜2”JÙÜ˜"Ÿ(™(¨(˜(Ó3Ö4äÐ-Ö.ð;	/ð< ˆùó;s   ¨D3c           	      ó>  — | j                  «        | j                  «        |r|| j                  |   in| j                  }| j                  |||¬«      D ]Â  \  }}||   D �cg c]  }|‘Œ }}|sUt	        d|› d|› d�«       | j                  |«      D ]$  \  }}	t	        d|› d|	j                  «       › �«       Œ& t	        «        Œot	        d|› d|› d�«       | j                  |«      D ]$  \  }}	t	        d|› d|	j                  «       › �«       Œ& t	        «        ŒÄ yc c}w )	zÛ
        Call Mace4 to build a model for each current discourse thread.

        :param thread_id: thread ID
        :type thread_id: str
        :param show: If ``True``, display the model that has been found.
        )rw   rt   zInconsistent discourse: ú ú:z    rm   zConsistent discourse: N)r�   r˜   ra   r“   ro   rx   rš   )
r   r¬   rw   rt   r¥   r€   rº   r�   Úidlistr‚   s
             r   r}   zDiscourseTester.models¾  s6  € ð 	× Ñ Ô"Ø×ÑÔ!Ù;D�9˜dŸm™m¨IÑ6Ñ7È$Ï-É-ˆà#×6Ñ6Ø˜$¨ð  7ó  
ò 	‰OˆC�ð &-¨S¡\Ö2˜c’cÐ2ˆFÐ2áÜÐ0°°°Q°v°h¸aÐ@ÔAØ$(×$7Ñ$7¸Ó$<ò ?‘L�C˜Ü˜D   R¨×(9Ñ(9Ó(;Ð'<Ð=Õ>ð?ä•äÐ.¨s¨e°1°V°H¸AÐ>Ô?Ø$(×$7Ñ$7¸Ó$<ò ?‘L�C˜Ü˜D   R¨×(9Ñ(9Ó(;Ð'<Ð=Õ>ð?ä•ñ	ùò 3s   Á!	Dc                 óè   — ddl m} t        |«      D ]>  \  }}t        ||«      sJ ‚|rt	        d|z  «       | j
                  j                  |«       Œ@ | j                  «        | j                  «        y)a0  
        Add a list of background assumptions for reasoning about the discourse.

        When called,  this method also updates the discourse model's set of readings and threads.
        :param background: Formulas which contain background information
        :type background: list(Expression)
        r   r   z"Adding assumption %s to backgroundN)	rc   r   r\   rd   ro   re   r|   r�   r˜   )r   rh   rt   r   Úcountrk   s         r   Úadd_backgroundzDiscourseTester.add_backgroundÚ  sn   € õ 	.ä! *Ó-ò 	'‰HˆE�1Ü˜a Ô,Ð,Ð,ÙÜÐ:¸UÑBÔCØ×Ñ×#Ñ# AÕ&ð		'ð 	× Ñ Ô"Ø×ÑÕ!r   c                 óN   — | j                   D ]  }t        t        |«      «       Œ y)z:
        Show the current background assumptions.
        N)re   ro   r{   )r   rk   s     r   rh   zDiscourseTester.backgroundî  s$   € ð ×!Ñ!ò 	ˆAÜ”#�a“&�Mñ	r   c                 óx   — g }| D ]2  }|D ]+  }g }||z  }|j                  |«       |j                  |«       Œ- Œ4 |S )aÛ  
        Multiply every thread in ``discourse`` by every reading in ``readings``.

        Given discourse = [['A'], ['B']], readings = ['a', 'b', 'c'] , returns
        [['A', 'a'], ['A', 'b'], ['A', 'c'], ['B', 'a'], ['B', 'b'], ['B', 'c']]

        :param discourse: the current list of readings
        :type discourse: list of lists
        :param readings: an additional list of readings
        :type readings: list(Expression)
        :rtype: A list of lists
        )r|   )Ú	discourser$   ÚresultÚsublistr›   Únews         r   r’   zDiscourseTester.multiplyù  sS   € ð ˆØ ò 	#ˆGØò #�Ø�Ø�w‘�Ø—
‘
˜1”Ø—‘˜cÕ"ñ	#ð	#ð ˆr   )NN)FF)TrB   )NFTFF)NTF)F)r*   r+   r,   Ú__doc__r4   rq   r…   r‰   r‹   ry   r�   r˜   r�   r¦   r$   rx   r“   r}   rÂ   rh   Ústaticmethodr’   r   r   r   rX   rX   ©   s€   „ ñó"ò>2ó $óDò02òAòò5ó"6ó"Cð0 ØØØØ"óó>
ó. óDó8"ò(ð ñó ñr   rX   c                 ó*  — g }t        | j                  «       «      D ]Q  \  }}|j                  «       }|j                  d«      s|dk(  rŒ-	 |j	                  t        j                  |«      «       ŒS |S # t        $ r}t        d|› d|› �«      |‚d}~ww xY w)a	  
    Temporarily duplicated from ``nltk.sem.util``.
    Convert a  file of first order formulas into a list of ``Expression`` objects.

    :param s: the contents of the file
    :type s: str
    :return: a list of parsed formulas.
    :rtype: list(Expression)
    ú#r    zUnable to parse line rm   N)	r\   Ú
splitlinesÚstripÚ
startswithr|   r   Ú
fromstringr¡   rˆ   )ÚsÚ
statementsÚlinenumÚlinerk   s        r   Úload_folrÕ     sŸ   € ð €JÜ" 1§<¡<£>Ó2ò O‰ˆ�Ø�z‰z‹|ˆØ�?‰?˜3Ô 4¨2¢:Øð	OØ×Ñœj×3Ñ3°DÓ9Õ:ðOð Ðøô ò 	OÜÐ4°W°I¸RÀ¸vÐFÓGÈQÐNûð	Oús   Á
$A2Á2	BÁ;BÂBc                 óº  — t        ddg| «      }|j                  «        t        «        t        «        |j                  «        t        «        |j	                  «        t        «        |j	                  d¬«       t        «        |j                  d«       |j                  d«       t        «        |j                  «        t        «        |j	                  d¬«       t        «        t        ddg| «      }t        «        |j                  d	d¬
«       t        «        |j	                  «        t        «        |j                  d	d¬«       t        «        |j                  «        t        «        |j	                  d«       t        «        |j                  dd¬«       t        g d¢| «      }|j	                  d¬«       ddl}t        j                  j                  ddd«      }|j                  j                  |«      }t        «        |j                  |d¬«       |j                  «        t        «        |j	                  d¬«       t        «        |j                  «        y)ú?
    Illustrate the various methods of ``DiscourseTester``
    zA boxer walkszEvery boxer chases a girlT)r©   Úd1zJohn is a boxerzA student danceszEvery student is a personzNo person dances)r   rs   zA person dances)r~   )zVincent is a boxerzFido is a boxerzVincent is marriedz
Fido barks)r£   r   NrF   Úbook_grammarszbackground.folF)rX   r}   ro   rq   r$   r…   r‰   Ú	nltk.datarK   rL   rM   ÚdataÚloadrÂ   rh   )rg   ÚdtÚnltkÚbackground_filerh   s        r   Údiscourse_demorà   *  s³  € ô 
Ø	Ð5Ð6¸ó
€Bð ‡I�I„KÜ	„Gä	„GØ‡L�L„NÜ	„GØ‡K�K„MÜ	„GØ‡K�K˜€KÔÜ	„GØ‡I�Iˆd„OØ‡O�OÐ%Ô&Ü	„GØ‡L�L„NÜ	„GØ‡K�K˜€KÔÜ	„GÜ	Ø	Ð8Ð9¸?ó
€Bô 
„GØ‡O�OÐ&°4€OÔ8Ü	„GØ‡K�K„MÜ	„GØ×ÑÐ*°DÐÔ9Ü	„GØ‡I�I„KÜ	„GØ‡K�KÐ!Ô"Ü	„GØ‡O�OÐ%°€OÔ6Ü	ÚUØó
€Bð ‡K�K�t€KÔÛä—g‘g—l‘l :¨Ð@PÓQ€OØ—‘—‘ Ó0€Jä	„GØ×Ñ�j¨%ÐÔ0Ø‡M�M„OÜ	„GØ‡K�K�t€KÔÜ	„GØ‡I�I…Kr   c                 ó  — t        ddg| «      }|j                  «        t        «        |j                  «        t        «        |j	                  «        t        «        |j	                  d¬«       t        «        |j	                  dd¬«       y)r×   zevery dog chases a boyzhe runsT)r¤   r¨   N)rX   r}   ro   rq   r$   )rg   rÝ   s     r   Údrt_discourse_demorâ   d  sc   € ô 
Ð2°IÐ>ÀÓ	P€BØ‡I�I„KÜ	„GØ‡L�L„NÜ	„GØ‡K�K„MÜ	„GØ‡K�K T€KÔ*Ü	„GØ‡K�K�t°$€KÕ7r   c                 ó    — t        d| z  «       y )NrŸ   )ro   )Únums    r   r¶   r¶   t  s   € Ü	ˆ#�‰)Õr   c                  óv   — t        «        t        g d¢«      } t        | ¬«      }t        t	        d|¬«      «       y )N))z^(chases|runs)$ÚVB)z^(a)$Úex_quant)z	^(every)$Ú
univ_quant)z^(dog|boy)$ÚNN)z^(he)$ÚPRP)ÚtaggerF)rI   rJ   )rà   r   r   râ   rD   )rë   rJ   s     r   Údemorì   x  s5   € ÜÔäò	
ó€Fô  &Ô)€IÜÜ°ÀÔKõr   Ú__main__rB   )é   )'rÉ   rK   Úabcr   r   Ú	functoolsr   Úoperatorr   r   rÚ   r   Únltk.inference.macer	   Únltk.inference.prover9r
   Ú
nltk.parser   Únltk.parse.maltr   Únltk.sem.drtr   r   Únltk.sem.gluer   rc   r   Únltk.tagr   r   r/   rD   rX   rÕ   rà   râ   r¶   rì   r*   r   r   r   ú<module>rù      s•   ðñ#óJ 
ß 'Ý ß å Ý +Ý 1Ý "Ý &ß FÝ !Ý %Ý !ô&˜wõ &ôR˜ô ô8# ˜Nô # ÷Leñ eòPó27ót8ó òð$ ˆzÒÙ…Fð r   