Python: module simpleparse.stt.TextTools.TextTools

simpleparse.stt.TextTools.TextTools (version 2.1.0) | index /home/mcfletch/pylive/simpleparse/stt/TextTools/TextTools.py

`mxTextTools - A tools package for fast text processing.
Copyright (c) 2000, Marc-Andre Lemburg; mailto:mal@lemburg.com
Copyright (c) 2000-2003, eGenix.com Software GmbH; mailto:info@egenix.com
See the documentation for further information on copyrights,
or contact the author. All Rights Reserved.`

Modules
`` |  |
simpleparse.stt.TextTools.mxTextTools.mxTextTools | string | time | types

Classes
`` |  | _timer
class _timer
`` | `timer class with a quite obvious interface - .start() starts a fairly accurate CPU-time timer plus an absolute timer - .stop() stops the timer and returns a tuple: the CPU-time in seconds and the absolute time elapsed since .start() was called`
| Methods defined here: __str__(self) abstime(self, clock=<built-in function clock>, time=<built-in function time>) start(self, clock=<built-in function clock>, time=<built-in function time>) stop(self, clock=<built-in function clock>, time=<built-in function time>) usertime(self, clock=<built-in function clock>, time=<built-in function time>) Data and other attributes defined here: atime = 0 utime = 0

