
    g                        d Z ddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
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mZ d	adada G d
 de      Zd ZdPd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Z/dZ0dZ1d Z2d!Z3d"Z4d#Z5d$Z6d%Z7d&Z$d'Z7d(Z6d)Z8d*Z9d+ Z:d, Z;d- Z<d.Z=d/Z>d0Z?d1 Z@d2 ZAd3 ZBd4 ZCd5 ZDd6 ZEd7 ZFd8 ZG eF eD eCd9                  d:z   ZHd; ZId< ZJ eK       fd=ZLd> ZM G d? d@ej                        ZO G dA dB      ZPdC ZQdD ZRdE ZSdF ZTdG ZUdH ZVdI ZWdJ ZXdK ZYdL ZZdM Z[e\dNk(  r e[        dOgZ]y)QaX  
A WordNet Browser application which launches the default browser
(if it is not already running) and opens a new tab with a connection
to http://localhost:port/ .  It also starts an HTTP server on the
specified port and begins serving browser requests.  The default
port is 8000.  (For command-line help, run "python wordnet -h")
This application requires that the user's web browser supports
Javascript.

BrowServer is a server for browsing the NLTK Wordnet database It first
launches a browser client to be used for browsing and then starts
serving the requests of that and maybe other clients

Usage::

    browserver.py -h
    browserver.py [-s] [-p <port>]

Options::

    -h or --help
        Display this help message.

    -l <file> or --log-file <file>
        Logs messages to the given file, If this option is not specified
        messages are silently dropped.

    -p <port> or --port <port>
        Run the web server on this TCP port, defaults to 8000.

    -s or --server-mode
        Do not start a web browser, and do not allow a user to
        shutdown the server through the web interface.
    N)defaultdict)BaseHTTPRequestHandler
HTTPServer)argv)unquote_plus)wordnet)LemmaSynsetTc                   &    e Zd Zd Zd ZddZd Zy)MyServerHandlerc                 $    | j                          y N)	send_head)selfs    I/var/www/openai/venv/lib/python3.12/site-packages/nltk/app/wordnet_app.pydo_HEADzMyServerHandler.do_HEADO   s        c                    | j                   dd  }t        |      dk(  r.t        rd}d}nt        d       t	        j
                  d       n|dk(  r+d}t        st        rd	at        d
      }nt        d	      }d}nt|j                  d      rd}t        |      }|dk(  rjd}t        j                   j                  |      r&t        |      5 }|j                         }d d d        n
t        |z  dz   |z   dz   dz   dz   dz   t        z   }n|}	 t        |      }n|j!                  d      rzd}|j#                  d      d   j#                  d      }|D cg c]7  }|j!                  d      r$|j#                  d      d   j%                  dd      9 c}d   }t'        |      \  }}nM|j!                  d      rd}|t)        d      d  }t+        |      \  }}n|dk(  rd}t'        d      \  }}nd}d|z  }| j-                         | j.                  j1                  j3                  d              y # 1 sw Y   ExY w# t        $ r
 d|z  }d}Y Zw xY wc c}w )!N   zSHUTDOWN THE SERVERz#Server must be killed with SIGTERM.z
text/plainzServer shutting down!r    z	text/htmlFTgreenz.html'NLTK Wordnet Browser Database Info.htmlz* Database Info *z <p>The database info file:<p><b>z</b>z<p>was not found. Run this:z<p><b>python dbinfo_html.py</b>z<p>to produce it.z4Internal error: Path for static page '%s' is unknownsearch?&nextWord=+ lookup_
start_pager   zCould not parse request: '%s'utf8)pathr   server_modeprintos_exitfirstClientget_static_index_pageendswithisfileopenreadhtml_headerhtml_trailerget_static_page_by_pathFileNotFoundError
startswithsplitreplacepage_from_wordlenpage_from_hrefr   wfilewriteencode)	r   sppagetypeworduspinfilepartsps	            r   do_GETzMyServerHandler.do_GETR   sl   YYqr]44<#-.2XD;#,T2,U3D[[!Dr"C??*77>>#&cf%{{} # %t+ 0! ! !! 8	8
 << .. ''  (237D
 ]]8$DXXc]1%,,S1E A<<
+ Q''S1 	D
 (-JD$]]9%DC	N$%B'+JD$< D'	2JD$D2R7D 	t

