framenet_tools.utils package


framenet_tools.utils.postagger module

class framenet_tools.utils.postagger.PosTagger(use_spacy: bool)

Bases: object

PosTagger provides options for assigning POS-tags to sentences.

Either by spacy or nltk.

get_tags(sentence: List[str])

Returns the POS-tags of a given sentence.

Parameters:sentence – The sentence, given as a list of words
Returns:A list of POS-tags
get_tags_nltk(tokens: List[str])

Gets lemma, pos and NE for each token

Parameters:tokens – A list of tokens from a sentence
Returns:A 2d-Array containing lemma, pos and NE for each token
get_tags_spacy(tokens: List[str])

The spacy version of the get_tags method

:param tokens:The sentence, given as a list of words :return: A list of POS-tags

framenet_tools.utils.postagger.get_pos_constants(tag: str)

Static function for tag conversion

Parameters:tag – The given pos tag
Returns:The corresponding letter

framenet_tools.utils.static_utils module str)

Downloads and extracts a file given as a url.

NOTE: The paths should NOT be changed in order for pyfn to work NOTE: Only extracts 7z files

Parameters:url – The url from where to get the file
framenet_tools.utils.static_utils.download_file(url: str, file_path: str)

Downloads a file and saves at a given path

  • url – The URL of the file to download
  • file_path – The destination of the file


Checks if the needed frame embeddings are already downloaded, if not they are downloaded.


Checks if the required resources from nltk are installed, if not they are downloaded.

framenet_tools.utils.static_utils.extract7z(path: str)

Extracts 7z Archive

Parameters:path – The path of the archive
framenet_tools.utils.static_utils.extract_file(file_path: str)

Extracts a zipped file

Parameters:file_path – The file to extract
framenet_tools.utils.static_utils.get_sentences(raw: str, use_spacy: bool = False)

Parses a raw string of text into structured sentences. This is either done via nltk or spacy; default being nltk.

  • raw – A raw string of text
  • use_spacy – True to use spacy, otherwise nltk

A list of sentences, consisting of tokens

framenet_tools.utils.static_utils.get_sentences_nltk(raw: str)

The nltk version of the get_sentences method.

Parameters:raw – A raw string of text
Returns:A list of sentences, consisting of tokens
framenet_tools.utils.static_utils.get_sentences_spacy(raw: str)

The spacy version of the get_sentences method.

Parameters:raw – A raw string of text
Returns:A list of sentences, consisting of tokens

Installs the required en_core_web_sm model

NOTE: Solution for Windows? TODO :return:

framenet_tools.utils.static_utils.load_pkl_from_path(str_path_file: str)

Taken from:

Parameters:str_path_file – The path of the pickle file to load the dict from
Returns:The loaded dict
framenet_tools.utils.static_utils.pos_to_int(pos: str)

Converts a pos tag to an integer according to the static dictionary.

Parameters:pos – The pos tag
Returns:The index of the pos tag
framenet_tools.utils.static_utils.print_dict_to_txt(str_path_file: str, dict_to_print: dict)

Taken from:

  • str_path_file – The path of the dict to save to
  • dict_to_print – The dict to save

framenet_tools.utils.static_utils.shuffle_concurrent_lists(l: List[List[object]])

Shuffles multiple concurrent lists so that pairs of (x, y) from different lists are still at the same index.

Parameters:l – A list of concurrent lists
Returns:The list of shuffled concurrent lists

Module contents