JL i dZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl m Z ddl mZmZddlmZddlmZddlmZddlmZmZd adadaGd d eZd ZdPd ZdZ dZ dZ!dZ"dZ#dZ$dZ%dZ&dZ'dZ(dZ)dZ*dZ+dZ,dZ-dZ.dZ/dZ0dZ1d Z2d!Z3d"Z4d#Z5d$Z6d%Z7d&Z$d'Z7d(Z6d)Z8d*Z9d+Z:d,Z;d-Zd0Z?d1Z@d2ZAd3ZBd4ZCd5ZDd6ZEd7ZFd8ZGeFeDeCd9d:zZHd;ZId<ZJeKfd=ZLd>ZMGd?d@ejZOGdAdBZPdCZQdDZRdEZSdFZTdGZUdHZVdIZWdJZXdKZYdLZZdMZ[e\dNk(re[dOgZ]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 ] Options:: -h or --help Display this help message. -l or --log-file Logs messages to the given file, If this option is not specified messages are silently dropped. -p or --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)LemmaSynsetTc&eZdZdZdZddZdZy)MyServerHandlerc$|jyN) send_head)selfs Z/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/nltk/app/wordnet_app.pydo_HEADzMyServerHandler.do_HEADOs  c|jdd}t|dk(r.trd}d}ntdt j dn|dk(r+d}tst rd atd }n td }d }nt|jd rd}t|}|d k(rjd}tjj|r&t|5}|j}dddn t|zdz|zdzdzdzdztz}n|} t|}n|j!drzd}|j#ddj#d}|Dcgc]7}|j!dr$|j#ddj%dd9c}d}t'|\}}nM|j!drd}|t)dd}t+|\}}n|dk(rd}t'd\}}nd}d|z}|j-|j.j1j3d y#1swYExYw#t$r d|z}d}YZwxYwcc}w)!NzSHUTDOWN THE SERVERz#Server must be killed with SIGTERM.z text/plainzServer shutting down!rz text/htmlFTgreenz.html'NLTK Wordnet Browser Database Info.htmlz* Database Info *z

The database info file:

zz

was not found. Run this:z

python dbinfo_html.pyz

