sage.database.core package

Submodules

sage.database.core.dataset module

class sage.database.core.dataset.Dataset(name: str, description: str, graphs: Dict[str, sage.database.core.graph.Graph], public_url: Optional[str] = None, default_query: Optional[str] = None, analytics=None, stateless=True, statefull_manager: Optional[sage.database.statefull.statefull_manager.StatefullManager] = None)

Bases: object

A collection of RDF graphs.

Args:
  • name: Name of the RDF dataset.

  • description: Description of the RDF dataset.

  • graphs: RDF Graphs of the dataset.

  • public_url: (Optional) URL that host the SaGe server

  • default_query: (Optional) A default query that can be executed against this dataset.

  • analytics: Google analytics credentials.

  • stateless: True if the dataset is queried in sateless mode, False if its is queried in statefull mode.

  • statefull_manager: StatefullManager used to store saved plan (required in statefull mode).

property analytics
property default_query
describe(url: str) → Iterable[Dict[str, str]]

Get a generator over dataset descriptions.

Args:
  • url: Public URL of the dataset.

Yields:

Dataset descriptions as dictionnaries.

get_graph(graph_uri: str) → Optional[sage.database.core.graph.Graph]

Get a RDF graph given its URI, otherwise returns None.

Args:
  • graph_uri: URI of the RDF graph to access.

Returns:

The RDF Graph associated with the URUI or None if it was not found.

has_graph(graph_uri: str) → bool

Test if a RDF graph exists in the RDF dataset.

Args:
  • graph_uri: URI of the RDF graph to access.

Returns:

True if the RDF graph exists in the RDF dataset, False otherwise.

property is_stateless
property long_description
property maintainer
property name
property public_url
property statefull_manager

sage.database.core.graph module

class sage.database.core.graph.Graph(uri: str, name: str, description: str, connector: sage.database.db_connector.DatabaseConnector, quantum=75, max_results=inf, default_queries: List[dict] = [])

Bases: object

A RDF Graph with a dedicated backend used to search/store RDF triples.

Args:
  • uri: URI of the RDF Graph.

  • name: Name of the RDF Graph.

  • description: Description of the RDF Graph.

  • connector: Database connector used to search/store RDF triples in this graph.

  • quantum: Time quantum associated with this graph.

  • max_results: Maximum number of results per query when executing a query with this graph.

  • default_queries: List of queries that can be executed with this graph.

abort() → None

Abort any ongoing transaction (at the database level).

commit() → None

Commit any ongoing transaction (at the database level).

connector() → sage.database.db_connector.DatabaseConnector

Get the underlying DatabaseConnector for this dataset.

delete(subject: str, predicate: str, obj: str)

Delete a RDF triple from the RDF graph.

Args:
  • subject: Subject of the RDF triple.

  • predicate: Predicate of the RDF triple.

  • obj: Object of the RDF triple.

describe(url: str) → dict

Describe the RDF Dataset in JSON-LD format.

property description
property example_queries
get_query(q_id: str) → Optional[str]

Get an example SPARQL query associated with the graph, or None if it was not found

insert(subject: str, predicate: str, obj: str)

Insert a RDF triple into the RDF graph.

Args:
  • subject: Subject of the RDF triple.

  • predicate: Predicate of the RDF triple.

  • obj: Object of the RDF triple.

property max_results
property name
property nb_triples
property quota
search(subject: str, predicate: str, obj: str, last_read: Optional[str] = None, as_of: Optional[datetime.datetime] = None) → Tuple[sage.database.db_iterator.DBIterator, int]

Get an iterator over all RDF triples matching a triple pattern.

Args:
  • subject: Subject of the triple pattern.

  • predicate: Predicate of the triple pattern.

  • object: Object of the triple pattern.

  • last_read: A RDF triple ID. When set, the search is resumed for this RDF triple.

  • as_of: A version timestamp. When set, perform all reads against a consistent snapshot represented by this timestamp.

Returns:

A tuple (iterator, cardinality), where iterator is a Python iterator over RDF triples matching the given triples pattern, and cardinality is the estimated cardinality of the triple pattern.

Example:
>>> iterator, cardinality = graph.search('?s', 'http://xmlns.com/foaf/0.1/name', '?name')
>>> print(f"The triple pattern '?s foaf:name ?o' matches {cardinality} RDF triples")
>>> for s, p, o in iterator:
>>>   print(f"RDF Triple {s} {p} {o}")
property uri

sage.database.core.rdf_config module

sage.database.core.rdf_config.load_config(config_file: str, format='ttl') → sage.database.core.dataset.Dataset

Parse a SaGe configuration file written in RDF and load the corresponding RDF dataset.

Args:
  • config_file: Path to the SaGe configuration file (in RDF format) to load.

  • format: Format of the RDF configuration file (ttl, nt, n3). Defaults to Turtle (ttl).

Returns:

A RDF dataset built according to the input configuration file.

sage.database.core.yaml_config module

sage.database.core.yaml_config.load_config(config_file: str) → sage.database.core.dataset.Dataset

Parse a SaGe configuration file written in YAML and load the corresponding RDF dataset.

Args:
  • config_file: Path to the SaGe configuration file (in YAML format) to load.

Returns:

A RDF dataset built according to the input configuration file.

Module contents