nltk.corpus.reader.LinThesaurusCorpusReader¶
- class nltk.corpus.reader.LinThesaurusCorpusReader[source]¶
Bases:
CorpusReader
Wrapper for the LISP-formatted thesauruses distributed by Dekang Lin.
- __init__(root, badscore=0.0)[source]¶
Initialize the thesaurus.
- Parameters
root (C{string}) – root directory containing thesaurus LISP files
badscore (C{float}) – the score to give to words which do not appear in each other’s sets of synonyms
- similarity(ngram1, ngram2, fileid=None)[source]¶
Returns the similarity score for two ngrams.
- Parameters
ngram1 (C{string}) – first ngram to compare
ngram2 (C{string}) – second ngram to compare
fileid (C{string}) – thesaurus fileid to search in. If None, search all fileids.
- Returns
If fileid is specified, just the score for the two ngrams; otherwise, list of tuples of fileids and scores.
- scored_synonyms(ngram, fileid=None)[source]¶
Returns a list of scored synonyms (tuples of synonyms and scores) for the current ngram
- Parameters
ngram (C{string}) – ngram to lookup
fileid (C{string}) – thesaurus fileid to search in. If None, search all fileids.
- Returns
If fileid is specified, list of tuples of scores and synonyms; otherwise, list of tuples of fileids and lists, where inner lists consist of tuples of scores and synonyms.
- synonyms(ngram, fileid=None)[source]¶
Returns a list of synonyms for the current ngram.
- Parameters
ngram (C{string}) – ngram to lookup
fileid (C{string}) – thesaurus fileid to search in. If None, search all fileids.
- Returns
If fileid is specified, list of synonyms; otherwise, list of tuples of fileids and lists, where inner lists contain synonyms.
- abspath(fileid)[source]¶
Return the absolute path for the given file.
- Parameters
fileid (str) – The file identifier for the file whose path should be returned.
- Return type
- abspaths(fileids=None, include_encoding=False, include_fileid=False)[source]¶
Return a list of the absolute paths for all fileids in this corpus; or for the given list of fileids, if specified.
- Parameters
fileids (None or str or list) – Specifies the set of fileids for which paths should be returned. Can be None, for all fileids; a list of file identifiers, for a specified set of fileids; or a single file identifier, for a single file. Note that the return value is always a list of paths, even if
fileids
is a single file identifier.include_encoding – If true, then return a list of
(path_pointer, encoding)
tuples.
- Return type
list(PathPointer)
- encoding(file)[source]¶
Return the unicode encoding for the given corpus file, if known. If the encoding is unknown, or if the given file should be processed using byte strings (str), then return None.
- ensure_loaded()[source]¶
Load this corpus (if it has not already been loaded). This is used by LazyCorpusLoader as a simple method that can be used to make sure a corpus is loaded – e.g., in case a user wants to do help(some_corpus).
- open(file)[source]¶
Return an open stream that can be used to read the given file. If the file’s encoding is not None, then the stream will automatically decode the file’s contents into unicode.
- Parameters
file – The file identifier of the file to read.
- raw(fileids=None)[source]¶
- Parameters
fileids – A list specifying the fileids that should be used.
- Returns
the given file(s) as a single string.
- Return type
str
- property root¶
The directory where this corpus is stored.
- Type