synonym
index
/home/max/LRApy/synonym.py

Project: LRApy
Author: Max Jakob (max.jakob@web.de)
Module: synonym
Module Description: This module contains functions and a parser to get
synonyms from an online similarity thesaurus. In LRApy this is used to
search for alternate word pairs.
 
Version: 1.0
Last change: 2007-02-05
 
Copyright 2007 by Max Jakob.
This code is released under the GNU GPL. See the accompanying LICENSE file.
 
Embedded documentation can be translated with the Python pydoc module.

 
Modules
       
HTMLParser
re
urllib

 
Classes
       
HTMLParser.HTMLParser(markupbase.ParserBase)
DependencyBasedSimilarityHTMLParser

 
class DependencyBasedSimilarityHTMLParser(HTMLParser.HTMLParser)
    (SAX-like) HTML-Parser for synonym pages from
http://www.cs.ualberta.ca/~lindek/demos/depsim.htm
 
Synonyms are inside <font></font> tags. After these tags, the similarity
scores occurr for that synonym. The rest of the data is ignored.
The parser is independent of the input word and merges all POS's.
The method getWholeSynonymList() returns synonyms decreasing in similarity
score.
 
Usage:
        p = DependencyBasedSimilarityHTMLParser()
        p.feed(htmlCode)
        p.close()
        synList = p.getCompleteSynonymList()
 
 
Method resolution order:
DependencyBasedSimilarityHTMLParser
HTMLParser.HTMLParser
markupbase.ParserBase

Methods defined here:
__init__(self)
getCompleteSynonymList(self)
Returns a list of synonyms, decreasing in similarity to the
word whoms HTML-code was fed. Multible POS's are merged.
handle_data(self, data)
handle_starttag(self, tag, attrs)
isProperWord(self, word)
Returns False if <word>
 - is shorter than 4 letters
 - contains non-alphabetical characters
 - contains capitalized letters
 - contains a hyphen
 - contains whitespace (multi-word phrases)
 - consists of just whitespace
and returns True otherwise.

Methods inherited from HTMLParser.HTMLParser:
check_for_whole_start_tag(self, i)
# Internal -- check to see if we have a complete starttag; return end
# or -1 if incomplete.
clear_cdata_mode(self)
close(self)
Handle any buffered data.
error(self, message)
feed(self, data)
Feed data to the parser.
 
        Call this as often as you want, with as little or as much text
        as you want (may include '
').
get_starttag_text(self)
Return full source of start tag: '<...>'.
goahead(self, end)
# Internal -- handle data as far as reasonable.  May leave state
# and data to be processed by a subsequent call.  If 'end' is
# true, force handling all data as if followed by EOF marker.
handle_charref(self, name)
# Overridable -- handle character reference
handle_comment(self, data)
# Overridable -- handle comment
handle_decl(self, decl)
# Overridable -- handle declaration
handle_endtag(self, tag)
# Overridable -- handle end tag
handle_entityref(self, name)
# Overridable -- handle entity reference
handle_pi(self, data)
# Overridable -- handle processing instruction
handle_startendtag(self, tag, attrs)
# Overridable -- finish processing of start+end tag: <tag.../>
parse_endtag(self, i)
# Internal -- parse endtag, return end or -1 if incomplete
parse_pi(self, i)
# Internal -- parse processing instr, return end or -1 if not terminated
parse_starttag(self, i)
# Internal -- handle starttag, return end or -1 if not terminated
reset(self)
Reset this instance.  Loses all unprocessed data.
set_cdata_mode(self)
unescape(self, s)
# Internal -- helper to remove special character quoting
unknown_decl(self, data)

Data and other attributes inherited from HTMLParser.HTMLParser:
CDATA_CONTENT_ELEMENTS = ('script', 'style')

Methods inherited from markupbase.ParserBase:
getpos(self)
Return current line number and offset.
parse_comment(self, i, report=1)
# Internal -- parse comment, return length or -1 if not terminated
parse_declaration(self, i)
# Internal -- parse declaration (for use by subclasses).
parse_marked_section(self, i, report=1)
# Internal -- parse a marked section
# Override this to handle MS-word extension syntax <![if word]>content<![endif]>
updatepos(self, i, j)
# Internal -- update line number and offset.  This should be
# called for each piece of data exactly once, in order -- in other
# words the concatenation of all the input strings to this
# function should be exactly the entire input.

 
Functions
       
getSynonymList(word, numSim=10)
Returns a list of the top <numSim> synonyms to <word>, using the
Dependency-based Word Similarity online-demo. Multible POS's are
merged.
test()