Package nltk :: Package toolbox :: Module toolbox
[hide private]
[frames] | no frames]

Module toolbox

source code

Module for reading, writing and manipulating Toolbox databases and settings files.

Classes [hide private]
StandardFormat
Class for reading and processing standard format marker files and strings.
ToolboxData
ToolboxSettings
This class is the base class for settings files.
Functions [hide private]
string
to_sfm_string(tree, encoding=None, errors='strict', unicode_fields=None)
Return a string with a standard format representation of the toolbox data in tree (tree can be a toolbox database or a single record).
source code
 
to_settings_string(tree, encoding=None, errors='strict', unicode_fields=None) source code
 
_to_settings_string(node, l, **kwargs) source code
 
remove_blanks(elem)
Remove all elements and subelements with no text and no child elements.
source code
 
add_default_fields(elem, default_fields)
Add blank elements and subelements specified in default_fields.
source code
 
sort_fields(elem, field_orders)
Sort the elements and subelements in order specified in field_orders.
source code
 
_sort_fields(elem, orders_dicts)
sort the children of elem
source code
 
add_blank_lines(tree, blanks_before, blanks_between)
Add blank lines before all elements and subelements specified in blank_before.
source code
 
demo() source code
Variables [hide private]
  _is_value = re.compile(r'\S')
Function Details [hide private]

to_sfm_string(tree, encoding=None, errors='strict', unicode_fields=None)

source code 

Return a string with a standard format representation of the toolbox data in tree (tree can be a toolbox database or a single record).

Parameters:
  • tree (ElementTree._ElementInterface) - flat representation of toolbox data (whole database or single record)
  • encoding (string) - Name of an encoding to use.
  • errors (string) - Error handling scheme for codec. Same as the encode inbuilt string method.
  • unicode_fields (dictionary or set of field names)
Returns: string
string using standard format markup

remove_blanks(elem)

source code 

Remove all elements and subelements with no text and no child elements.

Parameters:
  • elem (ElementTree._ElementInterface) - toolbox data in an elementtree structure

add_default_fields(elem, default_fields)

source code 

Add blank elements and subelements specified in default_fields.

Parameters:
  • elem (ElementTree._ElementInterface) - toolbox data in an elementtree structure
  • default_fields (dictionary of tuples) - fields to add to each type of element and subelement

sort_fields(elem, field_orders)

source code 

Sort the elements and subelements in order specified in field_orders.

Parameters:
  • elem (ElementTree._ElementInterface) - toolbox data in an elementtree structure
  • field_orders (dictionary of tuples) - order of fields for each type of element and subelement

add_blank_lines(tree, blanks_before, blanks_between)

source code 

Add blank lines before all elements and subelements specified in blank_before.

Parameters:
  • elem (ElementTree._ElementInterface) - toolbox data in an elementtree structure
  • blank_before (dictionary of tuples) - elements and subelements to add blank lines before