spr
type: Ontology
version info: 1.0.0
imports: spl
comment: A collection of SPIN functions that can be used to query, traverse and aggregate tabular data.

Aggregator
type: Class
comment: A pair of SPARQL functions that can be used to aggregate values of a SPR table. Instances of this class can be passed into the various aggregateXY functions.

Table class
type: Class
subclass of: Class
comment: Metaclass of classes that can represent tabular data. The classes that have this metaclass as their type need to specify SPARQL/SPIN functions for various look up tasks.

cell function
type: Property
sub property of: system property
range: Function
domain: Table class

system property
type: Property
comment: An "abstract" base property that groups together those system properties that the user will hardly ever need to see in property trees. This property may be dropped in future versions of this ontology - right now it's mainly here for convenience.

start value
type: Property
sub property of: system property
domain: Aggregator

result function
type: Property
sub property of: system property
range: Function
domain: Aggregator
comment: The URI of the SPIN Function that shall be called at the end of the steps.

colCount function
type: Property
sub property of: system property
range: Function
domain: Table class

colType function
type: Property
sub property of: system property
range: Function
domain: Table class

colWidth function
type: Property
sub property of: system property
range: Function
domain: Table class

rowCount function
type: Property
sub property of: system property
range: Function
domain: Table class

arg6
type: Property
sub property of: arg
comment: The sixth argument of a function call.

step function
type: Property
sub property of: system property
range: Function
domain: Aggregator
comment: The URI of the SPIN Function that shall be called at each step.

colName function
type: Property
sub property of: system property
range: Function
domain: Table class

col cells
type: MagicProperty
sub property of: system property
subclass of: Magic SPR properties
comment: Iterates over all rows of a given table (left side, ?arg1) at column ?arg2 and binds the variable on the right with the cell values. The second variable on the right may be bound to the row index as well.
constraint: Argument
  comment: The column index, starting at zero.
  value type: integer
  predicate: arg2
constraint: Argument
  comment: The spr:Table to get the values for.
  value type: Table
  predicate: arg1
body: Select
  where:
    subject: arg1
    predicate: row indices
    object:
      var name: row
  where: Bind
    variable:
      var name: value
    expression: cell
      arg3: arg2
      arg2:
        var name: row
      arg1: arg1
  result variables:
    var name: value
  result variables:
    var name: row

Magic SPR properties
type: MagicProperty
sub property of: system property
subclass of: MagicProperties
abstract: true

Table
type: Table class
comment: Base class of table classes. Must define the URIs of low-level SPARQL functions that are used by SPR to access individual table cells and table meta data.

row indices
type: MagicProperty
sub property of: system property
subclass of: Magic SPR properties
comment: Iterates over all rows of a given table (left side, ?arg1) and binds the variable on the right with the index of the rows.
constraint: Argument
  comment: The spr:Table to get the row indexes of.
  value type: Table
  predicate: arg1
body: Select
  where: Bind
    variable:
      var name: lastIndex
    expression: sub
      arg2: 1
      arg1: rowCount
        type: row count
        arg1: arg1
  where:
    subject:
      var name: index
    predicate: for
    object:
      var name: ?0
  where:
    subject:
      var name: ?0
    predicate: first
    object: 0
  where:
    subject:
      var name: ?0
    predicate: rest
    object:
      var name: ?1
  where:
    subject:
      var name: ?1
    predicate: first
    object:
      var name: lastIndex
  where:
    subject:
      var name: ?1
    predicate: rest
    object: nil
  result variables:
    var name: index

Aggregator result functions
type: Function
subclass of: SPR Functions
constraint: Argument
  comment: The total number of steps.
  predicate: arg2
constraint: Argument
  comment: The end result after stepping through the values.
  predicate: arg1
abstract: true

SPR Functions
type: Function
subclass of: Functions
comment: Base class of various SPR related functions.
abstract: true

column type
type: Function
subclass of: Column type functions
comment: Gets the (data) type of a column, if this information is present. The datatype may be derived from spin:Columns attached to the table data provider.
return type: Class
body: Select
  where:
    subject: arg1
    predicate: type
    object:
      var name: tableClass
  where:
    subject:
      var name: tableClass
    predicate: colType function
    object:
      var name: function
  where: Bind
    variable:
      var name: result
    expression: invoke
      arg3: arg2
      arg2: arg1
      arg1:
        var name: function
  result variables:
    var name: result