Functions
`` |  | BMS = TextSearch(...) `TextSearch(match[,translate=None,algorithm=default_algorithm]) Create a substring search object for the string match; translate is an optional translate-string like the one used in the module re.` CharSet(...) `CharSet(definition) Create a character set matching object from the string` FS = TextSearch(...) `TextSearch(match[,translate=None,algorithm=default_algorithm]) Create a substring search object for the string match; translate is an optional translate-string like the one used in the module re.` FSType = TextSearch(...) `TextSearch(match[,translate=None,algorithm=default_algorithm]) Create a substring search object for the string match; translate is an optional translate-string like the one used in the module re.` TagTable(...) `TagTable(definition[,cachable=1])` TextSearch(...) `TextSearch(match[,translate=None,algorithm=default_algorithm]) Create a substring search object for the string match; translate is an optional translate-string like the one used in the module re.` UnicodeTagTable(...) `TagTable(definition[,cachable=1])` _bench(file='mxTextTools/mxTextTools.c') _lookup_dict(l, index=0) `# aid for matching from a list of words` _replace2(text, what, with, start=0, stop=None, join=<built-in function join>, joinlist=<built-in function joinlist>, tag=<built-in function tag>, TextSearchType=<type 'TextSearch'>, TextSearch=<built-in function TextSearch>) `Analogon to string.replace; returns a string with all occurences of what in text[start:stop] replaced by with. This version uses a one entry tag-table and a Boyer-Moore-Search-object. what can be a string or a TextSearch search object. It's faster than string.replace in those cases, where the what-string gets long and/or many replacements are found; faster meaning from a few percent up to many times as fast start and stop define the slice of text to work in. stop defaults to len(text).` _replace3(text, what, with, join=<function join>, TextSearch=<built-in function TextSearch>, TextSearchType=<type 'TextSearch'>) _replace4(text, what, with, join=<built-in function join>, joinlist=<built-in function joinlist>, tag=<built-in function tag>, TextSearch=<built-in function TextSearch>, TextSearchType=<type 'TextSearch'>) _tagdict(text, dict, prefix, taglist) `# helper for tagdict` charsplit(...) `charsplit(text,char,start=0,stop=len(text)) Split text[start:stop] into substrings at char and return the result as list of strings.` cmp(...) `cmp(a,b) Compare two valid taglist tuples w/r to their slice position; this is useful for sorting joinlists.` collapse(text, separator=' ', join=<built-in function join>, charset=<Character Set object for '\r\n \t\x0b\r\n\x0c'>) `Eliminates newline characters and compresses whitespace characters into one space. The result is a one line text string. Tim Peters will like this function called with '-' separator ;-)` countlines(text, linecount_table=((None, 13, '\r', 1), (None, 13, '\n', 1), ('line', 41, <Character Set object for '^\r\n'>, 1, -2), (None, 101, 1, 1, 1000000), ('empty line', 102, 0, 0, -4))) `Returns the number of lines in text. Line ends are treated just like for splitlines() in a portable way.` find(text, what, start=0, stop=None, SearchObject=<built-in function TextSearch>) `A faster replacement for string.find(). Uses a search object for the task. Returns the position of the first occurance of what in text[start:stop]. stop defaults to len(text). Returns -1 in case no occurance was found.` findall(text, what, start=0, stop=None, SearchObject=<built-in function TextSearch>) `Find all occurances of what in text. Uses a search object for the task. Returns a list of slice tuples (l,r) marking the all occurances in text[start:stop]. stop defaults to len(text). Returns an empty list in case no occurance was found.` format_entry(table, i, TupleType=<type 'tuple'>) `Returns a pp-formatted tag table entry as string` format_table(table, i=-1) `Returns a pp-formatted version of the tag table as string` hex2str(...) `hex2str(text) Return text interpreted as two byte HEX values converted to a string.` invset(chars) `Return a set with all characters *except* the ones in chars.` is_whitespace(text, start=0, stop=None, charset=<Character Set object for '^ \t\x0b\r\n\x0c'>) `Return 1 iff text[start:stop] only contains whitespace characters (as defined in Constants/Sets.py), 0 otherwise.` isascii(...) `isascii(text,start=0,stop=len(text)) Return 1/0 depending on whether text only contains ASCII characters.` join(...) `join(joinlist,sep='',start=0,stop=len(joinlist)) Copy snippets from different strings together producing a new string The first argument must be a list of tuples or strings; tuples must be of the form (string,l,r[,...]) and turn out as string[l:r] NOTE: the syntax used for negative slices is different than the Python standard: -1 corresponds to the first character *after* the string, e.g. ('Example',0,-1) gives 'Example' and not 'Exampl', like in Python sep is an optional separator string, start and stop define the slice of joinlist that is taken into accont.` joinlist(...) `joinlist(text,list,start=0,stop=len(text)) Takes a list of tuples (replacement,l,r,...) and produces a taglist suitable for join() which creates a copy of text where every slice [l:r] is replaced by the given replacement - the list must be sorted using cmp() as compare function - it may not contain overlapping slices - the slices may not contain negative indices - if the taglist cannot contain overlapping slices, you can give this function the taglist produced by tag() directly (sorting is not needed, as the list will already be sorted) - start and stop set the slice to work in, i.e. text[start:stop]` linesplit = splitlines(text, tag=<built-in function tag>, linesplit_table=((None, 13, '\r', 1), (None, 13, '\n', 1), ('line', 2089, <Character Set object for '^\r\n'>, 1, -2), (None, 101, 1, 1, 1000000), ('empty line', 2150, 0, 0, -4))) `Split text into a list of single lines. The following combinations are considered to be line-ends: ' ', ' ', ' '; they may be used in any combination. The line-end indicators are removed from the strings prior to adding them to the list. This function allows dealing with text files from Macs, PCs and Unix origins in a portable way.` lower(...) `lower(text) Return text converted to lower case.` multireplace(text, replacements, start=0, stop=None, join=<built-in function join>, joinlist=<built-in function joinlist>) `Apply multiple replacement to a text at once. replacements must be list of tuples (replacement, left, right). It is used to replace the slice text[left:right] with the string replacement. Note that the replacements do not affect one another. Indices always refer to the original text string. Replacements must not overlap. Otherwise a ValueError is raised.` normlist(jlist, StringType=<type 'str'>) `Return a normalized joinlist. All tuples in the joinlist are turned into real strings. The resulting list is a equivalent copy of the joinlist only consisting of strings.` prefix(...) `prefix(text,prefixes,start=0,stop=len(text)[,translate]) Looks at text[start:stop] and returns the first matching prefix out of the tuple of strings given in prefixes. If no prefix is found to be matching, None is returned. The optional 256 char translate string is used to translate the text prior to comparing it with the given suffixes.` print_joinlist(joins, indent=0, StringType=<type 'str'>) `Print the joinlist joins using the given indent level` print_tags(text, tags, indent=0) `Print the taglist tags for text using the given indent level` print_tagtable(table) `Print the tag table` replace(text, what, with, start=0, stop=None, SearchObject=<built-in function TextSearch>, join=<built-in function join>, joinlist=<built-in function joinlist>, tag=<built-in function tag>, string_replace=<function replace>, type=<type 'type'>, StringType=<type 'str'>) `A fast replacement for string.replace. what can be given as string or search object. This function is a good example for the AppendTagobj-flag usage (the taglist can be used directly as joinlist).` set(...) `set(string,logic=1) Returns a character set for string: a bit encoded version of the characters occurring in string. - logic can be set to 0 if all characters *not* in string should go into the set` setfind(...) `setfind(text,set,start=0,stop=len(text)) Find the first occurence of any character from set in text[start:stop] set must be a string obtained with set() DEPRECATED: use CharSet().search() instead.` setsplit(...) `setsplit(text,set,start=0,stop=len(text)) Split text[start:stop] into substrings using set, omitting the splitting parts and empty substrings. set must be a string obtained from set() DEPRECATED: use CharSet().split() instead.` setsplitx(...) `setsplitx(text,set,start=0,stop=len(text)) Split text[start:stop] into substrings using set, so that every second entry consists only of characters in set. set must be a string obtained with set() DEPRECATED: use CharSet().splitx() instead.` setstrip(...) `setstrip(text,set,start=0,stop=len(text),mode=0) Strip all characters in text[start:stop] appearing in set. mode indicates where to strip (<0: left; =0: left and right; >0: right). set must be a string obtained with set() DEPRECATED: use CharSet().strip() instead.` split(text, sep, start=0, stop=None, translate=None, SearchObject=<built-in function TextSearch>) `A faster replacement for string.split(). Uses a search object for the task. Returns the result of cutting the text[start:stop] string into snippets at every sep occurance in form of a list of substrings. translate is passed to the search object as translation string if given. XXX Undocumented.` splitat(...) `splitat(text,char,nth=1,start=0,stop=len(text)) Split text[start:stop] into two substrings at the nth occurance of char and return the result as 2-tuple. If the character is not found, the second string is empty. nth may be negative: the search is then done from the right and the first string is empty in case the character is not found.` splitlines(text, tag=<built-in function tag>, linesplit_table=((None, 13, '\r', 1), (None, 13, '\n', 1), ('line', 2089, <Character Set object for '^\r\n'>, 1, -2), (None, 101, 1, 1, 1000000), ('empty line', 2150, 0, 0, -4))) `Split text into a list of single lines. The following combinations are considered to be line-ends: ' ', ' ', ' '; they may be used in any combination. The line-end indicators are removed from the strings prior to adding them to the list. This function allows dealing with text files from Macs, PCs and Unix origins in a portable way.` splitwords(text, charset=<Character Set object for ' \t\x0b\r\n\x0c'>) `Split text into a list of single words. Words are separated by whitespace. The whitespace is stripped before adding the words to the list.` str2hex(...) `str2hex(text) Return text converted to a string consisting of two byte HEX values.` suffix(...) `suffix(text,suffixes,start=0,stop=len(text)[,translate]) Looks at text[start:stop] and returns the first matching suffix out of the tuple of strings given in suffixes. If no suffix is found to be matching, None is returned. The optional 256 char translate string is used to translate the text prior to comparing it with the given suffixes.` tag(...) `tag(text,tagtable,sliceleft=0,sliceright=len(text),taglist=[],context=None) Produce a tag list for a string, given a tag-table - returns a tuple (success, taglist, nextindex) - if taglist == None, then no taglist is created` tagdict(text, *args) `Tag a text just like the function tag() and then convert its output into a dictionary where the tagobjects reference their respective strings This function emulates the interface of tag(). In contrast to tag() this funtion *does* make copies of the found stings, though. Returns a tuple (rc,tagdict,next) with the same meaning of rc and next as tag(); tagdict is the new dictionary or None in case rc is 0.` upper(...) `upper(text) Return text converted to upper case.` word_in_list(l) `Creates a lookup table that matches the words in l`

