Documentation
¶
Overview ¶
Package format contains functions for printing and formatting output
Index ¶
- func ASCIIEscapeUnicode(str string) string
- func CalculateQuartiles(data []int) (int, int, int)
- func CreateBoxAndWhiskersPlot(data []int) (string, int, int, int, int, int)
- func CreateIgnoreCaseMap(freq map[string]int) map[string]int
- func CreateVerboseStats(freq map[string]int) string
- func DeASCIIEscapeUnicode(str string) string
- func DecodeInputMap(input map[string]int, bypass bool, debug bool) map[string]int
- func DecodeString(s string) (string, string)
- func DehexMap(input map[string]int, bypass bool, debug bool) map[string]int
- func EncodeInputMap(input map[string]int, bypass bool, debug bool) map[string]int
- func EncodeString(s string) (string, string)
- func FilterTopN(freq map[string]int, n int) map[string]int
- func HexEncodeMap(input map[string]int, bypass bool, debug bool) map[string]int
- func PrintArrayToMarkdown(freq map[string]int, command string)
- func PrintArrayToSTDOUT(freq map[string]int, verbose bool)
- func PrintStatsToSTDOUT(freq map[string]int, verbose bool, maxItems int)
- func RemoveLengthRange(freq map[string]int, start int, end int) map[string]int
- func RemoveMinimumFrequency(freq map[string]int, minF int) map[string]int
- func RetainRemove(textMap map[string]int, retainMap map[string]int, removeMap map[string]int, ...) (map[string]int, error)
- func SaveArrayToJSON(path string, freq map[string]int) error
- func StatClassifyToken(s string) []string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ASCIIEscapeUnicode ¶
ASCIIEscapeUnicode will convert a string into an unicode escaped format
Args:
str (string): String to escape
Returns:
escapedRunes (string): Converted runes in string format
func CalculateQuartiles ¶ added in v0.2.5
CalculateQuartiles calculates the first, second, and third quartiles of a list of integers and returns the values.
Args: data ([]int): A list of integers
Returns: int: The first quartile value int: The second quartile value int: The third quartile value
func CreateBoxAndWhiskersPlot ¶ added in v0.2.5
CreateBoxAndWhiskersPlot creates a box and whiskers plot from a list of integers.
Args:
data ([]int): A list of integers Returns: string: A string representation of the box and whiskers plot int: The minimum value int: The first quartile value int: The second quartile value int: The third quartile value int: The maximum value
func CreateIgnoreCaseMap ¶ added in v0.3.8
CreateIgnoreCaseMap creates a new map of item frequencies with all keys with the same case-insensitive value. The new map will have the case-insensitive key as the key and the sum of the frequencies of all keys
Args: freq (map[string]int): A map of item frequencies
Returns: map[string]int: A new map of item frequencies with case-insensitive keys
func CreateVerboseStats ¶
CreateVerboseStats creates a string of verbose statistics about the frequency map including several statistics about the frequency map.
Args:
freq (map[string]int): A map of item frequencies
Returns:
string: A string of verbose statistics
func DeASCIIEscapeUnicode ¶
DeASCIIEscapeUnicode will convert a string from an unicode escaped format to its string representation. This function will only convert the unicode escaped characters if they are in the format \uXXXX where X is a hexadecimal digit.
Args:
str (string): String to unescape
Returns:
unescapedRunes (string): Converted runes in string format
func DecodeInputMap ¶
DecodeInputMap will decode a map of HTML and unicode escaped strings where possible and return a new map of decoded strings.
Args:
input (map[string]int): A map of input strings bypass (bool): If true, the map is not used for output or filtering debug (bool): If true, print additional debug information to stderr
Returns:
(map[string]int): A new map of decoded strings
func DecodeString ¶
DecodeString is used to URL and HTML decode a string where possible this will only return the decoded string if it is different from the input string
Args:
s (string): Input string
Returns:
htmlDecoded (string): Input string HTML decoded escapedDecoded (string): Input string unicode escaped decoded
func DehexMap ¶
DehexMap will decode a map of hex encoded strings and return a new map of decoded strings where possible
Args:
input (map[string]int): A map of hex encoded strings bypass (bool): If true, the map is not used for output or filtering debug (bool): If true, print additional debug information to stderr
Returns:
(map[string]int): A new map of decoded strings
func EncodeInputMap ¶
EncodeInputMap will encode a map of strings to HTML and unicode escaped strings where possible and return a new map of encoded strings
Args:
input (map[string]int): A map of input strings bypass (bool): If true, the map is not used for output or filtering debug (bool): If true, print additional debug information to stderr
Returns:
(map[string]int): A new map of encoded strings
func EncodeString ¶
EncodeString is used to URL and HTML encode a string where possible this will only return the encoded string if it is different from the input string
Args:
s (string): Input string
Returns:
htmlEncoded (string): Input string HTML encoded escapedEncoded (string): Input string unicode escaped encoded
func FilterTopN ¶ added in v0.3.2
FilterTopN removes all but the top N items from a map of item frequencies and returns a new map
Args: freq (map[string]int): A map of item frequencies n (int): The number of items to retain
Returns: map[string]int: A new map of the top N item frequencies
func HexEncodeMap ¶
HexEncodeMap will encode a map of strings to hex encoded strings where possible and return a new map of encoded strings
Args:
input (map[string]int): A map of input strings bypass (bool): If true, the map is not used for output or filtering debug (bool): If true, print additional debug information to stderr
Returns:
(map[string]int): A new map of encoded strings
func PrintArrayToMarkdown ¶ added in v0.3.6
PrintArrayToMarkdown prints an array of items to stdout in markdown format including the item and the frequency.
Args: freq (map[string]int): A map of item frequencies command (string): The command that was run
Returns: None
func PrintArrayToSTDOUT ¶
PrintArrayToSTDOUT prints an array of items to stdout
Args:
items (map[string]int): A map of item frequencies verbose (bool): If true, the count is printed
Returns:
None
func PrintStatsToSTDOUT ¶
PrintStatsToSTDOUT prints statistics about the frequency map to stdout including several statistics about the frequency map. If verbose is true, additional information is printed and increased number of items are printed. Items are printed in graph format with a # for each unit of item.
Args:
freq (map[string]int): A map of item frequencies verbose (bool): If true, additional information is printed maxItems (int): The maximum number of items to print
Returns:
None
func RemoveLengthRange ¶
RemoveLengthRange removes items from a map that are outside of a length range or not equal to the start of the end if no end is provided. The length of the range is inclusive.
Args:
freq (map[string]int): A map of item frequencies start (int): The start of the length range end (int): The end of the length range
Returns:
(map[string]int): A new map of item frequencies within the length range
func RemoveMinimumFrequency ¶
RemoveMinimumFrequency removes items from a map that are below a minimum frequency threshold and returns a new map
Args:
freq (map[string]int): A map of item frequencies minF (int): The minimum frequency threshold
Returns:
(map[string]int): A new map of item frequencies above the minimum threshold
func RetainRemove ¶
func RetainRemove(textMap map[string]int, retainMap map[string]int, removeMap map[string]int, debugInt int) (map[string]int, error)
RetainRemove compares a string against a list of words to retain and remove
Args:
text (map[string]int): The text to process retainMap (map[string]int): A map of words to retain removeMap (map[string]int): A map of words to remove debugInt (int): Represents the level of verbosity for debug output
Returns:
(map[string]int): A new map of words that have been retained and removed (error): An error if the text map is empty
func SaveArrayToJSON ¶
SaveArrayToJSON saves an array of items to a JSON file at the specified path with a generated filename. The filename is generated with the format "ptt-<timestamp>.json" where the timestamp is the current time in RFC3339 format.
Args:
path (string): The path to save the JSON file items (map[string]int): A map of item frequencies
Returns:
error: An error if the file cannot be saved
func StatClassifyToken ¶
StatClassifyToken classifies a token into a set of categories based on the token's content. "Short" and "long" are relative to ten characters currently.
Args:
s (string): The token to classify
Returns:
[]string: A list of categories that the token belongs to
Types ¶
This section is empty.