Column type functions
type: Function
subclass of: SPR Functions
constraint: Argument
  comment: The column index, starting at zero.
  value type: integer
  predicate: arg2
constraint: Argument
  comment: The table to get the column name for.
  value type: Table
  predicate: arg1
abstract: true

Avg
type: Aggregator
step function: add
start value: 0
result function: divide

aggregate row
type: Function
subclass of: Aggregator functions
comment: Applies the spr:Aggregator ?arg1 to all columns of row ?arg3 of spr:Table ?arg2.
constraint: Argument
  comment: The row index.
  value type: integer
  predicate: arg3
body: Select
  where:
    subject: arg1
    predicate: step function
    object:
      var name: stepFunction
  where:
    subject: arg1
    predicate: start value
    object:
      var name: startValue
  where: Optional
    elements:
      subject: arg1
      predicate: result function
      object:
        var name: resultFunction
  where: Bind
    variable:
      var name: colCount
    expression: colCount
      type: column count
      arg1: arg2
  where: Bind
    variable:
      var name: stepped
    expression: visitRow
      type: visit row
      arg6:
        var name: startValue
      arg5:
        var name: stepFunction
      arg4: sub
        arg2: 1
      arg3: 0
      arg2: arg3
      arg1: arg2
  where: Bind
    variable:
      var name: result
    expression: if
      arg3:
        var name: stepped
      arg2: invoke
      arg1: bound
  result variables:
    var name: result

Aggregator functions
type: Function
subclass of: SPR Functions
constraint: Argument
  comment: The spr:Table to iterate over.
  value type: Table
  predicate: arg2
constraint: Argument
  comment: The aggregator to perform.
  value type: Aggregator
  predicate: arg1
abstract: true

column width
type: Function
subclass of: Column width functions
comment: Gets the width (in pixels) of a given column. This may have been derived from spin:Columns attached to the table data provider.
return type: integer
body: Select
  where:
    subject: arg1
    predicate: type
    object:
      var name: tableClass
  where:
    subject:
      var name: tableClass
    predicate: colWidth function
    object:
      var name: function
  where: Bind
    variable:
      var name: result
    expression: invoke
      arg3: arg2
      arg2: arg1
      arg1:
        var name: function
  result variables:
    var name: result

Column width functions
type: Function
subclass of: SPR Functions
constraint: Argument
  comment: The column index, starting at zero.
  value type: integer
  predicate: arg2
constraint: Argument
  comment: The table to get the column name for.
  value type: Table
  predicate: arg1
abstract: true

Sum
type: Aggregator
step function: add
start value: 0

is empty
type: Function
subclass of: Row count functions
comment: Checks whether a given SPR table has zero rows.
return type: boolean
body: Ask
  where: Filter
    expression: eq
      arg2: 0
      arg1: rowCount
        type: row count
        arg1: arg1

Row count functions
type: Function
subclass of: SPR Functions
constraint: Argument
  comment: The spr:Table to get the number of rows for.
  value type: Table
  predicate: arg1
abstract: true

hasCell
type: Function
subclass of: Cell functions
comment: Checks if there is a cell value in a given Table (?arg1) at a given row (?arg2) and column (?arg3).
return type: boolean
constraint: Argument
  comment: The column index, starting at 0.
  value type: integer
  predicate: arg3
constraint: Argument
  comment: The row index, starting at 0.
  value type: integer
  predicate: arg2
constraint: Argument
  comment: The spr:Table to get the cell value of.
  value type: Table
  predicate: arg1
body: Ask
  where:
    subject: arg1
    predicate: type
    object:
      var name: tableClass
  where:
    subject:
      var name: tableClass
    predicate: cell function
    object:
      var name: function
  where: Bind
    variable:
      var name: result
    expression: invoke
      arg4: arg3
      arg3: arg2
      arg2: arg1
      arg1:
        var name: function
  where: Filter
    expression: bound
      arg1:
        var name: result

Cell functions
type: Function
subclass of: SPR Functions
abstract: true

aggregate row
type: Function
subclass of: Aggregator functions
comment: Applies the spr:Aggregator ?arg1 to all rows of column ?arg3 of spr:Table ?arg2.
constraint: Argument
  comment: The column index.
  value type: integer
  predicate: arg3