Data
`` |  | A2Z = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' A2Z_charset = <Character Set object for 'A-Z'> A2Z_set = '\x00\x00\x00\x00\x00\x00\x00\x00\xfe\xff\xff\x07\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' AllIn = 11 AllInCharSet = 41 AllInSet = 31 AllNotIn = 12 AppendMatch = 2048 AppendTagobj = 1024 AppendToTagobj = 512 BOYERMOORE = 0 Break = 0 Call = 201 CallArg = 202 CallTag = 256 EOF = 101 FASTSEARCH = 1 Fail = 100 Here = 1 Is = 13 IsIn = 14 IsInCharSet = 42 IsInSet = 32 IsNot = 15 IsNotIn = 15 Jump = 100 JumpTarget = 104 LookAhead = 4096 Loop = 205 LoopControl = 206 MatchFail = -1000000 MatchOk = 1000000 Move = 103 NoWord = 211 Reset = -1 Skip = 102 SubTable = 207 SubTableInList = 208 TRIVIAL = 2 Table = 203 TableInList = 204 ThisTable = 999 To = 0 ToBOF = 0 ToEOF = -1 Umlaute = '\xc4\xd6\xdc' Umlaute_charset = <Character Set object for '\xc4\xd6\xdc'> Word = 21 WordEnd = 23 WordStart = 22 _linecount_table = ((None, 13, '\r', 1), (None, 13, '\n', 1), ('line', 41, <Character Set object for '^\r\n'>, 1, -2), (None, 101, 1, 1, 1000000), ('empty line', 102, 0, 0, -4)) _linesplit_table = ((None, 13, '\r', 1), (None, 13, '\n', 1), ('line', 2089, <Character Set object for '^\r\n'>, 1, -2), (None, 101, 1, 1, 1000000), ('empty line', 2150, 0, 0, -4)) _wordsplit_table = ((None, 41, <Character Set object for ' \t\x0b\r\n\x0c'>, 1), ('word', 2089, <Character Set object for '^ \t\x0b\r\n\x0c'>, 1, -1), (None, 101, 1, 1, 1000000)) a2z = 'abcdefghijklmnopqrstuvwxyz' a2z_charset = <Character Set object for 'a-z'> a2z_set = '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xfe\xff\xff\x07\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' alpha = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' alpha_charset = <Character Set object for 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'> alpha_set = '\x00\x00\x00\x00\x00\x00\x00\x00\xfe\xff\xff\x07\xfe\xff\xff\x07\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' alphanumeric = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789' alphanumeric_charset = <Character Set object for 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'> alphanumeric_set = '\x00\x00\x00\x00\x00\x00\xff\x03\xfe\xff\xff\x07\xfe\xff\xff\x07\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' any = '\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !"#$%&\'()*+,-./...\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff' any_charset = <Character Set object for '\x00-\xff'> any_set = '\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff' formfeed = '\x0c' formfeed_charset = <Character Set object for '\x0c'> german_alpha = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\xe4\xf6\xfc\xdf\xc4\xd6\xdc' german_alpha_charset = <Character Set object for 'ABCDEFGHIJKLMNOPQRSTU...hijklmnopqrstuvwxyz\xe4\xf6\xfc\xdf\xc4\xd6\xdc'> german_alpha_set = '\x00\x00\x00\x00\x00\x00\x00\x00\xfe\xff\xff\x07\xfe\xff\xff\x07\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00@\x90\x10\x00@\x10' id2cmd = {-1000000: 'MatchFail', -1: 'ToEOF', 0: 'Fail/Jump', 1: 'Here', 11: 'AllIn', 12: 'AllNotIn', 13: 'Is', 14: 'IsIn', 15: 'IsNotIn', 21: 'Word', ...} newline = '\r\n' newline_charset = <Character Set object for '\r\n'> newline_set = '\x00$\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' nonwhitespace_charset = <Character Set object for '^ \t\x0b\r\n\x0c'> nonwhitespace_set = '\xff\xc1\xff\xff\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff' number = '0123456789' number_charset = <Character Set object for '0-9'> number_set = '\x00\x00\x00\x00\x00\x00\xff\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' sFindWord = 213 sWordEnd = 212 sWordStart = 211 tagtable_cache = {(46912536021760, 0): <String Tag Table object>, (46912540134840, 0): <String Tag Table object>, (46912541410080, 0): <String Tag Table object>, (46912541454848, 0): <String Tag Table object>, (46912541455136, 0): <String Tag Table object>, (46912541455208, 0): <String Tag Table object>, (46912541489264, 0): <String Tag Table object>, (46912541566016, 0): <String Tag Table object>, (46912543903688, 0): <String Tag Table object>, (46912543908136, 0): <String Tag Table object>, ...} to_lower = '\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !"#$%&\'()*+,-./...\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff' to_upper = '\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !"#$%&\'()*+,-./...\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff' umlaute = '\xe4\xf6\xfc\xdf' umlaute_charset = <Character Set object for '\xe4\xf6\xfc\xdf'> white = ' \t\x0b' white_charset = <Character Set object for ' \t\x0b'> white_set = '\x00\x02\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' whitespace = ' \t\x0b\r\n\x0c' whitespace_charset = <Character Set object for ' \t\x0b\r\n\x0c'> whitespace_set = '\x00&\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'