Search documentation of macula

# macula_mri_graph behaviour (macula v4.4.9)

View Source

MRI Graph Behaviour

Defines the interface for MRI relationship (graph) storage. Implementations must provide relationship CRUD and traversal.

Relationships are triples: {Subject, Predicate, Object} Both forward (subject→object) and reverse (object→subject) queries should be efficient.

Built-in predicates include: - Spatial: located_at, contains, adjacent_to - Organizational: member_of, has_member, manages, managed_by, owns, owned_by - Technical: depends_on, depended_on_by, provides, provided_by, connects_to - Data: trained_on, derived_from, source_of, version_of - Taxonomic: instance_of, has_instance, subclass_of, superclass_of

Custom predicates use the format: {custom, Binary} where Binary is the predicate name

# Summary

## Types

direction/0
predicate/0
relationship/0

## Callbacks

all_related/1
classes_of/1
create_relationship/3
create_relationship/4
delete_relationship/3
get_relationship/3
instances_of/1
instances_of_transitive/1
related_from/2
related_to/2
subclasses/1
superclasses/1
traverse_transitive/3

## Functions

adapter()

Get the configured graph adapter module.

all_related(Subject)

Get all relationships from a subject.

classes_of(Instance)

Get the classes an instance belongs to.

create_relationship(Subject, Predicate, Object)

Create a relationship between two MRIs.

create_relationship(Subject, Predicate, Object, Metadata)

Create a relationship with metadata.

delete_relationship(Subject, Predicate, Object)

Delete a relationship.

get_relationship(Subject, Predicate, Object)

Get a specific relationship with its metadata.

instances_of(Class)

Get direct instances of a class.

instances_of_transitive(Class)

Get all instances of a class including subclasses (transitive).

inverse_predicate(_)

Get the inverse of a predicate (for bidirectional queries).

is_builtin_predicate(_)

Check if a predicate is a built-in predicate.

related_from(Object, Predicate)

Query what relates to Object via Predicate.

related_to(Subject, Predicate)

Query what Subject relates to via Predicate.

set_adapter(Module)

Set the graph adapter module.

subclasses(Class)

Get direct subclasses of a class.

superclasses(Class)

Get direct superclasses of a class.

traverse_transitive(Start, Predicate, Direction)

Traverse relationships transitively.

# Types

# direction/0

    -type direction() :: forward | reverse.

# predicate/0

    -type predicate() :: atom() | {custom, binary()}.

# relationship/0

    -type relationship() ::
              #{subject := macula_mri:mri(),
                predicate := predicate(),
                object := macula_mri:mri(),
                metadata => map()}.

# Callbacks

# all_related/1

    -callback all_related(Subject :: macula_mri:mri()) -> [{predicate(), macula_mri:mri()}].

# classes_of/1

(optional)

    -callback classes_of(Instance :: macula_mri:mri()) -> [macula_mri:mri()].

# create_relationship/3

    -callback create_relationship(Subject :: macula_mri:mri(),
                                  Predicate :: predicate(),
                                  Object :: macula_mri:mri()) ->
                                     ok | {error, term()}.

# create_relationship/4

    -callback create_relationship(Subject :: macula_mri:mri(),
                                  Predicate :: predicate(),
                                  Object :: macula_mri:mri(),
                                  Metadata :: map()) ->
                                     ok | {error, term()}.

# delete_relationship/3

    -callback delete_relationship(Subject :: macula_mri:mri(),
                                  Predicate :: predicate(),
                                  Object :: macula_mri:mri()) ->
                                     ok | {error, term()}.

# get_relationship/3

    -callback get_relationship(Subject :: macula_mri:mri(),
                               Predicate :: predicate(),
                               Object :: macula_mri:mri()) ->
                                  {ok, relationship()} | {error, not_found | term()}.

# instances_of/1

(optional)

    -callback instances_of(Class :: macula_mri:mri()) -> [macula_mri:mri()].

# instances_of_transitive/1

(optional)

    -callback instances_of_transitive(Class :: macula_mri:mri()) -> [macula_mri:mri()].

# related_from/2

    -callback related_from(Object :: macula_mri:mri(), Predicate :: predicate()) -> [macula_mri:mri()].

# related_to/2

    -callback related_to(Subject :: macula_mri:mri(), Predicate :: predicate()) -> [macula_mri:mri()].

# subclasses/1

(optional)

    -callback subclasses(Class :: macula_mri:mri()) -> [macula_mri:mri()].

# superclasses/1

(optional)

    -callback superclasses(Class :: macula_mri:mri()) -> [macula_mri:mri()].

# traverse_transitive/3

    -callback traverse_transitive(Start :: macula_mri:mri(), Predicate :: predicate(), Direction :: direction()) ->
                                     [macula_mri:mri()].

# Functions

# adapter()

    -spec adapter() -> module().

Get the configured graph adapter module.

# all_related(Subject)

    -spec all_related(macula_mri:mri()) -> [{predicate(), macula_mri:mri()}].

Get all relationships from a subject.

# classes_of(Instance)

    -spec classes_of(macula_mri:mri()) -> [macula_mri:mri()].

Get the classes an instance belongs to.

# create_relationship(Subject, Predicate, Object)

    -spec create_relationship(macula_mri:mri(), predicate(), macula_mri:mri()) -> ok | {error, term()}.

Create a relationship between two MRIs.

# create_relationship(Subject, Predicate, Object, Metadata)

    -spec create_relationship(macula_mri:mri(), predicate(), macula_mri:mri(), map()) ->
                                 ok | {error, term()}.

Create a relationship with metadata.

# delete_relationship(Subject, Predicate, Object)

    -spec delete_relationship(macula_mri:mri(), predicate(), macula_mri:mri()) -> ok | {error, term()}.

Delete a relationship.

# get_relationship(Subject, Predicate, Object)

    -spec get_relationship(macula_mri:mri(), predicate(), macula_mri:mri()) ->
                              {ok, relationship()} | {error, not_found | term()}.

Get a specific relationship with its metadata.

# instances_of(Class)

    -spec instances_of(macula_mri:mri()) -> [macula_mri:mri()].

Get direct instances of a class.

# instances_of_transitive(Class)

    -spec instances_of_transitive(macula_mri:mri()) -> [macula_mri:mri()].

Get all instances of a class including subclasses (transitive).

# inverse_predicate(_)

    -spec inverse_predicate(predicate()) -> predicate() | undefined.

Get the inverse of a predicate (for bidirectional queries).

# is_builtin_predicate(_)

    -spec is_builtin_predicate(predicate()) -> boolean().

Check if a predicate is a built-in predicate.

# related_from(Object, Predicate)

    -spec related_from(macula_mri:mri(), predicate()) -> [macula_mri:mri()].

Query what relates to Object via Predicate.

# related_to(Subject, Predicate)

    -spec related_to(macula_mri:mri(), predicate()) -> [macula_mri:mri()].

Query what Subject relates to via Predicate.

# set_adapter(Module)

    -spec set_adapter(module()) -> ok.

Set the graph adapter module.

# subclasses(Class)

    -spec subclasses(macula_mri:mri()) -> [macula_mri:mri()].

Get direct subclasses of a class.

# superclasses(Class)

    -spec superclasses(macula_mri:mri()) -> [macula_mri:mri()].

Get direct superclasses of a class.

# traverse_transitive(Start, Predicate, Direction)

    -spec traverse_transitive(macula_mri:mri(), predicate(), direction()) -> [macula_mri:mri()].

Traverse relationships transitively.