-
Notifications
You must be signed in to change notification settings - Fork 0
API docs
In this page, more detail will be provided about each of the six classes in the library along with their individual methods. For a quick start, you can head over to Get started and for examples using each of these classes, you can head over to Examples
This is the main class in the CleanTweet library, it is the class for cleaning and other preprocessing techniques for the attached text document. The class currently has three methods: clean(), show_word_collocations(), and remove_curse_words(). This class will be the home for all preprocessing techniques that involves transforming the .txt document for easier feature engineering in the Natural Language Processing (NLP) task pipeline.
parameters:
tokenize_method: if set to True, it will sentence tokenize else it will word tokenize. The default is word tokenize.
return: the word tokens as a string.
return: a list of the word collocations.
remove_curse_words(): method to remove curse words like 'fuck', 'hell', and 'damn' from the .txt document.
return: a list of appropriate words in the text/corpus.
The class housing the different methods for creating NLP diagrams/charts for easy analysis and visual inference. This class is built ontop of both NLTK and Matplotlib and acts as an easy wrapper whereby in using the previous two libraries only, you'll need 5 or sometimes ten lines of code, using this class in some instances you'll need only 1 or 2 lines of code.
word_cloud(width: int = 1400, height: int = 800, max_words: int = 100, background_color: str = 'black', *args): method to draw a wordcloud from a
parameters:
width: the width of the wordcloud, default is 1400px
height: the height of the wordcloud, default is 800px
max_words: how many words do you want to appear in the wordcloud, default is 100
background_color: the background color of the wordcloud. You can enter the colors or hex codes as a string
args: you can pass any other argument that is expected of the Wordcloud library method; as this method is a wrapper for that.
return: a wordcloud display image
frequency_distribution(amount: int = 2): method for showing the frequency distribution (amount of times a particular word occurs) in the text/document.
parameters:
amount: how many words do you want to know their frequency amount? the default is 2. The argument must be an integer and not a float
value.
return: a frequency distribution image.
parameters:
word_amount: amount of words whose frequencies you want to see; default is 2.
return: a horizontal table showing the related words and their corresponding frequencies.
bar_chart(amount_of_bars: int = 10, bar_color: str = '#a4b2e2', background_color: str = 'lightgray', xlabel_name: str = 'Word', ylabel_name: str = 'Frequency', title: str = 'Most Frequent Words', x_ticks_rotation: int = 90, grid_color: str = '#272727', grid_alpha: float = 0.1): a method for showing the bar chart with the word on the x-axis and their frequencies on the y-axis
parameters:
amount_of_bars: the amount of bars to show in the bar chart; default value is 10 and maximum is 20. It's advisable to keep it below
15 for pleasing visual results.
bar_color: the color of the bars you want. It should be a string of either html color value names, or a valid color hex code.
background_color: change the background color of the bar chart, the default value is lightgray.
xlabel_name: the name of the xlabel, must be a string. The default value is Word.
ylabel_name: the name of the ylabel, must be a string. The default value is Frequency
title: the title of the bar graph, to add a title, pass a string as an argument.
x_ticks_rotation: the angle you want the xticks to be in, default is 90 degrees.
grid_color: the grid color you want, it must be a string.
grid_alpha: how much transparency do you want, default is 0.1. it must be a floating point value. e.g. 0.1, 0.2 etc. if unsure, leave
as it is.
return: a bar chart of the most frequent words in the document.
The class containing methods for getting the different textual statistics from a corpus or .txt document.
return: a list of special characters in the text/document.
count_special_characters(): method that returns the count of special characters in the .txt document.
return: the amount of special characters in the text
return: a list of empty strings
figure_of_speech(figure_of_speech: str, amount: int): method for splitting the text into the different parts of speech
parameters:
figure_of_speech: the specific type of figure of speech e.g. Nouns, Pronouns etc.
amount: the amount of words whose pos tags you want to see
return: a dictionary of words and frequencies for the keys and values respectively
amount_of_nouns(self, amount: int, plural: bool = False): total amount of singular nouns in the text. for plural nouns, change the plural parameter to True.
parameters:
amount: the amount of nouns you want to view, you can only pass an integer
plural: do you want to use singular or plural nouns? the default is singular and it expects a boolean argument.
return: prints out the total number of nouns in the text along with their frequencies; if plural is true does same but for plural nouns.
amount_of_proper_nouns(amount: int, plural: bool = False): method for knowing the amount of proper nouns in the given text object
parameters:
plural: is it a singular or plural pronoun? The default is singular.
amount: how many pronouns do you want to see?
return: a dictionary of each pronoun and their frequency
amount_of_verbs(amount: int, tense: str = ''): get the amount of verbs in the text. the default values will return the verbs in the base form e.g. run, eat, stand etc.
parameters:
amount: the amount of verbs you want to view, you can only pass an integer
tense: this parameter expects a string and will get the verbs in other forms. Here are the allowed arguments: 'past tense', 'gerund'
or 'present participle', 'past participle', 'non-third person', 'third person' or '3rd person' for past tense verbs e.g. ran, present
participle verbs e.g. running, past participle verbs e.g. run, non-3rd person singular present verbs e.g. run, and third-person
singular present verbs e.g. runs
return: it will print out the verbs and their related frequency in the text.
parameters:
amount: the amount of articles you want to see
return: a dictionary of articles and their corresponding frequencies
amount_of_adjectives(amount: int, modifier: str = ''): get the total amount of adjectives in the text
parameters:
amount: the amount of adjectives you want to view, you can only pass an integer
modifier: to view the other types of adjectives, you can pass two string values: 'comparative' e.g. quicker or 'superlative' e.g.
quickest.
return: it will print out the adjectives and their related frequency in the text.
parameters:
amount: the amount of adverbs you want to see
return: a dictionary of the adverbs and their corresponding frequencies
amount_of_conjunctions(amount: int = 10): method for determining the amount of conjunctions in the text object
parameters:
amount: the amount of conjunctions you want to see
return: a dictionary of the conjunctions and their corresponding frequencies
amount_of_pronouns(amount: int, modifier: str = ''): method for determining the amount of pronouns in the text object
parameters:
amount: the amount of pronouns you want to see.
modifier: choose the type of pronoun; pass it as string - 'possessive' or 'POSSESSIVE' or 'pos' or 'POS'. The default is a regular
pronoun.
return: a dictionary of the pronouns and their corresponding frequencies.
amount_of_prepositions(amount: int = 10): method for determining the amount of prepositions in the text object
parameters:
amount: the amount of prepositions you want to see.
return: a dictionary of the prepositions and their corresponding frequencies.
parameters:
amount: the amount of cardinal numbers you want to view in the text document
return: the amount of cardinal numbers in the text as dictionary of cardinal numbers and their corresponding frequencies.
parameters:
amount: the amount of existential there in the text document
return: the amount of 'there is' in the text as dictionary of cardinal numbers and their corresponding frequencies.
amount_of_foreign_word(amount: int): if there are foreign words e.g. foreign language words like french d'accord etc or other foreign language
words.
parameters:
amount: the amount of foreign words in the text document
return: the amount of foreign words in the text.
amount_of_list_item_marker(amount: int): how many list item markers are present in the text e.g. 1., A., i. etc.
parameters:
amount: the amount of list markers in the text document
return: the amount of list item markers in the text
parameters:
amount: the amount of modals in the text document.
return: the amount of modals present in the text.
parameters:
amount: the amount of predeterminers in the text document.
return: the amount of predeterminers present in the text.
parameters:
amount: the amount of possessive endings in the text document.
return: a dictionary of possessive ending words and their corresponding frequencies in the text.
parameters:
amount: the amount of possessive endings in the text document.
return: a dictionary of particle words and their corresponding frequencies in the text.
amount_of_symbol(amount: int): this method is similar to the show_special_characters method in the CleanTweet class; it shows the amount of special characters in the text e.g. &, %, &, * etc.
parameters:
amount: the amount of symbols in the text document.
return: a dictionary of the different symbols and their corresponding frequencies in the text.