body: Select
  where:
    subject: arg1
    predicate: step function
    object:
      var name: stepFunction
  where:
    subject: arg1
    predicate: start value
    object:
      var name: startValue
  where: Optional
    elements:
      subject: arg1
      predicate: result function
      object:
        var name: resultFunction
  where: Bind
    variable:
      var name: rowCount
    expression: rowCount
      type: row count
      arg1: arg2
  where: Bind
    variable:
      var name: stepped
    expression: visitCol
      type: visit row
      arg6:
        var name: startValue
      arg5:
        var name: stepFunction
      arg4: sub
        arg2: 1
      arg3: 0
      arg2: arg3
      arg1: arg2
  where: Bind
    variable:
      var name: result
    expression: if
      arg3:
        var name: stepped
      arg2: invoke
      arg1: bound
  result variables:
    var name: result

column name
type: Function
subclass of: Column name functions
comment: Gets the name of a column in a given result set. The name is usually derived from the variable name, but may also originate from spin:Columns attached to the table data provider.
return type: string
body: Select
  where:
    subject: arg1
    predicate: type
    object:
      var name: tableClass
  where:
    subject:
      var name: tableClass
    predicate: colName function
    object:
      var name: function
  where: Bind
    variable:
      var name: result
    expression: invoke
      arg3: arg2
      arg2: arg1
      arg1:
        var name: function
  result variables:
    var name: result

Column name functions
type: Function
subclass of: SPR Functions
constraint: Argument
  comment: The column index, starting at zero.
  value type: integer
  predicate: arg2
constraint: Argument
  comment: The table to get the column name for.
  value type: Table
  predicate: arg1
abstract: true

Aggregator step functions
type: Function
subclass of: SPR Functions
constraint: Argument
  comment: The current cell value that shall be aggregated on top of ?arg1.
  predicate: arg2
constraint: Argument
  comment: The old value to start with, e.g. 0 for SUM.
  predicate: arg1
abstract: true

row cells
type: MagicProperty
sub property of: system property
subclass of: Magic SPR properties
comment: Iterates over all colums of a given table (left side, ?arg1) at row ?arg2 and binds the variable on the right with the cell values. The second variable on the right may be bound to the column index as well.
constraint: Argument
  comment: The row index, starting at zero.
  value type: integer
  predicate: arg2
constraint: Argument
  comment: The spr:Table to get the values for.
  value type: Table
  predicate: arg1
body: Select
  where:
    subject: arg1
    predicate: row indices
    object:
      var name: col
  where: Bind
    variable:
      var name: value
    expression: cell
      arg3:
        var name: col
      arg2: arg2
      arg1: arg1
  result variables:
    var name: value
  result variables:
    var name: col

row indices
type: MagicProperty
sub property of: system property
subclass of: Magic SPR properties
comment: Iterates over all columns of a given table (left side, ?arg1) and binds the variable on the right with the index of the columns.
constraint: Argument
  comment: The spr:Table to get the row indexes of.
  value type: Table
  predicate: arg1
body: Select
  where: Bind
    variable:
      var name: lastIndex
    expression: sub
      arg2: 1
      arg1: colCount
        type: column count
        arg1: arg1
  where:
    subject:
      var name: index
    predicate: for
    object:
      var name: ?0
  where:
    subject:
      var name: ?0
    predicate: first
    object: 0
  where:
    subject:
      var name: ?0
    predicate: rest
    object:
      var name: ?1
  where:
    subject:
      var name: ?1
    predicate: first
    object:
      var name: lastIndex
  where:
    subject:
      var name: ?1
    predicate: rest
    object: nil
  result variables:
    var name: index

Product
type: Aggregator
step function: mul
start value: 1

visit row
type: Function
constraint: Argument
  comment: The current aggregate value.
  predicate: arg6
constraint: Argument
  comment: The step function.
  value type: Function
  predicate: arg5
subclass of: SPR Functions
constraint: Argument
  comment: The max number of steps to make.
  value type: integer
  predicate: arg4
comment: Visits a given column ?arg2 of Table ?arg1 with a given spr:AggregatorStepFunction (?arg5) and then calls itself recursively until the last value index (?arg4) has been reached. ?arg6 is the result of the previous step.
constraint: Argument
  comment: The current step index.
  value type: integer
  predicate: arg3
constraint: Argument
  comment: The row to iterate over.
  value type: integer
  predicate: arg2
