Utilities

s3dgraphy.utils.utils.debug_graph_structure(graph, node_id=None, max_depth=5, current_depth=0)[source]

Stampa informazioni dettagliate sulla struttura del grafo. Se node_id è specificato, si concentra sulle relazioni di quel nodo.

Parameters:
  • graph – Il grafo da analizzare

  • node_id – ID del nodo su cui concentrarsi (opzionale)

  • max_depth – Profondità massima di ricorsione

  • current_depth – Profondità corrente di ricorsione

s3dgraphy.utils.utils.convert_shape2type(yedtype, border_style, border_type='line')[source]

Converts YED node shape and border style to a specific stratigraphic node type.

Parameters:
  • yedtype (str) – The shape type of the node in YED.

  • border_style (str) – The border color of the node.

  • border_type (str) – The border line type (‘line’, ‘dashed’, etc.).

Returns:

A tuple with a short code for the node type and an extended description.

Return type:

tuple

s3dgraphy.utils.utils.get_stratigraphic_node_class(stratigraphic_type)[source]

Returns the stratigraphic node class corresponding to the specified type.

Parameters:

stratigraphic_type (str) – The type of stratigraphic unit.

Returns:

The corresponding stratigraphic node class.

Return type:

class

s3dgraphy.utils.utils.get_material_color(matname, rules_path=None)[source]

Ottiene i valori RGB per un dato tipo di materiale dal file di configurazione.

Parameters:
  • matname (str) – Nome del materiale/tipo di unità stratigrafica

  • rules_path (str, optional) – Percorso al file JSON delle regole. Se None, usa il path di default.

Returns:

(R, G, B, A) con valori tra 0 e 1 o None se il nodo non prevede un materiale

Return type:

tuple

s3dgraphy.utils.utils.get_document_vocabularies()[source]

Derive the three canonical Master-Document vocabularies from em_visual_rules.json.

Returns (DOCUMENT_ROLES, DOCUMENT_CONTENT_NATURES, DOCUMENT_GEOMETRIES) as tuples, reading from:

  • document_roles → keys (e.g. analytical, comparative)

  • document_content_natures → keys (e.g. 2d_object)

  • document_variant_styles → keys excluding default and any _comment entry (e.g. reality_based, observable, asserted)

The JSON is the single source of truth for the Master-Document classification vocabulary; adding a new value there flows through to constructor validation and UI dropdowns automatically.

s3dgraphy.utils.utils.get_document_variant_style(variant_key: str) → dict[source]

Return the render-style dict for a DocumentNode variant key.

In EM 1.6 variant_key is a geometry value ("reality_based", "observable", "asserted") or "default" when the document has no RM — see DocumentNode.variant_style_key().

The returned dict includes at least border_color, border_style and border_width; callers consume whichever they need to emit yEd XML. An unknown key falls back to "default" so an exporter is never left without a style.

s3dgraphy.utils.utils.get_original_node_id(node)[source]

Recupera l’ID originale di un nodo.

Parameters:

node – Il nodo da cui estrarre l’ID originale

Returns:

L’ID originale o l’ID corrente se non disponibile

Return type:

str

s3dgraphy.utils.utils.get_original_node_name(node)[source]

Recupera il nome originale di un nodo (senza prefisso del grafo).

Parameters:

node – Il nodo da cui estrarre il nome originale

Returns:

Il nome originale o il nome corrente se non disponibile

Return type:

str

s3dgraphy.utils.utils.get_graph_code_from_node(node)[source]

Estrae il codice del grafo da un nodo.

Parameters:

node – Il nodo da cui estrarre il codice

Returns:

Il codice del grafo o None se non disponibile

Return type:

str

s3dgraphy.utils.utils.manage_id_prefix(name: str, graph_code: str = None, action: str = 'add', separator: str = '.') → str[source]

Add or remove graph code prefix from element names.

This utility is useful for managing unique names when working with multiple graphs, especially when mapping to external systems with unique name constraints (e.g., 3D object names in Blender, database primary keys, file systems).

The function handles edge cases gracefully: - Adding a prefix when one already exists (replaces old prefix) - Removing prefix when none exists (returns name unchanged) - Handling empty or None values

Parameters:
  • name (str) – The name to modify

  • graph_code (str, optional) – The graph code to use as prefix. If None and action=’remove’, removes any existing prefix. Defaults to None.

  • action (str) – Operation to perform: ‘add’ or ‘remove’. Defaults to ‘add’.

  • separator (str) – Character(s) between prefix and name. Defaults to ‘.’.

Returns:

The modified name

Return type:

str

Raises:

