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):
# 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:
# get all atoms in the node
nodeIndexer = node.getNodes('node.type atom')
See also
SAMSON SDK: Node Specification Language
You can loop over the node indexer in a pythonic way:
for node in nodeIndexer:
print(node)
See also
SAMSON SDK: SBDDataGraphNodeIndexer
- class samson.SBNodeIndexer(*args, **kwargs)#
Bases:
pybind11_objectThis class describes a node indexer.
Overloaded function.
__init__(self: samson.SBNodeIndexer) -> None
Constructs a node indexer
__init__(self: samson.SBNodeIndexer, initialSize: typing.SupportsInt | typing.SupportsIndex) -> None
Constructs a node indexer with a pre-allocated
initialSize.__init__(self: samson.SBNodeIndexer, other: samson.SBNodeIndexer) -> None
Copy constructor
__init__(self: samson.SBNodeIndexer, iterable: collections.abc.Iterable) -> None
Constructor from iterable
- addNode(self: samson.SBNodeIndexer, node: samson.SBNode) int#
Add
nodeto 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.
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.getNodesand 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:
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.getNodesand merges the results intonodeIndexer.- 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:
- hasIndex(self: samson.SBNodeIndexer, node: samson.SBNode) bool#
Return
Trueifnodehas an index in this indexer.- Parameters:
node (samson.SBNode) – A node
- hasNode(*args, **kwargs)#
Overloaded function.
hasNode(self: samson.SBNodeIndexer, node: samson.SBNode) -> bool
Return
Trueifnodeis present in the indexer.- Parameters:
node (samson.SBNode) – A node
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
visitStringevaluates toTrue. WhenincludeDependenciesisTrue, 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:
Trueif 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
nodefrom the indexer.- Parameters:
node (samson.SBNode) – A node
- property isEmpty#
Trueif the indexer is empty.
- property size#
The size of the node indexer