Package nltk :: Package wordnet :: Package browser :: Module util
[hide private]
[frames] | no frames]

Module util

source code

Functions [hide private]
A dict or list
relations_2(synsetObj, rel_name=None, word_match=False)
Return a dict of relations or a list of word match pairs for synsetObj.
source code
 
_pos_match(pos_tuple) source code
 
_dispname_to_dbname(dispname) source code
 
_dbname_to_dispname(dbname) 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) source code
int
uniq_cntr()
Return a unique counter, a state is kept to ensure that the same counter is not provided multiple times.
source code
 
_get_synset(synset_key) source code
str
_collect_one(word, s_or_w, prev_synset_key)
Returns the HTML string for one synset or word
source code
 
_collect_all(word, pos) source code
 
_rel_ref(word, synset_keys, rel) source code
 
_anto_or_similar_anto(synset) source code
str
_synset_relations(word, link_type, synset_keys)
Builds the HTML string for the relations of a synset
source code
 
_hyponym_ul_structure(word, tree) source code
 
_hypernym_ul_structure(word, tree) source code
 
_word_ul_structure(word, synset, rel_name, synset_keys) source code
 
_relation_section(rel_name, word, synset_keys) source code
 
_w_b(word, overview) source code
Tuple (str,str)
new_word_and_body(word)
Return a 2-tuple of a new word and the HTML body consisting of all the synsets for all the POS that the word was found in
source code
 
_ul_section_removed(page, index)
Removes the first string <ul>...stuff...</ul> from the html page.
source code
A tuple (str,str)
page_word(page, word, 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_wx_help_page()
Return static WX help page.
source code
 
get_static_start_page()
Get the static start 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
Variables [hide private]
  _pos_tuples = [(<nltk.wordnet.dictionary.Dictionary instance f...
  implemented_rel_names = ['antonym', 'attribute', 'cause', 'der...
  rel_order = [('hyponym', 'direct hyponym/full hyponym'), ('hyp...
  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...
  _uniq_cntr = 0
  abbreviations = 'adverb adv adv. r'
  pos = 'adv'
  token = 'r'
  tokens = ['adverb', 'adv', 'adv.', 'r']
Function Details [hide private]

relations_2(synsetObj, rel_name=None, word_match=False)

source code 

Return a dict of relations or a list of word match pairs for synsetObj.

The dictionary keys are the names for the relations found. The dictionary items are lists of either synsets or words depending on the relation.

If rel_name is specified, a list of eiher synsets or words for only that relation type is returned.

If word_match is True a list of pairs (source,target) of matching word information is returned . Here source and target are tuples of form (synset,word_index), where 'word_index' is the 0-based index of the word in synset 'synset'

Parameters:
  • synsetObj (synset) - The synset whose relations we are using
  • rel_name (str) - A relation name we are interested in
  • word_match (truth value) - Tells if we want word-level matching or not
Returns: A dict or list
A relation dict or a list of word match pairs for synsetObj.

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

uniq_cntr()

source code 

Return a unique counter, a state is kept to ensure that the same counter is not provided multiple times.

Returns: int
A unique integer for this module instance.

_collect_one(word, s_or_w, prev_synset_key)

source code 

Returns the HTML string for one synset or word

Parameters:
  • word (str) - the current word
  • s_or_w (tuple or synset) - a tuple containing word information or a synset
  • prev_synset_key (str) - key of previous synset
Returns: str
The HTML string built for this synset or word

_synset_relations(word, link_type, synset_keys)

source code 

Builds the HTML string for the relations of a synset

Parameters:
  • word (str) - The current word
  • link_type (str) - The link type, word or synset
  • synset_keys (str) - synset keys for this and the previous synset
Returns: str
The HTML for a synset's relations

new_word_and_body(word)

source code 

Return a 2-tuple of a new word and the HTML body consisting of all the synsets for all the POS that the word was found in

Parameters:
  • word (str) - The word for which the HTML body is to be constructed
Returns: Tuple (str,str)
The tuple (word,body)

_ul_section_removed(page, index)

source code 

Removes the first string <ul>...stuff...</ul> from the html page.

The search starts at index. Note: ...stuff... may contain embedded <ul>-</ul> pairs but the search continues to the </ul> that is the pair of the starting <ul>

page_word(page, word, href)

source code 

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

Parameters:
  • page (str) - The currently active HTML page
  • word (str) - The currently active word
  • 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]

_pos_tuples

Value:
[(<nltk.wordnet.dictionary.Dictionary instance for noun>, 'N', 'noun')\
,
 (<nltk.wordnet.dictionary.Dictionary instance for verb>, 'V', 'verb')\
,
 (<nltk.wordnet.dictionary.Dictionary instance for adj>, 'J', 'adj'),
 (<nltk.wordnet.dictionary.Dictionary instance for adv>, 'R', 'adv')]

implemented_rel_names

Value:
['antonym',
 'attribute',
 'cause',
 'derivationally related form',
 'direct hypernym',
 'direct hyponym',
 'direct troponym',
 'domain category',
...

rel_order

Value:
[('hyponym', 'direct hyponym/full hyponym'),
 ('hyponym', 'direct troponym/full troponym'),
 ('class region', 'domain term region'),
 ('part holonym', 'part meronym'),
 ('attribute', 'attribute'),
 ('substance holonym', 'substance meronym'),
 ('substance meronym', 'substance holonym'),
 ('member meronym', 'member holonym'),
...

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>
'''