V,-a #$ ) (QTWWD'D(s$   H,H8 <I,H58I
INc                 j    | j                  d       | j                  d|       | j                          y )N   zContent-type)send_responsesend_headerend_headers)r   r=   s     r   r   zMyServerHandler.send_head   s,    3.r   c                     t         r>t         j                  | j                         d| j                         d||z  d       y y )Nz - - [z] 
)logfiler9   address_stringlog_date_time_string)r   formatargss      r   log_messagezMyServerHandler.log_message   s<     MM&&($*C*C*EvPT}V r   r   )__name__
__module____qualname__r   rC   r   rP    r   r   r   r   N   s    J.X
r   r   c                 R    | j                  d      }|dk7  rt        | |dz   d       S y)z\
    Extract the unique counter from the URL if it has one.  Otherwise return
    null.
    z%23   N)rfindint)r;   poss     r   get_unique_counter_from_urlr[      s0    
 ((5/C
by2sQwk?##r   c                 N   | a |r	 t        |dd      andadt        |       z   }d}d}|r t        j                         }t        ||      }t        d| ft              }t        rt        j                  d|z         |r|j                          	 |j                          |r|j#                          t        rt        j%                          yy# t        $ r@}t        j
                  j                  d||       t	        j                  d       Y d}~d}~ww xY w# t         $ r Y w xY w)a'  
    Run NLTK Wordnet Browser Server.

    :param port: The port number for the server to listen on, defaults to
                 8000
    :type  port: int

    :param runBrowser: True to start a web browser and point it at the web
                       server.
    :type  runBrowser: bool
    ar   z Couldn't open %s for writing: %sNzhttp://localhost:r   z0NLTK Wordnet browser server running serving: %s
)r$   r,   rK   OSErrorsysstderrr9   exitstr	threadingEventstartBrowserr   r   setserve_foreverKeyboardInterruptjoinclose)port
runBrowserlogfilenameeurlserver_readybrowser_threadservers           r   wnbrs      s   < !.K 	;Q/G
  D	
)CLN (%c<8 T
O4FICOP  ?  	JJ?aPHHQKK	2  s)   C D 	D6DD	D$#D$c                 b      fd}t        j                  |      }|j                          |S )Nc                       j                          t        j                  d       t        j                  dd       y )Nr      )new	autoraise)waittimesleep
webbrowserr,   )rp   ro   s   r   runzstartBrowser.<locals>.run  s*    

1a0r   )target)rc   Threadstart)ro   rp   r}   ts   ``  r   re   re      s(    1 	$AGGIHr   c                      t         j                  ddft         j                  ddft         j                  ddft         j                  ddfgS )	NNnounVverbJadjRadv)wnNOUNVERBADJADVrT   r   r   _pos_tuplesr     sD    	#v	#v	e	e	 r   c                     | d   dk(  rd| d   | d   f} t        |       D ]	  \  }}|	 n t               D ]  }|   | |   k(  s|c S  y)z
    This function returns the complete pos tuple for the partial pos
    tuple given to it.  It attempts to match it against the first
    non-null component of the given pos tuple.
    r   sr]   r   rv   N)	enumerater   )	pos_tuplenxpts       r   
_pos_matchr   (  sg     |s)A,	!5	)$1= % ma5IaL I  r   r   rv   rW                  	   
                                                   c                     fd |j                         D cg c]  }|j                  | k(  s ||       c}      S c c}w )Nc                 4    | g k(  rg S | d    | dd        z   S Nr   r   rT   )lflatterns    r   r   z lemma_property.<locals>.flatternZ  s(    7IQ4(1QR5/))r   )lemmasname)r>   synsetfuncr   r   s       @r   lemma_propertyr   Y  s;    * fmmoHo4T!WoHIIHs
   A
