nltk.corpus.reader.framenet module

Corpus reader for the FrameNet 1.7 lexicon and corpus.

class nltk.corpus.reader.framenet.AttrDict[source]

Bases: dict

A class that wraps a dict and allows accessing the keys of the dict as if they were attributes. Taken from here: https://stackoverflow.com/a/14620633/8879

>>> foo = {'a':1, 'b':2, 'c':3}
>>> bar = AttrDict(foo)
>>> pprint(dict(bar))
{'a': 1, 'b': 2, 'c': 3}
>>> bar.b
2
>>> bar.d = 4
>>> pprint(dict(bar))
{'a': 1, 'b': 2, 'c': 3, 'd': 4}
__init__(*args, **kwargs)[source]
class nltk.corpus.reader.framenet.FramenetCorpusReader[source]

Bases: XMLCorpusReader

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
__init__(root, fileids)[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 is file_id. If file_id is not in encoding, 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 is file_id will be the encoding value for the first tuple whose regexp matches the file_id. If no tuple’s regexp matches the file_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.

annotations(luNamePattern=None, exemplars=True, full_text=True)[source]

Frame annotation sets matching the specified criteria.

buildindexes()[source]

Build the internal indexes to make look-ups faster.

doc(fn_docid)[source]

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)

Parameters

fn_docid (int) – The Framenet id number of the document

Returns

Information about the annotated document

Return type

dict

docs(name=None)[source]

Return a list of the annotated full-text documents in FrameNet, optionally filtered by a regex to be matched against the document name.

docs_metadata(name=None)[source]

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
Parameters

name (str) – 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”.

Returns

A list of selected (or all) annotated documents

Return type

list of dicts, where each dict object contains the following keys:

  • ’name’

  • ’ID’

  • ’corpid’

  • ’corpname’

  • ’description’

  • ’filename’

exemplars(luNamePattern=None, frame=None, fe=None, fe2=None)[source]

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).

fe_relations()[source]

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>}
Returns

A list of all of the frame element relations in framenet

Return type

list(dict)

fes(name=None, frame=None)[source]

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
Parameters

name (str) – 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.

Returns

A list of matching frame elements

Return type

list(AttrDict)

frame(fn_fid_or_fname, ignorekeys=[])[source]

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

Parameters
  • fn_fid_or_fname (int or str) – The Framenet name or id number of the frame

  • ignorekeys (list(str)) – The keys to ignore. These keys will not be included in the output. (optional)

Returns

Information about a frame

Return type

dict

frame_by_id(fn_fid, ignorekeys=[])[source]

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 medical specialties and is closely related to the
Medical_professionals frame.  The FE Type characterizing a sub-are in a Specialty may also be
expressed. 'Ralph practices paediatric oncology.'"
Parameters
  • fn_fid (int) – The Framenet id number of the frame

  • ignorekeys (list(str)) – The keys to ignore. These keys will not be included in the output. (optional)

Returns

Information about a frame

Return type

dict

Also see the frame() function for details about what is contained in the dict that is returned.

frame_by_name(fn_fname, ignorekeys=[], check_cache=True)[source]

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 medical specialties and is closely related to the
  Medical_professionals frame.  The FE Type characterizing a sub-are in a Specialty may also be
  expressed. 'Ralph practices paediatric oncology.'"
Parameters
  • fn_fname (str) – The name of the frame

  • ignorekeys (list(str)) – The keys to ignore. These keys will not be included in the output. (optional)

Returns

Information about a frame

Return type

dict

Also see the frame() function for details about what is contained in the dict that is returned.

frame_ids_and_names(name=None)[source]

Uses the frame index, which is much faster than looking up each frame definition if only the names and IDs are needed.

frame_relation_types()[source]

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

A list of all of the frame relation types in framenet

Return type

list(dict)

frame_relations(frame=None, frame2=None, type=None)[source]
Parameters
  • frame (int or str or AttrDict) – (optional) frame object, name, or ID; only relations involving this frame will be returned

  • frame2 – (optional; ‘frame’ must be a different frame) only show relations between the two specified frames, in either direction

  • type – (optional) frame relation type (name or object); show only relations of this type

Returns

A list of all of the frame relations in framenet

Return type

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>]
frames(name=None)[source]

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.

Parameters

name (str) – A regular expression pattern used to match against Frame names. If ‘name’ is None, then a list of all Framenet Frames will be returned.

Returns

A list of matching Frames (or all Frames).

Return type