to produce it.z4Internal error: Path for static page '%s' is unknownsearch?&nextWord=+ lookup_ start_pagerzCould not parse request: '%s'utf8)pathr server_modeprintos_exit firstClientget_static_index_pageendswithisfileopenread html_header html_trailerget_static_page_by_pathFileNotFoundError startswithsplitreplacepage_from_wordlenpage_from_hrefrwfilewriteencode) rsppagetypeworduspinfilepartsps rdo_GETzMyServerHandler.do_GETRsr YYqr]  4 4<#-. 2XD;# ,T2,U3D [[ !Dr"C??*77>>#&c-f%{{}--%t+0!!!!8 8 < < . .''(237D ]]8 $DXXc]1%,,S1E<< + Q''S1 D (-JD$ ]]9 %DC N$%B'+JD$ < D' 2JD$D2R7D t V,-a--$)(QTWWD'D(s$ H, H8tj|jd|jd||zdyy)Nz - - [z]  )logfiler9address_stringlog_date_time_string)rformatargss r log_messagezMyServerHandler.log_messages<  MM&&($*C*C*EvPT}V  rr)__name__ __module__ __qualname__rrCrrPrrr r NsJ.X rr cR|jd}|dk7rt||dzdSy)z\ Extract the unique counter from the URL if it has one. Otherwise return null. z%23N)rfindint)r;poss rget_unique_counter_from_urlr[s0 ((5/C by2sQwk?##rcN| a|r t|ddandadt|z}d}d}|r tj}t||}td|ft}trtj d|z|r|j |j|r|j#trtj%yy#t$r@}tj j d||t jdYd}~d}~wwxYw#t $rYwxYw)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 arz Couldn't open %s for writing: %sNzhttp://localhost:rz0NLTK Wordnet browser server running serving: %s )r$r,rKOSErrorsysstderrr9exitstr threadingEvent startBrowserrr set serve_foreverKeyboardInterruptjoinclose)port runBrowser logfilenameeurl server_readybrowser_threadservers rwnbrss<!.K ;Q/G  D )CLN ( %c<8T O 4F ICOP  ?  JJ  ?a P HHQKK 2    s) C D D6DD D$#D$cbfd}tj|}|j|S)Ncjtjdtjddy)Nr)new autoraise)waittimesleep webbrowserr,)rprosrrunzstartBrowser..runs* 1 a0r)target)rcThreadstart)rorpr}ts`` rreres(1 $AGGI HrctjddftjddftjddftjddfgS) NNnounVverbJadjRadv)wnNOUNVERBADJADVrTrr _pos_tuplesrsD #v #v e e  rc|ddk(r d|d|df}t|D] \}}| ntD]}|||k(s|cSy)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. rsr]rrvN) enumerater) pos_tuplenxpts r _pos_matchr(sq |s)A, ! 5 )$1 = m a5IaL I rrrvrW  cfd|jDcgc]}|j|k(s||c}Scc}w)Nc4|gk(rgS|d|ddzSNrrrT)lflatterns rrz lemma_property..flatternZs( 7IQ4(1QR5/) )r)lemmasname)r>synsetfuncrrs @rlemma_propertyrYs7* fmmoH4T!WH IIHs A AcV|d}|dd}||Dcgc] }t|c}fScc}wr) rebuild_tree) orig_treenodechildrenrs rrrcs3 Qk(rt8dt;||dftd|j ftd|jftdt|jddft@d|jCftDd|jGftHd|jKftLd|jOft<dt;||dff S|jtjPk(s!|jtjRk(rlt8dt;||dftTd|jWftXdt;||dft4d|j7ftHd|jKffS|jtjZk(rt8dt;||d ffSt]d!t_|jz)"z Get synset relations data for a synset. Note that this doesn't yet support things such as full hyponym vs direct hyponym. HyponymszInstance hyponymszDirect hypernymszIndirect hypernymsc"|jSr hypernymsrs rz$get_relations_data..v 1;;=rrzInstance hypernymsz Part holonymsz Part meronymszSubstance holonymszSubstance meronymszMember holonymszMember meronyms AttributesAntonymsc"|jSrantonymsrs rrz$get_relations_data..s rzDerivationally related formc"|jSrderivationally_related_formsrs rrz$get_relations_data..A,J,J,LrAntonymc"|jSrrrs rrz$get_relations_data..  rHyponymc"|jSrrrs rrz$get_relations_data..rr EntailmentsCauseszAlso seez Verb Groupsc"|jSrrrs rrz$get_relations_data..rrc"|jSrrrs rrz$get_relations_data..rrz Similar to Pertainymsc"|jSr) pertainymsrs rrz$get_relations_data..s q||~rc"|jSrrrs rrz$get_relations_data..rrzUnhandled synset POS type: )0rZrrHYPONYMhyponymsINSTANCE_HYPONYMinstance_hyponymsHYPERNYMrINDIRECT_HYPERNYMSrtreeINSTANCE_HYPERNYMinstance_hypernyms PART_HOLONYM part_holonyms PART_MERONYM part_meronymsSUBSTANCE_HOLONYMsubstance_holonymsSUBSTANCE_MERONYMsubstance_meronymsMEMBER_HOLONYMmember_holonymsMEMBER_MERONYMmember_meronyms ATTRIBUTE attributesANTONYMrDERIVATIONALLY_RELATED_FORMr ENTAILMENT entailmentsCAUSEcausesALSO_SEE also_sees VERB_GROUP verb_groupsrADJ_SATSIMILAR similar_tos PERTAINYMr TypeErrorrb)r>rs rget_relations_dataris zz|rww j&//"3 4 2F4L4L4N O )6+;+;+= >"$V[[)@AB1E   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  if>T!U V i!2 3 )6+;+;+= >"$V[[)@AB1E  (:(:(< = Hfmmo . z6#3#3#5 6 (:(:(< =+-&"L   *  6::<2::#= if>T!U V lF$6$6$8 9tV-EF   f&7&7&9 : z6#3#3#5 6    if>T!U V  5FJJL8IIJJrau NLTK Wordnet Browser display of: %s z a