Ac                 V    | d   }| dd  }||D cg c]  }t        |       c}fS c c}w r   )rebuild_tree)	orig_treenodechildrenr   s       r   r   r   c  s7    Q<D}HH5Hq<?H5665s   &c                    |j                         t        j                  k(  r@t        d|j	                         ft
        d|j                         ft        d|j                         ft        dt        |j                  d             d   ft        d|j                         ft        d|j                         ft         d	|j#                         ft$        d
|j'                         ft(        d|j+                         ft,        d|j/                         ft0        d|j3                         ft4        d|j7                         ft8        dt;        | |d       ft<        dt;        | |d       ffS |j                         t        j>                  k(  rt8        dt;        | |d       ft        d|j	                         ft        d|j                         ft        dt        |j                  d             d   ft@        d|jC                         ftD        d|jG                         ftH        d|jK                         ftL        d|jO                         ft<        dt;        | |d       ff	S |j                         t        jP                  k(  s|j                   t        jR                  k(  rlt8        dt;        | |d       ftT        d|jW                         ftX        dt;        | |d       ft4        d|j7                         ftH        d|jK                         ffS |j                         t        jZ                  k(  rt8        dt;        | |d        ffS t]        d!t_        |j                               z         )"z
    Get synset relations data for a synset.  Note that this doesn't
    yet support things such as full hyponym vs direct hyponym.
    HyponymszInstance hyponymszDirect hypernymszIndirect hypernymsc                 "    | j                         S r   	hypernymsr   s    r   <lambda>z$get_relations_data.<locals>.<lambda>v  
    1;;=r   r   zInstance hypernymszPart holonymszPart meronymszSubstance holonymszSubstance meronymszMember holonymszMember meronyms
AttributesAntonymsc                 "    | j                         S r   antonymsr   s    r   r   z$get_relations_data.<locals>.<lambda>  s
    r   zDerivationally related formc                 "    | j                         S r   derivationally_related_formsr   s    r   r   z$get_relations_data.<locals>.<lambda>      A,J,J,Lr   Antonymc                 "    | j                         S r   r   r   s    r   r   z$get_relations_data.<locals>.<lambda>  
    

r   Hyponymc                 "    | j                         S r   r   r   s    r   r   z$get_relations_data.<locals>.<lambda>  r   r   EntailmentsCauseszAlso seezVerb Groupsc                 "    | j                         S r   r   r   s    r   r   z$get_relations_data.<locals>.<lambda>  r   r   c                 "    | j                         S r   r   r   s    r   r   z$get_relations_data.<locals>.<lambda>  r   r   z
Similar to
Pertainymsc                 "    | j                         S r   )
pertainymsr   s    r   r   z$get_relations_data.<locals>.<lambda>  s
    q||~r   c                 "    | j                         S r   r   r   s    r   r   z$get_relations_data.<locals>.<lambda>  r   r   zUnhandles synset POS type: )0rZ   r   r   HYPONYMhyponymsINSTANCE_HYPONYMinstance_hyponymsHYPERNYMr   INDIRECT_HYPERNYMSr   treeINSTANCE_HYPERNYMinstance_hypernymsPART_HOLONYMpart_holonymsPART_MERONYMpart_meronymsSUBSTANCE_HOLONYMsubstance_holonymsSUBSTANCE_MERONYMsubstance_meronymsMEMBER_HOLONYMmember_holonymsMEMBER_MERONYMmember_meronyms	ATTRIBUTE
attributesANTONYMr   DERIVATIONALLY_RELATED_FORMr   
ENTAILMENTentailmentsCAUSEcausesALSO_SEE	also_sees
VERB_GROUPverb_groupsr   ADJ_SATSIMILARsimilar_tos	PERTAINYMr   	TypeErrorrb   )r>   r   s     r   get_relations_datar  i  s   
 zz|rwwj&//"342F4L4L4NO)6+;+;+=>"$V[[)@AB1E  4f6O6O6QR?F,@,@,BC?F,@,@,BC 4f6O6O6QR 4f6O6O6QR.0F0F0HI.0F0F0HIf&7&7&9:j.v?U"VW+-&"L)
 	
