nltk.corpus.reader.VerbnetCorpusReader¶
- class nltk.corpus.reader.VerbnetCorpusReader[source]¶
Bases:
XMLCorpusReader
An NLTK interface to the VerbNet verb lexicon.
From the VerbNet site: “VerbNet (VN) (Kipper-Schuler 2006) is the largest on-line verb lexicon currently available for English. It is a hierarchical domain-independent, broad-coverage verb lexicon with mappings to other lexical resources such as WordNet (Miller, 1990; Fellbaum, 1998), XTAG (XTAG Research Group, 2001), and FrameNet (Baker et al., 1998).”
For details about VerbNet see: https://verbs.colorado.edu/~mpalmer/projects/verbnet.html
- __init__(root, fileids, wrap_etree=False)[source]¶
- Parameters
root (PathPointer or str) – A path pointer identifying the root directory for this corpus. If a string is specified, then it will be converted to a
PathPointer
automatically.fileids – A list of the files that make up this corpus. This list can either be specified explicitly, as a list of strings; or implicitly, as a regular expression over file paths. The absolute path for each file will be constructed by joining the reader’s root to each file name.
encoding –
The default unicode encoding for the files that make up the corpus. The value of
encoding
can be any of the following:A string:
encoding
is the encoding name for all files.A dictionary:
encoding[file_id]
is the encoding name for the file whose identifier isfile_id
. Iffile_id
is not inencoding
, then the file contents will be processed using non-unicode byte strings.A list:
encoding
should be a list of(regexp, encoding)
tuples. The encoding for a file whose identifier isfile_id
will be theencoding
value for the first tuple whoseregexp
matches thefile_id
. If no tuple’sregexp
matches thefile_id
, the file contents will be processed using non-unicode byte strings.None: the file contents of all files will be processed using non-unicode byte strings.
tagset – The name of the tagset used by this corpus, to be used for normalizing or converting the POS tags returned by the
tagged_...()
methods.
- lemmas(vnclass=None)[source]¶
Return a list of all verb lemmas that appear in any class, or in the
classid
if specified.
- wordnetids(vnclass=None)[source]¶
Return a list of all wordnet identifiers that appear in any class, or in
classid
if specified.
- classids(lemma=None, wordnetid=None, fileid=None, classid=None)[source]¶
Return a list of the VerbNet class identifiers. If a file identifier is specified, then return only the VerbNet class identifiers for classes (and subclasses) defined by that file. If a lemma is specified, then return only VerbNet class identifiers for classes that contain that lemma as a member. If a wordnetid is specified, then return only identifiers for classes that contain that wordnetid as a member. If a classid is specified, then return only identifiers for subclasses of the specified VerbNet class. If nothing is specified, return all classids within VerbNet
- vnclass(fileid_or_classid)[source]¶
Returns VerbNet class ElementTree
Return an ElementTree containing the xml for the specified VerbNet class.
- Parameters
fileid_or_classid – An identifier specifying which class should be returned. Can be a file identifier (such as
'put-9.1.xml'
), or a VerbNet class identifier (such as'put-9.1'
) or a short VerbNet class identifier (such as'9.1'
).
- fileids(vnclass_ids=None)[source]¶
Return a list of fileids that make up this corpus. If
vnclass_ids
is specified, then return the fileids that make up the specified VerbNet class(es).
- frames(vnclass)[source]¶
Given a VerbNet class, this method returns VerbNet frames
The members returned are: 1) Example 2) Description 3) Syntax 4) Semantics
- Parameters
vnclass – A VerbNet class identifier; or an ElementTree containing the xml contents of a VerbNet class.
- Returns
frames - a list of frame dictionaries
- subclasses(vnclass)[source]¶
Returns subclass ids, if any exist
Given a VerbNet class, this method returns subclass ids (if they exist) in a list of strings.
- Parameters
vnclass – A VerbNet class identifier; or an ElementTree containing the xml contents of a VerbNet class.
- Returns
list of subclasses
- themroles(vnclass)[source]¶
Returns thematic roles participating in a VerbNet class
Members returned as part of roles are- 1) Type 2) Modifiers
- Parameters
vnclass – A VerbNet class identifier; or an ElementTree containing the xml contents of a VerbNet class.
- Returns
themroles: A list of thematic roles in the VerbNet class
- longid(shortid)[source]¶
Returns longid of a VerbNet class
Given a short VerbNet class identifier (eg ‘37.10’), map it to a long id (eg ‘confess-37.10’). If
shortid
is already a long id, then return it as-is
- shortid(longid)[source]¶
Returns shortid of a VerbNet class
Given a long VerbNet class identifier (eg ‘confess-37.10’), map it to a short id (eg ‘37.10’). If
longid
is already a short id, then return it as-is.
- pprint(vnclass)[source]¶
Returns pretty printed version of a VerbNet class
Return a string containing a pretty-printed representation of the given VerbNet class.
- Parameters
vnclass – A VerbNet class identifier; or an ElementTree containing the xml contents of a VerbNet class.
- pprint_subclasses(vnclass, indent='')[source]¶
Returns pretty printed version of subclasses of VerbNet class
Return a string containing a pretty-printed representation of the given VerbNet class’s subclasses.
- Parameters
vnclass – A VerbNet class identifier; or an ElementTree containing the xml contents of a VerbNet class.
- pprint_members(vnclass, indent='')[source]¶
Returns pretty printed version of members in a VerbNet class
Return a string containing a pretty-printed representation of the given VerbNet class’s member verbs.
- Parameters
vnclass – A VerbNet class identifier; or an ElementTree containing the xml contents of a VerbNet class.
- pprint_themroles(vnclass, indent='')[source]¶
Returns pretty printed version of thematic roles in a VerbNet class
Return a string containing a pretty-printed representation of the given VerbNet class’s thematic roles.
- Parameters
vnclass – A VerbNet class identifier; or an ElementTree containing the xml contents of a VerbNet class.
- 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.
- pprint_frames(vnclass, indent='')[source]¶
Returns pretty version of all frames in a VerbNet class
Return a string containing a pretty-printed representation of the list of frames within the VerbNet class.
- Parameters
vnclass – A VerbNet class identifier; or an ElementTree containing the xml contents of a VerbNet class.
- 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
- words(fileid=None)[source]¶
Returns all of the words and punctuation symbols in the specified file that were in text nodes – ie, tags are ignored. Like the xml() method, fileid can only specify one file.
- Returns
the given file’s text nodes as a list of words and punctuation symbols
- Return type
list(str)