zeus

package module
v0.0.0-...-1ca21fd Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 27, 2023 License: GPL-3.0 Imports: 9 Imported by: 0

README

Logo

Zeus

Zeus uses a lexer to tokenize and analyze given text. This lexer is not very good or efficient but it provided a great learning opportunity for me to experiment with and figure out how lexers work.

Documentation

Index

Constants

View Source
const EmailRegex = `\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b`
View Source
const UrlRegex = `https?://[^\s]+`

Variables

This section is empty.

Functions

func AutomatedReadabilityIndex

func AutomatedReadabilityIndex(in string) float64

AutomatedReadabilityIndex calculates the Automated Readability Index (ARI) for a given text. It estimates the U.S. grade level required to understand the text.

Parameters:

  • in: The input text for which to calculate the ARI.

Returns:

  • The Automated Readability Index (ARI) as a float64.

func AverageSyllablesPerWord

func AverageSyllablesPerWord(in string) float64

AverageSyllablesPerWord calculates the average number of syllables per word in the given string (in).

Parameters:

  • in: The input string for which to calculate the average syllables per word.

Returns:

  • The average number of syllables per word as a float64.

func AverageWordsPerSentence

func AverageWordsPerSentence(in string) float64

AverageWordsPerSentence calculates the average number of words per sentence in the given string (in). If the number of sentences in the given string is 0, it returns the number of words as a float64.

Parameters:

  • in: The input string for which to calculate the average words per sentence.

Returns:

  • The average words per sentence as a float64.

func BrotliCompressText

func BrotliCompressText(data string) []byte

BrotliCompressText compresses a given text using the Brotli compression algorithm.

Parameters:

  • data: The input text to be compressed.

Returns:

  • The compressed data as a byte slice.

func BrotliDecompressText

func BrotliDecompressText(in []byte) (string, error)

BrotliDecompressText decompresses Brotli compressed data into a string.

Parameters:

  • in: The Brotli compressed data as a byte slice.

Returns:

  • The decompressed text as a string.
  • An error if decompression fails.

func ColemanLiauIndex

func ColemanLiauIndex(in string) float64

ColemanLiauIndex calculates the Coleman-Liau Index for a given text. It estimates the U.S. grade level required to understand the text.

Parameters:

  • in: The input text for which to calculate the Coleman-Liau Index.

Returns:

  • The Coleman-Liau Index as a float64.

func Concat

func Concat(strings ...string) string

Concat concatenates multiple strings together using goroutines and a mutex for synchronization. It is more efficient for large concatenations compared to NonConcurrentConcat.

Parameters:

  • strings: A variadic list of strings to concatenate.

Returns:

  • The concatenated string.

func ExtractEmails

func ExtractEmails(in string, max int) []string

ExtractEmails uses regular expressions to extract a given amount of emails (max) from a given string (in). Use a max value of -1 or less to return all emails found in the input string.

Parameters:

  • in: The input string from which to extract emails.
  • max: The maximum number of emails to extract. Use -1 to extract all emails.

Returns:

  • A slice of strings containing the extracted emails.

func ExtractHTMLTags

func ExtractHTMLTags(in string, max int) []string

ExtractHTMLTags extracts a given number of HTML tags from the given string (in) using the lexer. It returns a list of HTML tags with a maximum length of (max). Use a max value of -1 or less to return every tag found in the input string.

Parameters:

  • in: The input string from which to extract HTML tags.
  • max: The maximum number of HTML tags to extract. Use -1 to extract all HTML tags.

Returns:

  • A slice of strings containing the extracted HTML tags.

func ExtractUrls

func ExtractUrls(in string, max int) []string

ExtractUrls extracts a given number of URLs from the given string (in) using regular expressions. It returns a list of URLs with a maximum length of (max). Use a max value of -1 or less to return every URL found in the input string.

Parameters:

  • in: The input string from which to extract URLs.
  • max: The maximum number of URLs to extract. Use -1 to extract all URLs.

Returns:

  • A slice of strings containing the extracted URLs.

func FlateCompressText

func FlateCompressText(in string) ([]byte, error)