8 
	 if>T!UVi!23)6+;+;+=>"$V[[)@AB1E
 (:(:(<=Hfmmo.z6#3#3#56(:(:(<=+-&"L
 	
* 
	6::#;if>T!UVlF$6$6$89 tV-EF
 f&7&7&9:z6#3#3#56
 	
 
	 if>T!UV
 	

 5FJJL8IIJJr   au  
<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01//EN'
'http://www.w3.org/TR/html4/strict.dtd'>
<html>
<head>
<meta name='generator' content=
'HTML Tidy for Windows (vers 14 February 2006), see www.w3.org'>
<meta http-equiv='Content-Type' content=
'text/html; charset=us-ascii'>
<title>NLTK Wordnet Browser display of: %s</title></head>
<body bgcolor='#F5F5F5' text='#000000'>
z
</body>
</html>
a  
<h3>Search Help</h3>
<ul><li>The display below the line is an example of the output the browser
shows you when you enter a search word. The search word was <b>green</b>.</li>
<li>The search result shows for different parts of speech the <b>synsets</b>
i.e. different meanings for the word.</li>
<li>All underlined texts are hypertext links. There are two types of links:
word links and others. Clicking a word link carries out a search for the word
in the Wordnet database.</li>
<li>Clicking a link of the other type opens a display section of data attached
to that link. Clicking that link a second time closes the section again.</li>
<li>Clicking <u>S:</u> opens a section showing the relations for that synset.
</li>
<li>Clicking on a relation name opens a section that displays the associated
synsets.</li>
<li>Type a search word in the <b>Word</b> field and start the search by the
<b>Enter/Return</b> key or click the <b>Search</b> button.</li>
</ul>
<hr width='100%'>
c                     d| z  S )Nz	<b>%s</b>rT   txts    r   _boldr        r   c                     d| z  S )Nz<center>%s</center>rT   r  s    r   _centerr    s     3&&r   c                     d| || fz  S )Nz<h%d>%s</h%d>rT   )r   r  s     r   _hlevr    s    aa[((r   c                     d| z  S )Nz	<i>%s</i>rT   r  s    r   _italicr    r	  r   c                     d| z  S )N<li>%s</li>rT   r  s    r   _lir    s    3r   c                 (    t         | z  |z   t        z   S )a:  
    Return a HTML page of NLTK Browser format constructed from the
    word and body

    :param word: The word that the body corresponds to
    :type word: str
    :param body: The HTML body corresponding to the word
    :type body: str
    :return: a HTML page for the word-body combination
    :rtype: str
    )r.   r/   )r>   bodys     r   pgr    s     $$&55r   c                     d| z   dz   S )N<ul></ul>rT   r  s    r   _ulr    s    C<'!!r   c                 <    t        t        d| z   dz   dz               S )z0
    abbc = asterisks, breaks, bold, center
    z3<br><br><br><br><br><br><br><br><br><br>********** r   z
**********)r  r  r  s    r   _abbcr  	  s$     55;cAHLMNNr   z(has full hyponym continuation)rJ   c                 ,    t        j                  |       S )zf
    The synset key is the unique name of the synset, this can be
    retrieved via synset.name()
    )r   r   )
synset_keys    r   _get_synsetr    s    
 99Z  r   c                    
 t        |t              rt        d      d}t        |j	                         ddf      }|J d|j	                         z         |d   }t        j                  t         |            }|j                  |       |dz   }|j                         |v rt        |      }dt        ||       d| d	} fd