ValueError – If action is not ‘add’ or ‘remove’

Examples

>>> manage_id_prefix('US001', 'VDL16', 'add')
'VDL16.US001'
>>> manage_id_prefix('VDL16.US001', 'VDL16', 'remove')
'US001'
>>> manage_id_prefix('GT15.US001', None, 'remove')
'US001'
>>> manage_id_prefix('GT15.US001', 'VDL16', 'add')
'VDL16.US001'
>>> manage_id_prefix('US001', None, 'add')
'US001'
>>> manage_id_prefix('', 'VDL16', 'add')
''
s3dgraphy.utils.utils.get_base_name(name: str, separator: str = '.') → str[source]

Convenience function to extract base name without prefix.

This is a wrapper around manage_id_prefix with action=’remove’.

Parameters:
  • name (str) – The name potentially containing a prefix

  • separator (str) – Character(s) between prefix and name. Defaults to ‘.’.

Returns:

The base name without prefix

Return type:

str

Examples

>>> get_base_name('VDL16.US001')
'US001'
>>> get_base_name('US001')
'US001'
s3dgraphy.utils.utils.add_graph_prefix(name: str, graph_code: str, separator: str = '.') → str[source]

Convenience function to add graph code prefix to a name.

This is a wrapper around manage_id_prefix with action=’add’.

Parameters:
  • name (str) – The name to add prefix to

  • graph_code (str) – The graph code to use as prefix

  • separator (str) – Character(s) between prefix and name. Defaults to ‘.’.

Returns:

The name with prefix added

Return type:

str

Examples

>>> add_graph_prefix('US001', 'VDL16')
'VDL16.US001'
s3dgraphy.utils.utils.get_ai_prompt(language: str = None, include_validation: bool = True, include_checklist: bool = True, include_stratigraphy_only: bool = False, documents_folder: str = None, document_list: list = None, dosco_in_place: bool = True, ai_has_filesystem_access: bool = True) → str[source]

Build and return the StratiMiner extraction prompt (v5.1 schema).

Reads StratiMiner_Extraction_Prompt.md bundled inside the s3dgraphy package and produces a ready-to-paste prompt that instructs an AI assistant (Claude, ChatGPT, Gemini, …) to output a single em_data.xlsx file with the 5 typed sheets (Units, Epochs, Claims, Authors, Documents).

The prompt is now fully written in English: meta-instructions are universal, while the AI’s textual output (VALUE, EXTRACTOR excerpts, COMBINER_REASONING) is controlled by the language argument, substituted at the [OUTPUT_LANGUAGE] placeholder inside the prompt.

Parameters:
  • language – Output language for the values the AI writes into the xlsx (VALUE, EXTRACTOR, COMBINER_REASONING, DISPLAY_NAME). None / empty / “the same as the original document” → the AI is instructed to preserve each document’s original language on a per-claim basis.

  • include_validation – Include the embedded Python validation script. Default True.

  • include_checklist – Include the end-of-session checklist. Default True.

  • include_stratigraphy_only – Include the STRATIGRAPHY_ONLY appendix that describes the minimal flow for pre-existing archaeological databases (curator as sole author, no paradata chain). Default False.

  • documents_folder – Optional path to a folder of source PDFs; when provided, appended to the SOURCES PROVIDED section so the AI knows where to look.

  • document_list – Optional pre-catalogued document descriptors (each either a string or a dict with id / title / path).

  • dosco_in_place – When True (default) the AI renames files in place inside documents_folder with the D.NN_ prefix and uses the folder as the DosCo. When False the AI must treat the folder as read-only and produce the document catalog without actually renaming — the user will copy+rename offline.

  • ai_has_filesystem_access – When True (default) the AI is instructed to enumerate and read files from documents_folder. When False, the AI is told it won’t have filesystem access and should ask the user to upload the files into the conversation directly, with a data-sovereignty disclaimer.

Returns:

The assembled prompt ready to paste into an AI assistant.

Return type:

str

Raises:

FileNotFoundError – If the bundled prompt file cannot be located.

Visual Layout

Module for generating visual layouts for s3Dgraphy graphs using NetworkX.

This module provides functionality to generate hierarchical X, Y coordinates for nodes within a graph using NetworkX.

s3dgraphy.utils.visual_layout.generate_layout(graph: Graph)[source]

Generates X, Y coordinates for nodes in a graph based on a hierarchical layout.

Parameters:

graph – An instance of the Graph class containing nodes and edges.

Returns:

A dictionary with node IDs as keys and (x, y) tuples as values representing node coordinates.

Raises:

ImportError – If NetworkX is not installed.