Skip to content

cmem_client.repositories.graph_imports¤

Repository for the owl:imports relations between named graphs.

Provides GraphImportsRepository for adding and removing an import statement between two graphs, and for resolving the resulting import tree of a graph. Items are keyed by from_graph::::to_graph.

Examples:

Declare that one graph imports another and remove the relation again:

>>> from cmem_client.client import Client
>>> from cmem_client.models.graph_import import GraphImport
>>> client = Client.from_env()
>>> client.graph_imports.create_item(
...     GraphImport(
...         from_graph="https://example.org/data/",
...         to_graph="https://example.org/vocab/",
...     )
... )
>>> client.graph_imports.delete_item(
...     "https://example.org/data/::::https://example.org/vocab/"
... )

Resolve what a graph pulls in, directly and transitively:

>>> client.graph_imports.get_transitive_imports("https://example.org/data/")
>>> client.graph_imports.get_import_tree("https://example.org/data/")

Classes:

Attributes:

GRAPH_IMPORTS_CREATE_SPARQL¤

GRAPH_IMPORTS_CREATE_SPARQL = '\nPREFIX owl: <http://www.w3.org/2002/07/owl#>\n\nINSERT DATA {{\n  GRAPH <{from_graph}> {{\n    <{from_graph}> owl:imports <{to_graph}> .\n  }}\n}}\n'

GRAPH_IMPORTS_DELETE_SPARQL¤

GRAPH_IMPORTS_DELETE_SPARQL = '\nPREFIX owl: <http://www.w3.org/2002/07/owl#>\n\nDELETE DATA {{\n  GRAPH <{from_graph}> {{\n    <{from_graph}> owl:imports <{to_graph}> .\n  }}\n}}\n'

GRAPH_IMPORTS_LIST_SPARQL¤

GRAPH_IMPORTS_LIST_SPARQL = '\nPREFIX owl: <http://www.w3.org/2002/07/owl#>\n\nSELECT ?from_graph ?to_graph\nWHERE\n{\n  GRAPH ?from_graph {\n    ?from_graph owl:imports ?to_graph\n  }\n}\n'

GraphImportsCreateConfig¤

Bases: CreateConfig

Graph Imports creation configuration

Attributes:

  • model_config

GraphImportsDeleteConfig¤

Bases: DeleteConfig

Graph Imports deletion configuration.

Attributes:

  • model_config

GraphImportsRepository¤

Bases: Repository, CreateItemProtocol, DeleteItemProtocol

Repository for managing Graph Imports

Functions:

Attributes:

  • logger (Logger) – Gets the client logger

create_item¤

create_item(item, skip_if_existing=False, configuration=None)

Create (add) a new item to the repository

Parameters:

  • item (ItemType) – The item to add to the repository
  • skip_if_existing (bool) – If true, creating already existing items will be ignored
  • configuration (CreateItemConfig_contra | None) – Optional configuration

Raises:

delete_all¤

delete_all()

Delete all items from the repository

delete_item¤

delete_item(key, skip_if_missing=False, configuration=None)

Delete an item from the repository

Parameters:

  • key (str) – The key of the item to delete
  • skip_if_missing (bool) – If True, it is ignored if the deleted item even exists
  • configuration (DeleteItemConfig) – Optional configuration for deletion

Raises:

fetch_data¤

fetch_data()

Fetch new data and update the repository

get_import_tree¤

get_import_tree(graph_iri)

Get the hierarchical import tree structure for a graph.

Parameters:

  • graph_iri (str) – The IRI of the graph to retrieve the import tree for.

Returns:

  • GraphImportTree – A GraphImportTree with tree and ignored dicts mapping graph IRIs to lists of IRIs.

get_transitive_imports¤

get_transitive_imports(graph_iri)

Get the list of graphs imported by a graph, resolved transitively.

Parameters:

  • graph_iri (str) – The IRI of the graph to retrieve transitive imports for.

Returns:

  • list[str] – A flat list of graph IRIs that are transitively imported by graph_iri.

items¤

items()

Get the items of the repository

keys¤

keys()

Get the keys of the repository

logger¤

logger: logging.Logger

Gets the client logger

raise_modification_error¤

raise_modification_error(response)

Raise an exception if needed

values¤

values()

Get the values of the repository

Comments