Search Help

  • 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 green.
  • The search result shows for different parts of speech the synsets i.e. different meanings for the word.
  • 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.
  • 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.
  • Clicking S: opens a section showing the relations for that synset.
  • Clicking on a relation name opens a section that displays the associated synsets.
  • Type a search word in the Word field and start the search by the Enter/Return key or click the Search button.

c d|zS)Nz %srTtxts r_boldr  rc d|zS)Nz
%s
rTrs r_centerr s 3 &&rcd|||fzS)Nz %srT)rrs r_hlevr s aa[ ((rc d|zS)Nz %srTrs r_italicrr rc d|zS)N
  • %s
  • rTrs r_lirs 3 rc(t|z|ztzS)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 rpgrs $ $ & 55rcd|zdzS)N
      
    rTrs r_ulrs C<' !!rc<ttd|zdzdzS)z0 abbc = asterisks, breaks, bold, center z3









    ********** rz **********)r rrs r_abbcr s$ 55;cAHLM NNrz(has full hyponym continuation)rJc,tj|S)zf The synset key is the unique name of the synset, this can be retrieved via synset.name() )rr) synset_keys r _get_synsetrs 99Z  rc t|tr tdd}t|j ddf}|Jd|j z|d}t j t|}|j||dz}|j|vr t|}dt||d|d }fd  |d j fd |jDz }d j|jdjd|j!D} || zt#||zdzS)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_synsetSNz#pos_tuple is null: synset.pos(): %srv;z
  • z (z) c|jdd}|jk(r t|St|}t ||S)N_r)r4lowerr Referencemake_lookup_link)wrefr>s r format_lemmaz)_collect_one_synset..format_lemma7s@ IIc3  779 8OA,C#C+ +rz, c3JK|]}|jywr)r).0rr)s r z&_collect_one_synset..?sCa<)Cs #z ({}) {} z; c3&K|] }d|z yw)z"%s"NrT)r+rns rr,z&_collect_one_synset..Cs8&1*8sz
  • ) isinstancetupleNotImplementedErrorrrZcopydeepcopyr% toggle_synsetrrr&rirrN definitionexamples_synset_relations) r>rsynset_relationstyprdescrr( synset_labelrglr)s ` @r_collect_one_synsetr<s<&% !"MNN CFJJL$56I  V"G&**,"VV aLE -- $(89 :Cf9L {{}((\* \232eWB?A,C6==?C CCA  " " 8foo&788 B r6%dF4DE E QQrcjddjfdtj|DzS)z\ Return a HTML unordered list of synsets for the given word and part of speech. z
      %s
    rc38K|]}t|ywr)r<)r+rr7r>s rr,z'_collect_all_synsets..Ms#'  D&*:;'s)rirsynsets)r>rZr7s` `r_collect_all_synsetsr@Hs5 rww'jjs+'  rcj|vryt||fdfdddjfdt|Dzdz}|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 rct|tr7tt|j d|j dSt|t r|j St|tr6dj|ddjfd|dDStdt|d|)Nrz{}
      {}
    rc34K|]}d|zywz
  • %s
  • NrT)r+sr relation_htmls rr,z;_synset_relations..relation_html..osK-*;;Krz5r must be a synset, lemma or list, it was: type(r) = z, r = ) r.r r&r% lemma_namesr rr/rNrirr=)rrFs rrFz(_synset_relations..relation_htmles a #Iammoa.@$A1==?STCUV V 5 ! , , 5 !'--ad#KadKK  7A rcdttjj||z}|jj vr |ddj fd|Dzz }|S)Nz %s z
      %s
    rc34K|]}d|zywrDrT)r+rIrFs rr,z>_synset_relations..make_synset_html..~s 578-"225rG)r&r1r2toggle_synset_relationr7rri)db_name disp_namerels synset_htmlr(rFrs rmake_synset_htmlz+_synset_relations..make_synset_htmlws}#&6 MM#  5 5fg F '  c**6;;=9 9 ?RWW5<@5. KrrrJc3>K|]}|dgk7r d|zyw)rvrNrT)r+rel_datarQs rr,z$_synset_relations..s0 {b  ,h7 7 sr)rr%rir)r>rr7htmlrQr(rFs ` @@@rr6r6Ssn ;;=, , D* +C$   )) .tV<       KrceZdZdZdZy)RestrictedUnpicklerzW Unpickler that prevents any class or function from being used during loading. c:tjd|d|d)Nzglobal '.z' is forbidden)pickleUnpicklingError)rmodulers r find_classzRestrictedUnpickler.find_classs"$$xxqn%MNNrN)rQrRrS__doc__r\rTrrrVrVs OrrVcFeZdZdZefdZdZedZdZ dZ 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)rr>r7s r__init__zReference.__init__s 0rctj|j|jfd}t j |j S)zJ Encode this reference into a string to be used in a URL. rV)rYdumpsr>r7base64urlsafe_b64encodedecode)rstrings rr:zReference.encodes=tyy$*?*?@"E''/6688rctj|j}tt j |j \}}t||S)zB Decode a reference encoded with Reference.encode )rcurlsafe_b64decoder:rVioBytesIOloadr%)rfr>r7s rrezReference.decodesJ ))&--/:!4RZZ5G!H!M!M!O/00rc||j|jvr.|j|jj||S|j|jj||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. )r7rremoveadd)rrrelations rrLz Reference.toggle_synset_relationsi t,,V[[]; ;  ! !&++- 0 7 7 A   ! !&++- 0 4 4X > rc|j|jvr|j|j=|St|j|j<|S)zN Toggle displaying of the relation types for the given synset )rr7rf)rrs rr3zReference.toggle_synsetsR ;;=D11 1%%fkkm4 475D ! !&++- 0 rN) rQrRrSr]dictr`r: staticmethodrerLr3rTrrr%r%s6/3f 1911  rr%c0d|jd|dS)Nzz)r:)r(labels rr&r&s cjjl^2eWD 99rc*tt|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 rr5r5s y //rc>ttj|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) )rvr%re)hrefs rr7r7s y//5 66rc|j}tt}|jd}|Dcgc]0}|j j j dd2c}Dcgc] }|dk7s | }}t|dk(ry|D]z}tjtjtjtjfD]7}tj||}|s|||vs$||j|9|d}tD]B\}}} ||vs |t!d| dzz }||D]} |t#|||j$z }D|sd |z}||fScc}wcc}w#t&$rYBwxYw) rx,rr#rr)rz$Please specify a word to search for.rWrJz8The word or words '%s' were not found in the dictionary.)r>rlistr3stripr$r4r6rrrrrmorphyappendrr r@r7KeyError) ryr> pos_formswordsr'rZformrpos_strrs rrvrvs 99DD!I JJsOEFKL*223<L X1PQUWPWQ XE X 5zQ9,GGRWWbffbff5 ,C99Q$DIcN2#%%d+ ,, D)m Wd )  E!TNT) )Ds^ 0C9N9NOOD    IDP :3M X* s#5E&+ E+6E+=E00 E<;E<c|dk(r tdS|dk(r tdS|dk(ry|dk(r tdS|dk(r tdS|d k(r tS|d k(r tSt ) z8 Return a static HTML page from the path given. z index_2.htmlFz index.htmlTrz7Display of Wordnet Database Statistics is not supported upper_2.html upper.htmlz web_help.htmlz wx_help.html)r)get_static_upper_pageget_static_web_help_pageget_static_wx_help_pager1)r#s rr0r0+s ~$U++  $T** : :H  $U++  $T**  '))  &((  rcy)z* Return the static web help page. a NLTK Wordnet Browser display of: * Help *

    NLTK Wordnet Browser Help

    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.

    You are using the Javascript client part of the NLTK Wordnet BrowseServer. We assume your browser is in tab sheets enabled mode.

    For background information on Wordnet, see the Wordnet project home page: https://wordnet.princeton.edu/. For more information on the NLTK project, see the project home: https://www.nltk.org/. To get an idea of what the Wordnet version used by this browser includes choose Show Database Info from the View submenu.

    Word search

    The word to be searched is typed into the New Word field and the search started with Enter or by clicking the Search button. There is no uppercase/lowercase distinction: the search word is transformed to lowercase before the search.

    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 fLIeS as an obscure example gives one this. Click the previous link to see what this kind of search looks like and then come back to this page by using the Alt+LeftArrow key combination.

    The result of a search is a display of one or more synsets 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.

    Every synset has a hyperlink S: at the start of its display line. Clicking that symbol shows you the name of every relation 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.

    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 cheer up,clear up, 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 Alt+LeftArrow 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.

    There are also word level (lexical) relations recorded in the Wordnet database. Opening this kind of relation displays lines with a hyperlink W: at their beginning. Clicking this link shows more info on the word in question.

    The Buttons

    The Search and Help buttons need no more explanation.

    The Show Database Info button shows a collection of Wordnet database statistics.

    The Shutdown the Server 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.

    rTrTrrrr@s' rcy)z& Get the static welcome page. a

    Search Help

    • 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 green.
    • The search result shows for different parts of speech the synsets i.e. different meanings for the word.
    • 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.
    • 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.
    • Clicking S: opens a section showing the relations for that synset.
    • Clicking on a relation name opens a section that displays the associated synsets.
    • Type a search word in the Next Word field and start the search by the Enter/Return key or click the Search button.
    rTrTrrget_static_welcome_messagerns rc&d}|rd}||zSd}||zS)z$ Get the static index page. aY NLTK Wordnet Browser rrrT) with_shutdowntemplate upper_links rr)r)s2H$!  j  $ j  rc&d}|rd}||zSd}||zS)z Return the upper frame page, If with_shutdown is True then a 'shutdown' button is also provided to shutdown the server. a Untitled Document
    Current Word:  Next Word: 
    Help %s z*ShutdownrrT)rr shutdown_links rrrs2H0D  m ## m ##rc"tty)z0 Display the command line help message. N)r%r]rTrrusagers  'Nrc0tjtdddgd\}}d}d}d}d}|D]K\}}|dk(s|dk(r t|}|dk(s|d k(r t|}2|d k(s|d k(rd }?|d k(s|dk(sJd }M|r t yt || |y)Nrzl:p:sh)zlogfile=zport=z server-modehelp@Fz-lz --logfilez-pz--portz-sz --server-modeTz-hz--help)getoptrrbrYrrs)optsr#rkr$ help_modermoptvalues rapprs  QR(HIT1 DKIK U 4KSK/e*KTkshu:DTkso5KTkshI  Dk/;/r__main__r)rTN)^r]rcr1rrir&rYr_rcrzr| collectionsr http.serverrrr urllib.parser nltk.corpusrrnltk.corpus.reader.wordnetr r r(r$rKr r[rsrerrrrCLASS_REGIONALrrrrrrrrrrrrrrrFRAMESrCLASS_CATEGORY CLASS_USAGErrrrrr.r/ explanationrr r rrrrrfull_hyponym_cont_textrr<rqr@r6 UnpicklerrVr%r&r5r7rvr0rrr)rrrrQ__all__rTrrrs !N  #:%%4   \,\~ DN  ""                 J7 MK`    0') 6"OS)J!KLMPTT!*RZ6:V;|O&**O>>B: 0 7'^*+\0!<$$N02 zE 'r