FlateCompressText compresses a given text using the Flate (DEFLATE) compression algorithm.

Parameters:

  • in: The input text to be compressed.

Returns:

  • The compressed data as a byte slice.
  • An error if compression fails.

func FlateDecompressText

func FlateDecompressText(in []byte) (string, error)

FlateDecompressText decompresses Flate (DEFLATE) compressed data into a string.

Parameters:

  • in: The Flate compressed data as a byte slice.

Returns:

  • The decompressed text as a string.
  • An error if decompression fails.

func FleschKincaidGradeLevel

func FleschKincaidGradeLevel(in string) float64

FleschKincaidGradeLevel calculates the Flesch-Kincaid Grade Level for a given text. It estimates the number of years of education required to understand the text.

Parameters:

  • in: The input text for which to calculate the Grade Level.

Returns:

  • The Flesch-Kincaid Grade Level as a float64.

func FleschKincaidReadingEase

func FleschKincaidReadingEase(in string) float64

FleschKincaidReadingEase calculates the Flesch-Kincaid Reading Ease score for a given text. The higher the score, the easier the text is to read.

Parameters:

  • in: The input text for which to calculate the Reading Ease score.

Returns:

  • The Flesch-Kincaid Reading Ease score as a float64.

func FrequencyOfRune

func FrequencyOfRune(char rune, in string) int

FrequencyOfRune returns the number of times a given rune (char) appears in another given string (text). Parameters:

  • char: The rune to count in the input string.
  • in: The input string in which to count the rune.

Returns:

  • The frequency of the rune in the input string.

func FrequencyOfString

func FrequencyOfString(str string, in string) int

FrequencyOfString returns the number of times a given string (str) appears in another given string (in). Parameters:

  • str: The string to count in the input string.
  • in: The input string in which to count the string.

Returns:

  • The frequency of the string in the input string.

func GZIPCompressText

func GZIPCompressText(in string) ([]byte, error)

GZIPCompressText compresses a given text using the GZIP compression algorithm.

Parameters:

  • in: The input text to be compressed.

Returns:

  • The compressed data as a byte slice.
  • An error if compression fails.

func GZIPDecompressText

func GZIPDecompressText(in []byte) (string, error)

GZIPDecompressText decompresses GZIP compressed data into a string.

Parameters:

  • in: The GZIP compressed data as a byte slice.

Returns:

  • The decompressed text as a string.
  • An error if decompression fails.

func GetAllWords

func GetAllWords(in string) []string

GetAllWords returns a list of all words in the given string.

Parameters:

  • in: The input string from which to extract words.

Returns:

  • A slice of strings containing all the words in the input string.

func IsEmail

func IsEmail(in string) bool

Returns a bool checking if the given text matches a comprehensive email regex

func IsUrl

func IsUrl(in string) bool

Returns a bool checking if the given text matches a url regex

func LetterCount

func LetterCount(in string) int

LetterCount counts the number of letters (alphabetic characters) in a given input string.

Parameters:

  • in: The input string for which you want to count the letters.

Returns:

  • The count of letters in the input string.

func NonConcurrentConcat

func NonConcurrentConcat(strings ...string) string

NonConcurrentConcat concatenates multiple strings together without concurrency. This function is usually less efficient for small concatenations but works well for large concatenations.

Parameters:

  • strings: A variadic list of strings to concatenate.

Returns:

  • The concatenated string.

func PercentFrequencyOfRune

func PercentFrequencyOfRune(char rune, in string) float64

PercentFrequencyOfRune calculates the percentage frequency of a specific rune (char) within a string (in). Parameters:

  • char: The rune to calculate the percentage frequency of in the input string.
  • in: The input string in which to calculate the percentage frequency of the rune.

Returns:

  • The percentage frequency of the rune in the input string as a float64.

func PercentFrequencyOfString

func PercentFrequencyOfString(str string, in string) float64

PercentFrequencyOfString calculates the percentage frequency of a specific string (str) within another string (in). Parameters:

  • str: The string to calculate the percentage frequency of in the input string.
  • in: The input string in which to calculate the percentage frequency of the string.