|dj                  
fd|j                         D              z  }dj                  |j                         dj                  d |j!                         D                    }	||	z   t#         ||      z   dz   S )a|  
    Returns the HTML string for one synset or word

    :param word: the current word
    :type word: str
    :param synset: a synset
    :type synset: synset
    :param synset_relations: information about which synset relations
    to display.
    :type synset_relations: dict(synset_key, set(relation_id))
    :return: The HTML string built for this synset
    :rtype: str
    z)word not supported by _collect_one_synsetSNz#pos_tuple is null: synset.pos(): %srv   ;z<li>z (z) c                     | j                  dd      } | j                         k(  rt        |       S t        |       }t	        ||       S )N_r   )r4   lowerr  	Referencemake_lookup_link)wrefr>   s     r   format_lemmaz)_collect_one_synset.<locals>.format_lemma7  s@    IIc37798OA,C#C++r   z, c              3   J   K   | ]  } |j                                 y wr   )r   ).0r   r)  s     r   	<genexpr>z&_collect_one_synset.<locals>.<genexpr>?  s     C?a<)?s    #z ({}) <i>{}</i> z; c              3   &   K   | ]	  }d |z    yw)z"%s"NrT   )r+  rn   s     r   r,  z&_collect_one_synset.<locals>.<genexpr>C  s     8&7&1*&7s   z</li>
)
isinstancetupleNotImplementedErrorr   rZ   copydeepcopyr%  toggle_synsetr   r  r&  ri   r   rN   
definitionexamples_synset_relations)r>   r   synset_relationstypr   descrr(  synset_labelr   glr)  s   `         @r   _collect_one_synsetr<    s<    &% !"MNN
CFJJL$56I V"G&**,"VV aLE
--	$(89
:Cf9L{{}((\*
\232eWB?A, C6==?C	CCA		"	"		8foo&788
B r6%dF4DEE	QQr   c                 j     ddj                   fdt        j                   |      D              z  S )z\
    Return a HTML unordered list of synsets for the given word and
    part of speech.
    z<ul>%s
</ul>
r   c              3   8   K   | ]  }t        |        y wr   )r<  )r+  r   r7  r>   s     r   r,  z'_collect_all_synsets.<locals>.<genexpr>M  s#      '+F 	D&*:;+s   )ri   r   synsets)r>   rZ   r7  s   ` `r   _collect_all_synsetsr@  H  s5    
 rww 'jjs+'    r   c                     j                         |vryt        | |      fdfdddj                  fdt        |       D              z   dz   }|S )a  
    Builds the HTML string for the relations of a synset

    :param word: The current word
    :type word: str
    :param synset: The synset for which we're building the relations.
    :type synset: Synset
    :param synset_relations: synset keys and relation types for which to display relations.
    :type synset_relations: dict(synset_key, set(relation_type))
    :return: The HTML for a synset's relations
    :rtype: str
    r   c                    t        | t              r7t        t        | j	                         d         | j	                         d         S t        | t
              r | j                               S t        | t              r6dj                   | d         dj                  fd| d   D                    S t        dt        |       d|       )Nr   z{}
<ul>{}</ul>
r   c              3   4   K   | ]  }d  |      z    ywz<li>%s</li>
NrT   )r+  srrelation_htmls     r   r,  z;_synset_relations.<locals>.relation_html.<locals>.<genexpr>o  s     Kd-*;;d   r   z5r must be a synset, lemma or list, it was: type(r) = z, r = )r.  r
   r&  r%  lemma_namesr	   r   r/  rN   ri   r  r=   )rrF  s    r   rF  z(_synset_relations.<locals>.relation_htmle  s    a #Iammoa.@$A1==?STCUVV5! ,,5! '--ad#KadKK 
 7A r   c                     dt        t        j                        j                  |       |      z  }| j                  j                            v r |ddj                  fd|D              z  z  }|S )Nz
<i>%s</i>
z<ul>%s</ul>
r   c              3   4   K   | ]  }d  |      z    ywrD  rT   )r+  rI  rF  s     r   r,  z>_synset_relations.<locals>.make_synset_html.<locals>.<genexpr>~  s      5<@q-"22DrG  )r&  r1  r2  toggle_synset_relationr7  r   ri   )db_name	disp_namerelssynset_htmlr(  rF  r   s       r   make_synset_htmlz+_synset_relations.<locals>.make_synset_htmlw  s}    #&6MM#55fgF'
 

 c**6;;=99?RWW 5<@5 .  K r   r  rJ   c              3   >   K   | ]  }|d    g k7  r
d | z    yw)rv   r  NrT   )r+  rel_datarQ  s     r   r,  z$_synset_relations.<locals>.<genexpr>  s0      
<{b  ,h77<s   r  )r   r%  ri   r  )r>   r   r7  htmlrQ  r(  rF  s    `  @@@r   r6  r6  S  sn     ;;=,,
D*
+C$ 	
)) 
.tV<
 
	
 	 	 Kr   c                       e Zd ZdZd Zy)RestrictedUnpicklerzW
    Unpickler that prevents any class or function from being used during loading.
    c                 :    t        j                  d| d| d      )Nzglobal '.z' is forbidden)pickleUnpicklingError)r   moduler   s      r   
