laf 4.8.3

Submodules

laf.fabric module

class Bunch[source]

Bases: object

class LafAPI(names)[source]

Bases: laf.data.LafData

Makes all API methods available. API() returns a dict keyed by mnemonics and valued by API methods.

API()[source]
APIprep()[source]
get_all_features()[source]
class LafFabric(data_dir=None, laf_dir=None, output_dir=None, save=False, verbose=None)[source]

Bases: object

Process manager.

load(params): given the source, annox and task, loads the data, assembles the API, and returns the API.

load(source, annox, task, load_spec, add=False, compile_main=False, compile_annox=False, verbose='NORMAL', time_reset=True)[source]
load_again(load_spec, annox=None, add=False, compile_main=False, compile_annox=False, verbose='NORMAL')[source]
resolve_feature(kind, feature_given)[source]

laf.elements module

class Connection(lafapi, feature, inv)[source]

Bases: object

Connection info according to an edge feature.

Holds the mapping from nodes to a set of (node, value) pairs for which there is an edge for which this edge feature has value. Has distinct mappings for main source data and annox data.

v(node) yields the nodes (without the values). vv(node) yields the node/value pairs. endnodes(nodeset, value=None) yields the set of end nodes after traveling from ``nodeset along edges (having this feature with this value or any value).

e(n)[source]
endnodes(node_set, value=None, sort=False)[source]
v(n, sort=False)[source]
vv(n, sort=False)[source]
class Feature(lafapi, feature, kind)[source]

Bases: object

Feature data and lookup.

Holds the mapping from nodes/edges to values corresponding to a single feature. Has distinct mappings for main source data and annox data.

v(node_or_edge) is the lookup method. s(value=None) yields the nodes/edges that have this value or any value.

V(ne)[source]
s(value=None)[source]
v(ne)[source]
class PrimaryData(lafapi)[source]

Bases: object

Primary data.

data(node) is a list of chunks of primary data attached to that node. The chunk is delivered as a pair of the position where the chunk starts and the chunk itself. Empty chunks are possible. Consecutive chunks have been merged. The chunks appear in primary data order.

data(node)[source]
class XMLid(lafapi, kind)[source]

Bases: object

Mappings between XML identifiers in original LAF resource and integers identifying nodes and edges in compiled data.

r(node or edge int) = xml identifier and i(xml identifier) = node or edge int.

i(xml_id)[source]
r(int_code)[source]

laf.data module

class LafData[source]

Bases: object

Manage the compiling and loading of LAF/GraF data.

add_logfile(compile=None)[source]
compile_all(force)[source]
finish_task(show=True)[source]

Close all open files that have been opened by the API

load_all(req_items, prepare, add)[source]
prepare_all(api)[source]
prepare_dirs(annox)[source]
unload_all()[source]

laf.model module

model(origin, data_items, stamp)[source]

Augment the results of XML parsing by precomputing additional data structures.

normalize_ranges(ranges)[source]

laf.parse module

class AnnotationHandler(annotation_file, stamp)[source]

Bases: xml.sax.handler.ContentHandler

aid = None
characters(ch)[source]
endElement(name)[source]
file_name = None
nid = None
stamp = None
startElement(name, attrs)[source]
truth = {'off': False, 'false': False, 'no': False, '1': True, 'on': True, '0': False, 'true': True, 'yes': True}
class HeaderHandler[source]

Bases: xml.sax.handler.ContentHandler

characters(ch)[source]
endElement(name)[source]
startElement(name, attrs)[source]
init()[source]
parse(origin, graf_header_file, stamp, data_items)[source]

Parse a LAF/GrAF resource and deliver results.

laf.names module

exception FabricError(message, stamp, cause=None)[source]

Bases: Exception

class Names(data_dir, laf_dir, output_dir, save, verbose)[source]

Bases: laf.settings.Settings

Manage the names of compiled LAF data items.

Data items are stored in a dictionary with keys that tell a lot about the kind of data stored under that key. Keys have the following format:

origin group kind direction ( item )

and item is a comma separated list of a variable number of components, possibly zero.

Group:

  • P: primary data items,
  • G: items for regions, nodes, edges,
  • X: xml identifiers,
  • F: features,
  • C: connectivity,
  • T: temporary during compiling.

Origin: m or a meaning main and annox resp. Indicates the source data. The value z indicates that this data is not prepared by Laf-Fabric but by auxiliary modules.

