Documentation

fabric

# Fabric

The main class that works the core API.

This module defines `Fabric`, which provides: - Locating and loading CF feature files - Compiling to and loading from .cfm format - Managing the core API (F, E, L, T, S, N, C)

Classes

class

Fabric

Initialize the core API for a corpus.

Initialize the core API for a corpus. Top level management of * locating CF feature files * loading and saving feature data * pre-computing auxiliary data * caching pre-computed and compressed data CF is initialized for a corpus. It will search a set of directories and catalogue all `.tf` files it finds there. These are the features you can subsequently load. Here `directories` and `subdirectories` are strings with directory names separated by newlines, or iterables of directories. Parameters ---------- locations: string | iterable of strings, optional The directories specified here are used as base locations in searching for CF feature files. In general, they will not searched directly, but certain subdirectories of them will be searched, specified by the `modules` parameter. Defaults: ~/Downloads/text-fabric-data ~/text-fabric-data ~/github/text-fabric-data So if you have stored your main CF dataset in `text-fabric-data` in one of these directories you do not have to pass a location to Fabric. modules: string | iterable of strings The directories specified in here are used as sub directories appended to the directories given by the `locations` parameter. All `.tf` files (non-recursively) in any `location/module` will be added to the feature set to be loaded in this session. The order in `modules` is important, because if a feature occurs in multiple modules, the last one will be chosen. In this way you can easily override certain features in one module by features in an other module of your choice. Default: `['']` So if you leave it out, CF will just search the paths specified in `locations`. silent: string, optional "auto" Verbosity level: "verbose", "auto", "terse", or "deep" _withGc: boolean, optional False If False, it disables the Python garbage collector before loading features. Used to experiment with performance. !!! note "`otext@` in modules" If modules contain features with a name starting with `otext@`, then the format definitions in these features will be added to the format definitions in the regular `otext` feature (which is a `tf.parameters.WARP` feature). In this way, modules that define new features for text representation, also can add new formats to the Text-API. Returns ------- object An object from which you can call up all the of methods of the core API.

Attributes

NameTypeDescription
_withGc
bannerThe banner Context-Fabric.
featuresdict[(str, Data)]Dictionary of all features that CF has found, whether loaded or not.
featuresRequestedlist[str]
good
locationRep
locations
modules
silent
versionThe version number of the CF library.

Methods

__init__(self, locations: str | Iterable[str] | None = None, modules: str | Iterable[str] | None = None, silent: str = {'cls': 'ExprName', 'member': None, 'name': 'SILENT_D'}, _withGc: bool = False) None
Parameters
  • locations: str | Iterable[str] | None= None
  • modules: str | Iterable[str] | None= None
  • silent: str
  • _withGc: bool= False
compile(self, output_dir: str | None = None, silent: str = {'cls': 'ExprName', 'member': None, 'name': 'SILENT_D'}) bool

Compile .tf files to .cfm mmap format.

Parameters
  • output_dir: str | None= None
  • silent: str
explore(self, silent: str = {'cls': 'ExprName', 'member': None, 'name': 'SILENT_D'}, show: bool = True) dict[(str, tuple[(str, ...)])] | None

Makes categorization of all features in the dataset.

Parameters
  • silent: str
  • show: bool= True
load(self, features: str | Iterable[str], add: bool = False, silent: str = {'cls': 'ExprName', 'member': None, 'name': 'SILENT_D'}) Api | bool

Loads features from disk into RAM memory.

Parameters
  • features: str | Iterable[str]
  • add: bool= False
  • silent: str
loadAll(self, silent: str = {'cls': 'ExprName', 'member': None, 'name': 'SILENT_D'}) Api | bool

Load all loadable features.

Parameters
  • silent: str
save(self, nodeFeatures: NodeFeatureDict | None = None, edgeFeatures: EdgeFeatureDict | None = None, metaData: MetaDataDict | None = None, location: str | None = None, module: str | None = None, silent: str = {'cls': 'ExprName', 'member': None, 'name': 'SILENT_D'}) bool

Saves newly generated data to disk as CF features, nodes and / or edges.

Parameters
  • nodeFeatures: NodeFeatureDict | None= None
  • edgeFeatures: EdgeFeatureDict | None= None
  • metaData: MetaDataDict | None= None
  • location: str | None= None
  • module: str | None= None
  • silent: str