Core Classes
This section documents the core classes of s3dgraphy that form the foundation of the library.
Graph
Graph module for s3Dgraphy, responsible for managing nodes and edges in the knowledge graph.
- class s3dgraphy.graph.Graph(graph_id, name=None, description=None, audio=None, video=None, data=None)[source]
Bases:
objectClass representing a graph containing nodes and edges.
- property indices
Lazy loading degli indici con rebuild automatico se necessario
- static validate_connection(source_node_type, target_node_type, edge_type)[source]
Validates if a connection type between two nodes is allowed by the rules.
Uses the v1.5.3 connections datamodel for validation.
- add_edge(edge_id: str, edge_source: str, edge_target: str, edge_type: str) Edge[source]
Adds an edge to the graph with connection validation.
- Parameters:
- Returns:
The added edge.
- Return type:
- Raises:
ValueError – If the source or target node does not exist or if the edge is a duplicate.
- connect_paradatagroup_propertynode_to_stratigraphic(verbose=False)[source]
Identifica le relazioni tra unità stratigrafiche e ParadataNodeGroup, poi collega direttamente le unità stratigrafiche ai PropertyNode contenuti nel ParadataNodeGroup.
Questa funzione permette due modalità di collegamento: 1. Collegamento diretto: Unità Stratigrafica -> PropertyNode (modalità già supportata nel codice esistente) 2. Collegamento indiretto: Unità Stratigrafica -> ParadataNodeGroup -> PropertyNode In questo caso, crea anche collegamenti diretti tra Unità Stratigrafica e PropertyNode
Il risultato è una rete semantica più ricca, dove ogni unità stratigrafica può accedere direttamente alle sue proprietà, indipendentemente dalla struttura organizzativa scelta dall’utente (collegamento diretto o tramite gruppo).
- find_node_by_id(node_id)[source]
Finds a node by ID.
✅ OPTIMIZATION: O(1) lookup using indices instead of O(n) iteration
- filter_nodes_by_connection_to_type(node_id, node_type)[source]
Filters nodes connected to a given node by node type.
- get_nodes_by_type(node_type)[source]
Gets all nodes of a given type.
✅ OPTIMIZATION: O(1) lookup using type index instead of O(n) iteration
- find_edge_by_nodes(source_id, target_id)[source]
Cerca un arco basato sugli ID dei nodi sorgente e destinazione.
- get_connected_node_by_type(node, node_type)[source]
Ottiene un nodo collegato di un determinato tipo.
- get_connected_epoch_node_by_edge_type(node, edge_type: str)[source]
Ottiene il nodo EpochNode connesso tramite un arco di tipo specifico.
- Parameters:
- Returns:
Il nodo EpochNode connesso, oppure None se non trovato.
- Return type:
EpochNode | None
✅ OPTIMIZATION: O(1) lookup using composite index instead of O(E) iteration
- get_connected_epoch_nodes_list_by_edge_type(node, edge_type: str)[source]
Ottiene una lista di nodi EpochNode connessi tramite un arco di tipo specifico.
- Parameters:
- Returns:
Lista di nodi EpochNode connessi.
- Return type:
List[EpochNode]
✅ OPTIMIZATION: O(1) lookup using composite index instead of O(E) iteration
- calculate_chronology(graph=None)[source]
Calculate chronology for all stratigraphic nodes in this graph.
Protocol (hierarchy: specific > local > general): 1. Assign base times from epoch associations (has_first_epoch, survive_in_epoch) 2. Override with specific property values (absolute_time_start, absolute_time_end) 3. Propagate TPQ/TAQ constraints through stratigraphic relations
- Parameters:
graph – Deprecated, ignored. Kept for backwards compatibility.
- get_property(node, rule_id, default=None)[source]
Resolve a propagative property on
nodevia the registered rule.Convenience wrapper around
s3dgraphy.resolvers.resolve(). Walks the 3-level hierarchy (node > swimlane > graph) and returns the first non-null value, ordefault.Example:
author = graph.get_property(node, "author") start = graph.get_property(node, "absolute_time_start")
- Parameters:
node – The node to resolve the property for.
rule_id – Id of a registered PropagationRule (see
s3dgraphy.resolvers.list_rules()).default – Value to return when no level yields a non-null value.
- Raises:
KeyError – If
rule_idis not registered.
- filter_nodes_by_time_range(*args)[source]
Filter stratigraphic nodes that overlap with a given time range.
- Accepts:
filter_nodes_by_time_range(start_time, end_time) - new API filter_nodes_by_time_range(graph, start_time, end_time) - old API (graph ignored)
- get_connected_nodes_by_filters(node, target_node_type='all', edge_type='all')[source]
Ottiene una lista di nodi collegati in base ai filtri specificati su target_node_type ed edge_type.
- get_connected_nodes_by_edge_type(node_id, edge_type)[source]
Ottiene tutti i nodi connessi a un nodo specifico tramite un tipo di edge.
- Parameters:
- Returns:
Lista di nodi connessi attraverso il tipo di edge specificato
- Return type:
✅ OPTIMIZATION: O(1) lookup using composite index instead of O(E) iteration
- get_property_nodes_for_node(node_id)[source]
Ottiene tutti i nodi proprietà connessi a un nodo specifico.
- get_combiner_nodes_for_property(property_node_id)[source]
Ottiene tutti i nodi combiner connessi a un nodo proprietà.
- Parameters:
property_node_id (str) – ID del nodo proprietà
- Returns:
Lista di nodi combiner connessi
- Return type:
✅ OPTIMIZATION: O(1) lookup using source index instead of O(E) iteration
- get_extractor_nodes_for_node(node_id)[source]
Ottiene tutti i nodi extractor connessi a un nodo (proprietà o combiner).
- get_document_nodes_for_extractor(extractor_node_id)[source]
Ottiene tutti i nodi documento connessi a un nodo extractor.
- get_paradata_chain(strat_node_id)[source]
Ottiene la catena completa di paradata per un nodo stratigrafico.
- refine_edge_types(verbose=False)[source]
Refines placeholder edge types to more specific semantic types based on the types of connected nodes.
This method applies the same logic as the GraphML importer’s enhance_edge_type() to edges that are already in memory, transforming placeholders into semantic edge types according to the s3Dgraphy datamodel.
Refines both: - ‘has_data_provenance’ (placeholder for GraphML ‘dashed’ edges) - ‘generic_connection’ (placeholder for runtime-created edges)
Base Node
- s3dgraphy.nodes.base_node.load_json_mapping(filename)[source]
Load JSON mapping data from a specified file.
- class s3dgraphy.nodes.base_node.Node(node_id, name, description='')[source]
Bases:
objectBase class to represent a node in the graph.
- node_type_map = {'ActivityNodeGroup': <class 's3dgraphy.nodes.group_node.ActivityNodeGroup'>, 'BR': <class 's3dgraphy.nodes.stratigraphic_node.ContinuityNode'>, 'EpochNode': <class 's3dgraphy.nodes.epoch_node.EpochNode'>, 'Group': <class 's3dgraphy.nodes.group_node.GroupNode'>, 'LocationNodeGroup': <class 's3dgraphy.nodes.group_node.LocationNodeGroup'>, 'ParadataNode': <class 's3dgraphy.nodes.paradata_node.ParadataNode'>, 'ParadataNodeGroup': <class 's3dgraphy.nodes.group_node.ParadataNodeGroup'>, 'RSF': <class 's3dgraphy.nodes.stratigraphic_node.ReusedSpecialFind'>, 'SE': <class 's3dgraphy.nodes.stratigraphic_node.StratigraphicEventNode'>, 'SF': <class 's3dgraphy.nodes.stratigraphic_node.SpecialFindUnit'>, 'StratigraphicNode': <class 's3dgraphy.nodes.stratigraphic_node.StratigraphicNode'>, 'TSU': <class 's3dgraphy.nodes.stratigraphic_node.TransformationStratigraphicUnit'>, 'TimeBranchNodeGroup': <class 's3dgraphy.nodes.group_node.TimeBranchNodeGroup'>, 'UL': <class 's3dgraphy.nodes.stratigraphic_node.WorkingUnit'>, 'US': <class 's3dgraphy.nodes.stratigraphic_node.StratigraphicUnit'>, 'USD': <class 's3dgraphy.nodes.stratigraphic_node.DocumentaryStratigraphicUnit'>, 'USN': <class 's3dgraphy.nodes.stratigraphic_node.NegativeStratigraphicUnit'>, 'USVn': <class 's3dgraphy.nodes.stratigraphic_node.NonStructuralVirtualStratigraphicUnit'>, 'USVs': <class 's3dgraphy.nodes.stratigraphic_node.StructuralVirtualStratigraphicUnit'>, 'VSF': <class 's3dgraphy.nodes.stratigraphic_node.VirtualSpecialFindUnit'>, 'author': <class 's3dgraphy.nodes.author_node.AuthorNode'>, 'author_ai': <class 's3dgraphy.nodes.author_node.AuthorAINode'>, 'combiner': <class 's3dgraphy.nodes.combiner_node.CombinerNode'>, 'document': <class 's3dgraphy.nodes.document_node.DocumentNode'>, 'embargo': <class 's3dgraphy.nodes.embargo_node.EmbargoNode'>, 'extractor': <class 's3dgraphy.nodes.extractor_node.ExtractorNode'>, 'geo_position': <class 's3dgraphy.nodes.geo_position_node.GeoPositionNode'>, 'graph': <class 's3dgraphy.nodes.graph_node.GraphNode'>, 'license': <class 's3dgraphy.nodes.license_node.LicenseNode'>, 'link': <class 's3dgraphy.nodes.link_node.LinkNode'>, 'property': <class 's3dgraphy.nodes.property_node.PropertyNode'>, 'representation_model': <class 's3dgraphy.nodes.representation_node.RepresentationModelNode'>, 'representation_model_doc': <class 's3dgraphy.nodes.representation_node.RepresentationModelDocNode'>, 'representation_model_sf': <class 's3dgraphy.nodes.representation_node.RepresentationModelSpecialFindNode'>, 'representation_node': <class 's3dgraphy.nodes.representation_node.RepresentationNode'>, 'serSU': <class 's3dgraphy.nodes.stratigraphic_node.SeriesOfStratigraphicUnit'>, 'serUSD': <class 's3dgraphy.nodes.stratigraphic_node.SeriesOfDocumentaryStratigraphicUnit'>, 'serUSVn': <class 's3dgraphy.nodes.stratigraphic_node.SeriesOfNonStructuralVirtualStratigraphicUnit'>, 'serUSVs': <class 's3dgraphy.nodes.stratigraphic_node.SeriesOfStructuralVirtualStratigraphicUnit'>, 'unknown': <class 's3dgraphy.nodes.stratigraphic_node.UnknownNode'>}
- node_type = 'Node'
Edge
- class s3dgraphy.edges.edge.Edge(edge_id, edge_source, edge_target, edge_type)[source]
Bases:
objectRepresents an edge in the graph, connecting two nodes with a specific relationship type.
- to_dict()[source]
Converts the Edge instance to a dictionary format.
- Returns:
A dictionary representation of the edge, including its attributes.
- Return type:
Multi Graph Manager
- class s3dgraphy.multigraph.multigraph.MultiGraphManager[source]
Bases:
object- update_graph_metadata(current_graph_id, new_graph_id=None, new_name=None)[source]
Update the ID and/or name of a graph within the MultiGraphManager.
- Parameters:
- Raises:
ValueError – If the graph ID to update does not exist or if the new ID is already taken.