SQL Database Adapter

This wraps either a local or remote SQL Database

The schema is assumed to follow:

This uses the rdftab library to build an RDF-level statements table, on which numerous SQL Views are layered, providing higher level access

Initialization

If you omit a scheme and specify a filesystem path ending with .db then the SqlDatabase implementation is selected, with sqlite as a sub-scheme.

You can explicitly specify a sqlite database via a selector sqlite:path/to/sqlitefile.db

Code

class oaklib.implementations.sqldb.sql_implementation.SqlImplementation(resource: ~oaklib.resource.OntologyResource = None, strict: bool = False, _multilingual: bool = None, autosave: bool = <factory>, exclude_owl_top_and_bottom: bool = <factory>, ontology_metamodel_mapper: ~oaklib.mappers.ontology_metadata_mapper.OntologyMetadataMapper | None = None, _converter: ~curies.api.Converter | None = None, auto_relax_axioms: bool = None, cache_lookups: bool = False, property_cache: ~oaklib.utilities.keyval_cache.KeyValCache = <factory>, _edge_index: ~oaklib.indexes.edge_index.EdgeIndex | None = None, _entailed_edge_index: ~oaklib.indexes.edge_index.EdgeIndex | None = None, functional_writer: <module 'funowl.writers.FunctionalWriter' from '/home/runner/.cache/pypoetry/virtualenvs/oaklib-5bvmowLS-py3.9/lib/python3.9/site-packages/funowl/writers/FunctionalWriter.py'> = None, _association_index: ~oaklib.utilities.associations.association_index.AssociationIndex = None, normalizers: ~typing.List[~oaklib.interfaces.association_provider_interface.EntityNormalizer] = <factory>, engine: ~typing.Any = None, _session: ~typing.Any = None, _connection: ~typing.Any = None, _ontology_metadata_model: ~linkml_runtime.utils.schemaview.SchemaView = None, _prefix_map: ~typing.Mapping[str, str] = None, _information_content_cache: ~typing.Dict[~typing.Tuple, float] = None, _relationships_by_subject_index: ~typing.Dict[str, ~typing.List[~typing.Tuple[str, str, str]]] = None, max_items_for_in_clause: int = <factory>, can_store_associations: bool = False, **_kwargs)[source]

A OntologyInterface implementation that wraps a SQL Relational Database.

Currently this must be a SQLite database. PostgreSQL support is planned.

To connect, either use SqlImplementation directly:

>>> from oaklib.implementations.sqldb.sql_implementation import SqlImplementation
>>> from oaklib.resource import OntologyResource
>>> adapter = SqlImplementation(OntologyResource("tests/input/go-nucleus.db"))

or

>>> from oaklib import get_adapter
>>> adapter = get_adapter("sqlite:tests/input/go-nucleus.db")

you can also load from the semantic-sql repository:

>>> adapter = get_adapter("sqlite:obo:obi")

The schema is assumed to follow the semantic-sql schema.

This uses SQLAlchemy ORM Models:

  • Statements

  • Edge

See also:

classmethod create(resource: OntologyResource) OntologyInterface

Creates a new ontology interface from a resource

Parameters:

resource

Returns:

SQL Alchemy ORM Model

We use the SQLA Models from the semantic-sql project.

This is under-the-hood and users of oaklib don’t need to know the details. However, if you ever need to craft a custom complex query this can provide a useful way to do this.

class semsql.sqla.semsql.Statements(**kwargs)[source]

Represents an RDF triple

class semsql.sqla.semsql.Edge(**kwargs)[source]

A relation graph edge that connects two entities by a predicate. Note an edge is distinct from a statement, in that an axiom such as A SubClassOf R some B is represented as multiple statements, but is a single relation graph edge

class semsql.sqla.semsql.EntailedEdge(**kwargs)[source]

A relation graph edge that is inferred