← All compilation units

Flyology_N3.Model

Description

The N3 term model.

Terms are stored the way the RDF model stores them: one flat vector of nodes in child-before-parent order, with every reference an index. A formula holding statements holding terms holding formulas is mutually recursive, and a flat vector removes the recursion instead of managing it -- no cycle is representable, and a whole term is one allocation.

Append

procedure Append (Into : in out Builder; Value : Statement)

Add a formula statement.

Parameters
Into

Builder to extend

Value

Statement to add

Append

procedure Append (Into : in out Builder; Value : Term)

Add a list element.

Parameters
Into

Builder to extend

Value

Element to add

Append

procedure Append
  (Into : in out Builder; Subject, Predicate, Object : Term)

Add a formula statement assembled from its parts where it lands. Building the statement first and then adding it would copy every node of all three parts a second time.

Parameters
Into

Builder to extend

Subject

Subject term

Predicate

Predicate term

Object

Object term

Builder

type Builder is limited private;

Accumulates the parts of a list or a formula.

Terms are indefinite, so a sequence of them cannot be an array, and a container instantiated over them here would be a container over a type whose completion has not been seen. A builder sidesteps both, and holds the flat nodes directly rather than a sequence of whole terms that would only be spliced together afterwards.

Count

function Count (Value : Builder) return Natural

Report how many parts have been added.

Parameters
Value

Builder to measure

Return value

Part count

Create

function Create (Subject, Predicate, Object : Term) return Statement

Build a statement.

Parameters
Subject

Subject term

Predicate

Predicate term

Object

Object term

Return value

The corresponding statement

Element

function Element (Value : Term; Index : Positive) return Term

Return one element of a list.

Parameters
Value

Term to inspect

Index

One-based element position

Return value

The element

Raised exceptions
Invalid_Term

Value is not a list

Empty_Formula

function Empty_Formula return Term

The empty formula, which N3 writes as {}.

Return value

A formula holding no statements

Formula

function Formula (Items : in out Builder) return Term

Build a formula from accumulated statements. The parts move into the term rather than being copied, which is why the builder is left empty rather than reusable.

Parameters
Items

Builder holding the statements, in order; emptied

Return value

The corresponding N3 term

Raised exceptions
Invalid_Term

The result would exceed Maximum_Depth

From_RDF

function From_RDF (Value : RDF.Terms.Term) return Term

Wrap an RDF term.

Parameters
Value

The RDF term

Return value

The corresponding N3 term

Invalid_Term

Invalid_Term : exception;

Raised when a selector is applied to a term of the wrong kind.

IRI_Term

function IRI_Term (Value : RDF.IRIs.IRI) return Term

Build an IRI term.

Parameters
Value

The IRI

Return value

The corresponding N3 term

Kind

function Kind (Value : Term) return Term_Kind

Report which kind this term is.

Parameters
Value

Term to inspect

Return value

The term's kind

Length

function Length (Value : Term) return Natural

Return the number of elements in a list.

Parameters
Value

Term to inspect

Return value

Element count

Raised exceptions
Invalid_Term

Value is not a list

List

function List (Items : in out Builder) return Term

Build a list from accumulated elements. The parts move into the term rather than being copied, which is why the builder is left empty rather than reusable.

Parameters
Items

Builder holding the elements, in order; emptied

Return value

The corresponding N3 term

Raised exceptions
Invalid_Term

The result would exceed Maximum_Depth

Maximum_Depth

Maximum_Depth : constant Positive := 128;

Deepest nesting of formulas and lists a term may reach.

Name

function Name (Value : Term) return String

Return a variable's name, without its question mark.

Parameters
Value

Term to inspect

Return value

The variable name

Raised exceptions
Invalid_Term

Value is not a variable

Object

function Object (Value : Statement) return Term

Return a statement's object.

Parameters
Value

Statement to inspect

Return value

The object term

Predicate

function Predicate (Value : Statement) return Term

Return a statement's predicate.

Parameters
Value

Statement to inspect

Return value

The predicate term

RDF_Value

function RDF_Value (Value : Term) return RDF.Terms.Term

Return the wrapped RDF term.

Parameters
Value

Term to inspect

Return value

The RDF term

Raised exceptions
Invalid_Term

Value is not an RDF term

Statement

type Statement (<>) is private;

An N3 statement. Unlike RDF, the predicate is a term rather than an IRI, because N3 allows a variable or a path there.

Statement_At

function Statement_At (Value : Term; Index : Positive) return Statement

Return one statement of a formula.

Parameters
Value

Term to inspect

Index

One-based statement position

Return value

The statement

Raised exceptions
Invalid_Term

Value is not a formula

Statement_Count

function Statement_Count (Value : Term) return Natural

Return the number of statements in a formula.

Parameters
Value

Term to inspect

Return value

Statement count

Raised exceptions
Invalid_Term

Value is not a formula

Subject

function Subject (Value : Statement) return Term

Return a statement's subject.

Parameters
Value

Statement to inspect

Return value

The subject term

Term

type Term (<>) is private;

An N3 term.

Term_Kind

type Term_Kind is (RDF_Kind, Variable_Kind, List_Kind, Formula_Kind);

What an N3 term can be.

Enumeration literals
RDF_Kind

An IRI, blank node, or literal -- an RDF term

Variable_Kind

A universally or existentially quantified name

List_Kind

A first-class list

Formula_Kind

A quoted graph, written in braces

Variable

function Variable (Name : String) return Term

Build a variable.

Parameters
Name

Variable name without its question mark

Return value

The corresponding N3 term

Raised exceptions
Invalid_Term

Name is empty