list(AttrDict)

frames_by_lemma(pat)[source]

Returns a list of all frames that contain LUs in which the name attribute of the LU matches 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'))) 
[<frame ID=189 name=Quanti...>, <frame ID=2001 name=Degree>]
Returns

A list of frame objects.

Return type

list(AttrDict)

ft_sents(docNamePattern=None)[source]

Full-text annotation sentences, optionally filtered by document name.

help(attrname=None)[source]

Display help information summarizing the main methods.

lu(fn_luid, ignorekeys=[], luName=None, frameID=None, frameName=None)[source]

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

[LU] (227) guess.v in Coming_to_believe

[frame] (23) Coming_to_believe

[annotationSet] 2 annotation sets

[POS] 18 tags

[POS_tagset] BNC

[GF] 3 relations

[PT] 3 phrases

[Other] 1 entry

[text] + [Target] + [FE]

When he was inside the house , Culley noticed the characteristic
                                              ------------------
                                              Content

he would n't have guessed at .
--                ******* --
Co                        C1 [Evidence:INI]
 (Co=Cognizer, C1=Content)

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.

Parameters
  • fn_luid (int) – The id number of the lexical unit

  • ignorekeys (list(str)) – The keys to ignore. These keys will not be included in the output. (optional)

Returns

All information about the lexical unit

Return type

dict

lu_basic(fn_luid)[source]

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 
{'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'}
Parameters

fn_luid (int) – The id number of the desired LU

Returns

Basic information about the lexical unit

Return type

dict

lu_ids_and_names(name=None)[source]

Uses the LU index, which is much faster than looking up each LU definition if only the names and IDs are needed.

lus(name=None, frame=None)[source]

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.

Parameters

name (str) –

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

Returns

A list of selected (or all) lexical units

Return type

list of LU objects (dicts). See the lu() function for info about the specifics of LU objects.

propagate_semtypes()[source]

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
semtype(key)[source]
>>> from nltk.corpus import framenet as fn
>>> fn.semtype(233).name
'Temperature'
>>> fn.semtype(233).abbrev
'Temp'
>>> fn.semtype('Temperature').ID
233
Parameters

key (string or int) – The name, abbreviation, or id number of the semantic type

Returns

Information about a semantic type

Return type

dict

semtype_inherits(st, superST)[source]
semtypes()[source]

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

A list of all of the semantic types in framenet

Return type

list(dict)

sents(exemplars=True, full_text=True)[source]

Annotated sentences matching the specified criteria.

warnings(v)[source]

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.)

exception nltk.corpus.reader.framenet.FramenetError[source]

Bases: Exception

An exception class for framenet-related errors.

class nltk.corpus.reader.framenet.Future[source]

Bases: object

Wraps and acts as a proxy for a value to be loaded lazily (on demand). Adapted from https://gist.github.com/sergey-miryanov/2935416

__init__(loader, *args, **kwargs)[source]
Parameters

loader (callable) – when called with no arguments, returns the value to be stored

class nltk.corpus.reader.framenet.PrettyDict[source]

Bases: AttrDict

Displays an abbreviated repr of values where possible. Inherits from AttrDict, so a callable value will be lazily converted to an actual value.

__init__(*args, **kwargs)[source]
class nltk.corpus.reader.framenet.PrettyLazyConcatenation[source]

Bases: LazyConcatenation

Displays an abbreviated repr of only the first several elements, not the whole list.

class nltk.corpus.reader.framenet.PrettyLazyIteratorList[source]

Bases: LazyIteratorList

Displays an abbreviated repr of only the first several elements, not the whole list.

class nltk.corpus.reader.framenet.PrettyLazyMap[source]

Bases: LazyMap

Displays an abbreviated repr of only the first several elements, not the whole list.

class nltk.corpus.reader.framenet.PrettyList[source]

Bases: list

Displays an abbreviated repr of only the first several elements, not the whole list.

__init__(*args, **kwargs)[source]
class nltk.corpus.reader.framenet.SpecialList[source]

Bases: list

A list subclass which adds a ‘_type’ attribute for special printing (similar to an AttrDict, though this is NOT an AttrDict subclass).

__init__(typ, *args, **kwargs)[source]
nltk.corpus.reader.framenet.demo()[source]
nltk.corpus.reader.framenet.mimic_wrap(lines, wrap_at=65, **kwargs)[source]

Wrap the first of ‘lines’ with textwrap and the remaining lines at exactly the same positions as the first.