Documentation

node

# Mappings from nodes to values.

Every node feature is logically a mapping from nodes to values, string or integer.

A feature object gives you methods that you can pass a node and that returns its value for that node.

It is easiest to think of all node features as a dictionary keyed by nodes.

However, some features have an optimised representation, and do not have a dictionary underneath.

But you can still iterate over the data of a feature as if it were a dictionary: `cfabric.nodefeature.NodeFeature.items`

Classes

class

NodeFeature

Provides access to (node) feature data.

Provides access to (node) feature data. For feature `fff` it is the result of `F.fff` or `Fs('fff')`. Supports both dict-based storage (.tf loading) and mmap-based backends (.cfm loading) (StringPool for string features, IntFeatureArray for int features).

Attributes

NameTypeDescription
_cached_datadict[(int, str | int)] | None
_data
_is_mmap
api
datadict[(int, str | int)]Get data as dict (for backward compatibility).
metaMetadata of the feature.

Methods

__init__(self, api: Api, metaData: dict[(str, str)], data: dict[(int, str | int)] | StringPool | IntFeatureArray) None
Parameters
  • api: Api
  • metaData: dict[(str, str)]
  • data: dict[(int, str | int)] | StringPool | IntFeatureArray
freqList(self, nodeTypes: set[str] | None = None) tuple[(tuple[(str | int, int)], ...)]

Frequency list of the values of this feature.

Parameters
  • nodeTypes: set[str] | None= None
items(self) Iterator[tuple[(int, str | int)]]

A generator that yields the items of the feature, seen as a mapping.

s(self, val: str | int) tuple[(int, ...)]

Query all nodes having a specified feature value.

Parameters
  • val: str | int
v(self, n: int) str | int | None

Get the value of a feature for a node.

Parameters
  • n: int
class

NodeFeatures