Package nltk :: Package app :: Module wordnet_app
[hide private]
[frames] | no frames]

Module wordnet_app

source code

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
       shotdown the server through the web interface.
Classes [hide private]
MyServerHandler
Reference
A reference to a page that may be generated by page_word
Functions [hide private]
 
encode_icon() source code
 
favicon_data()
Return the data for the favicon image.
source code
 
get_unique_counter_from_url(sp)
Extract the unique counter from the URL if it has one.
source code
 
wnb(port=8000, runBrowser=True, logfilename=None)
Run NLTK Wordnet Browser Server.
source code
 
startBrowser(url, server_ready) source code
 
_pos_tuples() source code
 
_pos_match(pos_tuple)
This function returns the complete pos tuple for the partial pos tuple given to it.
source code
 
lemma_property(word, synset, func) source code
 
rebuild_tree(orig_tree) source code
 
get_relations_data(word, synset)
Get synset relations data for a synset.
source code
 
_bold(txt) source code
 
_center(txt) source code
 
_hlev(n, txt) source code
 
_italic(txt) source code
 
_li(txt) source code
str
pg(word, body)
Return a HTML page of NLTK Browser format constructed from the word and body
source code
 
_ul(txt) source code
 
_abbc(txt)
abbc = asterisks, breaks, bold, center
source code
 
_get_synset(synset_key)
The synset key is the unique name of the synset, this can be retrived via synset.name
source code
str
_collect_one_synset(word, synset, synset_relations)
Returns the HTML string for one synset or word
source code
 
_collect_all_synsets(word, pos, synset_relations={})
Return a HTML unordered list of synsets for the given word and part of speach.
source code
str
_synset_relations(word, synset, synset_relations)
Builds the HTML string for the relations of a synset
source code
 
decode_reference(string)
Decode a reference encoded with Reference.encode
source code
 
make_lookup_link(ref, label) source code
A tuple (str,str)
page_from_word(word)
Return a HTML page for the given word.
source code
A tuple (str,str)
page_from_href(href)
Returns a tuple of the HTML page built and the new current word
source code
A tuple (str,str)
page_from_reference(href)
Returns a tuple of the HTML page built and the new current word
source code
 
get_static_page_by_path(path)
Return a static HTML page from the path given.
source code
 
get_static_web_help_page()
Return the static web help page.
source code
 
get_static_welcome_message()
Get the static welcome page.
source code
 
get_static_index_page(with_shutdown)
Get the static index page.
source code
 
get_static_upper_page(with_shutdown)
Return the upper frame page,
source code
 
usage()
Display the command line help message.
source code
 
app() source code
Variables [hide private]
  firstClient = True
  server_mode = None
  logfile = None
  FAVICON_BASE64_DATA = ['AAABAAEAEBAAAAAAAABoBQAAFgAAACgAAAAQAA...
  HYPONYM = 0
  HYPERNYM = 1
  PART_HOLONYM = 3
  PART_MERONYM = 4
  ATTRIBUTE = 5
  SUBSTANCE_HOLONYM = 6
  SUBSTANCE_MERONYM = 7
  MEMBER_HOLONYM = 8
  MEMBER_MERONYM = 9
  VERB_GROUP = 10
  INSTANCE_HYPONYM = 12
  INSTANCE_HYPERNYM = 13
  CAUSE = 14
  ALSO_SEE = 15
  SIMILAR = 16
  ENTAILMENT = 17
  ANTONYM = 18
  FRAMES = 19
  PERTAINYM = 20
  CLASS_REGIONAL = 23
  CLASS_USAGE = 24
  CLASS_CATEGORY = 11
  DERIVATIONALLY_RELATED_FORM = 25
  INDIRECT_HYPERNYMS = 26
  html_header = '\n<!DOCTYPE html PUBLIC \'-//W3C//DTD HTML 4.01...
  html_trailer = '\n</body>\n</html>\n'
  explanation = '\n<h3>Search Help</h3>\n<ul><li>The display bel...
  full_hyponym_cont_text = '<ul><li><i>(has full hyponym continu...
Function Details [hide private]

get_unique_counter_from_url(sp)

source code 

Extract the unique counter from the URL if it has one. Otherwise return null.

wnb(port=8000, runBrowser=True, logfilename=None)

source code 

Run NLTK Wordnet Browser Server.

Parameters:
  • port (int) - The port number for the server to listen on, defaults to 8000
  • runBrowser (boolean) - True to start a web browser and point it at the web server.

_pos_match(pos_tuple)

source code 

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.

get_relations_data(word, synset)

source code 

Get synset relations data for a synset. Note that this doesn't yet support things such as full hyponym vs direct hyponym.

pg(word, body)

source code 

Return a HTML page of NLTK Browser format constructed from the word and body

Parameters:
  • word (str) - The word that the body corresponds to
  • body (str) - The HTML body corresponding to the word
Returns: str
a HTML page for the word-body combination

_collect_one_synset(word, synset, synset_relations)

source code 

Returns the HTML string for one synset or word

Parameters:
  • word (str) - the current word
  • synset (synset) - a synset
  • synset_relations (dict(synset_key, set(relation_id))) - information about which synset relations to display.
Returns: str
The HTML string built for this synset

_synset_relations(word, synset, synset_relations)

source code 

Builds the HTML string for the relations of a synset

Parameters:
  • word (str) - The current word
  • synset (Synset) - The synset for which we're building the relations.
  • synset_relations (dict(synset_key, set(relation_type))) - synset keys and relation types for which to display relations.
Returns: str
The HTML for a synset's relations

page_from_word(word)

source code 

Return a HTML page for the given word.

Parameters:
  • word (str) - The currently active word
Returns: A tuple (str,str)
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

page_from_href(href)

source code 

Returns a tuple of the HTML page built and the new current word

Parameters:
  • href (str) - The hypertext reference to be solved
Returns: A tuple (str,str)
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

page_from_reference(href)

source code 

Returns a tuple of the HTML page built and the new current word

Parameters:
  • href (str) - The hypertext reference to be solved
Returns: A tuple (str,str)
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

get_static_upper_page(with_shutdown)

source code 

Return the upper frame page,

If with_shutdown is True then a 'shutdown' button is also provided to shutdown the server.


Variables Details [hide private]

FAVICON_BASE64_DATA

Value:
['AAABAAEAEBAAAAAAAABoBQAAFgAAACgAAAAQAAAAIAAAAAEACAAAAAAAAAAAAAAAAAAA\
AAAA',
 'AAAAAAAAAAD___8A9___ANb3_wDO9_8AjPf_ALXv_wCc7_8AjO__AHvv_wBz7_8Aa-__\
AKXn',
 '_wCc5_8AlOf_AITn_wBz5_8Aa-f_AGPn_wBa5_8Ac97_AGve_wBj3v8AWt7_AFLe_wBK\
3v8A',
 'Qt7_AFrW_wBS1v8AStb_AELW_wA51v8AMdb_ACnO_wAhzv8AGM7_ABjG_wD___cA__f3\
APf3',
...

html_header

Value:
'''
<!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=
...

explanation

Value:
'''
<h3>Search Help</h3>
<ul><li>The display below the line is an example of the output the bro\
wser
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>synse\
ts</b>
...

full_hyponym_cont_text

Value:
'''<ul><li><i>(has full hyponym continuation)</i></li></ul>
'''