Kind: n or e meaning node and edge resp.

Direction: f or b meaning forward and backward resp.

The direction can mean the direction in which edges are followed, or the direction in which a mapping goes.

Components:

Features are items, with three components: (namespace, label, name).

In group P, G, T there are one-component items, such as (edges_from,) and (edges_to).

In group X there is only one item, and it has no components: ().

For each data item we have to know the conditions under which it has to be loaded and its data type.

The condition is a key in a dictionary of conditions. The loader determines the condition dictionary by filling in its slots with relevant components.

The data type is either array, or dict, or string.

Class methods The class methods comp and decomp and decompfull take care of the composition and decomposition of keys in meaningful bits.

Instance data and methods The instance data contains a list of datakeys, adapted to the present environment, which is based on the source, annox-es and task chosen by the user. The previous list is also remembered, so that the loader can load/unload the difference.

The instance method request_files determines the difference between previously and presently requested data items. It uses an instance method dinfo that provides all relevant information associated with a datakey, including the location and name of the corresponding data file on disk. This method is an instance method because it needs values from the current environment.

DCOMP_SEP = ','
E_ANNOT_NON = ('laf', '', 'x')
E_ANNOT_YES = ('laf', '', 'y')
apiname(dcomps)[source]
check_load_spec(load_spec, stamp)[source]
comp(dkeymin, dcomps)[source]
comp_file(dgroup, dkind, ddir, dcomps)[source]
decomp(dkey)[source]
decomp_full(dkey)[source]
deliver(computed_data, dest, data_items)[source]
dinfo(dkey)[source]
dmsg(dkey)[source]
kind_types = {False, True}
load_spec_keys = {'prepare', 'features', 'xmlids', 'primary'}
load_spec_subkeys = {'edge', 'node'}
maingroup(dgroup)[source]
orig_key(dkey)[source]
request_files(req_items, prepare_dict)[source]
request_init(req_items)[source]
set_annox()[source]

laf.settings module

class Settings(data_dir, laf_dir, output_dir, save, verbose)[source]

Bases: object

Manage the configuration.

The directory structure is built as a set of names in an environment dictionary. The method setenv builds a new structure based on user choices. Local settings can be passed as arguments to object creation, or in a config file in the current directory, or in a config file in the user’s home directory. It is possible to save these settings in the latter config file.

setenv(source=None, annox=None, task=None, zspace=None)[source]

all relevant config settings will be stored in self.env Most settings are just key - string value pairs. But the setting ‘annox’ will be a dict, keyed by the annox names passed through the annox param, and valued by dicts with annox-specific paths. The annox parameter may be None, [], ‘–’ (meaning no annox), a list of annoxes, or a string with a comma-separated series of annoxes.

laf.timestamp module

class Timestamp(log_file=None, verbose=None)[source]

Bases: object

Timed progress messages.

There are specialized methods for distinct verbosity levels: Emsg, Wmsg etc. With set_verbose you can set the verbosity of the application. Only messages with that verbosity level of lower will reach the output. You can suppress the time indication and the newline at the end.

raw_msg has complete flexibility. This method is exposed as msg in the API.

Dmsg(msg, newline=True, withtime=True)[source]
Emsg(msg, newline=True, withtime=True)[source]
Imsg(msg, newline=True, withtime=True)[source]
Nmsg(msg, newline=True, withtime=True)[source]
Smsg(msg, verbose, newline=True, withtime=True)[source]
Wmsg(msg, newline=True, withtime=True)[source]
Xmsg(msg, newline=True, withtime=True)[source]
connect_log(log_file)[source]
disconnect_log()[source]
raw_msg(msg, newline=True, withtime=True, verbose=None, error=True)[source]
reset()[source]
set_verbose(verbose)[source]
verbose_level = OrderedDict([('SILENT', -10), ('ERROR', -3), ('WARNING', -2), ('INFO', -1), ('NORMAL', 0), ('DETAIL', 1), ('DEBUG', 10)])

laf.lib module

arrayify(source_list)[source]
grouper(iterable, n, fillvalue=None)[source]

Collect data into fixed-length chunks or blocks

grouper([1,2,3,4,5], 2, 0) –> [1,2] [3,4] [5,0]

make_array_inverse(arraylist)[source]
make_inverse(mapping)[source]