Returns:

  • The percentage frequency of the string in the input string as a float64.

func RemoveExtraWhitespace

func RemoveExtraWhitespace(in string) string

RemoveExtraWhitespace removes extra whitespace between words in the given string (in) using the lexer.

Parameters:

  • in: The input string from which to remove extra whitespace.

Returns:

  • The input string with extra whitespace removed.

func ReplaceCommonHTMLCharacters

func ReplaceCommonHTMLCharacters(in string) string

ReplaceCommonHTMLCharacters replaces commonly used HTML entities with their corresponding characters.

Parameters:

  • in: The input string to perform replacements on.

Returns:

  • The input string with common HTML characters replaced.

func ReplaceEmails

func ReplaceEmails(in string, replacer string, max int) string

ReplaceEmails replaces a given amount of emails (max) from a given string (in) with a given string (replacer). This function first calls ExtractEmails(in, max) to extract the emails and then replaces them inside the input string with the provided replacer.

Parameters:

  • in: The input string in which to replace emails.
  • replacer: The string to replace emails with.
  • max: The maximum number of emails to replace. Use -1 to replace all emails.

Returns:

  • The input string with the specified emails replaced by the replacer string.

func ReplaceHTMLTags

func ReplaceHTMLTags(in string, replacer string, max int) string

ReplaceHTMLTags replaces a given number of HTML tags (max) from the given string (in) with a given string (replacer). This function first calls ExtractHTMLTags(in, max) to extract the HTML tags and then replaces them inside the input string with the provided replacer.

Parameters:

  • in: The input string in which to replace HTML tags.
  • replacer: The string to replace HTML tags with.
  • max: The maximum number of HTML tags to replace. Use -1 to replace all HTML tags.

Returns:

  • The input string with the specified HTML tags replaced by the replacer string.

func ReplaceProprietaryMicrosoftCharacters

func ReplaceProprietaryMicrosoftCharacters(in string) string

ReplaceProprietaryMicrosoftCharacters replaces commonly used (bad) Microsoft and Google ASCII characters with normal characters.

Parameters:

  • in: The input string to perform replacements on.

Returns:

  • The input string with proprietary Microsoft characters replaced.

func ReplaceUrls

func ReplaceUrls(in string, replacer string, max int) string

ReplaceUrls replaces a given number of URLs (max) from the given string (in) with a given string (replacer). This function first calls ExtractUrls(in, max) to extract the URLs and then replaces them inside the input string with the provided replacer.

Parameters:

  • in: The input string in which to replace URLs.
  • replacer: The string to replace URLs with.
  • max: The maximum number of URLs to replace. Use -1 to replace all URLs.

Returns:

  • The input string with the specified URLs replaced by the replacer string.

func SanitizeAll

func SanitizeAll(in string) string

SanitizeAll runs all sanitization functions on a given string (in). It performs multiple text sanitization operations to clean and normalize the input string.

Parameters:

  • in: The input string to sanitize.

Returns:

  • The sanitized string.

func SentenceCount

func SentenceCount(in string) int

SentenceCount returns the number of sentences in the given string (in). Note that this function may count unknown characters and abbreviations as sentences, which may not be accurate.

Parameters:

  • in: The input string for which to count sentences.

Returns:

  • The number of sentences in the input string.

func StringLongestCommonSubsequence

func StringLongestCommonSubsequence(a, b string) string

Returns the longest common subsequence between two given strings (a and b)

func SyllableCount

func SyllableCount(word string) (count int)

SyllableCount returns the number of syllables in the given word.

Parameters:

  • word: The word for which to count syllables.

Returns:

  • The number of syllables in the word.

func TotalSyllableCount

func TotalSyllableCount(in string) int

TotalSyllableCount iterates over every word in the given string (in) and returns the total number of syllables in all words combined.

Parameters:

  • in: The input string for which to calculate the total syllable count.

Returns:

  • The total number of syllables in the input string.

func WordCount

func WordCount(in string) int

WordCount returns the number of words in the given string (in).

Parameters:

  • in: The input string for which to count words.

Returns:

  • The number of words in the input string.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL