framenet_tools.utils package¶
Submodules¶
framenet_tools.utils.postagger module¶
-
class
framenet_tools.utils.postagger.PosTagger(use_spacy: bool)¶ Bases:
objectPosTagger provides options for assigning POS-tags to sentences.
Either by spacy or nltk.
Returns the POS-tags of a given sentence.
Parameters: sentence – The sentence, given as a list of words Returns: A list of POS-tags
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
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¶
-
framenet_tools.utils.static_utils.download(url: 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 Returns:
-
framenet_tools.utils.static_utils.download_file(url: str, file_path: str)¶ Downloads a file and saves at a given path
Parameters: - url – The URL of the file to download
- file_path – The destination of the file
Returns:
-
framenet_tools.utils.static_utils.download_frame_embeddings()¶ Checks if the needed frame embeddings are already downloaded, if not they are downloaded.
Returns:
-
framenet_tools.utils.static_utils.download_resources()¶ Checks if the required resources from nltk are installed, if not they are downloaded.
Returns:
-
framenet_tools.utils.static_utils.extract7z(path: str)¶ Extracts 7z Archive
Parameters: path – The path of the archive Returns:
-
framenet_tools.utils.static_utils.extract_file(file_path: str)¶ Extracts a zipped file
Parameters: file_path – The file to extract Returns:
-
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.
Parameters: - raw – A raw string of text
- use_spacy – True to use spacy, otherwise nltk
Returns: 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
-
framenet_tools.utils.static_utils.get_spacy_en_model()¶ 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: https://public.ukp.informatik.tu-darmstadt.de/repl4nlp17-frameEmbeddings/reader.py
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: https://public.ukp.informatik.tu-darmstadt.de/repl4nlp17-frameEmbeddings/reader.py
Parameters: - str_path_file – The path of the dict to save to
- dict_to_print – The dict to save
Returns:
-
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