class FramenetCorpusReader(XMLCorpusReader): (source)
Constructor: FramenetCorpusReader(root, fileids)
A corpus reader for the Framenet Corpus.
>>> from nltk.corpus import framenet as fn >>> fn.lu(3238).frame.lexUnit['glint.v'] is fn.lu(3238) True >>> fn.frame_by_name('Replacing') is fn.lus('replace.v')[0].frame True >>> fn.lus('prejudice.n')[0].frame.frameRelations == fn.frame_relations('Partiality') True
Method | __init__ |
No summary |
Method | annotations |
Frame annotation sets matching the specified criteria. |
Method | buildindexes |
Build the internal indexes to make look-ups faster. |
Method | doc |
Returns the annotated document whose id number is ``fn_docid``. This id number can be obtained by calling the Documents() function. |
Method | docs |
Return a list of the annotated full-text documents in FrameNet, optionally filtered by a regex to be matched against the document name. |
Method | docs |
Return an index of the annotated documents in Framenet. |
Method | exemplars |
Lexicographic exemplar sentences, optionally filtered by LU name and/or 1-2 FEs that are realized overtly. 'frame' may be a name pattern, frame ID, or frame instance. 'fe' may be a name pattern or FE instance; if specified, 'fe2' may also be specified to retrieve sentences with both overt FEs (in either order). |
Method | fe |
Obtain a list of frame element relations. |
Method | fes |
Lists frame element objects. If 'name' is provided, this is treated as a case-insensitive regular expression to filter by frame name. (Case-insensitivity is because casing of frame element names is not always consistent across frames... |
Method | frame |
Get the details for the specified Frame using the frame's name or id number. |
Method | frame |
Get the details for the specified Frame using the frame's id number. |
Method | frame |
Get the details for the specified Frame using the frame's name. |
Method | frame |
Uses the frame index, which is much faster than looking up each frame definition if only the names and IDs are needed. |
Method | frame |
Obtain a list of frame relation types. |
Method | frame |
:param frame: (optional) frame object, name, or ID; only relations involving this frame will be returned :param frame2: (optional; 'frame' must be a different frame) only show relations between the two specified frames, in either direction :param type: (optional) frame relation type (name or object); show only relations of this type :type frame: int or str or AttrDict :return: A list of all of the frame relations in framenet :rtype: list(dict)... |
Method | frames |
Obtain details for a specific frame. |
Method | frames |
Returns a list of all frames that contain LUs in which the ``name`` attribute of the LU matchs the given regular expression ``pat``. Note that LU names are composed of "lemma.POS", where the "lemma" part can be made up of either a single lexeme (e... |
Method | ft |
Full-text annotation sentences, optionally filtered by document name. |
Method | help |
Display help information summarizing the main methods. |
Method | lu |
Access a lexical unit by its ID. luName, frameID, and frameName are used only in the event that the LU does not have a file in the database (which is the case for LUs with "Problem" status); in this case, a placeholder LU is created which just contains its name, ID, and frame. |
Method | lu |
Returns basic information about the LU whose id is ``fn_luid``. This is basically just a wrapper around the ``lu()`` function with "subCorpus" info excluded. |
Method | lu |
Uses the LU index, which is much faster than looking up each LU definition if only the names and IDs are needed. |
Method | lus |
Obtain details for lexical units. Optionally restrict by lexical unit name pattern, and/or to a certain frame or frames whose name matches a pattern. |
Method | propagate |
Apply inference rules to distribute semtypes over relations between FEs. For FrameNet 1.5, this results in 1011 semtypes being propagated. (Not done by default because it requires loading all frame files, which takes several seconds... |
Method | readme |
Return the contents of the corpus README.txt (or README) file. |
Method | semtype |
:param key: The name, abbreviation, or id number of the semantic type :type key: string or int :return: Information about a semantic type :rtype: dict |
Method | semtype |
Undocumented |
Method | semtypes |
Obtain a list of semantic types. |
Method | sents |
Annotated sentences matching the specified criteria. |
Method | warnings |
Enable or disable warnings of data integrity issues as they are encountered. If v is truthy, warnings will be enabled. |
Method | _buildcorpusindex |
Undocumented |
Method | _buildframeindex |
Undocumented |
Method | _buildluindex |
Undocumented |
Method | _buildrelationindex |
Undocumented |
Method | _exemplar |
Given an exemplar sentence and a set of FE names, return the subset of FE names that are realized overtly in the sentence on the FE, FE2, or FE3 layer. |
Method | _handle |
Extracts and returns the attributes of the given element |
Method | _handle |
Undocumented |
Method | _handle |
Load fe coreset info from xml. |
Method | _handle |
Load the info for a Frame from a frame xml file |
Method | _handle |
Load the lexical unit info from an xml element in a frame's xml file. |
Method | _handle |
Load frame-relation element and its child fe-relation elements from frRelation.xml. |
Method | _handle |
Load frame-relation element and its child fe-relation elements from frRelation.xml. |
Method | _handle |
Load information from the given 'sentence' element. Each 'sentence' element contains a "text" and "annotationSet" sub elements. |
Method | _handle |
Load full annotation info for a document from its xml file. The main element (fullTextAnnotation) contains a 'header' element (which we ignore here) and a bunch of 'sentence' elements. |
Method | _handle |
Load information from the given 'annotationSet' element. Each 'annotationSet' contains several "layer" elements. |
Method | _handle |
Extracts corpus/document info from the fulltextIndex.xml file. |
Method | _handle |
Load information from the given 'layer' element. Each 'layer' contains several "label" elements. |
Method | _handle |
Load full info for a lexical unit from its xml file. This should only be called when accessing corpus annotations (which are not included in frame files). |
Method | _handle |
Load an annotation set from a sentence in an subcorpus of an LU |
Method | _handle |
Load a layer from an annotation set |
Method | _handle |
Load a sentence from a subcorpus of an LU from xml. |
Method | _handle |
Load a subcorpus of a lexical unit from the given xml. |
Method | _handle |
Undocumented |
Method | _load |
Extracts a subset of the attributes from the given element and returns them in a dictionary. |
Method | _loadsemtypes |
Create the semantic types index. |
Method | _lu |
Augment the LU information that was loaded from the frame file with additional information from the LU file. |
Method | _strip |
Gets rid of all tags and newline characters from the given input |
Method | _warn |
Undocumented |
Class Variable | _bad |
When loading LUs for a frame, those whose status is in this list will be ignored. Due to caching, if user code modifies this, it should do so before loading any data. 'Problem' should always be listed for FrameNet 1... |
Instance Variable | _cached |
Undocumented |
Instance Variable | _ferel |
Undocumented |
Instance Variable | _fnweb |
Undocumented |
Instance Variable | _frame |
Undocumented |
Instance Variable | _frame |
Undocumented |
Instance Variable | _frel |
Undocumented |
Instance Variable | _frel |
Undocumented |
Instance Variable | _freltyp |
Undocumented |
Instance Variable | _fulltext |
Undocumented |
Instance Variable | _fulltext |
Undocumented |
Instance Variable | _lu |
Undocumented |
Instance Variable | _lu |
Undocumented |
Instance Variable | _semtypes |
Undocumented |
Instance Variable | _warnings |
Undocumented |
Inherited from XMLCorpusReader
:
Method | raw |
Undocumented |
Method | words |
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. |
Method | xml |
Undocumented |
Instance Variable | _wrap |
Undocumented |
Inherited from CorpusReader
(via XMLCorpusReader
):
Method | __repr__ |
Undocumented |
Method | abspath |
Return the absolute path for the given file. |
Method | abspaths |
Return a list of the absolute paths for all fileids in this corpus; or for the given list of fileids, if specified. |
Method | citation |
Return the contents of the corpus citation.bib file, if it exists. |
Method | encoding |
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. |
Method | ensure |
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). |
Method | fileids |
Return a list of file identifiers for the fileids that make up this corpus. |
Method | license |
Return the contents of the corpus LICENSE file, if it exists. |
Method | open |
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. |
Class Variable | root |
Undocumented |
Method | _get |
Undocumented |
Instance Variable | _encoding |
The default unicode encoding for the fileids that make up this corpus. If encoding is None, then the file contents are processed using byte strings. |
Instance Variable | _fileids |
A list of the relative paths for the fileids that make up this corpus. |
Instance Variable | _root |
The root directory for this corpus. |
Instance Variable | _tagset |
Undocumented |
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 is file_id. If file_id is not in encoding, then the file contents 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. |
Returns the annotated document whose id number is ``fn_docid``. This id number can be obtained by calling the Documents() function. The dict that is returned from this function will contain the following keys: - '_type' : 'fulltextannotation' - 'sentence' : a list of sentences in the document - Each item in the list is a dict containing the following keys: - 'ID' : the ID number of the sentence - '_type' : 'sentence' - 'text' : the text of the sentence - 'paragNo' : the paragraph number - 'sentNo' : the sentence number - 'docID' : the document ID number - 'corpID' : the corpus ID number - 'aPos' : the annotation position - 'annotationSet' : a list of annotation layers for the sentence - Each item in the list is a dict containing the following keys: - 'ID' : the ID number of the annotation set - '_type' : 'annotationset' - 'status' : either 'MANUAL' or 'UNANN' - 'luName' : (only if status is 'MANUAL') - 'luID' : (only if status is 'MANUAL') - 'frameID' : (only if status is 'MANUAL') - 'frameName': (only if status is 'MANUAL') - 'layer' : a list of labels for the layer - Each item in the layer is a dict containing the following keys: - '_type': 'layer' - 'rank' - 'name' - 'label' : a list of labels in the layer - Each item is a dict containing the following keys: - 'start' - 'end' - 'name' - 'feID' (optional) :param fn_docid: The Framenet id number of the document :type fn_docid: int :return: Information about the annotated document :rtype: dict
Return a list of the annotated full-text documents in FrameNet, optionally filtered by a regex to be matched against the document name.
Return an index of the annotated documents in Framenet. Details for a specific annotated document can be obtained using this class's doc() function and pass it the value of the 'ID' field. >>> from nltk.corpus import framenet as fn >>> len(fn.docs()) in (78, 107) # FN 1.5 and 1.7, resp. True >>> set([x.corpname for x in fn.docs_metadata()])>=set(['ANC', 'KBEval', 'LUCorpus-v0.3', 'Miscellaneous', 'NTI', 'PropBank']) True :param name: A regular expression pattern used to search the file name of each annotated document. The document's file name contains the name of the corpus that the document is from, followed by two underscores "__" followed by the document name. So, for example, the file name "LUCorpus-v0.3__20000410_nyt-NEW.xml" is from the corpus named "LUCorpus-v0.3" and the document name is "20000410_nyt-NEW.xml". :type name: str :return: A list of selected (or all) annotated documents :rtype: list of dicts, where each dict object contains the following keys: - 'name' - 'ID' - 'corpid' - 'corpname' - 'description' - 'filename'
Lexicographic exemplar sentences, optionally filtered by LU name and/or 1-2 FEs that are realized overtly. 'frame' may be a name pattern, frame ID, or frame instance. 'fe' may be a name pattern or FE instance; if specified, 'fe2' may also be specified to retrieve sentences with both overt FEs (in either order).
Obtain a list of frame element relations.
>>> from nltk.corpus import framenet as fn >>> ferels = fn.fe_relations() >>> isinstance(ferels, list) True >>> len(ferels) in (10020, 12393) # FN 1.5 and 1.7, resp. True >>> PrettyDict(ferels[0], breakLines=True) {'ID': 14642, '_type': 'ferelation', 'frameRelation': <Parent=Abounding_with -- Inheritance -> Child=Lively_place>, 'subFE': <fe ID=11370 name=Degree>, 'subFEName': 'Degree', 'subFrame': <frame ID=1904 name=Lively_place>, 'subID': 11370, 'supID': 2271, 'superFE': <fe ID=2271 name=Degree>, 'superFEName': 'Degree', 'superFrame': <frame ID=262 name=Abounding_with>, 'type': <framerelationtype ID=1 name=Inheritance>}
:return: A list of all of the frame element relations in framenet :rtype: list(dict)
Lists frame element objects. If 'name' is provided, this is treated as a case-insensitive regular expression to filter by frame name. (Case-insensitivity is because casing of frame element names is not always consistent across frames.) Specify 'frame' to filter by a frame name pattern, ID, or object. >>> from nltk.corpus import framenet as fn >>> fn.fes('Noise_maker') [<fe ID=6043 name=Noise_maker>] >>> sorted([(fe.frame.name,fe.name) for fe in fn.fes('sound')]) [('Cause_to_make_noise', 'Sound_maker'), ('Make_noise', 'Sound'), ('Make_noise', 'Sound_source'), ('Sound_movement', 'Location_of_sound_source'), ('Sound_movement', 'Sound'), ('Sound_movement', 'Sound_source'), ('Sounds', 'Component_sound'), ('Sounds', 'Location_of_sound_source'), ('Sounds', 'Sound_source'), ('Vocalizations', 'Location_of_sound_source'), ('Vocalizations', 'Sound_source')] >>> sorted([(fe.frame.name,fe.name) for fe in fn.fes('sound',r'(?i)make_noise')]) [('Cause_to_make_noise', 'Sound_maker'), ('Make_noise', 'Sound'), ('Make_noise', 'Sound_source')] >>> sorted(set(fe.name for fe in fn.fes('^sound'))) ['Sound', 'Sound_maker', 'Sound_source'] >>> len(fn.fes('^sound$')) 2 :param name: A regular expression pattern used to match against frame element names. If 'name' is None, then a list of all frame elements will be returned. :type name: str :return: A list of matching frame elements :rtype: list(AttrDict)
Get the details for the specified Frame using the frame's name or id number. Usage examples: >>> from nltk.corpus import framenet as fn >>> f = fn.frame(256) >>> f.name 'Medical_specialties' >>> f = fn.frame('Medical_specialties') >>> f.ID 256 >>> # ensure non-ASCII character in definition doesn't trigger an encoding error: >>> fn.frame('Imposing_obligation') frame (1494): Imposing_obligation... The dict that is returned from this function will contain the following information about the Frame: - 'name' : the name of the Frame (e.g. 'Birth', 'Apply_heat', etc.) - 'definition' : textual definition of the Frame - 'ID' : the internal ID number of the Frame - 'semTypes' : a list of semantic types for this frame - Each item in the list is a dict containing the following keys: - 'name' : can be used with the semtype() function - 'ID' : can be used with the semtype() function - 'lexUnit' : a dict containing all of the LUs for this frame. The keys in this dict are the names of the LUs and the value for each key is itself a dict containing info about the LU (see the lu() function for more info.) - 'FE' : a dict containing the Frame Elements that are part of this frame The keys in this dict are the names of the FEs (e.g. 'Body_system') and the values are dicts containing the following keys - 'definition' : The definition of the FE - 'name' : The name of the FE e.g. 'Body_system' - 'ID' : The id number - '_type' : 'fe' - 'abbrev' : Abbreviation e.g. 'bod' - 'coreType' : one of "Core", "Peripheral", or "Extra-Thematic" - 'semType' : if not None, a dict with the following two keys: - 'name' : name of the semantic type. can be used with the semtype() function - 'ID' : id number of the semantic type. can be used with the semtype() function - 'requiresFE' : if not None, a dict with the following two keys: - 'name' : the name of another FE in this frame - 'ID' : the id of the other FE in this frame - 'excludesFE' : if not None, a dict with the following two keys: - 'name' : the name of another FE in this frame - 'ID' : the id of the other FE in this frame - 'frameRelation' : a list of objects describing frame relations - 'FEcoreSets' : a list of Frame Element core sets for this frame - Each item in the list is a list of FE objects :param fn_fid_or_fname: The Framenet name or id number of the frame :type fn_fid_or_fname: int or str :param ignorekeys: The keys to ignore. These keys will not be included in the output. (optional) :type ignorekeys: list(str) :return: Information about a frame :rtype: dict
Get the details for the specified Frame using the frame's id number. Usage examples: >>> from nltk.corpus import framenet as fn >>> f = fn.frame_by_id(256) >>> f.ID 256 >>> f.name 'Medical_specialties' >>> f.definition "This frame includes words that name ..." :param fn_fid: The Framenet id number of the frame :type fn_fid: int :param ignorekeys: The keys to ignore. These keys will not be included in the output. (optional) :type ignorekeys: list(str) :return: Information about a frame :rtype: dict Also see the ``frame()`` function for details about what is contained in the dict that is returned.
Get the details for the specified Frame using the frame's name. Usage examples: >>> from nltk.corpus import framenet as fn >>> f = fn.frame_by_name('Medical_specialties') >>> f.ID 256 >>> f.name 'Medical_specialties' >>> f.definition "This frame includes words that name ..." :param fn_fname: The name of the frame :type fn_fname: str :param ignorekeys: The keys to ignore. These keys will not be included in the output. (optional) :type ignorekeys: list(str) :return: Information about a frame :rtype: dict Also see the ``frame()`` function for details about what is contained in the dict that is returned.
Uses the frame index, which is much faster than looking up each frame definition if only the names and IDs are needed.
Obtain a list of frame relation types.
>>> from nltk.corpus import framenet as fn >>> frts = sorted(fn.frame_relation_types(), key=itemgetter('ID')) >>> isinstance(frts, list) True >>> len(frts) in (9, 10) # FN 1.5 and 1.7, resp. True >>> PrettyDict(frts[0], breakLines=True) {'ID': 1, '_type': 'framerelationtype', 'frameRelations': [<Parent=Event -- Inheritance -> Child=Change_of_consistency>, <Parent=Event -- Inheritance -> Child=Rotting>, ...], 'name': 'Inheritance', 'subFrameName': 'Child', 'superFrameName': 'Parent'}
:return: A list of all of the frame relation types in framenet :rtype: list(dict)
:param frame: (optional) frame object, name, or ID; only relations involving this frame will be returned :param frame2: (optional; 'frame' must be a different frame) only show relations between the two specified frames, in either direction :param type: (optional) frame relation type (name or object); show only relations of this type :type frame: int or str or AttrDict :return: A list of all of the frame relations in framenet :rtype: list(dict)
>>> from nltk.corpus import framenet as fn >>> frels = fn.frame_relations() >>> isinstance(frels, list) True >>> len(frels) in (1676, 2070) # FN 1.5 and 1.7, resp. True >>> PrettyList(fn.frame_relations('Cooking_creation'), maxReprSize=0, breakLines=True) [<Parent=Intentionally_create -- Inheritance -> Child=Cooking_creation>, <Parent=Apply_heat -- Using -> Child=Cooking_creation>, <MainEntry=Apply_heat -- See_also -> ReferringEntry=Cooking_creation>] >>> PrettyList(fn.frame_relations(274), breakLines=True) [<Parent=Avoiding -- Inheritance -> Child=Dodging>, <Parent=Avoiding -- Inheritance -> Child=Evading>, ...] >>> PrettyList(fn.frame_relations(fn.frame('Cooking_creation')), breakLines=True) [<Parent=Intentionally_create -- Inheritance -> Child=Cooking_creation>, <Parent=Apply_heat -- Using -> Child=Cooking_creation>, ...] >>> PrettyList(fn.frame_relations('Cooking_creation', type='Inheritance')) [<Parent=Intentionally_create -- Inheritance -> Child=Cooking_creation>] >>> PrettyList(fn.frame_relations('Cooking_creation', 'Apply_heat'), breakLines=True) [<Parent=Apply_heat -- Using -> Child=Cooking_creation>, <MainEntry=Apply_heat -- See_also -> ReferringEntry=Cooking_creation>]
Obtain details for a specific frame. >>> from nltk.corpus import framenet as fn >>> len(fn.frames()) in (1019, 1221) # FN 1.5 and 1.7, resp. True >>> x = PrettyList(fn.frames(r'(?i)crim'), maxReprSize=0, breakLines=True) >>> x.sort(key=itemgetter('ID')) >>> x [<frame ID=200 name=Criminal_process>, <frame ID=500 name=Criminal_investigation>, <frame ID=692 name=Crime_scenario>, <frame ID=700 name=Committing_crime>] A brief intro to Frames (excerpted from "FrameNet II: Extended Theory and Practice" by Ruppenhofer et. al., 2010): A Frame is a script-like conceptual structure that describes a particular type of situation, object, or event along with the participants and props that are needed for that Frame. For example, the "Apply_heat" frame describes a common situation involving a Cook, some Food, and a Heating_Instrument, and is evoked by words such as bake, blanch, boil, broil, brown, simmer, steam, etc. We call the roles of a Frame "frame elements" (FEs) and the frame-evoking words are called "lexical units" (LUs). FrameNet includes relations between Frames. Several types of relations are defined, of which the most important are: - Inheritance: An IS-A relation. The child frame is a subtype of the parent frame, and each FE in the parent is bound to a corresponding FE in the child. An example is the "Revenge" frame which inherits from the "Rewards_and_punishments" frame. - Using: The child frame presupposes the parent frame as background, e.g the "Speed" frame "uses" (or presupposes) the "Motion" frame; however, not all parent FEs need to be bound to child FEs. - Subframe: The child frame is a subevent of a complex event represented by the parent, e.g. the "Criminal_process" frame has subframes of "Arrest", "Arraignment", "Trial", and "Sentencing". - Perspective_on: The child frame provides a particular perspective on an un-perspectivized parent frame. A pair of examples consists of the "Hiring" and "Get_a_job" frames, which perspectivize the "Employment_start" frame from the Employer's and the Employee's point of view, respectively. :param name: A regular expression pattern used to match against Frame names. If 'name' is None, then a list of all Framenet Frames will be returned. :type name: str :return: A list of matching Frames (or all Frames). :rtype: list(AttrDict)
Returns a list of all frames that contain LUs in which the ``name`` attribute of the LU matchs the given regular expression ``pat``. Note that LU names are composed of "lemma.POS", where the "lemma" part can be made up of either a single lexeme (e.g. 'run') or multiple lexemes (e.g. 'a little').
Note: if you are going to be doing a lot of this type of searching, you'd want to build an index that maps from lemmas to frames because each time frames_by_lemma() is called, it has to search through ALL of the frame XML files in the db.
>>> from nltk.corpus import framenet as fn >>> from nltk.corpus.reader.framenet import PrettyList >>> PrettyList(sorted(fn.frames_by_lemma(r'(?i)a little'), key=itemgetter('ID'))) # doctest: +ELLIPSIS [<frame ID=189 name=Quanti...>, <frame ID=2001 name=Degree>]
:return: A list of frame objects. :rtype: list(AttrDict)
Access a lexical unit by its ID. luName, frameID, and frameName are used only in the event that the LU does not have a file in the database (which is the case for LUs with "Problem" status); in this case, a placeholder LU is created which just contains its name, ID, and frame. Usage examples: >>> from nltk.corpus import framenet as fn >>> fn.lu(256).name 'foresee.v' >>> fn.lu(256).definition 'COD: be aware of beforehand; predict.' >>> fn.lu(256).frame.name 'Expectation' >>> pprint(list(map(PrettyDict, fn.lu(256).lexemes))) [{'POS': 'V', 'breakBefore': 'false', 'headword': 'false', 'name': 'foresee', 'order': 1}] >>> fn.lu(227).exemplars[23] exemplar sentence (352962): [sentNo] 0 [aPos] 59699508 <BLANKLINE> [LU] (227) guess.v in Coming_to_believe <BLANKLINE> [frame] (23) Coming_to_believe <BLANKLINE> [annotationSet] 2 annotation sets <BLANKLINE> [POS] 18 tags <BLANKLINE> [POS_tagset] BNC <BLANKLINE> [GF] 3 relations <BLANKLINE> [PT] 3 phrases <BLANKLINE> [Other] 1 entry <BLANKLINE> [text] + [Target] + [FE] <BLANKLINE> When he was inside the house , Culley noticed the characteristic ------------------ Content <BLANKLINE> he would n't have guessed at . -- ******* -- Co C1 [Evidence:INI] (Co=Cognizer, C1=Content) <BLANKLINE> <BLANKLINE> The dict that is returned from this function will contain most of the following information about the LU. Note that some LUs do not contain all of these pieces of information - particularly 'totalAnnotated' and 'incorporatedFE' may be missing in some LUs: - 'name' : the name of the LU (e.g. 'merger.n') - 'definition' : textual definition of the LU - 'ID' : the internal ID number of the LU - '_type' : 'lu' - 'status' : e.g. 'Created' - 'frame' : Frame that this LU belongs to - 'POS' : the part of speech of this LU (e.g. 'N') - 'totalAnnotated' : total number of examples annotated with this LU - 'incorporatedFE' : FE that incorporates this LU (e.g. 'Ailment') - 'sentenceCount' : a dict with the following two keys: - 'annotated': number of sentences annotated with this LU - 'total' : total number of sentences with this LU - 'lexemes' : a list of dicts describing the lemma of this LU. Each dict in the list contains these keys: - 'POS' : part of speech e.g. 'N' - 'name' : either single-lexeme e.g. 'merger' or multi-lexeme e.g. 'a little' - 'order': the order of the lexeme in the lemma (starting from 1) - 'headword': a boolean ('true' or 'false') - 'breakBefore': Can this lexeme be separated from the previous lexeme? Consider: "take over.v" as in: Germany took over the Netherlands in 2 days. Germany took the Netherlands over in 2 days. In this case, 'breakBefore' would be "true" for the lexeme "over". Contrast this with "take after.v" as in: Mary takes after her grandmother. *Mary takes her grandmother after. In this case, 'breakBefore' would be "false" for the lexeme "after" - 'lemmaID' : Can be used to connect lemmas in different LUs - 'semTypes' : a list of semantic type objects for this LU - 'subCorpus' : a list of subcorpora - Each item in the list is a dict containing the following keys: - 'name' : - 'sentence' : a list of sentences in the subcorpus - each item in the list is a dict with the following keys: - 'ID': - 'sentNo': - 'text': the text of the sentence - 'aPos': - 'annotationSet': a list of annotation sets - each item in the list is a dict with the following keys: - 'ID': - 'status': - 'layer': a list of layers - each layer is a dict containing the following keys: - 'name': layer name (e.g. 'BNC') - 'rank': - 'label': a list of labels for the layer - each label is a dict containing the following keys: - 'start': start pos of label in sentence 'text' (0-based) - 'end': end pos of label in sentence 'text' (0-based) - 'name': name of label (e.g. 'NN1') Under the hood, this implementation looks up the lexical unit information in the *frame* definition file. That file does not contain corpus annotations, so the LU files will be accessed on demand if those are needed. In principle, valence patterns could be loaded here too, though these are not currently supported. :param fn_luid: The id number of the lexical unit :type fn_luid: int :param ignorekeys: The keys to ignore. These keys will not be included in the output. (optional) :type ignorekeys: list(str) :return: All information about the lexical unit :rtype: dict
Returns basic information about the LU whose id is ``fn_luid``. This is basically just a wrapper around the ``lu()`` function with "subCorpus" info excluded.
>>> from nltk.corpus import framenet as fn >>> lu = PrettyDict(fn.lu_basic(256), breakLines=True) >>> # ellipses account for differences between FN 1.5 and 1.7 >>> lu # doctest: +ELLIPSIS {'ID': 256, 'POS': 'V', 'URL': 'https://framenet2.icsi.berkeley.edu/fnReports/data/lu/lu256.xml', '_type': 'lu', 'cBy': ..., 'cDate': '02/08/2001 01:27:50 PST Thu', 'definition': 'COD: be aware of beforehand; predict.', 'definitionMarkup': 'COD: be aware of beforehand; predict.', 'frame': <frame ID=26 name=Expectation>, 'lemmaID': 15082, 'lexemes': [{'POS': 'V', 'breakBefore': 'false', 'headword': 'false', 'name': 'foresee', 'order': 1}], 'name': 'foresee.v', 'semTypes': [], 'sentenceCount': {'annotated': ..., 'total': ...}, 'status': 'FN1_Sent'}
:param fn_luid: The id number of the desired LU :type fn_luid: int :return: Basic information about the lexical unit :rtype: dict
Uses the LU index, which is much faster than looking up each LU definition if only the names and IDs are needed.
Obtain details for lexical units. Optionally restrict by lexical unit name pattern, and/or to a certain frame or frames whose name matches a pattern. >>> from nltk.corpus import framenet as fn >>> len(fn.lus()) in (11829, 13572) # FN 1.5 and 1.7, resp. True >>> PrettyList(sorted(fn.lus(r'(?i)a little'), key=itemgetter('ID')), maxReprSize=0, breakLines=True) [<lu ID=14733 name=a little.n>, <lu ID=14743 name=a little.adv>, <lu ID=14744 name=a little bit.adv>] >>> PrettyList(sorted(fn.lus(r'interest', r'(?i)stimulus'), key=itemgetter('ID'))) [<lu ID=14894 name=interested.a>, <lu ID=14920 name=interesting.a>] A brief intro to Lexical Units (excerpted from "FrameNet II: Extended Theory and Practice" by Ruppenhofer et. al., 2010): A lexical unit (LU) is a pairing of a word with a meaning. For example, the "Apply_heat" Frame describes a common situation involving a Cook, some Food, and a Heating Instrument, and is _evoked_ by words such as bake, blanch, boil, broil, brown, simmer, steam, etc. These frame-evoking words are the LUs in the Apply_heat frame. Each sense of a polysemous word is a different LU. We have used the word "word" in talking about LUs. The reality is actually rather complex. When we say that the word "bake" is polysemous, we mean that the lemma "bake.v" (which has the word-forms "bake", "bakes", "baked", and "baking") is linked to three different frames: - Apply_heat: "Michelle baked the potatoes for 45 minutes." - Cooking_creation: "Michelle baked her mother a cake for her birthday." - Absorb_heat: "The potatoes have to bake for more than 30 minutes." These constitute three different LUs, with different definitions. Multiword expressions such as "given name" and hyphenated words like "shut-eye" can also be LUs. Idiomatic phrases such as "middle of nowhere" and "give the slip (to)" are also defined as LUs in the appropriate frames ("Isolated_places" and "Evading", respectively), and their internal structure is not analyzed. Framenet provides multiple annotated examples of each sense of a word (i.e. each LU). Moreover, the set of examples (approximately 20 per LU) illustrates all of the combinatorial possibilities of the lexical unit. Each LU is linked to a Frame, and hence to the other words which evoke that Frame. This makes the FrameNet database similar to a thesaurus, grouping together semantically similar words. In the simplest case, frame-evoking words are verbs such as "fried" in: "Matilde fried the catfish in a heavy iron skillet." Sometimes event nouns may evoke a Frame. For example, "reduction" evokes "Cause_change_of_scalar_position" in: "...the reduction of debt levels to $665 million from $2.6 billion." Adjectives may also evoke a Frame. For example, "asleep" may evoke the "Sleep" frame as in: "They were asleep for hours." Many common nouns, such as artifacts like "hat" or "tower", typically serve as dependents rather than clearly evoking their own frames. :param name: A regular expression pattern used to search the LU names. Note that LU names take the form of a dotted string (e.g. "run.v" or "a little.adv") in which a lemma preceeds the "." and a POS follows the dot. The lemma may be composed of a single lexeme (e.g. "run") or of multiple lexemes (e.g. "a little"). If 'name' is not given, then all LUs will be returned. The valid POSes are: v - verb n - noun a - adjective adv - adverb prep - preposition num - numbers intj - interjection art - article c - conjunction scon - subordinating conjunction :type name: str :type frame: str or int or frame :return: A list of selected (or all) lexical units :rtype: list of LU objects (dicts). See the lu() function for info about the specifics of LU objects.
Apply inference rules to distribute semtypes over relations between FEs. For FrameNet 1.5, this results in 1011 semtypes being propagated. (Not done by default because it requires loading all frame files, which takes several seconds. If this needed to be fast, it could be rewritten to traverse the neighboring relations on demand for each FE semtype.)
>>> from nltk.corpus import framenet as fn >>> x = sum(1 for f in fn.frames() for fe in f.FE.values() if fe.semType) >>> fn.propagate_semtypes() >>> y = sum(1 for f in fn.frames() for fe in f.FE.values() if fe.semType) >>> y-x > 1000 True
nltk.corpus.reader.CorpusReader.readme
Return the contents of the corpus README.txt (or README) file.
>>> from nltk.corpus import framenet as fn >>> fn.semtype(233).name 'Temperature' >>> fn.semtype(233).abbrev 'Temp' >>> fn.semtype('Temperature').ID 233
:param key: The name, abbreviation, or id number of the semantic type :type key: string or int :return: Information about a semantic type :rtype: dict
Obtain a list of semantic types.
>>> from nltk.corpus import framenet as fn >>> stypes = fn.semtypes() >>> len(stypes) in (73, 109) # FN 1.5 and 1.7, resp. True >>> sorted(stypes[0].keys()) ['ID', '_type', 'abbrev', 'definition', 'definitionMarkup', 'name', 'rootType', 'subTypes', 'superType']
:return: A list of all of the semantic types in framenet :rtype: list(dict)
Enable or disable warnings of data integrity issues as they are encountered. If v is truthy, warnings will be enabled.
(This is a function rather than just an attribute/property to ensure that if enabling warnings is the first action taken, the corpus reader is instantiated first.)
Given an exemplar sentence and a set of FE names, return the subset of FE names that are realized overtly in the sentence on the FE, FE2, or FE3 layer.
If 'fes' is None, returns all overt FE names.
Load information from the given 'sentence' element. Each 'sentence' element contains a "text" and "annotationSet" sub elements.
Load full annotation info for a document from its xml file. The main element (fullTextAnnotation) contains a 'header' element (which we ignore here) and a bunch of 'sentence' elements.
Load information from the given 'annotationSet' element. Each 'annotationSet' contains several "layer" elements.
Extracts corpus/document info from the fulltextIndex.xml file.
Note that this function "flattens" the information contained in each of the "corpus" elements, so that each "document" element will contain attributes for the corpus and corpusid. Also, each of the "document" items will contain a new attribute called "filename" that is the base file name of the xml file for the document in the "fulltext" subdir of the Framenet corpus.
Load full info for a lexical unit from its xml file. This should only be called when accessing corpus annotations (which are not included in frame files).
Extracts a subset of the attributes from the given element and returns them in a dictionary.
:param d: A dictionary in which to store the attributes. :type d: dict :param elt: An ElementTree Element :type elt: Element :return: Returns the input dict ``d`` possibly including attributes from ``elt`` :rtype: dict
Augment the LU information that was loaded from the frame file with additional information from the LU file.
Gets rid of all tags and newline characters from the given input
:return: A cleaned-up version of the input string :rtype: str