chrontext.chrontext

class Engine:

The hybrid query engine of chrontext. Initialize Engine using: - A SPARQL Database: either in the form of a SPARQL endpoint or an embedded Oxigraph SPARQL database - A Timeseries Database: one of the supported databases: Google Cloud BigQuery or OPC UA HA

Engine( sparql_endpoint: str = None, sparql_embedded_oxigraph: chrontext.chrontext.SparqlEmbeddedOxigraph = None, timeseries_bigquery_db: chrontext.chrontext.TimeseriesBigQueryDatabase = None, timeseries_opcua_db: chrontext.chrontext.TimeseriesOPCUADatabase = None)

Construct a new hybrid query engine. Specify exactly one of sparql_endpoint and sparql_embedded_oxigraph. Specify exactly one of timeseries_bigquery_db and timeseries_opcua_db

Parameters
def init(self) -> None:

Initialize the hybrid query engine.

Returns
def query(self, query: str) -> polars.dataframe.frame.DataFrame:
Parameters
  • query: The SPARQL query.
Returns

The query result.

class TimeseriesTable:

TimeseriesTable, which maps an SQL table to the chrontext predicates, so that they can be queried as part of a virtual knowledge graph.

TimeseriesTable( resource_name: str, time_series_table: str, value_column: str, timestamp_column: str, identifier_column: str, schema: str = None, year_column: str = None, month_column: str = None, day_column: str = None)

Create a new TimeseriesTable, which maps an SQL table to the chrontext predicates.

Parameters
  • **resource_name: Name of the resource. This is the object of the ct**: hasResource-property.
  • schema: In BigQuery, this is the data set id, otherwise the name of the database schema.
  • time_series_table: Table containing timeseries data.
  • **value_column: Column containing the values. This is the object of the ct**: hasValue-property.
  • **timestamp_column: Column containing the timestamps. This is the object of the ct**: hasTimestamp-property.
  • **identifier_column: Column containing the identity of the timeseries. This is the object of the ct**: hasExternalId-property.
  • year_column: Optionally the column containing the year of the timestamp, used for parititioning.
  • month_column: Optionally the column containing the day of the timestamp, used for parititioning.
  • day_column: Optionally the column containing the day of the timestamp, used for parititioning.
class TimeseriesBigQueryDatabase:

BigQuery containing timeseries data.

TimeseriesBigQueryDatabase(tables: List[chrontext.chrontext.TimeseriesTable], key: str)

Create a new mapping to a BigQuery database containing timeseries data.

Parameters
  • tables: The referenced tables.
  • key: Path to service account JSON key with credentials.
class TimeseriesOPCUADatabase:

OPC UA History Access Endpoint.

TimeseriesOPCUADatabase()

Initialize the OPC UA History Access endpoint.

class SparqlEmbeddedOxigraph:

Embedded oxigraph SPARQL database, stored in a local folder.

SparqlEmbeddedOxigraph(ntriples_file: str, path: str = None)

Initialize from NTriples or open an embedded SPARQL oxigraph from a path. If you want to re-initialize the database, simply delete the folder.

Parameters
  • ntriples_file: The path of the NTriples (.nt) file that should be loaded into the embedded database.
  • path: The path (a folder) where the embedded oxigraph should be stored.