modules/rdf/store.zzm

rdf-0.0.3 documentation

NAME

rdf/store - std/db-backed RDF quad store.

SYNOPSIS

  from rdf/store import RDFStore;
  from rdf/term import rdf_iri, rdf_literal, rdf_quad;

  let store := RDFStore.temp();
  store.install_schema();
  store.add_quad(rdf_quad(
      rdf_iri("http://example.com/s"),
      rdf_iri("http://example.com/p"),
      rdf_literal("value"),
  ));

  let quads := store.find(rdf_iri("http://example.com/s"));

DESCRIPTION

RDFStore stores RDF quads in relational tables managed through std/db. Terms are interned, quads are indexed for lookup, and all graph operations use RDF term identity rather than object identity. The schema must be installed before use.

EXPORTS

Classes

  • RDFStore

    Construct with new RDFStore(dbh: dbh) for SQLite or with an explicit backend of sqlite, mysql, or postgresql. prefix controls the table name prefix and defaults to rdf_.

    • temp()

      Returns new RDFStore(dbh: DB.temp()).

    • install_schema()

      Creates the store tables and indexes if needed.

    • schema_version()

      Returns the installed schema version, or 0 if the schema is absent.

    • verify_schema(Boolean strict := true)

      Checks that required schema objects exist. Throws on failure when strict is true; otherwise returns false.

    • drop_schema()

      Drops the store tables for this prefix.

    • begin(), commit(), rollback()

      Transaction helpers delegated to the database handle.

    • with_transaction(Function todo)

      Runs todo inside a transaction, committing on success and rolling back on exception.

    • add_term(term)

      Interns an RDF term and returns its database id.

    • term_for_key(String key)

      Returns the RDF term previously interned for key, or null.

    • add_quad(RDFQuad quad), add_quads(Array quads)

      Adds one or more quads. Duplicate quads are ignored by the store schema.

    • add_quads_bulk(Array quads)

      Adds many quads inside a transaction.

    • remove_quad(RDFQuad quad), remove_quads(Array quads)

      Removes one or more exact quads.

    • remove_match(subject := null, predicate := null, object := null, graph := null)

      Removes quads matching the supplied RDF term pattern. null is a wildcard.

    • clear()

      Removes every quad.

    • clear_graph(graph := null)

      Removes quads in the supplied graph, or the default graph when omitted.

    • graph_names()

      Returns named graph terms present in the store.

    • graph_exists(graph := null)

      Returns whether the supplied graph has any quads.

    • copy_graph(source := null, target := null)

      Copies all quads from source to target.

    • add_graph(source := null, target := null)

      Adds quads from source into target without clearing target.

    • move_graph(source := null, target := null)

      Copies then clears source.

    • replace_graph(graph := null, Array quads := [])

      Clears graph and inserts the supplied quads into it.

    • merge_store(RDFStore other)

      Adds all quads from another store.

    • count_quads(), count_terms()

      Return store counts.

    • statistics()

      Returns a dictionary of store counts and graph information.

    • diagnostics()

      Returns schema and backend diagnostic information.

    • explain_find(subject := null, predicate := null, object := null, graph := null)

      Returns a description of the lookup path selected for a pattern.

    • explicit_find(subject := null, predicate := null, object := null, graph := null)

      Returns matching stored quads without entailment.

    • find(subject := null, predicate := null, object := null, graph := null)

      Returns matching quads. Subclasses may add inferred quads.

    • serialize(serializer := null)

      Serializes all quads in the store. Defaults to NQuadsSerializer when no serializer object is supplied.

    • serialize_to(Path path, serializer := null)

      Serializes all quads in the store to path. Defaults to NQuadsSerializer when no serializer object is supplied.

COPYRIGHT AND LICENCE

rdf/store is copyright Toby Inkster.

It is free software; you may redistribute it and/or modify it under the terms of either the Artistic License 1.0 or the GNU General Public License version 2.