SBNodeIndexer#

This class describes a node indexer (a list of nodes).

You can get node indexers directly from the active document using the SAMSON facade (SAMSON.getNodes()) or from a node using the SBNode.getNodes() function. To select specific nodes you can use the Node Specification Language.

Getting nodes using the SAMSON facade (SAMSON):

Getting nodes from the active document#
# get all nodes in the active document
nodeIndexer = SAMSON.getNodes()

# get all atoms in the active document
nodeIndexer = SAMSON.getNodes('node.type atom')

# the same using short names
nodeIndexer = SAMSON.getNodes('n.t a')

# you can check the size of the indexer
print(len(nodeIndexer))

Getting node’s children nodes:

Getting nodes from a node#
# get all atoms in the node
nodeIndexer = node.getNodes('node.type atom')

You can loop over the node indexer in a pythonic way:

Printing node information#
for node in nodeIndexer:
        print(node)

See also

SAMSON SDK: SBDDataGraphNodeIndexer

class samson.SBNodeIndexer(*args, **kwargs)#

Bases: pybind11_object

This class describes a node indexer.

Overloaded function.

  1. __init__(self: samson.SBNodeIndexer) -> None

Constructs a node indexer

  1. __init__(self: samson.SBNodeIndexer, initialSize: typing.SupportsInt | typing.SupportsIndex) -> None

Constructs a node indexer with a pre-allocated initialSize.

  1. __init__(self: samson.SBNodeIndexer, other: samson.SBNodeIndexer) -> None

Copy constructor

  1. __init__(self: samson.SBNodeIndexer, iterable: collections.abc.Iterable) -> None

Constructor from iterable

addNode(self: samson.SBNodeIndexer, node: samson.SBNode) int#

Add node to the indexer and return its index.

Parameters:

node (samson.SBNode) – A node

clear(self: samson.SBNodeIndexer) None#

Clears the node indexer

getIndex(self: samson.SBNodeIndexer, node: samson.SBNode) int#

Return the index associated with node.

Parameters:

node (samson.SBNode) – A node

getNode(self: samson.SBNodeIndexer, index: SupportsInt | SupportsIndex) samson.SBNode#

Returns a node with the given index.

Parameters:

index (int) – An index

getNodes(*args, **kwargs)#

Overloaded function.

  1. getNodes(self: samson.SBNodeIndexer, selectionString: str = ‘*’, visitString: str = ‘*’, includeDependencies: bool = False) -> samson.SBNodeIndexer

Return nodes collected from the indexed nodes using selectionString.

For each indexed node, this function delegates to samson.SBNode.getNodes and merges the results.

Parameters:
  • selectionString (str, default='*') – A Node Specification Language expression (SAMSON API: Node Specification Language) that describes what nodes should be selected.

  • visitString (str, default='*') – A Node Specification Language expression (SAMSON API: Node Specification Language) that describes what nodes should be visited.

  • includeDependencies (bool, default=False) – Whether to include matching dependencies that are not descendants.

Returns:

Node indexer containing the collected nodes.

Return type:

samson.SBNodeIndexer

  1. getNodes(self: samson.SBNodeIndexer, nodeIndexer: samson.SBNodeIndexer, selectionString: str = ‘*’, visitString: str = ‘*’, includeDependencies: bool = False) -> None

Append nodes collected from the indexed nodes to nodeIndexer.

For each indexed node, this function delegates to samson.SBNode.getNodes and merges the results into nodeIndexer.

Parameters:
  • nodeIndexer (samson.SBNodeIndexer) – Destination indexer. It is not cleared by this function.

  • selectionString (str, default='*') – A Node Specification Language expression (SAMSON API: Node Specification Language) that describes what nodes should be selected.

  • visitString (str, default='*') – A Node Specification Language expression (SAMSON API: Node Specification Language) that describes what nodes should be visited.

  • includeDependencies (bool, default=False) – Whether to include matching dependencies that are not descendants.

getRootNodes(self: samson.SBNodeIndexer) samson.SBNodeIndexer#

Returns a node indexer with the root nodes among the indexed nodes, i.e. the nodes that do not have indexed ascendants.

For example, if the indexed nodes contain two nodes - an atom and its direct parent node (e.g. a backbone node) - then only this parent node will be added in the resulting node indexer.

Returns:

A node indexer.

Return type:

samson.SBNodeIndexer

hasIndex(self: samson.SBNodeIndexer, node: samson.SBNode) bool#

Return True if node has an index in this indexer.

Parameters:

node (samson.SBNode) – A node

hasNode(*args, **kwargs)#

Overloaded function.

  1. hasNode(self: samson.SBNodeIndexer, node: samson.SBNode) -> bool

Return True if node is present in the indexer.

Parameters:

node (samson.SBNode) – A node

  1. hasNode(self: samson.SBNodeIndexer, selectionString: str = ‘*’, visitString: str = ‘*’, includeDependencies: bool = False) -> bool

Check whether any indexed node yields a match for selectionString.

For each indexed node, this function delegates to samson.SBNode.hasNode.

Traversal is depth-first and only visits nodes for which visitString evaluates to True. When includeDependencies is True, the check also considers matching dependencies that are not descendants of an indexed node.

Parameters:
  • selectionString (str, default='*') – A Node Specification Language expression (SAMSON API: Node Specification Language) that describes what nodes should be checked.

  • visitString (str, default='*') – A Node Specification Language expression (SAMSON API: Node Specification Language) that describes what nodes should be visited.

  • includeDependencies (bool, default=False) – Whether to include matching dependencies that are not descendants.

Returns:

True if at least one matching node is found.

Return type:

bool

Examples

Checks for the presence of atoms in a node indexer:

>>> res = node_indexer.hasNode('node.type atom')
index(self: samson.SBNodeIndexer, node: samson.SBNode) int#

Return the index associated with node.

Parameters:

node (samson.SBNode) – A node

removeNode(self: samson.SBNodeIndexer, node: samson.SBNode) int#

Remove node from the indexer.

Parameters:

node (samson.SBNode) – A node

property isEmpty#

True if the indexer is empty.

property size#

The size of the node indexer