find_classzRestrictedUnpickler.find_class  s"    $$xxqn%MNNr   N)rQ   rR   rS   __doc__r\  rT   r   r   rV  rV    s    Or   rV  c                   F    e Zd ZdZ e       fdZd Zed        Zd Z	d Z
y)r%  zB
    A reference to a page that may be generated by page_word
    c                      || _         || _        y)a1  
        Build a reference to a new page.

        word is the word or words (separated by commas) for which to
        search for synsets of

        synset_relations is a dictionary of synset keys to sets of
        synset relation identifaiers to unfold a list of synset
        relations for.
        N)r>   r7  )r   r>   r7  s      r   __init__zReference.__init__  s     	 0r   c                     t        j                  | j                  | j                  fd      }t	        j
                  |      j                         S )zJ
        Encode this reference into a string to be used in a URL.
        rV   )rY  dumpsr>   r7  base64urlsafe_b64encodedecode)r   strings     r   r:   zReference.encode  s=     tyy$*?*?@"E''/6688r   c                     t        j                  | j                               } t        t	        j
                  |             j                         \  }}t        ||      S )zB
        Decode a reference encoded with Reference.encode
        )rc  urlsafe_b64decoder:   rV  ioBytesIOloadr%  )rf  r>   r7  s      r   re  zReference.decode  sJ    
 ))&--/:!4RZZ5G!H!M!M!O/00r   c                     || j                   |j                            v r.| j                   |j                            j                  |       | S | j                   |j                            j                  |       | S )z
        Toggle the display of the relations for the given synset and
        relation type.

        This function will throw a KeyError if the synset is currently
        not being displayed.
        )r7  r   removeadd)r   r   relations      r   rL  z Reference.toggle_synset_relation  si     t,,V[[];;!!&++-077A  !!&++-044X>r   c                     |j                         | j                  v r| j                  |j                         = | S t               | j                  |j                         <   | S )zN
        Toggle displaying of the relation types for the given synset
        )r   r7  rf   )r   r   s     r   r3  zReference.toggle_synset  sR     ;;=D111%%fkkm4  475D!!&++-0r   N)rQ   rR   rS   r]  dictr`  r:   staticmethodre  rL  r3  rT   r   r   r%  r%    s6     /3f 19 1 1	r   r%  c                 0    d| j                          d| dS )Nz<a href="lookup_z">z</a>)r:   )r(  labels     r   r&  r&    s    cjjl^2eWD99r   c                 *    t        t        |             S )a#  
    Return a HTML page for the given word.

    :type word: str
    :param word: The currently active word
    :return: A tuple (page,word), where page is the new current HTML page
        to be sent to the browser and
        word is the new current word
    :rtype: A tuple (str,str)
    )page_from_referencer%  )r>   s    r   r5   r5     s     y//r   c                 >    t        t        j                  |             S )Q  
    Returns a tuple of the HTML page built and the new current word

    :param href: The hypertext reference to be solved
    :type href: str
    :return: A tuple (page,word), where page is the new current HTML page
             to be sent to the browser and
             word is the new current word
    :rtype: A tuple (str,str)
    )rv  r%  re  )hrefs    r   r7   r7     s     y//566r   c                    | j                   }t        t              }|j                  d      }|D cg c]0  }|j	                         j                         j                  dd      2 c}D cg c]
  }|dk7  s	| }}t        |      dk(  ry|D ]z  }t        j                  t        j                  t        j                  t        j                  fD ]7  }t        j                  ||      }|s|||   vs$||   j                  |       9 | d}t               D ]B  \  }}}	||v s|t!        d|	      dz   z  }||   D ]  }	 |t#        ||| j$                        z  } D |sd	|z  }||fS c c}w c c}w # t&        $ r Y Bw xY w)
rx  ,r   r#  r   r   )r   z$Please specify a word to search for.rW   rJ   z8The word or words '%s' were not found in the dictionary.)r>   r   listr3   stripr$  r4   r6   r   r   r   r   r   morphyappendr   r  r@  r7  KeyError)
ry  r>   	pos_formswordsr'  rZ   formr  pos_strr   s
             r   rv  rv    ss    99DD!IJJsOEFKLe*223<eLXL1PQUWPWQLEX
5zQ9 GGRWWbffbff5C99Q$DIcN2#%%d+ 6 
 D)mWd)E!TNT))Ds^0C9N9NOOD	 $ , IDP:3 MX*   s#   5E&+
E+6E+=E00	E<;E<c                     | dk(  rt        d      S | dk(  rt        d      S | dk(  ry| dk(  rt        d      S | dk(  rt        d      S | d	k(  r
t               S | d
k(  r
t               S t	               )z8
    Return a static HTML page from the path given.
    zindex_2.htmlFz
index.htmlTr   z7Display of Wordnet Database Statistics is not supportedupper_2.html
upper.htmlzweb_help.htmlzwx_help.html)r)   get_static_upper_pageget_static_web_help_pageget_static_wx_help_pager1   )r#   s    r   r0   r0   +  s     ~$U++		$T**	:	:H		$U++		$T**		 '))		&((

r   c                       y)z*
    Return the static web help page.
    a  
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
     <!-- Natural Language Toolkit: Wordnet Interface: Graphical Wordnet Browser
            Copyright (C) 2001-2024 NLTK Project
            Author: Jussi Salmela <jtsalmela@users.sourceforge.net>
            URL: <https://www.nltk.org/>
            For license information, see LICENSE.TXT -->
     <head>
          <meta http-equiv='Content-Type' content='text/html; charset=us-ascii'>
          <title>NLTK Wordnet Browser display of: * Help *</title>
     </head>
<body bgcolor='#F5F5F5' text='#000000'>
<h2>NLTK Wordnet Browser Help</h2>
<p>The NLTK Wordnet Browser is a tool to use in browsing the Wordnet database. It tries to behave like the Wordnet project's web browser but the difference is that the NLTK Wordnet Browser uses a local Wordnet database.
<p><b>You are using the Javascript client part of the NLTK Wordnet BrowseServer.</b> We assume your browser is in tab sheets enabled mode.</p>
<p>For background information on Wordnet, see the Wordnet project home page: <a href="https://wordnet.princeton.edu/"><b> https://wordnet.princeton.edu/</b></a>. For more information on the NLTK project, see the project home:
<a href="https://www.nltk.org/"><b>https://www.nltk.org/</b></a>. To get an idea of what the Wordnet version used by this browser includes choose <b>Show Database Info</b> from the <b>View</b> submenu.</p>
<h3>Word search</h3>
<p>The word to be searched is typed into the <b>New Word</b> field and the search started with Enter or by clicking the <b>Search</b> button. There is no uppercase/lowercase distinction: the search word is transformed to lowercase before the search.</p>
<p>In addition, the word does not have to be in base form. The browser tries to find the possible base form(s) by making certain morphological substitutions. Typing <b>fLIeS</b> as an obscure example gives one <a href="MfLIeS">this</a>. Click the previous link to see what this kind of search looks like and then come back to this page by using the <b>Alt+LeftArrow</b> key combination.</p>
<p>The result of a search is a display of one or more
<b>synsets</b> for every part of speech in which a form of the
search word was found to occur. A synset is a set of words
having the same sense or meaning. Each word in a synset that is
underlined is a hyperlink which can be clicked to trigger an
automatic search for that word.</p>
<p>Every synset has a hyperlink <b>S:</b> at the start of its
display line. Clicking that symbol shows you the name of every
<b>relation</b> that this synset is part of. Every relation name is a hyperlink that opens up a display for that relation. Clicking it another time closes the display again. Clicking another relation name on a line that has an opened relation closes the open relation and opens the clicked relation.</p>
<p>It is also possible to give two or more words or collocations to be searched at the same time separating them with a comma like this <a href="Mcheer up,clear up">cheer up,clear up</a>, for example. Click the previous link to see what this kind of search looks like and then come back to this page by using the <b>Alt+LeftArrow</b> key combination. As you could see the search result includes the synsets found in the same order than the forms were given in the search field.</p>
<p>
There are also word level (lexical) relations recorded in the Wordnet database. Opening this kind of relation displays lines with a hyperlink <b>W:</b> at their beginning. Clicking this link shows more info on the word in question.</p>
<h3>The Buttons</h3>
<p>The <b>Search</b> and <b>Help</b> buttons need no more explanation. </p>
<p>The <b>Show Database Info</b> button shows a collection of Wordnet database statistics.</p>
<p>The <b>Shutdown the Server</b> button is shown for the first client of the BrowServer program i.e. for the client that is automatically launched when the BrowServer is started but not for the succeeding clients in order to protect the server from accidental shutdowns.
</p></body>
</html>
rT   rT   r   r   r  r  @  s    'r   c                       y)z&
    Get the static welcome page.
    a  
<h3>Search Help</h3>
<ul><li>The display below the line is an example of the output the browser
shows you when you enter a search word. The search word was <b>green</b>.</li>
<li>The search result shows for different parts of speech the <b>synsets</b>
i.e. different meanings for the word.</li>
<li>All underlined texts are hypertext links. There are two types of links:
word links and others. Clicking a word link carries out a search for the word
in the Wordnet database.</li>
<li>Clicking a link of the other type opens a display section of data attached
to that link. Clicking that link a second time closes the section again.</li>
<li>Clicking <u>S:</u> opens a section showing the relations for that synset.</li>
<li>Clicking on a relation name opens a section that displays the associated
synsets.</li>
<li>Type a search word in the <b>Next Word</b> field and start the search by the
<b>Enter/Return</b> key or click the <b>Search</b> button.</li>
</ul>
rT   rT   r   r   get_static_welcome_messager  n  s    r   c                 &    d}| rd}||z  S d}||z  S )z$
    Get the static index page.
    aY  
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"  "http://www.w3.org/TR/html4/frameset.dtd">
<HTML>
     <!-- Natural Language Toolkit: Wordnet Interface: Graphical Wordnet Browser
            Copyright (C) 2001-2024 NLTK Project
            Author: Jussi Salmela <jtsalmela@users.sourceforge.net>
            URL: <https://www.nltk.org/>
            For license information, see LICENSE.TXT -->
     <HEAD>
         <TITLE>NLTK Wordnet Browser</TITLE>
     </HEAD>

<frameset rows="7%%,93%%">
    <frame src="%s" name="header">
    <frame src="start_page" name="body">
</frameset>
</HTML>
r  r  rT   )with_shutdowntemplate
upper_links      r   r)   r)     s2    H$ !
 j   $
j  r   c                 &    d}| rd}||z  S d}||z  S )z
    Return the upper frame page,

    If with_shutdown is True then a 'shutdown' button is also provided
    to shutdown the server.
    a  
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
    <!-- Natural Language Toolkit: Wordnet Interface: Graphical Wordnet Browser
        Copyright (C) 2001-2024 NLTK Project
        Author: Jussi Salmela <jtsalmela@users.sourceforge.net>
        URL: <https://www.nltk.org/>
        For license information, see LICENSE.TXT -->
    <head>
                <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <title>Untitled Document</title>
    </head>
    <body>
    <form method="GET" action="search" target="body">
            Current Word:&nbsp;<input type="text" id="currentWord" size="10" disabled>
            Next Word:&nbsp;<input type="text" id="nextWord" name="nextWord" size="10">
            <input name="searchButton" type="submit" value="Search">
    </form>
        <a target="body" href="web_help.html">Help</a>
        %s

</body>
</html>
z*<a href="SHUTDOWN THE SERVER">Shutdown</a>r   rT   )r  r  shutdown_links      r   r  r    s2    H0 D m## m##r   c                  "    t        t               y)z0
    Display the command line help message.
    N)r%   r]  rT   r   r   usager    s     
'Nr   c                  0   t        j                   t        dd  dg d      \  } }d}d}d}d }| D ]K  \  }}|dk(  s|dk(  rt        |      }|dk(  s|d	k(  rt        |      }2|d
k(  s|dk(  rd}?|dk(  s|dk(  sJd}M |rt	                y t        || |       y )Nr   zl:p:sh)zlogfile=zport=zserver-modehelp@  Fz-lz	--logfilez-pz--portz-sz--server-modeTz-hz--help)getoptr   rb   rY   r  rs   )optsr#  rk   r$   	help_moderm   optvalues           r   appr    s    QR(HIT1 DKIK
U4KSK/e*KTkshu:DTkso5KTkshI  Dk/;/r   __main__r  )r  TN)^r]  rc  r1  r  ri  r&   rY  r_   rc   rz   r|   collectionsr   http.serverr   r   r   urllib.parser   nltk.corpusr   r   nltk.corpus.reader.wordnetr	   r
   r(   r$   rK   r   r[   rs   re   r   r   r   r   CLASS_REGIONALr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   FRAMESr  CLASS_CATEGORYCLASS_USAGEr   r   r   r   r  r.   r/   explanationr  r  r  r  r  r  r  r  full_hyponym_cont_textr  r<  rq  r@  r6  	UnpicklerrV  r%  r&  r5   r7   rv  r0   r  r  r)   r  r  r  rQ   __all__rT   r   r   <module>r     s  !N    	 	  
    # :  % % 4  \, \~	DN	"" 	  
  



		   J7MK`
0')6"O S)J!KLMPTT !*RZ 6:V ;|O&** O> >B:07'^*+\0!<$$N02 zE'r   