body: Select
  where: Bind
    variable:
      var name: value
    expression: cell
      arg3: arg2
      arg2: arg3
      arg1: arg1
  where: Bind
    variable:
      var name: next
    expression: if
      arg3:
        var name: arg6
      arg2: invoke
        arg1: arg5
      arg1: bound
  where: Bind
    variable:
      var name: result
    expression: if
      arg3:
        var name: next
      arg2: visitCol
        type: visit row
        arg5: arg5
        arg4: arg4
        arg3: add
        arg2: arg2
        arg1: arg1
      arg1: lt
        arg2: arg4
        arg1: arg3
  result variables:
    var name: result
constraint: Argument
  comment: The spr:Table to iterate over.
  value type: Table
  predicate: arg1

visit row
type: Function
constraint: Argument
  comment: The max number of steps to make.
  value type: integer
  predicate: arg4
subclass of: SPR Functions
constraint: Argument
  comment: The current aggregate value.
  predicate: arg6
constraint: Argument
  comment: The row to iterate over.
  value type: integer
  predicate: arg2
body: Select
  where: Bind
    variable:
      var name: value
    expression: cell
      arg3: arg3
      arg2: arg2
      arg1: arg1
  where: Bind
    variable:
      var name: next
    expression: if
      arg3:
        var name: arg6
      arg2: invoke
        arg1: arg5
      arg1: bound
  where: Bind
    variable:
      var name: result
    expression: if
      arg3:
        var name: next
      arg2: visitRow
        type: visit row
        arg5: arg5
        arg4: arg4
        arg3: add
        arg2: arg2
        arg1: arg1
      arg1: lt
        arg2: arg4
        arg1: add
  result variables:
    var name: result
comment: Visits a given row ?arg2 of Table ?arg1 with a given spr:AggregatorStepFunction (?arg5) and then calls itself recursively until the last value index (?arg4) has been reached. ?arg6 is the result of the previous step.
constraint: Argument
  comment: The current step index.
  value type: integer
  predicate: arg3
constraint: Argument
  comment: The step function.
  value type: Function
  predicate: arg5
constraint: Argument
  comment: The spr:Table to iterate over.
  value type: Table
  predicate: arg1

row count
type: Function
subclass of: Row count functions
comment: Gets the number of rows in a given table.
return type: integer
body: Select
  where:
    subject: arg1
    predicate: type
    object:
      var name: tableClass
  where:
    subject:
      var name: tableClass
    predicate: rowCount function
    object:
      var name: function
  where: Bind
    variable:
      var name: result
    expression: invoke
      arg2: arg1
      arg1:
        var name: function
  result variables:
    var name: result

Column count functions
type: Function
subclass of: SPR Functions
constraint: Argument
  comment: The table to get the number of columns of.
  value type: Table class
  predicate: arg1
abstract: true

column count
type: Function
subclass of: Column count functions
comment: Gets the number of columns of a given result set.
return type: integer
body: Select
  where:
    subject: arg1
    predicate: type
    object:
      var name: tableClass
  where:
    subject:
      var name: tableClass
    predicate: colCount function
    object:
      var name: function
  where: Bind
    variable:
      var name: result
    expression: invoke
      arg2: arg1
      arg1:
        var name: function
  result variables:
    var name: result

cell
type: Function
subclass of: Cell functions
comment: Gets the cell value of a given Table (?arg1) at a given row (?arg2) and column (?arg3).
constraint: Argument
  comment: The column index, starting at 0.
  value type: integer
  predicate: arg3
constraint: Argument
  comment: The row index, starting at 0.
  value type: integer
  predicate: arg2
constraint: Argument
  comment: The spr:Table to get the cell value of.
  value type: Table
  predicate: arg1
body: Select
  where:
    subject: arg1
    predicate: type
    object:
      var name: tableClass
  where:
    subject:
      var name: tableClass
    predicate: cell function
    object:
      var name: function
  where: Bind
    variable:
      var name: result
    expression: invoke
      arg4: arg3
      arg3: arg2
      arg2: arg1
      arg1:
        var name: function
  result variables:
    var name: result

var name: colCount

var name: colCount

var name: stepped

var name: resultFunction

var name: resultFunction

var name: rowCount

var name: rowCount

var name: stepped

var name: resultFunction

var name: resultFunction

var name: value

var name: arg6

var name: value

var name: next

add
arg2: 1
arg1: arg3

var name: value

var name: arg6

var name: value

var name: next

add
arg2: 1
arg1: arg3

add
arg2: 1
arg1: arg3